akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

signed main()
{
    int A = 0;
    string S;
    cin >> S;
    for (auto &&x : S)
    {
        if (x == '+')
            A++;
        else
        {
            A--;
        }
    }
    cout << A << endl;
}

Measured memory_bytes: 256
# ARC 059: C – いっしょ / Be Together
N = int(input())
a = [int(s) for s in input().split()]

costs = 1000000

for i in range(-100, 101):
    costs_tmp = 0

    for j in range(N):
        costs_tmp += (a[j] - i) ** 2
    
    costs = min(costs, costs_tmp)

print(costs)

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

using namespace std;

const int INF = 10000;

int solve(string s, int tar) {
	int res;
	for (res = 0; ; res++) {
		bool flag = (s[0] - 'a' == tar);
		for (int i = 1; i + res < s.length(); i++) {
			if (s[i] - 'a' != tar) {
				flag = false;
				continue;
			}
			s[i - 1] = 'a' + tar;
		}
		if (flag) break;
	}
	return res;
}

bool used[26];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	for (char& c : s) used[c - 'a'] = true;
	int ans = INF;
	for (int i = 0; i < 26; i++) {
		if (!used[i]) continue;
		ans = min(ans, solve(s, i));
	}
	cout << ans << endl;
	return 0;
}

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

const int N = 1e5 + 10;
int h[N], c[N], n, m, ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n >> m;
	c[0] = 1;
	for (int i = 0; i < n; i++)
		h[i] = 1;
	for (int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		x--;y--;
		c[y] |= c[x];
		h[x]--;
		h[y]++;
		if(h[x] == 0)
			c[x] = 0;
	}	
	for (int i = 0; i < n; i++)
		ans += c[i];
	cout << ans;
	
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

lint le(VEC(lint)& array, lint pos)
{
    int lb = lower_bound(ALL(array), pos + 1) - BEGIN(array);
    return array[lb - 1];
}

lint ge(VEC(lint)& array, lint pos)
{
    return *lower_bound(ALL(array), pos);
}

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int A, B, Q;
    cin >> A >> B >> Q;
    VEC(lint) shrines(A), temples(B);
    READVEC(shrines);
    READVEC(temples);

    while (Q--) {
        lint X;
        cin >> X;

        lint ret = 100000000011LL;
        // only go left.
        if (temples[0] < X && shrines[0] < X) {
            lint t = le(temples, X);
            lint s = le(shrines, X);
            ret = min(ret, max(X - t, X - s));
        }

        // only go right.
        if (temples.back() > X && shrines.back() > X) {
            lint t = ge(temples, X);
            lint s = ge(shrines, X);
            ret = min(ret, max(t - X, s - X));
        }

        // go left for temple, and right for shrine.
        if (temples[0] < X && shrines.back() > X) {
            lint t = le(temples, X);
            lint s = ge(shrines, X);
            ret = min(ret, X - t + X - t + s - X);
            ret = min(ret, s - X + s - X + X - t);
        }

        // opposite of prev. strategy.
        if (temples.back() > X && shrines[0] < X) {
            lint t = ge(temples, X);
            lint s = le(shrines, X);
            ret = min(ret, t - X + t - X + X - s);
            ret = min(ret, X - s + X - s + t - X);
        }

        cout << ret << endl;
    }
    return 0;
};


Measured memory_bytes: 2944
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int M = 1e9+7;    
const int N = 5e5;  // limit for array size
int tests() {
  int n,q ;
  int posn,R,type ;
  string S ;
  int i ; 
  cin >> n >> S >> q ; 
  set <int> s[26] ; 
  forn(i,0,n)
    s[S[i]-'a'].insert(i) ; 
  
  while(q--){
    cin >> type >> posn ;
    posn -= 1; 
    if(type == 1 ){
      char ch ;
      cin >> ch  ; 
      // if()
      s[S[posn]-'a'].erase(posn);
      S[posn] = ch ;
      s[ch-'a'].insert(posn) ;
    }
    else{
      cin >> R ;
      R -= 1 ; 
      int ans = 0 ; 
        forn(i,0,26){ 
          auto it = s[i].lower_bound(posn) ;
          if(it == s[i].end())
          continue ;  
          ans += (it != s[i].end() && *it <= R) ;
        }
        cout << ans << '\n' ; 
    }
  }

  return 0; 
}
int main(){
    I__O ;  
    int cases = 1 ;
    // cin >> cases ; 
    while(cases--)
      tests(); 
  return 0 ; 
}

