akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = 998244353;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt();
        int s = sc.nextInt();

        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        long[] dp = new long[s + 1];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = s - as[i]; j >= 0; j--) if (dp[j] >= 0) {
                if (dp[j + as[i]] < 0) dp[j + as[i]] = 0;
                if (j == 0) dp[j + as[i]] += i + 1;
                else {
                    dp[j + as[i]] = (dp[j + as[i]] + dp[j]) % MOD;
                }
            }
            if (dp[s] >= 0) {
                ans = (ans + (dp[s] * (n - i))) % MOD;
                dp[s] = 0;
            }
        }

        out.println(ans);

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

Measured memory_bytes: 26468
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$k = (int)$input[0];
$x = (int)$input[1];

$max = min(1000000, $x+$k-1);
$min = max(-1000000, $x-$k+1);

$res = [];
for ($i=$min; $i <= $max ; $i++) { 
	$res[] = $i;
}
echo implode(' ', $res);

Measured memory_bytes: 4856
import sys
from collections import defaultdict as dd
from bisect import bisect_left as bl
input = sys.stdin.readline

N, M = map(int, input().split())
a = [x % M for x in list(map(int, input().split()))]
#print(a)
cs = [0] * (N + 1)
d = dd(list)
for i in range(N):
  cs[i + 1] = (cs[i] + a[i]) % M
  d[cs[i + 1]].append(i)

#print(cs, d)
res = 0
for i in range(N):
  t = (M + cs[i]) % M
  ind = bl(d[t], i)
  #print(i, "t=", t, ind)
  res += len(d[t]) - ind
  #print("r", res)
print(res)

