akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using  ll = long long;
using ull = unsigned long long;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
constexpr ll kINF = 1152921504606846976;//2^60
constexpr double kEPS = 1e-6;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define rep(i,n) REP(i,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep(i,n) RREP(i,n)
#define mp make_pair
#define fi first
#define sc second

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

// --!!!!ここからコピペする!!!!--

template<typename T> struct Edge {
  int to;
  Edge(int to_) : to(to_) {}
};

template<typename T,template <typename ELEM> class EDGE> struct AdListGraph {
  vector<vector<EDGE<T>>> G;
  vector<bool> used;
  vector<bool> is_ancetor;
  int V;//0,...,|V|-1

  AdListGraph (int V_) {
    Init(V_);
  }

  void Init(int V_) {
    V = V_;

    G.clear();
    G.resize(V);
  }

  // https://faithandbrave.hateblo.jp/entry/20080310/1205149207
  template <typename FROM, class... Args>
  void AddEdge(FROM from, Args&&... arg) {
    G[from].emplace_back(arg...);
  }

  bool DFSForTopologicalSort (int i, vector<int>& sorted) {
    if (is_ancetor[i]) return false;
    if (used[i]) return true;

    used[i] = true;
    is_ancetor[i] = true;

    for(const auto& v : G[i]) {
      if(!DFSForTopologicalSort(v.to, sorted)) return false;
    }

    is_ancetor[i] = false;
    sorted.emplace_back(i);//dfsの帰りがけの順

    return true;
  }

  template<typename ID_TYPE>
  bool TopologicalSort (vector<ID_TYPE>& sorted) { // 成功ならtrue 失敗(DAG出ない)ならfalseを返す
    used.clear();
    used.resize(V,false);
    is_ancetor.clear();
    is_ancetor.resize(V, false);

    sorted.clear();

    rep (i,V) {
      if(!DFSForTopologicalSort(i, sorted)) {
        return false;
      }
    }

    reverse(sorted.begin(),sorted.end());

    return true;
  }

};

using ll = long long;

int dp[100010];

int main() {
  ll V,E;
  cin >> V >> E;
  AdListGraph<ll, Edge> G(V);
  AdListGraph<ll, Edge> rG(V);
  rep(i,E) {
    ll s,t;
    cin >> s >> t;
    s--;t--;
    G.AddEdge(s, t);
    rG.AddEdge(t, s);
  }

  vector<int> sorted;

  G.TopologicalSort(sorted);

  for (auto v : sorted) {
     for (auto u : rG.G[v]) {
       chmax(dp[v],dp[u.to] + 1);
     }
  }

  int ans = 0;

  rep(i,V) {
    chmax(ans, dp[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13176
#include <bits/stdc++.h>
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef pair<int, int> P;
const int maxn = 200005;
typedef long long ll;
int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, y;
    cin >> x >> y;
    if(x == y || x%y == 0)puts("-1");
    else{
        cout << x << endl;
    }
}

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

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

    y /= 1000;

    // 10000 yen
    for (size_t i = 0; i < n + 1; i++)
    {
        int remaining = n - i;

        for (size_t j = 0; j < remaining + 1; j++)
        {
            int total = i * 10 + j * 5 + (n - i - j);
            if (total == y)
            {
                cout << i << " " << j << " " << (n - i - j) << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


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

int A[55],B[55];
bool graph[55][55];

bool visited[55];

void dfs(int v){
    visited[v]=true;
    for (int i=0; i<n;i++){
    if(graph[v][i]==false) continue;
    if(visited[i]==true) continue;
    dfs(i);
    }
}

int main(){
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int a,b;
        cin>>a>>b;
        A[i]=a;
        B[i]=b;
        graph[a-1][b-1]=true;
        graph[b-1][a-1]=true;
    }
    int counter=0;
    for(int i=0; i<m; i++){
        graph[A[i]-1][B[i]-1]=false;
        graph[B[i]-1][A[i]-1]=false;
        for(int j=0; j<n; j++) visited[j]=false;
        dfs(0);
        bool t=false;
        for(int j=0; j<n; j++){
            if (visited[j]==false){t=true;}
        }
           graph[A[i]-1][B[i]-1]=true;
        graph[B[i]-1][A[i]-1]=true;
        if(t) counter++;
        
    }
    cout<<counter<<endl;
    }


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

int main()
{
	int n;
	cin >> n;
	vector<int> X(n,0);
	for (int i=0; i<n; i++)
	{
		int x;
		cin >> x;
		X.at(i) = x;
	}
	sort(X.begin(), X.end());

	int minimum= 900000000;
	for (int i=X.front(); i<=X.back(); i++)
	{
		int sum=0;
		for (int x:X)
		{
			sum += pow(x-i,2);
		}
		minimum = min(minimum, sum);
	}

	cout << minimum << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        String S = st.nextToken();
        String[] strArray = S.split("");

        int result = 0;
        boolean breakFlag = false;

        for(String str : strArray) {
            if ("R".equals(str)) {
                result++;
                breakFlag = true;
            } else if(breakFlag) {
                break;
            }
        }

        pw.println(result);
        br.close();
        pw.close();
    }
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N; cin >> N;
    int H[N]; rep(i, N) cin >> H[i];
    int dp[N]; dp[0] = 0; dp[1] = abs(H[1] - H[0]);
    for(int i = 2; i < N; i++){
        dp[i] = min(dp[i-1] + abs(H[i] - H[i-1]), dp[i-2] + abs(H[i] - H[i-2]));
    }
    cout << dp[N-1] << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 1024
null = -1

class Node:
    def __init__(self):
        self.parent = null
        self.left = null
        self.right = null
        self.id = null
        self.depth = null
        self.height = null
        self.sibling = null
        self.type = null
        self.degree = 0
        
    
def setDepth(u, d):
    if u == null:
        return  
    Tree[u].depth = d
    setDepth(Tree[u].left, d + 1)
    setDepth(Tree[u].right, d + 1)
    
def setHeight(u):
    h1 = 0
    h2 = 0
    if Tree[u].left != null:
        h1 = setHeight(Tree[u].left) + 1
    if Tree[u].right != null:
        h2 = setHeight(Tree[u].right) + 1
    Tree[u].height = max(h1, h2)
    return Tree[u].height

def setType():
    global root
    for i in range(n):
        if Tree[i].parent == null:
            Tree[i].type = "root"
            root = i
        elif Tree[i].left == null and Tree[i].right == null:
            Tree[i].type = "leaf"
        else:
            Tree[i].type = "internal node"
            
def getSibling(i):
    if Tree[i].parent == null:
        return null
    elif Tree[Tree[i].parent].left != i and Tree[Tree[i].parent].left != null:
        return Tree[Tree[i].parent].left
    elif Tree[Tree[i].parent].right != i and Tree[Tree[i].parent].right != null:
        return Tree[Tree[i].parent].right
    return null
        
Tree = []
root = 0

n = int(input())
for i in range(n):
    Tree.append(Node())
    
for i in range(n):
    tmp = list(map(int, input().split()))
    
    Tree[tmp[0]].id = tmp[0]
    
    if tmp[1] != -1:
        Tree[tmp[0]].left = tmp[1]
        Tree[tmp[1]].parent = tmp[0]
        Tree[tmp[0]].degree += 1
    if tmp[2] != -1:
        Tree[tmp[0]].right = tmp[2]
        Tree[tmp[2]].parent = tmp[0]
        Tree[tmp[0]].degree += 1

setType()
setDepth(root, 0)
setHeight(root)

for i in range(n):
    #print(Tree[i].depth, Tree[i].height)
    print("node", Tree[i].id, end = "")
    print(": parent =", Tree[i].parent, end = "")
    print(", sibling =",getSibling(i), end = "")
    print(", degree =",Tree[i].degree, end = "")
    print(", depth =",Tree[i].depth, end = "")
    print(", height =",Tree[i].height, end = "")
    print(",", Tree[i].type)
    













Measured memory_bytes: 5648
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } } _io;
typedef long long ll; typedef long double db;

int exgcd(int a, int b, int& x, int& y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y);
    int t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
}
int getInv(int a, int mod)
{
    int x, y;
    return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

ll mod = 1e9 + 7;

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    ll t = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
        a[i] %= mod;
        t = ((t % mod) + a[i]) % mod;
    }
    t = (t * t) % mod;
    for (int i = 0; i < N; ++i)
    {
        t = ((t % mod) - (a[i] * a[i]) % mod + mod) % mod;
    }
    t = ((t % mod) * getInv(2, mod)) % mod;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 4712
n = int(input())

ans = n+1
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        if(ans > i + int(n/i)):
            ans = i + int(n/i)
        if i != n // i:
            if(ans > n//i + int(n/(n//i))):
                ans = n // i + int(n / (n // i))
print(ans-2)


Measured memory_bytes: 3060
def sum_of(n):
    return n * (n - 1) // 2

N, K = map(int, input().split())
mod = 10**9 + 7
ans = 0

for i in range(K, N + 2):
    mini = sum_of(i)
    maxi = sum_of(N + 1) - sum_of(N - i + 1)
    ans += (maxi - mini + 1)

print(ans % mod)

Measured memory_bytes: 65188
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.
	
	input = input.split("\n").map((s)=>s.trim());
	var n = parseInt(input[0]);

	var dic = {};
	for (var i = 1; i <= n; i++) {

		if(dic[input[i]]!=undefined){
			console.log('No');
			return;
		}else{
			dic[input[i]] = true;
			if(i>1){
				if(input[i][0]!=input[i-1][input[i-1].length-1]){
					console.log('No');
					return;
				}
			}
		}
	}
	console.log('Yes');
}
// Don't edit this line!
//Main(require("fs").readFileSync(__dirname+'/in.txt', "utf8"));
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x <<endl; 
#define De(...)
using namespace std; 

int _; 

int k;

int main()
{
	scanf("%d",&k);
	int ans=k*360/__gcd(k,360);
	printf("%d\n",ans/k);
	return 0;
}

Measured memory_bytes: 3756
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    k = int(input())
    if k >= len(s):
        for i in range(len(s)):
            if s[i] != "1":
                print(s[i])
                break
        else:
            print(1)
    else:
        for i in range(k):
            if s[i] != "1":
                print(s[i])
                break
        else:
            print(1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
import java.util.*;

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

        List<String> list = new ArrayList<>();

        for (int i=0; i < line.length(); i++) {
            char ch = line.charAt(i);

            if (ch == 'B') {
                if (list.size() != 0) list.remove(list.size() - 1);
            } else {
                list.add(String.valueOf(ch));
            }
        }

        System.out.println(String.join("", list));
    }
}

Measured memory_bytes: 22868
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#define INF 1e16
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
 
 
 
int main(void){
    int n;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    if(a[0]==0)cout<<0<<endl;
    else{
        ll ans = 1;
        for(int i=0;i<n;i++){
            if(ans*a[i]>1000000000000000000){
                cout<<-1<<endl;
                return 0;
            }
            if(ans*a[i]<=0){
                cout<<-1<<endl;
                return 0;
            }
            ans*=a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
using namespace std;
typedef long long ll;
ll fac[100001];
ll mod = 1e9 + 7;
ll fact(ll n) {
    if (n == 0 || n == 1) return fac[n] = 1;
    if (fac[n] != 0) return fac[n];
    return fac[n] = (fact(n-1) * n) % mod;
}
int main() {
    int N;
    cin >> N;
    cout << fact(N) << endl;
}

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

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

  int total = 0;
  for (int i = 0; i < N; i++) {
      int L;
      int R;
      cin >> L >> R;

      total += R - L + 1;
  }

    cout << total << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll INF = 1LL << 60;

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

    vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(2, vector<ll>(2, -INF)));

    ll ans = 0;

    if(N % 2 == 0) {
        dp[0][0][0] = 0;
        for(int i = 0; i < N; i++) {
            if(i % 2 == 0) {
                dp[i + 1][0][0] = max(dp[i][0][0], dp[i][0][1]);
                dp[i + 1][0][1] = -INF;
                dp[i + 1][1][0] = -INF;
                dp[i + 1][1][1] = dp[i][0][0] + a[i];
            }
            else {
                dp[i + 1][0][0] = max(dp[i][1][0], dp[i][1][1]);
                dp[i + 1][0][1] = dp[i][0][0] + a[i];
                dp[i + 1][1][0] = -INF;
                dp[i + 1][1][1] = -INF;
            }
        }

        ans = max(dp[N][0][0], dp[N][0][1]);
    }

    else {
        dp[0][1][0] = 0;
        for(int i = 0; i < N; i++) {
            if(i % 2 == 0) {
                dp[i + 1][0][0] = max(dp[i][1][0], dp[i][1][1]);
                dp[i + 1][0][1] = dp[i][0][0] + a[i];
                dp[i + 1][1][0] = -INF;
                dp[i + 1][1][1] = dp[i][1][0] + a[i];
            }
            else {
                dp[i + 1][0][0] = max(dp[i][0][0], dp[i][0][1]);
                dp[i + 1][0][1] = -INF;
                dp[i + 1][1][0] = max(dp[i][1][0], dp[i][1][1]);
                dp[i + 1][1][1] = dp[i][0][0] + a[i];
            }
        }

        ans = max(dp[N][0][0], dp[N][0][1]);
    }

    /*
    for(int i = 0; i <= N; i++) {
        cout << setw(15) << dp[i][0][0] << " " << dp[i][0][1] << " " << dp[i][1][0] << " " << dp[i][1][1] << endl;
    }
    */

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

Measured memory_bytes: 34376
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace algorithm
{
	class Program
	{
		public static void Main()
		{
			long[] nm = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
			long n = nm[0], m = nm[1]/2;
			
			long tmp = m-n;
			//M<N
			if (tmp < 0)
			{
				Console.WriteLine(m);
			}
			//N
			else if (tmp < 2)
			{
				Console.WriteLine(n);
			}
			//M>N
			else if (tmp > 1)
			{
				Console.WriteLine(n + tmp/2);
			}
			



		}
	}
}




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

int main(){
  int n,h,s;
  double a,b,ans;
  cin>>n;
  while(n--){
    scanf("%d:%d",&h,&s);
    b=s*6;
    a=h*30+30*b/360;
    ans=abs(a-b);
    if(ans>180)ans=360-ans;
    if(0<=ans&&ans<30)cout<<"alert"<<endl;
    else if(90<=ans&&ans<=180)cout<<"safe"<<endl;
    else cout<<"warning"<<endl;
  }
  return 0;
}

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

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back

struct Location {
  int name, want;
  Location(int i):name(i),want(0){}
  bool operator>(const Location& a) const {
    if (want == a.want) return name < a.name;
    return want > a.want;
  }
  bool operator<(const Location& a) const {
    if (want == a.want) return name > a.name;
    return want < a.want;
  }
};

int n, m;

void solve() {
  vector<Location> v;
  rep(i,m) v.pb(Location(i));
  
  rep(i,n) rep(j,m) {
    int t; cin>>t;
    if (t) v[j].want++;
  }
  
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  cout<<v[0].name+1;
  REP(i,1,v.size()) cout<<" "<<v[i].name+1;
  cout<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n>>m, n||m) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using vi = vector<int>;
using pi = pair<int, int>;
using ll = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

const int mxn = 1e4+10;
const int Mod = 1e9+7;

void solve()
{
    int n, k;
    cin>>n>>k;
    long long Ans = 0;
    long long x = 0, y = 0, p=0, q=n;
    for(int i=1 ; i<=k ; i++){
        x+=p, y+=q;
        p++, q--;
    }
    long long ss1 = x, ss2=y;
    while(ss1 <= ss2){
        Ans+=(ss2-ss1+1+Mod)%Mod;
        Ans%=Mod;
        ss1+=p, ss2+=q;
        p++, q--;
    }
    cout<<Ans<<endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int tc = 1;
    //cin>>tc;
    while(tc--) solve();

    return 0;
}


Measured memory_bytes: 3656
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);

  std::string X, Y;
  
  std::cin >> X >> Y;

  std::cout << (X[0] < Y[0] ? '<' : X[0] == Y[0] ? '=' : '>') << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;

	ll int tc=1;
	//cin>>tc;
	while(tc--)
	{
		ll int n,x;
		cin>>n>>x;
		
		if(500*n>=x)
		cout<<"Yes";else
		cout<<"No";
		

	}
}




Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, P; cin >> N >> P;
  int a;
  map<int,int> cnt; 
  rep(i,N) {
    cin >> a;
    cnt[a%2]++;
  }
  ll retval;
  
  if (cnt[1]==0 && P==1) retval = 0;
  else if (cnt[1]==0 && P==0) retval = (1ll<<cnt[0]);
  else retval = (1ll<<(cnt[0]+cnt[1]-1));
  
  cout << retval << endl;




  // cout << fixed << setprecision(10);
  
  return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n,k;
	cin>>n>>k;
	vi d(k),c;
	rep(i,k){
		cin>>d[i];
	}
	for(int i=n;i<=100000;++i){
		int x=i;
		bool b=true;
		while(x>0){
			rep(i,k){
				if(x%10==d[i]){
					b=false;
				}
			}
			if(!b)break;
			x/=10;
		}
		if(b){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

// use std::collections::BTreeMap;

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let a: u32 = iter.read();
	let b: u32 = iter.read();
	let c: u32 = iter.read();

	let s: u32 = a + b + c;
	let m: u32 = vec![a, b, c].into_iter().max().unwrap();

	println!("{}", s - m);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=998244353;

int p[MX];

int main()
{

    FasterIO;

    int n, x;

    cin>>n;

    for(int i=1; i<=n; p[x]=i, i++) cin>>x;

    int mx=0, cnt=0, px=0;

    for(int i=1; i<=n; i++)
    {
        if(p[i]>px) cnt++, px=p[i];
        else
        {
            mx=max(mx, cnt); cnt=1, px=p[i];
        }
    }
    mx=max(mx, cnt);

    cout<<n-mx<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>

 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long

ll int N,M;
ll int B[100004],C[100004];
vector<pair<ll int,ll int>> BC;
ll int A[100004];
int main(void){
    scanf("%lld %lld",&N,&M);
    ll int ans=0;
    rep(i,N){
        scanf("%lld",&A[i]);
        ans+=A[i];
    }
    sort(A,A+N);
    rep(i,M){
        scanf("%lld %lld",&B[i],&C[i]);
        BC.pb(mp(C[i],B[i]));
    }
    sort(BC.begin(),BC.end());
    int BCsize=BC.size();
    int Anext=0;
    rep(i,BCsize){
        int j=BCsize-1-i;
        pair<ll int,ll int> p=BC[j];
        ll int Bj=p.second;ll int Cj=p.first;
       
        while(Bj>0){
            if(Anext>=N)break;
            if(Cj>A[Anext]){
                Bj--;
                ans+=Cj-A[Anext];
            }
            Anext++;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4212
import java.util.Scanner;

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

		int N = sc.nextInt();
		int[] ary = new int[N];

		for (int i = 0; i < N; i++)
		{
			ary[i] = sc.nextInt();
		}

		int numSwap = 0;

		for (int i = 0; i < N; i++)
		{
			int minj = i;
			for (int j = i; j < N; j++)
			{
				if (ary[j] < ary[minj])
				{
					minj = j;
				}
			}

			if (i != minj)
			{
				numSwap++;
				int temp = ary[i];
				ary[i] = ary[minj];
				ary[minj] = temp;
			}
		}


		for (int i = 0; i < N; i++)
		{
			System.out.print(ary[i]);
			if (i < N - 1)
			{
				System.out.print(" ");
			}
		}
		System.out.println("");
		System.out.println(numSwap);
	}
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int N, M;

int main() {
	cin >> N;
	string U[N];
	rep(i, N) cin >> U[i];
	bool lock = false;
	cin >> M;
	rep(i, M) {
		string T; cin >> T;
		rep(j, N) {
			if (T == U[j]) {
				if (lock) {
					cout << "Closed by " << T << endl;
					lock = false;
					break;
				} else {
					cout << "Opened by " << T << endl;
					lock = true;
					break;
				}
			} else if (j == N - 1) {
				cout << "Unknown " << T << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<stdbool.h>
#define e 1000000007
#define PI 3.141592653589793

typedef  long long ll;

int int_cmp(const void *a, const void *b){ 
    const int *ia = (const int *)a;
    const int *ib = (const int *)b;
    return *ia  - *ib; 
} 


ll int_cmp1(const void *a, const void *b){ 
    const int *ia = (const int *)a;
    const int *ib = (const int *)b;
    return *ia  - *ib; 
} 



ll max(ll a,ll b){
	if(a<b)
		a=b;
	return a;	
}

ll min(ll a,ll b){
	if(a>b)
		a=b;
	return a;	
}

int absolu(int n){
	if(n<0)
		n*=-1;
	
	return n;	
}


void solve(){ 
	char t[1001];
	int i;
	scanf("%s",&t);
	int l=strlen(t);
	if(t[l-1]!='s')
		printf("%ss\n",t);
	else
		printf("%ses\n",t);		
}

int main(){
 /* int t;
	scanf("%d",&t);
	
	while(t--)*/
		solve();
	
	return 0;
}	
	

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

int main(void) {
    int n;
    int a, b;

    scanf("%d", &n);

    if ( n == 1 ) {
        printf("Hello World\n");
    } else {
        scanf("%d", &a);
        scanf("%d", &b);
        printf("%d\n", a+b);

    }
    return 0;
}


Measured memory_bytes: 256
function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const n =  Number(stdin.shift());
    const T = [];
    for (let i = 0, l = stdin.length; i < l; i++) {
        T[i] = {parent: null, left: null, right: null};
    }

    for (const item of stdin) {
        const it = item.split(' ').map(Number);
        if (it.length > 2) {
            const children = it.slice(2);
            T[it[0]].left = children[0];
            for (let i = 0, l = children.length; i < l; i++) {
                T[children[i]].parent = it[0];
                if (children[i + 1] !== undefined) {
                    T[children[i]].right = children[i + 1];
                }
            }
        }
    }

    for (let i = 0, l = T.length; i < l; i++) {
        let type = T[i].parent === null ? 'root' : T[i].left === null ? 'leaf' : 'internal node';
        let children = T[i].left !== null ? getChildren(T[i].left, T) : '';
        let depth = getDepth(i, T);
        console.log(`node ${i}: parent = ${T[i].parent === null ? -1 : T[i].parent}, depth = ${depth}, ${type}, [${children}]`);
    }
}

function getDepth(id, T) {
    let depth = 0;
    while(T[id].parent !== null){
        id = T[id].parent;
        depth++;
    }
    return depth;
}

function getChildren(id, T){
    let children = `${id}`;
    while (T[id].right !== null) {
        children += `, ${T[id].right}`;
        id = T[id].right;
    }
    return children;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

int main()
{
  vector<int> fibs(20,0);
  fibs[1]=1;
  fibs[2]=1;
  int i,j;
  for(i=3;i<=10;i++)fibs[i]=fibs[i-1]+fibs[i-2];
  int h,w,k;cin>>h>>w>>k;
  vector<vector<ll>> dp(h+1,vector<ll>(w,0));
  dp[0][0]=1;
  for(i=1;i<=h;i++)
  {
    rep(j,w)
    {
      int left=j;
      int right=w-j-1;
      if(j!=0)dp[i][j]+=dp[i-1][j-1]*(fibs[left-1+1]*fibs[right+1]);
      if(j!=w-1)dp[i][j]+=dp[i-1][j+1]*(fibs[right-1+1]*fibs[left+1]);
      dp[i][j]+=dp[i-1][j]*(fibs[left+1]*fibs[right+1]);
      dp[i][j]%=MOD;
    }
  }
  cout<<dp[h][k-1]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n + 1){
    if(i % 3 != 0 && i % 5 != 0){
      ans = ans + i;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 3592
#include  <iostream>
#include <algorithm>

using namespace std;

int main () {
	int n;

	cin >> n;

	int henA, henB, henC;
	for (int i = 0; i < n; i++) {
		cin >> henA >> henB >> henC;

		if(henA > henC ) {			
			swap(henA, henC);
		}

		if(henB > henC ){
			swap(henB, henC);
	}

		if (henA * henA + henB * henB == henC * henC)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize ("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long; using uint = unsigned int; using uInt = unsigned long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 998244353;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rer(i,l,r) for(int i=(l); i<=(r); ++i)
#define gnr(i,l,r) for(int i=(r); i>=(l); --i)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
#define fil(a,v) memset((a),v,sizeof(a))
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;

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

  cin>>n>>m; int a[n]; rep(i,n)cin>>a[i]; sort(a,a+n);
  bool dp[100001]; dp[0]=0;
  rer(i,1,m){
    ok=0;
    rep(j,n){
      if(a[j]>i)break;
      else if(!dp[i-a[j]]){ok=1; break;}
    }
    dp[i]=ok;
  }
  priend(dp[m]?"First":"Second");
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline

def solve():
    maxV = 12800

    H, W = map(int, input().split())
    Ass = [tuple(map(int, input().split())) for _ in range(H)]
    Bss = [tuple(map(int, input().split())) for _ in range(H)]

    dp = [[0]*(W) for _ in range(H)]
    diff = abs(Ass[0][0] - Bss[0][0])
    dp0 = 1<<maxV
    dp[0][0] = (dp0<<diff) | (dp0>>diff)
    for i in range(H):
        for j in range(W):
            diff = abs(Ass[i][j] - Bss[i][j])
            if i > 0:
                dp0 = dp[i-1][j]
                dp[i][j] |= (dp0<<diff) | (dp0>>diff)
            if j > 0:
                dp0 = dp[i][j-1]
                dp[i][j] |= (dp0<<diff) | (dp0>>diff)

    ans = maxV
    dpHW = dp[-1][-1]
    for i in range(2*maxV+1):
        if (dpHW>>i) & 1:
            j = abs(i-maxV)
            if j < ans:
                ans = j

    print(ans)


solve()


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n >> j;
    long long ans = 0;
    if(n < 10) ans = j+100*(10-n);
    else ans = j;
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
string s;
int cnt[N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> s;
 	for(int i=0; i<sz(s);)
 	{
 		int j = i;
 		while(s[j]=='R') j++;
 		int x = j - i;
 		i = j;
 		while(s[j]=='L') j++;
 		int y = j - i;
 		if(x > y and (x-y)&1)
 		{
 			if(y&1) cnt[i]++;
 			else cnt[i-1]++;
 		}
 		if(x < y and (y-x)&1)
 		{
 			if(x&1) cnt[i-1]++;
 			else cnt[i]++;
 		}
 		if(x > y) swap(x, y);
 		cnt[i-1] += x + (y-x)/2, cnt[i] += x + (y-x)/2;
 		i = j;
 	}
 	for(int i=0; i<sz(s); i++) cout << cnt[i] << " \n"[i==sz(s)-1];
	return 0;
}


Measured memory_bytes: 1104
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 3001;
int dp[maxn][maxn][2];
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int>a(n + 1);
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 0; i < maxn; i++) {
		for (int j = 0; j < maxn; j++) {
			dp[i][j][0] = LLONG_MIN;
			dp[i][j][1] = LLONG_MAX;
		}
	}
	for (int i = 1; i <= n; i++) {
		dp[i][i][0] = a[i];
		dp[i][i][1] = -a[i];
	}
	for (int len = 1; len <= n - 1; len++) {
		for (int l = 1; l <= n; l++) {
			int r = l + len;
			if (r > n)break;
			dp[l][r][0] = max(dp[l][r][0], dp[l + 1][r][1] + a[l]);
			dp[l][r][0] = max(dp[l][r][0], dp[l][r - 1][1] + a[r]);
			dp[l][r][1] = min(dp[l][r][1], dp[l + 1][r][0] - a[l]);
			dp[l][r][1] = min(dp[l][r][1], dp[l][r - 1][0] - a[r]);
		}
	}
	cout << dp[1][n][0];
	return 0;
}

Measured memory_bytes: 141056
n = int(input())
al = sorted(list(map(int,input().split())))
bl = sorted(list(map(int,input().split())))
cl = sorted(list(map(int,input().split())))

import bisect
bbl = []
import bisect

for b in bl:
   idx = bisect.bisect_right(cl,b)
   bbl.append(n-idx)
aal = []
for a in al:
   idx = bisect.bisect_right(bl,a)
   aal.append(idx)
import itertools
bbl = list(itertools.accumulate(bbl[::-1]))[::-1]
bbl.append(0)
ans = 0
for a in aal:
   ans += bbl[a] 
print(ans)

Measured memory_bytes: 28724
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

fn solve() {
	let(n,m) = read!(usize,f64);
	let a = read!([f64]);
	let mut sum = 0.0;
	for &i in &a {
		sum += i;
	}
	let mut ans = 0;
	for &i in &a {
		if i >= sum/(4.0*m) {
			ans += 1;
		}
	}
	if ans >= m as i64 {
		println!("Yes");
	}
	else {
		println!("No");
	}
}

fn run() {
    solve();
}


Measured memory_bytes: 8572
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

vector<int> G[200010];
int cnt[200010];
void dfs(int v, int parent) {
	//cnt[v] += cnt[parent];
	for (int to : G[v]) {
		if (to == parent) continue;
		cnt[to] += cnt[v];
		dfs(to, v);
	}
}
int main()
{
	int N, Q;
	cin >> N >> Q;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for (int i = 0; i < Q; i++) {
		int p, x;
		cin >> p >> x;
		cnt[p - 1] += x;
	}
	dfs(0, 0);
	for (int i = 0; i < N; i++) {
		cout << cnt[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 23424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		while (true) {
			String[] array = br.readLine().split(" ");
			int a = Integer.parseInt(array[0]);
			int b = Integer.parseInt(array[2]);

			if ("?".equals(array[1])) {
				break;
			}
			if ("+".equals(array[1])) {
				sb.append((a + b)).append("\n");
			} else if ("-".equals(array[1])) {
				sb.append((a-b)).append("\n");
			} else if ("*".equals(array[1])) {
				sb.append((a*b)).append("\n");
			} else if ("/".equals(array[1])) {
				sb.append((a/b)).append("\n");
			}
		}

		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 24308
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    int s,w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe";
    else cout<<"safe";

    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define ll long long
int main(){
    string s;
    cin >> s;

    int n=s.size();
    int half=(n-1)/2;
    rep(i,n/2){
        if(s.at(i)!=s.at(n-1-i)){
            cout <<"No"<<endl;
            return 0;
        }
    }
    rep(i,half){
        if(s.at(i)!=s.at(half-1-i)){
            cout <<"No"<<endl;
            return 0;
        }
    }
    half=(n+3)/2;
    rep(i,(n-3)/2){
        if(s.at(half-1+i)!=s.at(n-1-i)){
            cout <<"No"<<endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 312345;
ll A[MAX_N];
const ll MOD = (ll)(1e9 + 7);

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextLong();

  ll ans = 0;
  for (int k = 0; k <= 60; k++) {
    ll count[2] = {0, 0};
    REP(i, N) {
      int v = A[i] >> k & 1;
      count[v]++;
    }
    ans += (1LL << k) % MOD * count[0] % MOD * count[1] % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

  int n,m;
  cin >> n>>m;

  vvi jobs(m);
  rep(i,0,n) {
    int a, b;
    cin >> a >> b; // days, reward
    if (a <= m)
      jobs[m-a].pb(b);
  }

  ll ans=0;
  priority_queue<ll> q;
  int d = m-1;
  while (d >= 0) {
    trav(k,jobs[d]) q.push(k);
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
    --d;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5632
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <string>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc120_b(vector<vector<int>> v) {

    int a = v[0][0];
    int b = v[0][1];
    int k = v[0][2];

    int cnt = 0;
    int i = min(a,b);
    while (cnt < k) {

        if ((a % i == 0) && (b % i == 0)) {
            cnt += 1;
        }

        i -= 1;

    }

    cout << i+1 << endl;

}

int main() {

    vector<vector < int>> vec_arr_result;
    //    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    abc120_b(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 256
import java.util.Scanner;

//Magical Tiles
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int h = sc.nextInt();
			int w = sc.nextInt();
			if(h==0&&w==0)break;
			boolean[][] visit = new boolean[h][w];
			char[][] map = new char[h][w];
			for(int i=0;i<h;i++)map[i]=sc.next().toCharArray();
			int x = 0;
			int y = 0;
			boolean loop = false;
			boolean goal = false;
			while(!loop && !goal){
				if(visit[y][x]){
					loop = true;
					break;
				}
				visit[y][x] = true;
				switch(map[y][x]){
				case '>': x++;break;
				case '<': x--;break;
				case '^': y--;break;
				case 'v': y++;break;
				case '.': goal = true;break;
				}
			}
			System.out.println(loop?"LOOP":x+" "+y);
		}
	}
}

Measured memory_bytes: 12000