Measured memory_bytes: 24220
var
 a,b,i:longint;
 s:ansistring;
 q,p:boolean;
begin
 readln(a,b);
 readln(s);
 if s[a+1]='-' then p:=true;
 q:=true;
 for i:=1 to a+b+1 do
  if i<>a+1 then
   if not(s[i] in ['0'..'9']) then 
    begin
     q:=false;
     break;
    end;
 if p and q then writeln('Yes')
                 else writeln('No');
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include<con>
using namespace std;
const int N = 110;
char str[N];
int cut1,cut2,n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>str[i];
    for(int i=1;i<=n;i++){
        if(str[i]=='(') cut1++;
        if(str[i]==')'){
            cut1--;
            if(cut1<0) cut2++,cut1 = 0;
        }
    }
    for(int i=1;i<=cut2;i++)
        cout<<"(";
    for(int i=1;i<=n;i++)
        cout<<str[i];
    for(int i=1;i<=cut1;i++)
        cout<<")";
    cout<<"\n";
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}
func main() {
	C := nextString()

	runeC := []rune(C)
	fmt.Println(string(runeC[0] + 1))
}


Measured memory_bytes: 640
def readinput():
    n = int(input())
    return n

def main(n):
    for i in range(1,10):
        for j in range(1,i+1):
            if i*j == n:
                return 'Yes'
    return 'No'

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)

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

signed main() {
	int64_t N;
	cin>>N;
	int64_t ans=0;
	if(N%(2LL)==1LL){
		ans=0;
	}
	else{
		int64_t k=N/2;
		int64_t tmp=1;
		while(tmp<=N){
			tmp*=5;
			ans+=(k/tmp);
		}
	}
	cout<<ans<<endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    for(int i = 1;i <= n;i++){
        cout << "node " << i << ": key = " << a[i] << ", ";
        if(i / 2 >= 1)cout << "parent key = " <<a[i / 2] << ", ";
        if(2 * i <= n)cout << "left key = " << a[2 * i] << ", ";
        if(2 * i + 1<= n)cout << "right key = " << a[2 * i + 1] << ", ";
        cout << endl;
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;

void solve()
  {
    int r,g,b,k,cnt= 0;
    cin>>r>>g>>b>>k;
    while(g<=r)
     {
      g *= 2;
      cnt++;
     }
    while(b<=g)
      {
        b *= 2;
        cnt++;
      }
    if(cnt<=k)
     cout<<"Yes";
    else
     cout<<"No"; 
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

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


int main()
{
   int n , cnt(0);
  	string s;
  	cin >> n >> s;
  
	for(int i = 0;i <=n-3;i++){
     if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
        cnt++;
      }
    }
      cout << cnt;
	
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a;
  cin >> n;
  cin >> a;

  string out;
  if (n % 500 <= a) {
    out = "Yes";
  } else {
    out = "No";
  }
  cout << out << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  static int cursor = 0;
  static char[] input;

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    input = scan.next().toCharArray();
    System.out.println((check()&&(cursor==input.length))?"Cat":"Rabbit");
  }

  public static boolean check() {
    if(input[cursor]!='m') return false;
    cursor++;
    if(input[cursor]=='m') {
      if(!check()) return false;
    }
    if(input[cursor]!='e') return false;
    cursor++;
    if(input[cursor]=='m') {
      if(!check()) return false;
    }
    if(input[cursor]!='w') return false;
    cursor++;

    return true;
  }
}

Measured memory_bytes: 26252
import math
A,B = list(map(int,input().split()))

for i in range(1009):
    a = math.floor((i+1)*0.08)
    b = math.floor((i+1)*0.1)
    if  a==A and b==B:
        print(i+1)
        break
    elif i == 1008:
        print("-1")

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

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

	LL N; cin >> N;
	map<LL, int> D;
	for(int i=0; i<N; i++){
		LL d; cin >> d;
		if(D.count(d) == 0){
			D[d] = 1;
		}
		else{
			D[d]++;
		}
	}
	LL M; cin >> M;
	vector<LL> T;
	for(int i=0; i<M; i++){
		LL t; cin >> t;
		if(D.count(t) !=0 && D[t] > 0){
			D[t]--;
		}
		else{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 16088
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
             var input = Console.ReadLine();                                                   
 
            Console.WriteLine(int.Parse(input) < 1200 ? "ABC" : "ARC");
        }
    }
}

Measured memory_bytes: 2648
#include<stdio.h>
#include<algorithm>
using namespace std;
int A[210000];

