akhauriyash/Code-Regression huggingface dataset:
//{
#include<bits/stdc++.h>
using namespace std;
 
#define DEBUG

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif
//}

string solve(ll a, ll b, ll c, ll d) {
    if((abs(a - b) <= d and abs(c - b) <= d) or abs(a - c) <= d) {
        return "Yes";
    } else {
        return "No";
    }
    
}

void Input() {
    rd4(ll, a, b, c, d);
    cout << solve(a,b,c,d);
}

int main() {
	
	fastio;

    // rd1(ll, t);
	ll t = 1;

    while(t--) {
        Input();
    }
    
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long n,m;
    cin>>n>>m;
    string str,t;
    cin>>str>>t;
    long long g=__gcd(n,m);
    long long l=n/g*m;
    bool flag=true;
    n/=g;
    m/=g;
    for(long long i=0;i<g;i++){
        if(str[i*n]!=t[i*m]){
            flag=false;
            break;
        }
    }
    if(flag) 
      cout<<l;
    else 
      cout<<-1;
  return 0;
}

Measured memory_bytes: 3732
import math
import fractions
from typing import List


def compute_prime_factor(n: int) -> None:
    global prime_factors
    sqrt_n = int(math.sqrt(n)) + 1
    for i in range(2, sqrt_n + 1):
        if 0 == (n % i):
            prime_factors.append(i)
            compute_prime_factor(n // i)
            return
    if 1 != n:
        prime_factors.append(n)
        return


def euler_phi(n: int, prime_factors: List[int]) -> int:
    distinct_factors = set(prime_factors)
    result = 1
    for f in distinct_factors:
        result *= (1 - fractions.Fraction(1, f))
    result *= n
    return result.numerator


if __name__ == "__main__":
    n = int(input())
    prime_factors = []  # type: ignore
    compute_prime_factor(n)
    print(euler_phi(n, prime_factors))



Measured memory_bytes: 7532
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        long[] xx = new long[n];
        long[] yy = new long[m];
        for (int i=0;i<n;i++) {
            xx[i] = Long.parseLong(sc.next());
        }
        for (int i=0;i<m;i++) {
            yy[i] = Long.parseLong(sc.next());
        }
        long[] x = new long[n-1];
        long[] y = new long[m-1];
        for (int i=0;i<n-1;i++) {
            x[i]=xx[i+1]-xx[i];
        }
        for (int i=0;i<m-1;i++) {
            y[i]=yy[i+1]-yy[i];
        }
        int mod = 1_000_000_007;
        long x_sum = 0L;
        long tmp_x=n-1;
        long add_x=n-1;
        for (int i=0;i<n-1;i++) {
            if (i<(n-1)/2) {
                if (i!=0) {
                    add_x-=2;
                    tmp_x+=add_x;
                }
                x_sum = (x_sum+tmp_x*x[i])%mod;
            } else {
                if ((n-1)%2==0 && i==(n-1)/2) {
                } else if (i==(n-1)/2){
                    add_x-=2;
                    tmp_x+=add_x;
                } else {
                    if (i!=(n-1)/2+1) {
                        add_x+=2;
                    }
                    tmp_x-=add_x;
                }
                x_sum = (x_sum+tmp_x*x[i])%mod;
            }
        }
        long y_sum = 0L;
        long tmp_y=m-1;
        long add_y=m-1;
        for (int i=0;i<m-1;i++) {
            if (i<(m-1)/2) {
                if (i!=0) {
                    add_y-=2;
                    tmp_y+=add_y;
                }
                y_sum = (y_sum+tmp_y*y[i])%mod;
            } else {
                if ((m-1)%2==0 && i==(m-1)/2) {
                } else if(i==(m-1)/2){
                    add_y-=2;
                    tmp_y+=add_y;
                } else {
                    if (i!=(m-1)/2+1) {
                        add_y+=2;
                    }
                    tmp_y-=add_y;
                }
                // System.out.println("y: " + tmp_y);
                y_sum = (y_sum+tmp_y*y[i])%mod;
            }
        }
        // System.out.println(x_sum + " " + y_sum);
        if (n==2 && m==2) {
            System.out.println(x[0]*y[0]);
        } else {
            System.out.println(x_sum*y_sum%mod);
        }
    }
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int a, b;
    cin >> a >> b;
    if (b % a == 0)
        cout << a + b << endl;
    else
        cout << b - a << endl;

    return 0;
}