Measured memory_bytes: 63012
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int n;
  cin >> n;
  int a, b;
  if (n == 1){
    cout << "Hello World" << endl;
  }
  else {
    cin >> a;
    cin >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct edge{ int to,cost; };
vector<int> dikstra(int s,vector<vector<edge>> G){
  typedef pair<int, int> P;
  const int INF = 1LL << 60;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(G.size(),INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  return d;
}

signed main(){

  int n, k, q; cin >> n;
  vector<vector<edge>> G(n);
  for(int i = 0; i < n-1; i++){
    int a, b, c; cin >> a >> b >> c;
    a--, b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }

  cin >> q >> k;
  k--;
  auto dp = dikstra(k, G);
  for(int i = 0; i < q; i++){
    int x, y; cin >> x >> y;
    x--, y--;
    cout << dp[x] + dp[y] << endl;
  }

  return 0;
}


Measured memory_bytes: 18160
#include<iostream>
using namespace std;
int euler(int num){
    int res=num;
    for(int i=2;i*i<=num;i++){
        if(num%i==0){
            res=res/i*(i-1);
            while(num%i==0) num/=i;
        }
    }
    if(num!=1){
        res=res/num*(num-1);
    }
    return res;
}
int main(){
    int n;cin>>n;
    cout<<euler(n)<<endl;
}


Measured memory_bytes: 3120
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  static constexpr u64 max = 1000000000;
  const u64 s = scan<u64>();
  u64 r = max - s % max;
  if (s % max == static_cast<u64>(0)) {
    r = static_cast<u64>(0);
  }
  std::cout << 0 << " " << 0 << " " << max << " " << r << " " << 1 << " "
            << (s + r) / max << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (mut a, mut b, k): (isize, isize, isize);
    input!(a, b, k);
    let mut z = k - a;
    a = std::cmp::max(0, a - k);
    if a == 0 {
        b = std::cmp::max(0, b - z);
    }
    println!("{} {}", a, b);
}


Measured memory_bytes: 4352
#include <atcoder/fenwicktree>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
int main() {
	int N, Q;
	cin >> N >> Q;
	fenwick_tree<ll> fw(N);
	for (int i = 0; i < N; ++ i) {
		int x;
		cin >> x;
		fw.add(i, x);
	}
	for (int i = 0; i < Q; ++ i) {
		int t;
		cin >> t;
		if (t == 0) {
			int p, x;
			cin >> p >> x;
			fw.add(p, x);
		} else {
			int l, r;
			cin >> l >> r;
			cout << fw.sum(l, r) << endl;
		}
	}
}


Measured memory_bytes: 8212
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin). unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	() => (get().parse::<i64>().unwrap());
    	($t:ty) => (get().parse::<$t>().unwrap());
    }
    let n = get!(usize);
    let mut ds = vec![0; n];
    for i in 0..n {
    	ds[i] = get!();
    }
    ds.sort();
    
    let mut ans = 1;
    for i in 0..n-1 {
    	if ds[i] < ds[i+1] {
        	ans += 1;
        }
    }
    
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        string S,T;
        cin>>S;
        if(S==".") break;
        cin>>T;
        
        if(S==T){
            cout<<"IDENTICAL"<<endl;
        }else{
            int a=0,b=0,c=0,d=0,e=0,f=0;
            for(int i=0;i<min(S.size(),T.size());i++){
                if(S[i]!=T[i]){
                    for(int j=0;j<i;j++){
                        if(S[j]=='"') a++;
                    }
                    for(int j=0;j<i;j++){
                        if(T[j]=='"') d++;
                    }
                    break;
                }
            }
            
            reverse(all(S));
            reverse(all(T));
            
            for(int i=0;i<min(S.size(),T.size());i++){
                if(S[i]!=T[i]){
                    for(int j=0;j<i;j++){
                        if(S[j]=='"') b++;
                    }
                    for(int j=0;j<i;j++){
                        if(T[j]=='"') e++;
                    }
                    break;
                }
            }
            
            reverse(all(S));
            reverse(all(T));
            
            for(int i=0;i<S.size();i++){
                if(S[i]=='"') c++;
            }
            for(int i=0;i<T.size();i++){
                if(T[i]=='"') f++;
            }
            //cout<<a<<" "<<b<<" "<<c;
            if(a%2==1&&b%2==1&&a+b==c&&d%2==1&&e%2==1&&d+e==f) cout<<"CLOSE"<<endl;
            else cout<<"DIFFERENT"<<endl;
        }
    }
    
}



Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n,k;
    int h[110000];

    cin >> n >> k;
    rep(i,n) cin >> h[i];

    int count = 0;
    rep(i,n){
        if(h[i] >= k){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int64 n,sum=0;
  cin>>n;
  int64 a[n];
  rep(i,n){
    cin>>a[i];
  }
  rep(i,n){
    sum+=a[i];
  }
  if(sum%2==0){
    cout<<"YES";
  }else{
    cout<<"NO";
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    double ans;
    double p[n];
    for(int i=0;i<n;i++){
    	cin>>p[i];
    	p[i]=(p[i]+1)/2;
    }
    double num=0.0;
    int index=0;
    for(int i=0;i<k;i++){
    	num+=p[i];
    }
    ans=num;
    for(int i=k;i<n;i++){
    	num+=p[i];
    	num-=p[index];
    	index++;
    	ans=max(ans,num);
    }
    doublecout(ans);
    return 0;
}


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

int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;
    K = min(K, 13);
    string ret = S;

    for (int i = 0; i < N; i++)
    {
        string T = S;
        for (int k = 0; k < K; k++)
        {
            string Tinv = T;
            reverse(Tinv.begin(), Tinv.end());
            T += Tinv;
            if (k == 0) T = T.substr(N - i, N);
            else if (k == K - 1)
            {
                int j = N - 1;
                while (j >= 0 and T[j] == T[N - 1]) j--;
                T = T.substr(j + 1, N);
            }
            else
            {
                int j = N - 1;
                while (j < 2 * N and T[j] == T[N - 1]) j++;
                T = T.substr(j - N, N);
            }
        }
        ret = min(ret, T);
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    vector<set<int>> c(26);
    rep(i, n){
        c[s[i]-'a'].insert(i);
    }

    ll ans = 0;
    int l = 0;
    rep(i, t.size()){
        auto lb = c[t[i]-'a'].lower_bound(l);
        if(lb != c[t[i]-'a'].end()){
            ans += *lb - l + 1;
            l = *lb + 1;
        }else{
            ans += n - l + 1;
            l = 0;
            lb = c[t[i]-'a'].lower_bound(l);
            if(lb == c[t[i]-'a'].end()){
                cout << -1 << endl;
                return 0;
            }
            ans += *lb - l;
            l = *lb + 1;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e3 + 5;
int n , m;
string a[maxn];
int dp[maxn][maxn];
const int mod = 1e9 + 7;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    cin >> n >> m;
    for(int i = 1 ; i <= n;++i)
    {
        cin >> a[i];
        a[i] = " " + a[i];
    }
    dp[1][1] = 1;
    for(int i = 1 ; i <= n ; ++i)
    {
        for(int j = 1 ; j <= m ; ++j)
        {
            if(i == 1 && j == 1)continue;
            if(a[i][j] == '#')continue;
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]);
            if(dp[i][j] >= mod)dp[i][j] -= mod;
        }
    }
    cout << dp[n][m];
}


Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main()
{
   char s1[200],s2[200];
   cin>>s1>>s2;
   int len = strlen(s1);
   int flag=0;
   int i,j=0,k;
   for(i=0;i<len;i++)
   {
       k=i;
       for(j=0;j<len;j++)
       {
           if(k==len) k=0;
           if(s1[k] != s2[j]) break;
           else
           {
               k++;
           }
       }
       if(j==len){flag=1;break;}
   }
   if(flag) printf("Yes\n");
   else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc159/tasks/abc159_c"

#include<bits/stdc++.h>

using namespace std;

int main()
{
    double l;
    cin>>l;

    cout<<fixed;
    cout<<setprecision(12)<<pow(l/3.0,3);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int Ai[100000];
int main() {
  int H,N,sum;
  cin>>H>>N;
  sum=0;
  int g= H-1;
  int flag;
  for(int i=0; i<N;i++){
     cin>>Ai[i];
     if (Ai[i]>=1 && Ai[i]<=10000){
        continue;
     }
  }
  if (H>=1 && H<=1000000000 &&N>=1&&N<=100000 ){
    for (int i=0; i<N;i++){
        sum=sum+Ai[i];
        if (sum>=H or  sum>H+1){
          flag=0;
        }
        else{
          flag=1;
        }
     }
  }
  if (flag==0){
    cout<<("Yes");
  }
  else if (flag==1){
    cout<<("No");
  }

}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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


Measured memory_bytes: 3084
#include<iostream>
using namespace std;
typedef unsigned long long ullong;

ullong powerLargeNum(int m, int n, int mod) {
    if (n == 0) return 1;
    ullong ans = powerLargeNum(m, n/2, mod);
    ans = (ans * ans) % mod;
    if (n % 2 == 1) ans = (ans * m) % mod;
    return ans;
}

int main() {
    int m, n;
    cin >> m >> n;
    cout << powerLargeNum(m, n, 1000000007) << endl;
}

Measured memory_bytes: 3096
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int r = sc.NextInt();

        string answer = r < 1200 ? "ABC" : (r < 2800 ? "ARC" : "AGC");

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

ll N;

signed main(){
    cin >> N;
    if(N%10==3) cout << "bon";
    else if(N%10==0||N%10==1||N%10==6||N%10==8) cout << "pon";
    else cout << "hon";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 3*(int)1e3 + 10;

int n, k;

#define ll int
ll power(ll a, ll b, ll m = mod){if(b < 0)b += m-1; ll r = 1; while(b){if(b&1)r=(r*a)%m; a = (a*a)%m; b>>=1;}return r;}

int fact[N+10], ifact[N+10];
void pre(int N){
   fact[0] = 1;
   for (int i = 1; i <= N; ++i)
   {
      fact[i] = (i*fact[i-1])%mod;
   }
   ifact[N] = power(fact[N], -1);
   for (int i = N-1; i >= 0; --i)
   {
      ifact[i] = ((i+1)*ifact[i+1])%mod;
   }
}

int nCr(int n, int r){
   if(n < r)return 0;
   return ((fact[n]*ifact[r])%mod * ifact[n-r])%mod;
}


int solve(int turns){
   int x = nCr(n-k+1, turns);
   int y = nCr(k-1, turns-1);
   return (x*y) % mod;
}

int32_t main(){_

   pre(N);

   cin>>n>>k;   

   for (int turns = 1; turns <= k; ++turns)
   {
      cout<< solve(turns) << endl;
   }
      

   return 0;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

bool sosuuCheck(int n){
	if (n % 2 == 0)	return false;
	for (int i = 3;i<=sqrt((double)n);i+=2){
		if (n%i == 0)	return false;
	}
	return true;
}

int solve(int n){
	int ans = 0;
	for (int i = 3; i <= n / 2; i += 2){
		if (sosuuCheck(i)){
			if (sosuuCheck(n - i)){
				ans++;
			}
		}
	}
	return ans;
}

int main(){
	fastIO;
	int n;

	while (cin >> n, n){
		cout << solve(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
          string input_line = Console.ReadLine();
          if(input_line[0] == input_line[1] && input_line[1] == input_line[2])
          {
            Console.WriteLine("No");
          }else
          {
            Console.WriteLine("Yes");
          }
        }
    }
}


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

#define ll long long

int main(void){

    int n;
    cin>>n;

    int l[n];
    int sum=0;
    int maxl=0;
    for(int i=0;i<n;i++){
        cin>>l[i];
        sum +=l[i];
        maxl=max(l[i],maxl);
    }
    if(sum-maxl>maxl)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;  
    char S[6];
    cin>>S;
    if(S[2] == S[3] && S[4] == S[5]){
    	cout<<"Yes";
    }else{
    	cout<<"No";
    }


        return 0;

}


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

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int q; cin >> q;
	while(q--) {
		int k; cin >> k;
		int64_t d = 0, m = 0, dm = 0;
		int64_t dmc = 0;
		for(int i = 0; i < n; ++i) {
			char c = s[i];
			if(c == 'D') {
				++d;
			}
			if(c == 'M') {
				++m;
				dm += d;
			}
			if(c == 'C') {
				dmc += dm;
			}
			if(i - k + 1 >= 0) {
				c = s[i - k + 1];
				if(c == 'D') {
					--d;
					dm -= m;
				}
				if(c == 'M') {
					--m;
				}
			}
			// cerr << s[i] << " " << d << " " << m << " " << dm << " " << dmc << '\n';
		}
		cout << dmc << '\n';
	}
	return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int k,a,b;
  cin>>k;
  cin>>a>>b;
  for(int j=0;j<1000;j++){
    if(a<=k*j && k*j<=b){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
}

Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main () {
  long long a,b=500,v=0,g=5,d,e;
  cin >> a;
  while(a>=b){
    a=a-b;
    v=v+1000;
  }
    while(a>=g){
     a=a-g;
      v=v+5;
    }
  cout << v << endl;
 return 0; 
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC169C2
#include <iostream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    long long A,iB,ans;
    string B;
    cin>>A>>B;
    iB=(B.at(0)-'0')*100+(B.at(2)-'0')*10+(B.at(3)-'0'); // 文字列として読み込み、整数にする
    
    ans=A*iB/100; // 整数同士の割り算なので、少数以下は切り捨てられる
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> l(n),r(n);
  int sum = 0;
  for(int i = 0;i < n;i++){
    cin >> l[i] >> r[i];
    sum += r[i] - l[i] + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	string s, t;
	cin>>s>>t;
	ll a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(u==t){
		b--;
	}
	if(u==s)
		a--;
	cout<<a<<" "<<b;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
/*                        
                            In the name of Almighty ALLAH

   code from :::::::::::::::::::::
   ******************************* R E S H A D ********************************
   
   
   
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
                 FREE PALESTINE           FREE PALESTINE            FREE PALESTINE 
                 
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
                 FREE PALESTINE           FREE PALESTINE            FREE PALESTINE
                 
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
 
*/     

#include <bits/stdc++.h>

#define ll               long long
#define db               double
#define Pi               2*acos(0.0)
#define pb(a)            push_back(a)
#define VI               vector <int>
#define FASTIO           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull              unsigned long long
#define all(a)           a.begin(),a.end()
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define TEST_CASE(t)     for(int z=1;z<=t;z++)
// 90 degree = acos(x)*180/acos(0.0)

using namespace std;

int main() {
    
    FASTIO;
    
    char c;
    ll sum = 0;
    while(cin >> c){
        sum += (c-'0');
    }
    
    if(sum%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
	return 0;
}

Measured memory_bytes: 3656
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));
		int n,s=0;
		String[] str;
		long[] hen=new long[3];
		n=Integer.parseInt(br.readLine());
		StringBuilder out=new StringBuilder();
		for(int i=0;i<n;i++){
			str=br.readLine().split(" ");
			long max=0;
			for(int j=0;j<3;j++){
				hen[j]=Integer.parseInt(str[j]);
				if(max<hen[j]){	max=hen[j];	s=j;}
			}
			hen[s]=0;
			if(max*max == hen[0]*hen[0]+hen[1]*hen[1]+hen[2]*hen[2]){
				out.append("YES" + "\n");
			}else out.append("NO"+"\n");
		}
		out.delete(out.length()-1,out.length());
		System.out.println(out);
	}
}

Measured memory_bytes: 20100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  sort(A.rbegin(), A.rend());
  for (int i = 0; i < min(N, K); i++) {
    A[i] = 0;
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
const main = (inputs) => {
  var array = String(inputs[0]).split('');
  for(var i = 0; i < array.length; i++){
    if((i+1)%2 != 0){
      if(array[i] === 'R' || array[i] === 'U' || array[i] === 'D'){

      }
      else{
        console.log('No');
        return false;
      }
    }
    else{
      if(array[i] === 'L' || array[i] === 'U' || array[i] === 'D'){

      }

      else{
        console.log('No');
        return false;
      }
    }
  }
  console.log('Yes');
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

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

using namespace std;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-')
			f = -1;
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
	}
	return x * f;
}

int main() {
	int n = rd(), k = rd();
	for (int i = -(n - 1); i <= n - 1; i ++ ) {
		printf("%d ", k + i);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int n, m;
  int k, a;
  int x[31] = {};
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> a;
      x[a]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    if (x[i] == n) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int h,w,k;
int main(){
    cin>>h>>w>>k;
    w--;k--;
    //h 100 w 8
    /*
    w--,k--で考えるよ
    右移動-左移動=kならokだけどそれ使うか？
    まぁDPだろう
    縦の上からj cmまでのところで左からk本目までのとこに行くのは
    何通りかどうかを考えるんじゃないか？
     */
    ll dp[105][10]={};
    dp[0][0]=1;
    //f自由にしていいところの数
    ll *f;
    ll dum[21];
    f=dum+10;
    for(int i=-10;i<11;i++){
        f[i]=1;
    }
    f[1]=2;f[2]=3;f[3]=5;f[4]=8;f[5]=13;f[6]=21;f[7]=34;f[8]=55;f[9]=89;f[10]=144;
    for(int i=0;i<h;i++){
        for(int j=0;j<=w;j++){
            dp[i+1][j]=(dp[i+1][j]+(dp[i][j]*(f[w-j-1]*f[j-1])%mod)%mod)%mod;

            if(j+1<=w){
                dp[i+1][j+1]=(dp[i+1][j+1]+(dp[i][j]*(f[w-j-2]*f[j-1])%mod)%mod)%mod;
            }

            if(j-1>=0){
                dp[i+1][j-1]=(dp[i+1][j-1]+(((dp[i][j]*f[w-j-1])%mod)*f[j-2])%mod)%mod;
            }

        }
    }
    cout<<dp[h][k]<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

struct SegTree {
	std::vector<int> data;
	int n;
	SegTree(int n_) {
		for (n = 1; n < n_; n *= 2);
		data.resize(2 * n);
	}
	int sum(int l, int r) {
		int res = 0;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) r--, res += data[r];
			if (l & 1) res += data[l], l++;
		}
		return res;
	}
	void add(int i, int val) {
		for (i += n; i; i >>= 1) data[i] += val;
	}
};

int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int l = -1, r = 1000000001;
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		int b[n + 1];
		b[0] = n;
		for (int i = 0; i < n; i++) b[i + 1] = b[i] + (a[i] <= m ? 1 : -1);
		SegTree tree(2 * n + 1);
		tree.add(b[0], 1);
		int64_t num = 0;
		for (int i = 1; i <= n; i++) {
			num += tree.sum(0, b[i]);
			tree.add(b[i], 1);
		}
		if (num > (int64_t) n * (n + 1) / 4) r = m;
		else l = m;
	}
	std::cout << r << std::endl;
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;
const ll MAXx=1e5+5;

ll d[MAXn];
ll dp[MAXn][MAXx];
int main(){
    IOS();
    ll n,x;
    cin >> n >> x;
    REP (i,n) cin >> d[i];
    sort(d,d+n);
    REP (i,x+1) dp[0][i] = i;
    REP1 (i,n) {
        REP (j,x+1) {
            dp[i][j] = (dp[i-1][j%d[i-1]] + dp[i-1][j] * (i-1)) % MOD;
        }
    }
    cout << dp[n][x] << endl;
}


Measured memory_bytes: 157952
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	long[] as = rlong(n);
	
	long[] sum = [0];
	foreach(a; as) sum ~= sum[$ - 1] + a;
	
	long total = sum[$ - 1];
	long best = total;
	foreach(s; sum) best = min(best, abs(total - s * 2));
	
	best.writeln;
}


Measured memory_bytes: 11540
def inpl():
    return input().split()

n = int(input())
a = list(map(int, inpl()))
d = {}
for i in range(n):
    d[a[i]] = d.get(a[i], 0) + 1

ans = 0
for k in d.keys():
    b = 0
    b += d.get(k - 1, 0)
    b += d.get(k, 0)
    b += d.get(k + 1, 0)
    ans = max(ans, b)
print(ans)

Measured memory_bytes: 13964
// Shift-JIS（シフトジス）

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N = 0, sr = 0, sb = 0;
    cin >> N;
    string s;
    cin >> s;
    char c;
    for (int i = 0; i < N; i++) {
        c = s.at(i);
        if (c == 'R') {
            sr++;
        } else {
            sb++;
        }
    }
    if (sr > sb) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

typedef vector<int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
#define sz(a)  int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define forn(i,n) for(int i=0;i<n;++i)
#define foru(i,n) for(int i=1;i<=n;++i)
#define fortr(i,v) for(auto &i:v)
#define set(n) __builtin_popcount(n)
#define ll long long
#define MOD 1000000007

int main()
{
	ll n,m;
	cin>>n>>m;
	if(n==m)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define nmax 100005
#define inf 999999999
#define lld long long
#define ld long double
using namespace std;

pair<int,bool>pro[nmax];

int main(){
    int n, m, nr;
    string ver;
    cin>>n>>m;
    int a1 = 0, a2 = 0;
    for (int i=1;i<=m;++i){
        cin>>nr>>ver;
        if (ver == "AC"){
            pro[nr].second = true;
        } else {
            if (pro[nr].second == false){
                ++pro[nr].first;
            }
        }
    }
    for (int i=1;i<=n;++i){
        if (pro[i].second){
            ++a1;
            a2 += pro[i].first;
        }
    }
    cout<<a1<<' '<<a2<<'\n';
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int a, b;
    cin>>a>>b;
    int ans=max({a+b,a-b,a*b});
    cout<<ans<<"\n";



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<vector<int>> G;
vector<ll> A;

void no(){
    output("NO");
    exit(0);
}

ll dfs(int par = -1, int cur = 0){
    vector<ll> B;
    ll sum = 0;
    if(G[cur].size() == 1){
        if(G[cur][0] == par){
//            cout << par << "," << cur << ":" << A[cur] <<  endl;
            return A[cur];
        }
    }
    
    for(int v: G[cur]){
        if(par == v) continue;
        ll d = dfs(cur, v);
        B.pb(d);
        sum += d;
    }
    ll sub = sum - A[cur];
    if(sub < 0){
        no();
    }
    sort(all(B));
    if(sum - B[B.size() - 1] < sub){
        no();
    }
    
    if(cur == 0 && G[cur].size() == 1)
    {
//        cout << par << "," << cur << ":" << sum - A[0] <<  endl;

        return sum - A[0];
    }
//    cout << par << "," << cur << ":" << A[cur] - sub <<  endl;
    if(A[cur] - sub < 0) no();
    return A[cur] - sub;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    G.resize(N);
    A.resize(N);
    rep(i, N){
        cin >> A[i];
    }
    
    rep(i, N - 1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    rep(i, N){
        if(G[i].size() == 2){
            for(int v: G[i]){
                if(G[v].size() <= 2 && A[v] != A[i]){
//                    cout << "shut" << endl;
                    no();
                }
            }
        }
    }
    
    ll d = dfs();
    if(d == 0){
        output("YES");
    }
    else {
        output("NO");
    }
    
    
    return 0;
}

Measured memory_bytes: 17152
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }.toList()

fun main(args: Array<String>) {
    val (H, W) = readInts()
    val a = (0 until H).map { readLine()!! }

    var newMap: List<String>
    newMap = a.filter { it.contains("#") }.toList()
    newMap = (0 until newMap[0].length)
            .filter { v -> newMap.any { s -> s[v] == '#' } }
            .let { indexes ->
                newMap.map { str -> str.filterIndexed { index, str -> indexes.contains(index) } }
            }

    newMap.forEach { println(it) }
}

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

int main(){
        string s;
        int i,j,c,cnt,ans=1e6;
        cin >> s;
        for(i=0;i<2;++i){
                c = i;
                cnt  = 0;
                for(j=0;j<s.length();++j){
                        if((int)s[j]-48!=c) ++cnt;
                        c = (c+1)%2;
                }
                ans = min(ans,cnt);
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
	long long int a, b;
	cin >> a >> b;
	long long int k = 1;
	long long int y;
	y = __gcd(a, b);
	for(long long int i = 2; y >= i && i<= 1000001 ;i++)
	{
		int x = 0;
		while (1)
		{
			if (y % i == 0)
			{
				if (x == 0)
				{
					k++;
					x = 1;
				}
				y = y / i;
				}
			else
			{
				break;
			}
		}
	}
	if (y != 1)
	{
		k++;
	}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,m,a,b,r[100]={0},i;
	scanf("%d %d", &n, &m);
	for(i=0; i<m; i++)
	{
		scanf("%d %d", &a, &b);
		r[a]++;
		r[b]++;
	}
	for(i=1; i<=n; i++)
	printf("%d\n", r[i]);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(int argc, char*argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k;
	cin >>n>>k;
	int items[n][k];
	for (int i =0; i< n ; i++)
		cin >> items[i][0] >> items[i][1];
	
	//Sort the items by weights
	
	vector<vector<unsigned long long>> dp(k+1, vector<unsigned long long>(n+1, 0));
	
	for (int i=1; i<=k; i++) // Iterate over the knapsack weight
	{
		for (int j= 1; j<=n;j++) // iterate all items
		{
			if(items[j-1][0]>i) // is knapsack weight good enough to hold first item?
				dp[i][j] = dp[i][j-1];
			else
				dp[i][j] = max (items[j-1][1]+dp[i-items[j-1][0]][j-1], dp[i][j-1]);
		}
	}
	cout << dp[k][n];
}



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

int main () {
  int a , b , c , d ;
  cin >> a >> b >> c >> d ;
  int dx = c - a , dy = d - b ;
  
  for(int i = 0 ; i < dx ; i++ ) cout << 'R' ;
  for(int i = 0 ; i < dy ; i++ ) cout << 'U' ;
  for(int i = 0 ; i < dx ; i++ ) cout << 'L' ;
  for(int i = 0 ; i < dy ; i++ ) cout << 'D' ;
  cout << 'L' ;
  for(int i = 0 ; i < dy + 1 ; i++ ) cout << 'U' ;
  for(int i = 0 ; i < dx + 1 ; i++ ) cout << 'R' ;
  cout << 'D' ;
  cout << 'R' ;
  for(int i = 0 ; i < dy + 1 ; i++ ) cout << 'D' ;
  for(int i = 0 ; i < dx + 1 ; i++ ) cout << 'L' ;
  cout << 'U' << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  string a;
  cin >>a;
  
  cout << (a[0]=='7' ||a[1]=='7' ||a[2]=='7'?"Yes":"No") << endl;
  
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1);
}
template<typename T> T combination(T n, T k){
    vector<vector<T>> v(n+1, vector<T>(n+1, 0)); //dpテーブル
    REP(i, v.size()){
        v[i][0] = 1; v[i][i] = 1;
    }
    for(int j=1; j<v.size(); j++){
        for(int k=1; k<j; k++){
            v[j][k] = v[j-1][k-1] + v[j-1][k];
        }
    }
    return v[n][k];
}
struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    ll h, w; cin >> h >> w;
    ll ans;
    if(h == 1 || w == 1){
        ans = 1;
        cout << ans << endl;
        return 0;
    }
    if(w%2 == 0 || h%2 == 0){
        ans = w * h / 2;
        cout << ans << endl;
        return 0;
    }else{
        ans = w * h /2 + 1;
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int main()
{
    int n,r;
    cin>>n>>r;
    if(n<10){
        cout<<(10-n)*100+r;
    }
    else cout<<r;
	return 0;
}


Measured memory_bytes: 256