int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i)
	{
		scanf("%d", A + i);
	}
	std::sort(A, A + N);
	for (int i = 0; i < N - 1; ++i)
	{
		if (A[i] == A[i + 1])
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}


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

int main(void)
{
    using namespace std;
    string s;
    int res;
    while (true) {
        cin >> s;
        res = 0;
        if (s.at(0) == '0') {
            break;
        }
        for (int i = 0; i < s.size(); i++) {
            res += s.at(i) - '0';
        }
        printf("%d\n", res);
    }
}


Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "abcdefghijklmnopqrstuvwxyz") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
    p--;
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};


int main() {
    ll N;
    cin >>N;
    Radix r;
    cout << r.to(N, 26) << endl;



    return 0;
    

}

Measured memory_bytes: 3576
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  ll A;
  double B;
  cin >> A >> B;
  ll ans = A * (ll)(B * 100 + 0.9);
  cout << ans / 100 << endl;
  return 0;
}

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
import sys
import random

def main():
	Q = int(input())
	maps = []
	r_max = 0
	for _ in range(Q):
		l, r = map(int, input().split(" "))
		maps.append((l, r))
		if r_max < r:
			r_max = r
			
	#marix = getPrimeNumList(r_max)
				
	base = [0] * (r_max+1)
	counts = 0
	for i in range(r_max+1):
		if i == 0 or i == 1:
			continue
		if (i+1) % 2 == 0 and is_prime(i) == True:
			tmp = (i+1) / 2
			if is_prime(tmp) == True:
				counts += 1
		base[i] = counts
			
	
	for i in maps:
		l, r = i
		print(base[r] - base[l-1])
			
		
def getPrimeNumList(n):
	is_prime = [True] * (n + 1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(n**0.5) + 1):
		if not is_prime[i]:
			continue
		for j in range(i * 2, n + 1, i):
			is_prime[j] = False
	return [i for i in range(n + 1) if is_prime[i]]
	
def is_prime(n): 
  i = 2
  while i * i <=n:
    if n % i == 0:
      return False
    i += 1
  return True
	
if __name__ == "__main__":
	main()


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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long x[n], left[n], right[n];
    for (long long i = 0; i < n; i++) {
        cin >> x[i];
    }
    left[0] = 0;
    for (long long i = 1, gap = 0; i < n; i++) {
        left[i] = left[i - 1] + min(b, (x[i] - x[i - 1]) * a);
    }
    right[n - 1] = b;
    for (long long k = n - 2; k >= 0; k--) {
        right[k] = right[k + 1] + min(b, (x[k + 1] - x[k]) * a);
    }
    long long result = left[n - 1];
    for (long long i = 1; i < n; i++) {
        result = min(result, left[i - 1] + right[i]);
    }
    cout << result;
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, e[50];

int main() {
	cin >> n >> m;
	inc(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		e[a]++;
		e[b]++;
	}
	
	inc(i, n) {
		cout << e[i] << "\n";
	}
	
	return 0;
}


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