Measured memory_bytes: 3500
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let _N: usize = sc.get();
    let M: usize = sc.get();
    let mut ab = Vec::new();
    for _ in 0..M {
        let a: i64 = sc.get();
        let b: i64 = sc.get();
        ab.push((a, b));
    }
    ab.sort_by_key(|&(_, b)| b);
    let mut cur = 0;
    let mut ans = 0;
    for &(a, b) in &ab {
        if cur <= a {
            ans += 1;
            cur = b;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;


int main()
{
    int N,cnt=0,ans=-1;
    cin>>N;
    vector<int>H(N);
    for(int i=0;i<N;i++) cin>>H[i];
    
    for(int i=1;i<N;i++){
        if(H[i-1]>=H[i]){
            cnt++;
        }else if(ans<cnt){
            ans=cnt;
            cnt=0;
        }else{
            cnt=0;
        }
    }
    
    if(ans<cnt)cout<<cnt<<endl;
    else cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = ReadLine();
        var f = true;
        if (N.Length == 1)
        {
            WriteLine(int.Parse(N));
            return;
        }
        for (int i = 1; i < N.Length; i++)
        {
            if (N[i] != '9')
            {
                f = false;
            }
        }
        if (f)
        {
            WriteLine(N.Sum(x => x - '0'));
            return;
        }

        WriteLine((N.Length - 1) * 9 + N[0] - '0' - 1);
    }
}


Measured memory_bytes: 13268
#n,k=map(int,input().split())
from collections import defaultdict
from sys import stdout
n=int(input())
l=list(map(int,input().split()))
x=l[0]^l[1]
for i in range(2,n):
  x^=l[i]
for i in range(n):
  stdout.write(str(x^l[i])+' ')






Measured memory_bytes: 33344
S, K = open(0).read().split()

cGroups = []
tempList = []
for i, c in zip(range(len(S)), S):
    tempList.append(c)
    if (i == len(S) - 1) or c != S[i + 1]:
        cGroups.append(tempList)
        tempList = []

singleResult = 0
for g in cGroups:
    if len(g) > 1:
        singleResult += len(g) // 2

result = singleResult * int(K)

if cGroups[0][0] == cGroups[-1][0] and len(cGroups[0]) % 2 == 1 and len(cGroups[-1]) % 2 == 1:
    if len(cGroups) == 1:
        result += int(K) // 2
    else:
        result += int(K) - 1

print(result)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(void){
    string input;
    
    while(getline(cin, input), !cin.eof()){
        int a, b;
        sscanf(input.c_str(), "%d %d", &a, &b);
        
        if(a < b){
            printf("a < b\n");
        }
        else if(a > b){
            printf("a > b\n");
        }
        else{
            printf("a == b\n");
        }
        
    }
    
    return(0);
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
 
long f(long n) {
  if (n < 10) return n;
  
  long a = 100, b = 1, c = 11; 
  while (true) {
    if (n < a) return n/(a/10)*c + f(n%(a/10))*2;
    a *= 10;
    b *= 2;
    c = 10*c + b;
  }
}

int main() {
  long x;
  cin >> x;
  cout << f(x) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll dp[202020][5];
int main(){
	int n;
	cin>>n;
	ll a[n];
	rep(i,n)cin>>a[i];
	rep(i,n){
		dp[i+1][0]=dp[i][0]+a[i];
		dp[i+1][1]=min(dp[i+1][0],dp[i][1]+a[i]%2+(!a[i])*2);
		dp[i+1][2]=min(dp[i+1][1],dp[i][2]+!(a[i]&1));
		dp[i+1][3]=min(dp[i+1][2],dp[i][3]+a[i]%2+(!a[i])*2);
		dp[i+1][4]=min(dp[i+1][3],dp[i][4]+a[i]);
	}
	cout<<dp[n][4]<<endl;
	return 0;
}


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

int main(void){
  int N;
  cin>>N;
  int cnt=0;
  vector<int> L(N,0);
  for(int i=0;i<N;i++){
    cin>>L[i];
  }
  for(int i=0;i<N-2;i++){
    vector<int> L3(3,0);
    L3[0]=L[i];
    for(int j=i+1;j<N-1;j++){
      if(L[i]==L[j])continue;
      L3[1]=L[j];
      for(int k=j+1;k<N;k++){
        if(L[j]==L[k] || L[i]==L[k])continue;
        L3[2]=L[k];
        vector<int> tmp;
        tmp =L3;
        sort(L3.begin(),L3.end());
        //cout<<"("<<i+1<<","<<j+1<<","<<k+1<<")"<<endl;
        if(L3[0]+L3[1]>L3[2]){
          cnt++;
          //cout<<L3[0]<<" "<<L3[1]<<" "<<L3[2]<<endl;
        }
        L3=tmp;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}

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

namespace ConsoleApp15
{
    class Class42
    {
        static void Main()
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            Dictionary<char, char> rule = new Dictionary<char, char>();
            bool ans = true;
            for(int i = 0; i < S.Length; i++)
            {
                if (!rule.ContainsKey(S[i])) rule[S[i]] = T[i];
                else if (rule[S[i]] != T[i]) ans = false;
            }

            List<char> used = new List<char>();
            foreach(var pair in rule)
            {
                if (!used.Contains(pair.Value)) used.Add(pair.Value);
                else ans = false;
            }
            Console.WriteLine(ans ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 14816
def main():
    n = int(input())
    d = [0 for i in range(n+1)]
    for i in range(1,int(n**0.5)+1):
        for j in range(i,n//i+1):
            if j==i:
                d[i*j]+=1
            else:
                d[i*j]+=2
    ans = 0
    for i in range(n):
        ans += d[i]
    print(ans)

if __name__ == "__main__":
    main()

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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        if (a.at(i) % 2 == 0)
        {
            if ((a.at(i) % 3 == 0) || (a.at(i) % 5 == 0))
            {
            }
            else
            {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  ll A,B,K;cin>>A>>B>>K;
  ll Kcnt=0;
  RREPS(i,min(A,B)){
    if(A%i==0&&B%i==0){
      Kcnt++;
      if(Kcnt==K){
        cout<<i;
        exit(0);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n, k = getList()
    nums = getList()
    ans = 0
    for num in nums:
        if num >= k:
            ans += 1

    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if (s.length() == (size_t)N)
    {
        cout << s.c_str() << endl;
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx) : mx), N);
        }
    }
}

int bfs(int a, int b, int h, int w, char tmp[][101])
{
    int ans[101][101] = {0};
    char c[101][101] = {0};
    queue<pair<int, int>> s;

    for (int i = 0; i <= h; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            c[i][j] = tmp[i][j];
        }
    }

    s.push(make_pair(a, b));

    while (s.size() > 0)
    {

        pair<int, int> tmp = s.front();
        s.pop();
        c[tmp.first][tmp.second] = '#';
        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (tmp.first + i < 1 || tmp.first + i > h)
                {
                    continue;
                }
                if (tmp.second + j < 1 || tmp.second + j > w)
                {
                    continue;
                }
                if (i != 0 && j != 0)
                {
                    continue;
                }
                if (i == 0 && j == 0)
                {
                    continue;
                }
                if (c[tmp.first + i][tmp.second + j] == '#')
                {
                    continue;
                }
                c[tmp.first + i][tmp.second + j] = '#';
                if (ans[tmp.first + i][tmp.second + j] == 0)
                {
                    ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
                }
                else
                {
                    ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1);
                }
                s.push(make_pair(tmp.first + i, tmp.second + j));
            }
        }
    }

    int asd = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            asd = max(a, ans[i][j]);
        }
    }

    return asd;
}

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

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

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

    if (n[0] == '7' || n[1] == '7' || n[2] == '7'){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
import java.math.*;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int x = stdIn.nextInt();
    int a = stdIn.nextInt();
    if(x>=a) {
      System.out.println(10);
    } else {
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e;
  string s,ss,sss;
  cin>>a;
  vi A(a);
  for(auto &aa:A)cin>>aa;
  //sort(ALL(A));
  ll ans=llINF;
  for(int i=0;i<A.size();i++){
    ll mi=0,ma=0;
    for(int j=0;j<A.size();j++){
      if(j<=i)mi+=A[j];
      else ma+=A[j];
    }
    ans=min(ans,abs(ma-mi));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())

edges = [[] for _ in range(N)]
for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

P = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    P[p - 1] += x

ans = [-1] * N
st = deque([(0, 0)])
while st:
    now, val = st.pop()

    if ans[now] >= 0:
        continue
    val += P[now]
    ans[now] = val

    for to in edges[now]:
        st.append((to, val))

print(*ans)

Measured memory_bytes: 68716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1e18;

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;
map<int,int> m;
vector<int> a(200050);
int len=0;
int len2=0;
void dfs(int i){
    if(m.count(i) == 1 and m[i] >1){
        return;
    }
    if(m.count(i) == 0)len++;
    if(m.count(i) == 1)len2++,len--;
    m[i]++;
    dfs(a[i]);
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>a[i];a[i]--;
    }
    dfs(0);
    ll one = len;
    if(k <= one){
        int cur = 0;
        for(int i=0;i<min(k,one);++i){
            cur = a[cur];
        }
        cout << cur+1 << endl;
    }else {
        int cur = 0;
        for(int i=0;i<one;++i){
            cur = a[cur];
        }
        k -= one;
        for(int i=0;i<k%len2;++i){
            cur = a[cur];
        }
        cout << cur+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 35536
struct DFS {
    c: Vec<usize>,
    g: Vec<Vec<usize>>,
    extra_size: Vec<i64>,
    ans: Vec<i64>,
}

impl DFS {
    fn new(n: usize, c: Vec<usize>, g: Vec<Vec<usize>>) -> DFS {
        DFS {
            c, g,
            extra_size: vec![0; n],
            ans: vec![n as i64 * (n as i64 + 1) / 2; n],
        }
    }

    fn search(&mut self, t: usize, u: usize) -> i64 {
        let tmp = self.extra_size[self.c[u]];
        let mut main_size = 1;
        for v in self.g[u].clone() {
            if t == v { continue; }
            self.extra_size[self.c[u]] = 0;
            let sub_size = self.search(u, v);
            let x = sub_size - self.extra_size[self.c[u]];
            self.ans[self.c[u]] -= x * (x + 1) / 2;
            main_size += sub_size;
        }
        self.extra_size[self.c[u]] = tmp + main_size;
        main_size
    }
}

fn main () {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let c: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse::<usize>().unwrap() - 1).collect()
    };

    let mut g: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let (a, b): (usize, usize) = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            (
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            )
        };
        g[a].push(b);
        g[b].push(a);
    }

    let mut dfs = DFS::new(n, c, g);
    dfs.search(!0, 0);
    for i in 0..n {
        let x = n as i64 - dfs.extra_size[i];
        dfs.ans[i] -= x * (x + 1) / 2
    }

    println!(
        "{}",
        dfs.ans.iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}

Measured memory_bytes: 51964
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main(){
  int n;
  cin>>n;
  
  int ans=100000;
  rep(i,n){
    ans += ans/20;
    if(ans%1000 != 0) ans=(ans+999)/1000*1000;
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 2964
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def getComb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


N,K = map(int,input().split())
A = sorted([int(i) for i in input().split()])

# ref: https://www.planeta.tokyo/entry/5195/
mod = 10**9+7
fact = [1, 1]
factinv = [1, 1] 
inv = [0, 1]
for i in range(2,N+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

cmb = [0] * (N-K+1)
for i in range(N-K+1):
    cmb[i] = getComb(i+(K-1),K-1,mod)

sum_max = 0
for i in range(K-1,N):
    sum_max = (sum_max + cmb[i-(K-1)] * A[i]) % mod

sum_min = 0
for i in range(N-K,-1,-1):
    sum_min = (sum_min + cmb[(N-K)-i] * A[i]) % mod

answer = sum_max - sum_min
print(answer % mod)

Measured memory_bytes: 22788
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define mo 19930726
using namespace std;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int a[10001],b[10001],c[10001],tot;
int n,k,q,ans=inf;
inline void find(int l,int r)
{
	for(int i=l;i<=r;i++) b[i]=a[i];
	sort(b+l,b+1+r);
	for(int i=l;i<=r-k+1;i++) c[++tot]=b[i];
}
inline void solve(int x)
{
	int cut=1;tot=0;a[n+1]=-inf;
	for(int i=1;i<=n+1;i++){
		if(a[i]<x){
			if(i-cut>=k) find(cut,i-1);
			cut=i+1;
		}
	}
	sort(c+1,c+tot+1);
	if(tot<q) return;
	ans=min(ans,c[q]-c[1]);
}
int main()
{
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) solve(a[i]);
	cout<<ans;
}

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

using namespace std;

typedef vector<int> vi;
typedef long long ll;
#define all(c) begin(c),end(c)

ll f(ll a, ll b) {
//    if (a == 0) return 0;
//    if (b == 0)return 0;

    if (a == b)
        return a;

    if (a < b) {
        ll rem = b % a;
        ll d = b / a;
        if (rem == 0)
            return 2 * (d-1) * a + a;
        return 2 * d * a + f(a, rem);
    } else {
        ll rem = a % b;
        ll d = a / b;
        if (rem == 0)
            return 2 * (d-1) * b + b;
        return 2 * d * b + f(rem, b);
    }

}

auto solve() {
    ll N, X;
    cin >> N >> X;

    return N + f(N - X, X);
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, k;
    scan(n, k);
    auto point = aryread(); // r, s, p
    auto t = readln().chomp().map!(x => "rsp".countUntil(x)).array();

    auto dp = new long[][](3, n);
    foreach (i; iota(n))
    {
        foreach (j; iota(3))
        {
            dp[j][i] = (j == (t[i] + 2) % 3) ? point[j] : 0;
            if (i >= k)
                dp[j][i] += max(dp[(j + 1) % 3][i - k], dp[(j + 2) % 3][i - k]);
        }
    }
    long ans;
    foreach (i; iota(k))
    {
        ans += only(dp[0][$ - 1 - i], dp[1][$ - 1 - i], dp[2][$ - 1 - i]).reduce!(max);
    }
    ans.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int main()
{
    int N, A;
    cin >> N >> A;
    int L = A;
    int R = A + N - 1;
    int eat;
    if (R <= 0)
        eat = R;
    else if (0 <= L)
        eat = L;
    else
        eat = 0;

    int ans = (R + L) * (R - L + 1) / 2 - eat;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N, M;
int PAR[100000];
int RANK[100000];
int total;

void init(int n){
    REP(i,n) PAR[i] = i;
}

int find(int x){
    if(PAR[x] == x){
        return x;
    }else{
        return PAR[x] = find(PAR[x]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y){
        return;
    }else{
        total--;
        if(RANK[x] < RANK[y]) PAR[x] = y;
        else{
            PAR[y] = x;
            if(PAR[x] == PAR[y]) RANK[x]++;
        }
    }
}

int main(void){
    cin >> N >> M;
    init(N);
    total = N;
    int x, y, z;
    REP(i,M){
        cin >> x >> y >> z;
        x--;
        y--;
        unite(x, y);
    }
    cout << total << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x)
{
    while (x->left != NIL) x = x->left;
    return x;
}

Node treeMaximum(Node x)
{
    while (x->right != NIL) x = x->right;
    return x;
}

Node treeSearch(Node x, int k)
{
    if (x == NIL || k == x->key) return x;
    if (k < x->key) return treeSearch(x->left, k);
    else return treeSearch(x->right, k);
}

Node treeSuccessor(Node x)
{
    if (x->right != NIL) return treeMinimum(x->right);
    Node y = x->parent;
    while (y != NIL && x == y->right)
    {
        x = y;
        y = y->parent;
    }
    return y;
}

//void treeDelete(Node z){
//  Node y; // node to be deleted
//  Node x; // child of y
//
//
//
//}

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
  
    while (x != NIL)
    {
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    
    z->parent = y;
    
    if (y == NIL) root = z;
    else if (z->key < y->key) y->left = z;
    else y->right = z;
}

void inorder(Node u)
{
    if (u != NIL)
    {
        inorder(u->left);
        printf(" %d", u->key);
        inorder(u->right);
    }
}
void preorder(Node u)
{
    if (u != NIL) 
    {
        printf(" %d", u->key);
        preorder(u->left);
        preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");}
//    } else if ( com[0] == 'd' ){
//      scanf("%d", &x);
//      treeDelete(treeSearch(root, x));
//    }
  }

  return EXIT_SUCCESS;
}



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

long long node[101000];
long long n,m,a,b;

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

    cin>>n>>m;
    for(int i = 0 ; i < m ; i++){
        cin>>a>>b;
        node[a]++;
        node[b]--;
    }
    long long sum = 0;
    for(int i = 1; i <= n; i ++){
        sum += node[i];
        if (sum%=2){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  int v[5];
  for(int i = 0; i < 5; i++) cin >> v[i];
  sort( v, v + 5 );
  reverse(v, v + 5);
  cout << v[0];
  for(int i = 1; i < 5; i++) cout << " " << v[i];
  cout << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define ull         unsigned long long int
#define ll          long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> 
 
const long long INF = (long long) 1e16+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

ll power(ll x,ll y){
  ll res=1;
  while(y>0){
    if(y%2) res=(x*res);
    x=(x*x);    
    y=y/2;
  }
  
  return res;
}
 
ll modinv(ll x){
  return power(x,hell-2);
}

ll gcd(ll a,ll b){
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}    
    
void fastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}     
    
void solve(){
    ll x,k,d;
    cin>>x>>k>>d;
    
    x=abs(x);
    
    ll f1=x/d;
    ll f2=f1++;
    ll f3=f1--;
    
    ll a1=1e16,a2=1e16,a3=1e16;
    
    if(f1<=k and abs(f1-k)%2==0){
        a1=abs(x-f1*d);
    }
    if(f2<=k and abs(f2-k)%2==0){
        a2=abs(x-f2*d);
    }
    if(f3<=k and abs(f3-k)%2==0){
        a3=abs(x-f3*d);
    }
    ll ans=min({a1,a2,a3});
    
    if(ans==1e16){
        cout<<x-k*d;
    }else{
        cout<<ans;
    }
}    
    
int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
   
   while(test--)
   solve();
}    

Measured memory_bytes: 3580
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while(true) {
            String[] tmp = br.readLine().split(" ");
            int n = Integer.parseInt(tmp[0]);
            int x = Integer.parseInt(tmp[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for(int i = 3;i <= n;i++){
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
 
}

Measured memory_bytes: 25000
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
int A,B,C;
int main(){
    cin>>A>>B>>C;

    bool D[101]={};
    int k=A%B;
    int R;
    for(int i=1;i<101;i++){
    	R=(k*i)%B;
    	D[R]=true;
    }
    if(D[C])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 764
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

int C[3];

int main(){
    int N,A,B,Q;
    cin>>N>>A>>B;
    for(int i=0;i<N;i++){
        cin>>Q;
        if(Q<=A) C[0]++;
        else if(Q<=B) C[1]++;
        else C[2]++;
    }
    cout<<min(  C[0], min(C[1],C[2])    )<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int A, B,X;
char op;
int N, M;

int main(){
	cin >> N;
	vector <int> a(N);

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int i = 0,j=0,res;

	while (1) {
	
		res = a[i]; //a[0]3 -> a[3-1]
		if (j > 100000) {
			cout << -1 << endl;  break;//1 a[0]3,a[2]1
		}

		i=a[i]-1;//0 -> 
		j++;

		if (res == 2) {
			cout << j << endl;
			break;
		}
	
		//ループが戻ったら止める　a[0] 3 a[1]4 a[2]1 -> a[0]
	}


	}
	

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

using namespace std;
const int N = 505;

char s[N][N], a[N][N], b[N][N];
int n, m;

void init(){
	scanf("%d%d",&n,&m);
	for(int i = 0; i < n; i++){
		scanf("%s",s[i]);
		strcpy(a[i],s[i]);
		strcpy(b[i],s[i]);
	}
	for(int i = 0; i < n; i++){
		for(int j = 1; j < m - 1; j++){
			if(s[i][j] == '#') continue;
			if(i & 1) a[i][j] = '#';
			else b[i][j] = '#';
		}
		a[i][0] = '#';
		b[i][m - 1] = '#';
	}
	for(int i = 0; i < n; i++){
		printf("%s\n",a[i]);
	}
	printf("\n");
	for(int i = 0; i < n; i++){
		printf("%s\n",b[i]);
	}
}

int main(){
	
	init();
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;

#define MOD 998244353

int main(){
    ll n;
    cin >> n;
    cout << n*n << endl;
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    long long ans = 1LL;
    long long mod = 1e9 + 7;
    for (int i = 1; i <= N; i++)
    {
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline

n, k = map(int, input().split())
kakuritu = 0

for saikoro in range(1, n + 1):
    if(saikoro < k):
        kaisu = math.ceil(math.log2(k / saikoro))
        kakuritu += 2 ** (-1 * kaisu)
    else:
        kakuritu += 1

print(kakuritu/n)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a >> b >> c >> d;
	if (a > c && a - c <= d  ||  a < c && c - a <= d) {
		cout << "Yes" << "\n";
	}
	else if ((a > b && a - b <= d  ||  b > a && b - a <= d) && (b > c && b - c <= d  ||  c > b && c - b <= d)) {
		cout << "Yes" << "\n";
	}
	else if (a == c) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
	std::cin >> e;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int a,b,n,i,j,k,ans=0,x;
	cin>>a>>b>>n;
	x=min(b-1,n);
	ans=(a*x)/b;
	ans-=a*(x/b);
	if(b==1)ans=0;
	cout<<ans;
	getchar();getchar();
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1.1e18; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    string s;
    cin >> s;
    if(s.size()%2!=0){
        cout << "No" << endl;
        return 0;
    }
    rep(i,s.size()){
        if(i%2==0 && s[i]!='h'){
            cout << "No" << endl;
            return 0;
        }
        if(i%2==1 && s[i]!='i'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
import numpy as np
import sys
N, K = map(int,input().split())
h = np.fromstring(input(), dtype=np.int64, sep=' ')

# コスト無限大で初期化
INF = 10**10
dp = np.array([INF]*N)
dp[0] = 0
for i in range(1, N):
  # i番目の梯子までの最小移動コストは、
  # 「i-1番目までの移動コスト」+「i-1番目からi番目への移動コスト」
  # もしくは、
  # 「i-2番目までの移動コスト」+「i-2番目からi番目への移動コスト」
  # ...
  # もしくは、
  # 「i-K番目までの移動コスト」+「i-K番目からi番目への移動コスト」
  # のうち、最も小さいものが、最小移動コストになる
  
  # jをi-Kからi-1まで変化させながら、最小の組み合わせを探す
  # ただし、jが負の値にならないよう注意
  j_min = max(0, i-K)
  dp[i] = np.min(dp[j_min: i] + np.abs(h[i] - h[j_min: i]))

print(dp[N-1])

Measured memory_bytes: 20772
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");

const [n, d]: number[] = input[0].split(" ").map((x: string): number => +x);
const li: number[][] = [];
for(let i=0;i<n;i++){
	li.push(input[i+1].split(" ").map((x:string):number=>+x));
}

function kyori(a, b){
    return (a-b)*(a-b);
}

let ans: number = 0;
for(let i = 0; i<n; i++){
    for(let j = i+1; j<n; j++){
        let temp: number = 0;
        for(let k = 0; k<d; k++){
            temp += kyori(li[i][k], li[j][k]);
        }
        temp = Math.sqrt(temp);
        if (temp === Math.floor(temp)){
            ans ++
        }
    }
}
console.log(ans);

Measured memory_bytes: 7500
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	var r, g []int
	b := map[int]bool{}
	for i, c := range s {
		switch c {
		case 'R':
			r = append(r, i)
		case 'G':
			g = append(g, i)
		case 'B':
			b[i] = true
		}
	}

	var cnt int
	for _, x := range r {
		for _, y := range g {
			var z1, z2, z3 int
			if x > y {
				z1 = 2*y - x
			} else {
				z1 = 2*x - y
			}
			if b[z1] {
				cnt++
			}

			if (x+y)%2 == 0 {
				z2 = (x + y) / 2
				if b[z2] {
					cnt++
				}
			}

			if x > y {
				z3 = 2*x - y
			} else {
				z3 = 2*y - x
			}
			if b[z3] {
				cnt++
			}
		}
	}
	fmt.Println(len(r)*len(g)*len(b) - cnt)
}


Measured memory_bytes: 2012
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,q,c,up,low,t,x,y,arr[3],a,b;
string str;
bool f;

int main()
{
    cin >> n >> t >> q;
    if (n>=q)
        n-=q;
    else
    {
        q-=n;
        n=0;
        if (t>=q)
        t-=q;
        else
            t=0;
    }
    cout << n << " " << t << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
P lft[100005]={P(0,0)},rit[100005]={P(0,0)};
ll lmax[100005]={0},rmax[100005]={0};
int main(){
  int n;
  cin>>n;
  ll c;
  cin>>c;
  vector<P> vec;
  for(int i=0;i<n;i++){
    ll x,v;
    cin>>x>>v;
    vec.push_back(P(x,v));
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<n;i++){
    lft[i+1].first=lft[i].first+vec[i].second;
    lft[i+1].second=vec[i].first;
    rit[n-(i+1)].first=rit[n-i].first+vec[n-(i+1)].second;
    rit[n-(i+1)].second=c-vec[n-(i+1)].first;
    lmax[i+1]=max(lmax[i],lft[i+1].first-lft[i+1].second);
    rmax[n-(i+1)]=max(rmax[n-i],rit[n-(i+1)].first-rit[n-(i+1)].second);
  }
  ll ans=0;
  for(int i=0;i<=n;i++) {
    ll lans=lft[i].first-lft[i].second;
    lans=max(lans,lans-lft[i].second+rmax[i]);
    ll rans=rit[i].first-rit[i].second;
    rans=max(rans,rans-rit[i].second+lmax[i]);
    ans=max({ans,lans,rans});
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nummax 110000
using namespace std;

int main() {
	double ans = 0.0, y, i, N, K, x;
	cin >> N >> K;
	for (i = 1; i <= N; i++)
	{
		x = 0;
		while (1)
		{
			if (i * pow(2, (double)x) >= K)
				break;
			x++;
		}
		x *= -1;
		y = pow(2, (double)x);
		ans += y;
	}
	ans /= N;
	//cout << ans << endl;
	printf("%.10f\n", ans);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int a[100010];
typedef pair <int, int> pii;

int main(int argc, char const *argv[])
{
	/* code */
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	map <int, int> cnt1, cnt2;
	for(int i = 1; i <= n; i += 2) {
		cnt1[a[i]] += 1;
	}
	for(int i = 2; i <= n; i += 2) {
		cnt2[a[i]] += 1;
	}
	int ans = n;
	int mx1 = 0;
	int mx2 = 0;
	vector <pii> v1, v2;
	for(auto i : cnt1) {
		v1.push_back(pii(i.second, i.first));
	}
	for(auto i : cnt2) {
		v2.push_back(pii(i.second, i.first));
	}
	sort(v1.begin(), v1.end());
	reverse(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	reverse(v2.begin(), v2.end());

	ans = min(ans, n - v1[0].first);
	ans = min(ans, n - v2[0].first);

	for(int i = 0; i <= 1; i++) {
		for(int j = 0; j <= 1; j++) {
			if(i < v1.size() && j < v2.size()) {
				if(v1[i].second != v2[j].second) {
					ans = min(ans, n - v1[i].first - v2[j].first);
				}
			}
		}
	}	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6520
n,a,b,c,d = map(int,input().split())
b = max(a,b)-min(a,b)
n -= 1
dif = d-c
for i in range(n%2,n+1,2):
    if c*i-dif*((n-i)//2) <= b <= d*i+dif*((n-i)//2):
        print("YES")
        exit()
print("NO")



Measured memory_bytes: 9052
n = int(input())
s = input().strip()
cnt = {k:0 for k in list(s)}
for k in s:
  cnt[k] = cnt[k] + 1
  
mod = 10 ** 9 + 7
ans = 1
for v in cnt.values():
  ans = (ans * (v+1)) % mod
ans = (ans + mod-1) % mod
print (ans)

Measured memory_bytes: 3956
#include <stdio.h>

#define abs(X) ((X) < 0 ? -(X) : X)
#define swap(X, Y) {int temp = (X); (X) = (Y); (Y) = temp;}

int main()
{
    int a[3];
    int i, j;
    int min_p;

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

    min_p = 0;
    for (i = 0; i < 2; i++) {
        min_p = i;
        for (j = i + 1; j < 3; j++) {
            if (a[min_p] > a[j]) {
                min_p = j;
            }
        }
        swap(a[min_p], a[i]);
    }

    printf("%d\n", abs(a[0] - a[1]) + abs(a[2] - a[1]));

    return 0;
}        


Measured memory_bytes: 128