int main()
{
    int N,K;
    string S;
    cin >> N >> K >> S;
    for(int i=0;i<N;i++){
        if(K-1==i){
            S[i] = S[i] - 'A' + 'a';
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int N = 110, W = 2e5 + 10, mod = 1e9 + 7; 
long long a[N], b[N], dp[N][W], ans;
int main(){
    int n, w;
    cin >> n >> w;
    for(int i = 1; i <= n; i++){
        cin >> b[i] >> a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= w; j++){
            dp[i][j] = dp[i - 1][j];
            if(j >= b[i])dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
}  

Measured memory_bytes: 156416
N = int(input())

edge_list = [list(map(int,input().split())) for i in range(N-1)]

adj_dict = {}

for edge in edge_list:
    if edge[0] not in adj_dict.keys():
        adj_dict[edge[0]] = [(edge[1])]
    else:
        adj_dict[edge[0]].append(edge[1])

max_color = -1

# print(adj_dict)

# Create a queue for BFS
queue = [1]

# Mark the source node as
# visited and enqueue it

painted = {}


while queue:

    # Dequeue a vertex from
    # queue and print it
    s = queue.pop(0)

    # Get all adjacent vertices of the
    # dequeued vertex s. If a adjacent
    # has not been visited, then mark it
    # visited and enqueue it
    if s not in adj_dict:
        continue

    for i in range(len(adj_dict[s])):
        color = 1 + i
        if painted.get(s) is not None:
            if 0 < painted[s] <= color:
                color += 1
        # print(s, i)
        painted[adj_dict[s][i]] = color
        max_color = max(max_color, color)
        queue.append(adj_dict[s][i])

print(max_color)

for edg in edge_list:
    print(painted[edg[1]])


'''
9
1 6
1 4
1 9
4 5
1 7
2 3
4 8
1 2

5
1
2
3
1
4
1
3
5
'''


Measured memory_bytes: 43136
import cmath
EPS = 1e-8

#cmath.rect(r, th) 極座標→直交座標
#cmath.polar(c) 複素数→極座標
#print("{:.12f}.format(hoge)") 桁数指定

n, k = map(int, input().split())
d = []
for _ in range(n):
	x, y, c = list(map(int, input().split()))
	d.append((complex(x, y), c))

ok, ng = 10**6, 0
for _ in range(60):
	t = (ok+ng)/2
	#t = 2.41

	res = 1
	#wrapped = [1 for _ in range(n)]
	for i in range(n):
		o1, r1 = d[i][0], t / d[i][1]
		cnt0 = 1
		for j in range(n):
			if j == i:
				continue
			o2, r2 = d[j][0], t / d[j][1]
			if abs(o1 - o2) + EPS <= r2:
				cnt0 += 1

		res = max(res, cnt0)
		for j in range(i+1, n):
			o2, r2 = d[j][0], t / d[j][1]
			if abs(o1 - o2) - EPS >= r1 + r2:
				#print(i, j)
				continue
			elif abs(o1 - o2) + min(r1, r2) + EPS <= max(r1, r2):
				continue
			else:
				co = (r1**2 - r2**2 + abs(o1 - o2)**2) / (2 * abs(o1 - o2) * r1)
				si = cmath.sqrt(1 - co**2)
				p1 = o1 + (o2 - o1) * (co + 1j * si) * r1 / abs(o1 - o2)
				p2 = o1 + (o2 - o1) * (co - 1j * si) * r1 / abs(o1 - o2)				#print(i, j, p1, p2)

			cnt1, cnt2 = 2, 2
			for l in range(n):
				if l == i or l == j:
					continue
				else:
					o3, r3 = d[l][0], t / d[l][1]
					if abs(p1 - o3) + EPS <= r3:
						cnt1 += 1
					if abs(p2 - o3) + EPS <= r3:
						cnt2 += 1
			#print(i, j, cnt1, cnt2)
			res = max(res, cnt1, cnt2)

	#res = max(res, max(wrapped))
	if res >= k:
		ok = t
	else:
		ng = t

if ok < 1e-6:
	print(0)
else:
	print(ok)

Measured memory_bytes: 63580
from operator import itemgetter
from bisect import bisect_right
import sys
input = sys.stdin.readline

n, d, a = map(int, input().split())
monster = [tuple(map(int, input().split())) for _ in range(n)]
monster.sort(key=itemgetter(0))
xx = [xi for xi, hi in monster]

ans = 0
imos = [0] * (n + 1)
for i, (xi, hi) in enumerate(monster):
    hi -= imos[i]
    if hi > 0:
        c = (hi + a - 1) // a
        ans += c
        idx = bisect_right(xx, xi + 2 * d)
        imos[i] += c * a
        imos[idx] -= c * a

    # update imos
    imos[i + 1] += imos[i]

print(ans)


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

int main()
{
  int H, W, K, cnt = 1;
  cin >> H >> W >> K;
  vector<vector<char>> G(H, vector<char>(W));
  vector<vector<int>> Gi(H, vector<int>(W, -1));
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> G.at(i).at(j);
      if (G.at(i).at(j) == '#')
      {
        Gi.at(i).at(j) = cnt;
        cnt++;
      }
    }
  }
  int prev_cnt = -1;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (G.at(i).at(j) == '.')
      {
        Gi.at(i).at(j) = prev_cnt;
      }
      else
      {
        prev_cnt = Gi.at(i).at(j);
      }
    }
    for (int j = W - 1; j >= 0; j--)
    {
      if (Gi.at(i).at(j) == -1)
      {
        if (j == W - 1)
        {
          continue;
        }
        else
        {
          Gi.at(i).at(j) = Gi.at(i).at(j + 1);
        }
      }
    }
    prev_cnt = -1;
  }

  for (int i = 0; i < H; i++)
  {
    if (Gi.at(i).at(0) == -1)
    {
      if (i == 0)
      {
        for (int j = i + 1; j < H; j++)
        {
          if (Gi.at(j).at(0) != -1)
          {
            Gi.at(i) = Gi.at(j);
            break;
          }
        }
      }
      else
      {
        Gi.at(i) = Gi.at(i - 1);
      }
    }
  }

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cout << Gi.at(i).at(j);
      if (j == W - 1)
      {
        cout << endl;
      }
      else
      {
        cout << ' ';
      }
    }
  }
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mm multimap<ll,ll>
#define mp make_pair
#define pii pair<ll,ll>

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
 string s,z;
        cin>>s>>z;
        ll n=s.length();
       ll m=z.length();
        //reverse(s.begin(),s.end());
        ll dp[m+1][n+1];
        memset(dp,0,sizeof(dp));
        for(ll i=1;i<=m;i++)
        {
            for(ll j=1;j<=n;j++)
            {
                if(z[i-1]==s[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
                else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        string p="";
        ll j=n;
        for(ll i=m;i>=1&& j>=1;)
        {
            if(dp[i][j]!=dp[i-1][j] && dp[i][j]!=dp[i][j-1])
            {p+=z[i-1];i--;j--;}
            else if(dp[i-1][j]>dp[i][j-1])
            i--;
            else j--;
            
            
        }
        
reverse(p.begin(),p.end());
cout<<p;

}

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

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n = sc.nextInt();
        int k = sc.nextInt();

        BigDecimal ans = new BigDecimal(0);

        BigDecimal nbd = new BigDecimal(n);
        BigDecimal add;
        for (int i=1; i <= n; i++) {
            add = new BigDecimal("0.5").pow(countPowOf2(k, i)).divide(nbd, 15, BigDecimal.ROUND_HALF_UP);

            ans = ans.add(add);
        }

        System.out.println(ans.toString());
    }

    private static int countPowOf2(int target, int orig) {
        int pow = 0;
        while (orig < target) {
            orig *= 2;
            pow++;
        }
        return pow;
    }

}


Measured memory_bytes: 37076
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N];
    int mi = INT_MAX, ma = INT_MIN;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        mi = min(mi,A[i]);
        ma = max(ma,A[i]);
    }
    cout << ma-mi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<algorithm>
const long long mod=1e9+7;
typedef long long ll;
using namespace std;

ll f[1000010],revf[1000010];//数组大小至少要为1e5*2

ll qpow(ll a,ll b){
  ll ret=1;
  while(b){
    if(b&1) ret=(ret*a)%mod;
    a=(a*a)%mod;
    b>>=1;
  }
  return ret;
}

void init(){
  f[0]=1; revf[0]=qpow(f[0],mod-2);
  for(ll i=1;i<1000010;i++){
    f[i]=i*f[i-1]%mod;
    revf[i]=qpow(f[i],mod-2);
  }
}

ll C(ll n,ll m){
  return (f[n]*revf[m])%mod*revf[n-m]%mod;
}

ll count_ways(ll a,ll b,ll c,ll d){
  ll tot=(c-a)+(d-b);
  ll down=(c-a);
  ll ret=C(tot,down);
  return ret;
}

int main()
{
    init();
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    ll tot=count_ways(1,1,h,w);
    for(ll i=1;i<=b;i++){
        ll tmp=count_ways(1,1,h-a,i)*count_ways(h-a+1,i,h,w)%mod;
        while(tot<tmp) tot+=mod;//防止出现负数
        tot=(tot-tmp)%mod;
    }
    cout<<tot<<endl;
    return 0;
}

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

int k;
string s;

int main() {
	cin>>k;
	cin>>s;
	if(s.length()<=k) cout<<s<<"\n";
	else {
		for(int i=0; i<k; i++) cout<<s[i];
		cout<<"...\n";
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

int main()
{
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    ll ans = 0;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N;j++)
        {
            if ((N - (R * i + j * G)) >= 0 && (N - (R * i + j * G)) % B == 0)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
const ll MAX_N = 100000000;
int main() {
//input
ll n,k,s;
scanf("%lld",&n);
scanf("%lld",&k);
scanf("%lld",&s);
if(s ==1){
	rep(i,k)cout <<1<< " ";
	for(int i = k;i<n;i++)cout <<s+1<< " ";
}
else if(s==1000000000){
		for(int i=0;i<k;i++) printf("%d ",s);
		for(int i=k;i<n;i++) printf("%d ",1);puts("");
}
else if(n==k){
	rep(i,n){
	cout << s <<" ";
	}
}
else{
rep(i,k+1){
	if(i%2 ==1)	cout << 1<<" ";
	if(i%2 ==0)	cout << s-1<<" ";
}
for(int i = k+1;i<n;i++) cout <<s+1<< " ";
}
//compute
 
//output
 
	return 0;
}


Measured memory_bytes: 1280
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())


//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

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

	//dp[i番目までみたとき]の最小コスト

	vector<int> dp(n + 2, INF);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);

	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}

	cout << dp[n-1] << endl;
	

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250002
#define in(x)  cin>>x
#define o(x)  cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<P>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS];
ll board[502][502];
int main()
{
    fast;
    in(x>>k>>p);
    x=abs(x);
      l=min(k,x/p);
       k-=l;
       x-=p*l;
       if(k%2)x-=p;
       o(abs(x));
}


Measured memory_bytes: 3680
def main():
    h1, m1, h2, m2, k = [int(x) for x in input().split()]
    t1 = 60 * h1 + m1
    t2 = 60 * h2 + m2
    ans = t2 - k - t1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> S;
    cin >> T;

    rep(i,S.size())
    {
        if(S[i] != T[i])
        {
            A++;
        }
    }

    cout << A;
    
    return 0;
}

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

int main () {
  int A, B, C;
  cin >> A >> B >> C;
  
  vector<int> vec = {A, B, C};
  sort(vec.begin(), vec.end());
  
  cout << vec.at(2) * 10 + vec.at(1) + vec.at(0) << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
X = int(input())
y = X // 100
if y <= 5:
    print(8)
elif y <= 7:
    print(7)
elif y <= 9:
    print(6)
elif y <= 11:
    print(5)
elif y <= 13:
    print(4)
elif y <= 15:
    print(3)
elif y <= 17:
    print(2)
else:
    print(1)

Measured memory_bytes: 10584
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef unsigned long long ull;

int main() {
    string s;
    cin >> s;
    ull zero_c, one_c;
    zero_c =  count(s.cbegin(), s.cend(), '0');
    one_c = s.length() - zero_c;

    cout << min(zero_c, one_c) * 2 << endl;

    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353
    N=I()
    D=LI()
    L=[0]*N
    N2=max(D)

    
    for i in range(N):
        L[D[i]]+=1
    prev=1
    ans=1
    if D[0]!=0 or L[0]!=1:
        print(0)
    else:
        for i in range(1,N2+1):
            now=L[i]
            ans=(ans*pow(prev,now,mod))%mod
            prev=now
            
        print(ans)
            
        
    

main()


Measured memory_bytes: 53276
import math
n, m = map(int, input().split())

mod = (10 ** 9) + 7
if abs(n - m) >= 2:
    print("0")
else:
    nn = math.factorial(n)
    mm = math.factorial(m)
    if abs(n - m) >= 1:
        print((nn * mm) % mod)
    else:
        ans = nn * 2 % mod
        ans = ans * mm % mod
        print(ans)

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

const int N = 2e5 + 10;
int n, a[N], t[2][N << 2];

inline int read() {
	int s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline void add(int o, int pos, int l, int r, int cnt) {
	if (a[cnt] < a[t[o][pos]])	t[o][pos] = cnt;
	if (l == r)	return;
	int mid = (l + r) >> 1;
	if (cnt <= mid)	add(o, pos << 1, l, mid, cnt);
	else	add(o, pos << 1 | 1, mid + 1, r, cnt);
}

inline int ask(int o, int pos, int l, int r, int L, int R) {
	if (l > R || r < L)	return 0;
	if (L <= l && r <= R)	return t[o][pos];
	int mid = (l + r) >> 1;
	int lans = ask(o, pos << 1, l, mid, L, R);
	int rans = ask(o, pos << 1 | 1, mid + 1, r, L, R);
	return a[lans] < a[rans] ? lans : rans;
}

struct node {
	int l, r, v;
	node() {}
	node(int _l, int _r){ l = _l, r = _r, v = l > r ? 0 : ask(l & 1, 1, 1, n, l, r); }
	friend bool operator < (node A,node B) { return a[A.v] < a[B.v]; }
};

set <node> s;

int main() {
	n = read();
	a[0] = n + 1;
	for(int i = 1; i <= n; ++i) {
		a[i] = read();
		add(i & 1, 1, 1, n, i);
	}
	s.clear();
	s.insert(node(1, n));
	for(int i = 1; i <= n >> 1; ++i) {
		node now = *s.begin();
		s.erase(s.begin());
		int l = now.l, r = now.r;
		int lmid = now.v, rmid = ask((lmid & 1) ^ 1, 1, 1, n, lmid, r);
		printf("%d %d ", a[lmid], a[rmid]);
		s.insert(node(l, lmid - 1));
		s.insert(node(lmid + 1, rmid - 1));
		s.insert(node(rmid + 1, r));
	}
	puts("");
	return 0;
}

Measured memory_bytes: 11008
package main

import (
	"fmt"
)

var (
	m = make(map[int]int)
	n int
)

func main() {
	fmt.Scan(&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	for _, v := range a {
		m[v-1]++
		m[v]++
		m[v+1]++
	}

	max := 0
	for _, v := range m {
		if max < v {
			max = v
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 8960
#include <math.h>
#include <stdio.h>

struct Point {
    double x, y;
};

void koch(int n, Point a, Point b) {
    if (n == 0) return;
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}

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

    scanf("%d", &n);

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string t;
	cin >> t;
	int len = t.length();
	if (t[0] == '?' && t[1] == '?') {
		t[0] = 'P';
		t[1] = 'D';
	} else if (t[0] == '?' && t[1] == 'D') {
		t[0] = 'P';
	} else if (t[0] == '?' && t[1] == 'P') {
		t[0] = 'D';
	}
	for (int i = 1; i < len - 1; ++i) {
		if (t[i] == '?') {
			if (t[i - 1] == 'P') {
				t[i] = 'D';
			} else if (t[i + 1] == '?') {
				t[i] = 'P';
				t[i + 1] = 'D';
			} else if (t[i + 1] == 'D') {
				t[i] = 'P';
			} else {
				t[i] = 'D';
			}
		}
	}
	if (t[len - 1] == '?') {
		t[len - 1] = 'D';
	}
	cout << t << '\n';
	
	return 0;
}


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

const int Maxn = 200005;

int n, q;
vector <int> neigh[Maxn];
int res[Maxn];

void Traverse(int v, int p)
{
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        res[u] += res[v];
        Traverse(u, v);
    }
}

int main()
{
    scanf("%d %d", &n, &q);
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    while (q--) {
        int p, x; scanf("%d %d", &p, &x);
        res[p] += x;
    }
    Traverse(1, 0);
    for (int i = 1; i <= n; i++)
        printf("%d%c", res[i], i + 1 <= n? ' ': '\n');
    return 0;
}


Measured memory_bytes: 26624
n,k= list(map(int, input().split()))
from math import factorial
if n>1:
    a=factorial(n)//factorial(2)//factorial(n-2)
else:
    a=0
if k>1:
    b=factorial(k)//factorial(2)//factorial(k-2)
else:
    b=0
print(a+b)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int w, a, b;
int main(){
  cin >> w >> a >> b;
  int len = 0;
  if(a == b) cout << len << endl;
  if(a < b) {
    if(a+w < b) cout << b-a-w << endl;
    else cout << len << endl;
  }
  if(a > b) {
    if(b+w < a) cout << a-b-w << endl;
    else cout << len << endl;
  }
}

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

string s;
long long k;

int main()
{
	cin >> s;
	cin >> k;

	char ans = '1';
	for( int i = 0; i < min( (long long)s.size(), k ); i++ ) {
		if( s[i] != '1' ) {
			ans = s[i];
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

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

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

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

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

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算




int main() {

	COMinit();

	ll N;
	ll x[MAX];
	cin >> N;
	repn(i, N) cin >> x[i];

	ll F = fac[N-1];

	ll f[MAX];

	for (int i = 1; i <= N - 1; i++) {
		f[i]=F*inv[i]%MOD;
	}

	ll sum[MAX] = {};
	
	for (int i = 1; i<=N-1; i++) {
		sum[i] = (sum[i - 1] + f[i]) % MOD;
	}

	ll ans = 0;

	for (int i = 1; i <= N-1; i++) {
		ans += sum[i] * (x[i+1] - x[i]);
		ans %= MOD;
	}

	cout << ans;
	


	system("PAUSE");


}


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

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

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

auto DS = [[1,0], [-1,0], [0,1], [0,-1]];

wchar[50][50] MAP;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];

    foreach (i; 0..H) {
        foreach (j, c; readln.chomp.to!(wchar[])) {
            MAP[i][j] = c;
        }
    }

    foreach (y, line; MAP[0..H]) {
        foreach (x, c; line[0..W]) {
            if (c == '#') {
                bool valid;
                foreach (d; DS) {
                    auto xd = x + d[0];
                    auto yd = y + d[1];
                    if (xd < 0 || xd >= W || yd < 0 || yd >= H) continue;
                    if (MAP[yd][xd] == '#') {
                        valid = true;
                        break;
                    }
                }
                if (!valid) {
                    writeln("No");
                    return;
                }
            }
        }
    }

    writeln("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <iomanip>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define point complex<ld>
#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;
const ll INF = 1e18;
const int mod = 1e4, N = 1e5 + 5, inf = 1e9;

int main()
{
    IO
    int a, b, c, d, i, j, n, m;
    cin >> a >> b >> c >> d;
    i = c - (d - b);
    j = d + (c - a);
    n = a - (d - b);
    m = b + (c - a);
    cout << i << ' ' << j << ' ' << n << ' ' << m << '\n';
    return 0;
}

Measured memory_bytes: 3608
K=int(input())

memo={}
def gcd(a,b):
    if a<b:
        a,b=b,a

    aa=a
    bb=b
    if (a,b) in memo.keys():
        return memo[a,b]
    while b != 0:
        a,b, = b, a%b
    memo[aa,bb]=a
    return a





memo3={}

def gcd3(a,b,c):
    if a>b:
        a,b = b,a
    if a>c:
        a,c = c,a
    if b>c:
        b,c = c,b
    if (a,b,c) in memo3.keys():
        return memo3[(a,b,c)]
    
    g = gcd(gcd(a,b),c)
    memo3[(a,b,c)]=g
    return g


sum=0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            
            if i==j & j==k:
                sum += gcd3(i,j,k)
                continue
            if i==j & j!=k:
                sum += gcd3(i,j,k)*3
                continue
            if i!=j & j==k:
                sum += gcd3(i,j,k)*3
                continue
            sum += gcd3(i,j,k)*6
print(sum)





Measured memory_bytes: 348828
#include <bits/stdc++.h>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;

int main(){
    long long a,b;
    double inb;
    cin >> a >> inb;
    inb += 0.001;
    inb *= 100;
    b=inb;
    a*=b;
    long long temp;
    temp = a%100;
    a -= temp;
    a /=100;
    cout << a << endl;
}


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

int main() 
{
    int N;
    cin >> N;
    string ans;
    string A,B;
    cin >> A >> B;
    for(int i=0; i<N; i++)
    {
        ans+=A.at(i);
        ans+=B.at(i);
    }
    cout << ans <<endl;

}

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

typedef long long int llint;

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

  x -= a;

  if(x == 0 || x > 0 && x <= b) cout<< "YES" <<endl;
  else                          cout<< "NO"  <<endl;

  return 0;
}


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

int main() {
  long long n,m;
  cin>>n>>m;
  vector<string>p(m);
  vector<string>s(m);
  for(long long i=0;i<m;i++){
    cin>>p[i]>>s[i];
  }
  long long cnt=0;
  long long cnt2=0;
  map<string,int>mp;
  map<string,int>mp2;
  for(long long i=0;i<m;i++){
    if(s[i]=="AC"&&mp[p[i]]==0){
      mp[p[i]]++;
      cnt++;
      cnt2+=mp2[p[i]];
    }
    if(s[i]=="WA"&&mp[p[i]]==0){
      mp2[p[i]]++;
    }
  }
  cout<<cnt<<" "<<cnt2<< endl;
  return 0;
}

Measured memory_bytes: 25172
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	String an[]=new String[a];
	for(int i=0;i!=a;i++) {
		an[i]=scan.next();
	}
	for(int i=0;i!=b+2;i++) {
		System.out.print("#");
	}
	System.out.println();
	for(int i=0;i!=a;i++) {
		System.out.println("#"+an[i]+"#");
	}
	for(int i=0;i!=b+2;i++) {
		System.out.print("#");
	}
	System.out.println();
	
}
}

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

using namespace std;

int main(){
 int N,M; cin >> N >> M;
  vector<bool> flag(N); flag[0] = true;
  vector<int> cnt(N,1);
  
  for(int i = 0; i < M; i++){
    int x,y; cin >> x >> y; x--; y--;
    if( flag[x]){
      if( cnt[x] > 1){ flag[y] = true; cnt[x]--; cnt[y]++;}
      else{ flag[x] = false; flag[y] = true; cnt[x]--; cnt[y]++;}
    }
    else{
      cnt[x]--; cnt[y]++;}
  }
  int ans = 0;
  for(int i = 0; i < N; i++){ if(flag[i]){ans++;}}
  
  cout << ans << endl; return 0;}
  

Measured memory_bytes: 640