akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto A = RD;
	auto V = RD;
	auto B = RD;
	auto W = RD;
	auto T = RD;

	auto d = abs(A-B);
	auto v = V - W;
	auto ans = v * T >= d; 

	writeln(ans ? "YES" : "NO");
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 2708
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
  long long int b;
  long long int index;
  for(int i=sqrt(n);i>=1;i--)
  {
    if(n%i==0)
    {
      b=n/i;
      index=i;
      break;
    }
  }
  cout<<index+b-2;
}

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

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    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 << 'D';
    for(int i=0; i<dx+1; i++){
        cout << 'R';
    }
    for(int i=0; i<dy+1; i++){
        cout << 'U';
    }
    cout << 'L';
    cout << 'U';
    for(int i=0; i<dx+1; i++){
        cout << 'L';
    }
    for(int i=0; i<dy+1; i++){
        cout << 'D';
    }
    cout << 'R';
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    alice = 0
    bob = 0
    for i in range(N):
        if i % 2 == 0: alice += A[i]
        if i % 2 != 0: bob += A[i]
    print(alice - bob)

if __name__ == "__main__":
    main()


Measured memory_bytes: 61716
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define INF 1e9+5
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
 
int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
int n,w;
cin>>n>>w;
vector<ll>weight(n),val(n);
ll valmax=0;
loop(i,0,n) cin>>weight[i]>>val[i],valmax+=val[i];
// loop(i,0,n) cout<<val[i]<<" ";
vector<ll>dp(valmax+1,INF);
dp[0]=0;
loop(i,0,n){
    for(int value = valmax-val[i]; value >= 0; --value){
        dp[value + val[i]] = min(dp[value + val[i]] ,dp[value] + weight[i]); 
    }
}
ll ans=0;
loop(i,0,valmax+1){
    if(dp[i] <= w) ans=max(ans,(ll) i);
}
cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<int> R(n+1), W(n+1);
    for (int i = 0; i < n; ++i) {
        R[i+1] = R[i] + int(s[i] == 'R');
        W[i+1] = W[i] + int(s[i] == 'W');
    }
    int an = n+11;
    for (int i = 0; i <= n; ++i) {
        // first i is 'R', n-i is 'W'
        int a = W[i];
        int b = R[n] - R[i];
        an = min(an, min(a, b) + abs(a-b));
    }
    cout << an << '\n';
    return 0;
}

Measured memory_bytes: 5144
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int n,m,k;

int main(){
	cin>>n>>m>>k;
	vi a(k);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		for(int j=x-m;j<x+m;j++) if(0<=j&&j<k) a[j]++;
	}
	int res=0;
	for(int i=0;i<k;i++) if(!a[i]) res++;
	cout<<res<<endl;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
#include <fstream>
using namespace std;

int main()
{
    //  freopen("timber_input.txt", "r", stdin);
   // freopen("out3_test.txt", "w", stdout);
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--) {
    ll n1,n2,i,j,w;
    string s,t;
    cin>>s>>t;
    n1=s.length();
    n2=t.length();
    ll dp[n1+5][n2+5];
    for(i=0;i<=n1;i++)
        dp[i][0]=0;
    for(i=0;i<=n2;i++)
        dp[0][i]=0;
    for(i=1;i<=n1;i++)
        for(j=1;j<=n2;j++)
    {
        if(s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
        else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
    stack<char> st;
    i=n1;
    j=n2;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            st.push(s[i-1]);
            --i;
            --j;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                --i;
            else
                --j;
        }
    }
    while(!st.empty())
    {
        cout<<st.top();
        st.pop();
    }
    }

}


Measured memory_bytes: 74080
fn main() {
    let a: i64 = readln();
    let b: i64 = readln();
    let c: i64 = readln();
    let s: i64 = readln();
    let mut answer = 0;
    for a500 in (0..a + 1) {
        for a100 in (0..b + 1) {
            for a50 in (0..c + 1) {
                let x = a500 * 500 + a100 * 100 + a50 * 50;
                if x == s {
                    answer += 1;
                }
            }
        }
    }
    println!("{}", answer);
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 4476
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int N,X;
int x[100002];
int y[100002];

int gcd(int x,int y){
      if(y==0) return x;
      if(x<y) return gcd(y,x);
      return gcd(y,x%y);
}

int main(){
      cin>>N>>x[0];
      rep1(i,N){
            cin>>x[i];
      }
      sort(x,x+N+1);
      rep0(i,N){
            y[i]=x[i+1]-x[i];
      }
      int ans=y[0];
      rep0(i,N){
            ans=gcd(ans,y[i]);
      }
      cout<<ans<<endl;


      return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
inline int lowbit(int x){
    return x & (-x);
}
inline int modadd(int x, int y){
    return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
    return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
    return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, b >>= 1;
    }
    return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

int seg[1050000] = {0}, siz;
int n, k, a[300005], maxi = 0;
void init(){
    n = read(), k = read();
    REP(i, 1, n) a[i] = read() + 1, maxi = max(maxi, a[i]);
    for (siz = 1; siz < maxi; siz <<= 1)
        ;
}
void update(int x, int pos){
    pos += siz - 1;
    seg[pos] = max(seg[pos], x);
    while (pos > 1){
        pos >>= 1;
        seg[pos] = max(seg[pos << 1], seg[pos << 1 | 1]);
    }
}
int _l, _r;
int query(int id, int l, int r){
    if (l > _r || r < _l) return 0;
    if (l >= _l && r <= _r) return seg[id];
    int mid = (l + r) >> 1;
    return max(query(id << 1, l, mid), query(id << 1 | 1, mid + 1, r));
}
void solve(){
    int ans = 0;
    REP(i, 1, n){
        int res = 0;
        _l = max(1, a[i] - k);
        _r = min(maxi, a[i] + k);
        res = query(1, 1, siz);
        ans = max(ans, res + 1);
        update(res + 1, a[i]);
    }
    printf("%d\n", ans);
}
int main(){
    int T = 1;
    while (T--){
        init();
        solve();
    }
    return 0;
}

Measured memory_bytes: 7300
// Aizu Vol-2 0277: Ticket Sales
// 2017.8.6

#include <stdio.h>

int f[] = { 0, 6000, 4000, 3000, 2000 };
int main()
{
	int i = 4, t, n;

	while (i--) {
		scanf("%d%d", &t, &n);
		printf("%d\n", f[t] * n);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
double x=0,y=0,z=0,w=0,n=0,m=0,a=0,b=0;
string s;
std::cin >> x;
rep(i,x){
  std::cin >> y;
  z+=1/y;
}
std::cout << 1/z << '\n';
}


Measured memory_bytes: 256
using System;

namespace C___Digits_in_Multiplication
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            long B = (long)Math.Sqrt(N);

            while(N % B != 0) B--;
            long A = N / B;

            int result = 0;

            while(A != 0)
            {
                A = (long)A/10;
                result++;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int main(){
    int n,x,tmp,min=1001;    cin>>n>>x;
    for(int i = 0; i < n; i++){
        cin>>tmp;
        if(tmp<min)min=tmp;
        x-=tmp;
    }
    cout<<n+x/min<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

ll f(ll n){
    ll res = 1;
    for(int i = 0; i < 5; i++){
        res *= n;
    }
    return res;
}

int main()
{
    ll x; cin >> x;
    ll a = 0;
    for(int i = -1500; i < 1500; i++){
        for(int j = -1500; j < 1500; j++){
            if(f(i)-f(j) == x){
                cout << i << " " << j << endl;
                system("pause");
                return 0;
            }
        }
    }
    system("pause");
}

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

using namespace std;

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

  int p = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
	if (i * 500 + j * 100 + k * 50 == x)
	  p++;
      }
    }
  }
  cout << p << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define mp make_pair
#define pb push_back
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N;
int a[MAXN];
int num[5],cnt[5];
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
        read(a[i]);
        if(!cnt[1] || num[1] == a[i]) {num[1] = a[i];++cnt[1];}
        else if(!cnt[2] || num[2] == a[i]) {num[2] = a[i];++cnt[2];}
        else if(!cnt[3] || num[3] == a[i]) {num[3] = a[i];++cnt[3];}
        else {puts("No");return;}
    }
    if(cnt[1] == N && num[1] == 0) {puts("Yes");return;}
    if(N % 3) {puts("No");return;}
    int t = 0;
    for(int i = 1 ; i <= 3 ; ++i) {
        if(cnt[i] % (N / 3)) {puts("No");return;}
        if(cnt[i] == 2 * N / 3) t ^= 0;
        else t ^= num[i];
    }
    if(!t) puts("Yes");
    else puts("No");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> out(N+1);
    vector<vector<int>> in(N+1);
    vector<double> dp(N+1, 0);
    
    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        out[s].push_back(t);
        in[t].push_back(s);
    }
    
    for (int i = N-1; i >= 1; i--) {
        int n = (int)out[i].size();
        for (int j : out[i]) dp[i] += dp[j];
        dp[i] = dp[i] / n + 1;
    }
    
    double ans = dp[1];
    
    for (int i = N-1; i >= 1; i--) {
        vector<double> dp_cut(N+1, 0);
        for (int j = i+1; j <= N; j++) dp_cut[j] = dp[j];
        int n = (int)out[i].size();
        if (n == 1) continue;
        double cut = 0;
        for (int j : out[i]) {
            cut = max(cut, dp[j]);
            dp_cut[i] += dp[j];
        }
        dp_cut[i] = (dp_cut[i] - cut) / (n - 1) + 1;
        
        for (int j = i-1; j >= 1; j--) {
            int m = (int)out[j].size();
            for (int k : out[j]) dp_cut[j] += dp_cut[k];
            dp_cut[j] = (dp_cut[j] / m) + 1;
        }
        
        ans = min(ans, dp_cut[1]);
    }
    
    printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			B[i] = A[i];
		}
		Arrays.sort(A);
		for (int i=0;i<N;i++) {
			if (B[i]==A[N-1]) {
				System.out.println(A[N-2]);
			} else {
				System.out.println(A[N-1]);
			}
		}
	}
}

Measured memory_bytes: 87104
#include <iostream>
#include <vector>
#include <memory>

int main()
{
    int N;
    long long K;
    std::cin >> N >> K;
    std::vector<int> dir(N + 1);
    for (int i = 1; i <= N; i++)
    {
        int A;
        std::cin >> A;
        dir[i] = A;
    }
    std::vector<long long> visited(N + 1);
    for (auto &&e : visited)
        e = -1;
    int pos = 1;
    visited[1] = 0;
    for (long long i = 1; i <= K; i++)
    {
        pos = dir[pos];
        if (visited[pos] == -1)
        {
            visited[pos] = i;
        }
        else
        {
            long long diff = i - visited[pos];
            i += (K - i) / diff * diff;
        }
    }
    std::cout << pos << std::endl;
}

Measured memory_bytes: 5620
import sys
#sys.setrecursionlimit(10**6)
def input():
	return sys.stdin.readline()[:-1]

n, q = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)

queries = [0 for _ in range(n)]
for _ in range(q):
	p, x = map(int, input().split())
	queries[p-1] += x

ans = [0 for _ in range(n)]

st = [(0, 0, -1)]
while st:
	l = st.pop()
	ans[l[0]] = l[1] + queries[l[0]]
	for v in adj[l[0]]:
		if v != l[2]:
			st.append((v, ans[l[0]], l[0]))

print(*ans)

Measured memory_bytes: 110628
import sys
sys.setrecursionlimit(int(2e9))
class obj:
    def __init__(self, N):
        self.fa = [i for i in range(N)]
    def find(self, x):
        if x == self.fa[x]:
            return x
        else:
            self.fa[x] = self.find(self.fa[x])
            return self.fa[x]

N = int(input())
node = [{"x":0, "y":0, "id":i} for i in range(N)]
edge = [{"u":0, "v":0, "d":0} for i in range(2*(N-1))]
ob = obj(N)
for i in range(N):
    node[i]["x"], node[i]["y"] = map(int, input().split())
    node[i]["id"] = i

xnode = sorted(node, key=lambda x:x["x"])
for i in range(N-1):
    edge[i]["u"] = xnode[i]["id"]
    edge[i]["v"] = xnode[i+1]["id"]
    edge[i]["d"] = xnode[i+1]["x"] - xnode[i]["x"]
ynode = sorted(node, key=lambda x:x["y"])
for i in range(N-1):
    edge[i+N-1]["u"] = ynode[i]["id"]
    edge[i+N-1]["v"] = ynode[i+1]["id"]
    edge[i+N-1]["d"] = ynode[i+1]["y"] - ynode[i]["y"]
dedge = sorted(edge, key=lambda x:x["d"])
ans = 0
for i in range(2*(N-1)):
    if ob.find(dedge[i]["u"]) != ob.find(dedge[i]["v"]):
        ans += dedge[i]["d"]
        ob.fa[ob.fa[dedge[i]["u"]]] = ob.fa[dedge[i]["v"]]
print(ans)

Measured memory_bytes: 194944
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int main(){
  int n, m;
  while (cin >> n >> m, n | m){
    vector<int> a(n + m);
    rep(i, n + m) cin >> a[i];
    a.push_back(0);
    sort(all(a));
    a.erase(unique(all(a)), end(a));
    int res = 0;
    rep(i, a.size() - 1) chmax(res, a[i + 1] - a[i]);
    cout << res << endl;
  }
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m,x; cin>>n>>m>>x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    rep(i,n) {
        cin>>c[i];
        rep(j,m) cin>>a[i][j];
    }

    ll ans = LINF;
    for (int bit = 0; bit < (1<<n); ++bit) {
        ll tmp = 0;
        vector<int> t(m);
        rep(i,n) if (bit & (1<<i)) {
            tmp += c[i];
            rep(j,m) {
                t[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) {
            if (t[j] < x) ok = false;
        }
        if (ok) chmin(ans, tmp);
    }

    if (ans==LINF) cout << -1 << '\n';
    else cout << ans << '\n';
    return 0;
}

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

a, b, h, m = [int(x) for x in input().split()]

minutes = h*60 + m

long_ = minutes / (12*60) * 360
short_ = (minutes % 60) / 60 * 360

theta = abs(long_ - short_)
import math
ans = b**2 + a**2 - 2*a*b*math.cos(math.radians(theta))


print(ans**(1/2))

Measured memory_bytes: 62452
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll n; cin >> n;
	if( n % 2 == 1 ){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	ll k = 10;
	while( k <= n ){
		ans += n/k;
		k *= 5;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M;
  cin>>N>>M;
  rep(i,(M+1)/2) cout<<i+1<<" "<<N-i<<endl;
  rep(i,M-(M+1)/2) cout<<(N-1)/2-i<<" "<<(N-1)/2+1+i+1<<endl;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<stdbool.h>

int main(){
 	int a[200010],len=0,sum,t[200010]={0},j,i,n,nb=1;
	scanf("%d",&n);
	
	for(i=2 ; i<=n ; i++)
		scanf("%d",&a[i]);
		
	for(i=2 ; i<=n ; i++){
		t[a[i]]++;
	}
	
	for(i=1 ; i<=n ;i++)
		printf("%d\n",t[i]);
	
	

	
		
	return 0;

}

								


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
constexpr int tv[]={-3,-1,1,3};
constexpr int p10[]={100000000,10000000,1000000,100000,10000,1000,100,10,1};
 
int main(){
    int h,v;
    string a="123456789",b="123456789";
    using data=pair<int,int>;
    
    while(cin>>h>>v, h or v){
        int tc[]={v,h,h,v};
        rep(i,9)cin>>a[i];
        rep(i,9)cin>>b[i];
        int sa=stoi("1"+a)-1000000000,sb=stoi("1"+b)-1000000000;

        unordered_map<int,int> s;

        priority_queue<data> q;
        q.emplace(0,sa);
        
        while(1){
            int cost=q.top().fs;
            int board=q.top().sc;
            if(board==sb){
                cout<<-cost<<endl;
                break;
            }
            q.pop();
            int index=to_string(board).find('0');
            if(index==-1)index=0;
            rep(i,4){
                int fixed=(index+tv[i]+9)%9;
                int next=board;
                int fx=next/p10[fixed]%10;
                next=next-p10[fixed]*fx+p10[index]*fx;
                if((s.find(next)==s.end() || s[next]<cost-tc[i]) && cost-tc[i]>-(h+v)*10){
                    q.emplace(cost-tc[i], next);
                    s[next]=cost-tc[i];
                }
            }
        }
    }
}



Measured memory_bytes: 21272
{-# LANGUAGE ScopedTypeVariables #-}

import Data.Array
import Data.Array.IO
import Data.IORef
import Data.List
import Control.Monad

main = do
    [h, w] <- map read . words <$> getLine :: IO [Int]
    str <- concat <$> replicateM h getLine :: IO String
    (grid :: IOUArray (Int,Int) Char) <- thaw $ (listArray ((1,1),(h,w)) str)
    res <- newIORef False
    forM_ [1..h] $ \i ->
        forM_ [1..w] $ \j -> do
            ((miny,minx), (maxy,maxx)) <- getBounds grid
            r <- readArray grid (i,j)
            ns <- filterM (\p@(ni,nj) -> do
                if (ni < miny || nj < minx || ni > maxy || nj > maxx)
                    then return False
                    else do
                        rn <- readArray grid p
                        return $ rn == '#' 
                ) [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]
            when (null ns && r == '#') $  modifyIORef' res (||True)
    readIORef res >>= \r -> putStrLn $ if r then "No" else "Yes"

Measured memory_bytes: 1020
#include <iostream>
#include <set>
using namespace std;
set<long long>s;
long long n, p;
signed main() {
	cin >> n; for (int i = 0; i < n; i++) { cin >> p; s.insert(p); }
	cin >> n; for (int i = 0; i < n; i++) { cin >> p; cout << s.count(p) << endl; }
}


Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;int a[n];int s[n];
  
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i==0)s[0]=abs(a[i]);
    if(i>=1)s[i]=s[i-1]+abs(a[i]-a[i-1]);
  }
  for(int i=0;i<n;i++){
    int sum=0;
    if(i==0){
      sum+=abs(a[1]);
      sum+=s[n-1]-s[1];
      cout<<sum+abs(a[n-1])<<endl;
    }
    else if(i==n-1){
      sum+=s[n-2];
      cout<<sum+abs(a[n-2])<<endl;
    }
    else{
      sum+=s[i-1];
      sum+=abs(a[i+1]-a[i-1]);
      sum+=s[n-1]-s[i+1];
      cout<<sum+abs(a[n-1])<<endl;
    }
  }
}
    
  

Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int D;
vector<int> c(26);
vector<vector<int>> s;

int main() {
  cin >> D;

  rep(i, 26) { cin >> c[i]; }

  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) { cin >> s[i][j]; }

  vector<vector<int16_t>> last;
  vector<int> parent;
  vector<char> kind;

  using P = pair<int64_t, int>;
  priority_queue<P, vector<P>, greater<P>> q;

  last.push_back(vector<int16_t>(26, -1));
  parent.push_back(-1);
  kind.push_back(-1);
  q.push(P(0, 0));

  const int width = 1'000;
  rep(i, D) {
    priority_queue<P, vector<P>, greater<P>> nxt;

    while (!q.empty()) {
      int64_t z;
      int idx;
      tie(z, idx) = q.top();
      q.pop();

      int64_t penalty = 0;
      rep(j, 26) { penalty += c[j] * (i - last[idx][j]); }

      rep(j, 26) {
        int nidx = last.size();
        int64_t w = z + s[i][j] - penalty + c[j] * (i - last[idx][j]);
        nxt.push(P(w, nidx));
        if (nxt.size() > width) {
          nxt.pop();
        }

        last.push_back(last[idx]);
        last[nidx][j] = i;
        parent.push_back(idx);
        kind.push_back(j);
      }
    }

    q = move(nxt);
  }

  while (q.size() > 1) {
    q.pop();
  }

  int64_t score;
  int idx;
  tie(score, idx) = q.top();
  vector<int> sln;
  while (idx != 0) {
    sln.push_back(kind[idx]);
    idx = parent[idx];
  }
  rrep(i, D) { cout << sln[i] + 1 << "\n"; }
  cerr << score << "\n";

  return 0;
}

Measured memory_bytes: 961368
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define maxn 100005
#define x second
#define y first
#define INF 210000000
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	pii p[maxn];
	for(int i=0; i<n; i++) {
		int x, l;
		cin >> x >> l;
		p[i] = pii(x+l, x-l);
	}
	sort(p, p+n);
	int end = -INF;
	int ans = 0;
	for(int i=0; i<n; i++) {
		if(p[i].x >= end) {
			ans++;
			end = max(end, p[i].y);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
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(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int n,k,a[200];
int dp[200000][3];
int recurs(int k,int pos)
{
	if(k<0) return pos;
	if(dp[k][pos]!=-1) return dp[k][pos];
	int ch;
	for (int i = 0; i <n; ++i)
	{
		ch=recurs(k-a[i],(pos+1)%2);
		if(ch==pos) break;
	}
	dp[k][pos]=ch;
//	cout<<k<<" "<<pos<<" "<<dp[k][pos]<<"\n";
	return dp[k][pos];
}
int main()
{
    ios_base::sync_with_stdio(false);//this works only
    cin.tie(NULL);// when first all inputs are from user
    cout.tie(NULL);//you will see all outputs afterwards
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    int ans=recurs(k,1);
    if(ans==1) cout<<"First";
    else cout<<"Second";
    return 0;
}

Measured memory_bytes: 10368
S = str(input())
ans="Yes"
for i, str in enumerate(S):
    if (i+1)%2==1:#奇数の時
        if not str=="R" and not str=="U" and not str=="D":
            ans="No"
    elif (i+1)%2==0:
        if not str=="L" and not str=="U" and not str=="D":
            ans="No"
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//条件式は=じゃないぞ!!!==だぞ!!!
int main() {
  int N,K,ans;
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    int h;
    cin >> h;
    if (h >= K) {
      ans = ans + 1;
    };
  };
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int cprime=0,num,i,numb[10000],j,b=1;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&numb[i]);
  }
  for(i=0;i<num;i++){
    b=1;
    while(b!=0){
      if(numb[i]==2){
	cprime++;
	b=0;
      }
      if(numb[i]<2||numb[i]%2==0){
	b=0;
      }
      else{
	for(j=2;j<=sqrt((double)numb[i]);j+=1){
	  if(numb[i]%j==0){
	    b=0;
	  }
	}
	if(b==1){
	cprime++;
	b=0;
	}
      }
    }
  }

  printf("%d\n",cprime);
  return 0;
}

Measured memory_bytes: 632
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
long long a[200007];
map<long long,long long>b;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,k;
    cin>>n>>k;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    for(int i=1;i<=n;++i)
        a[i]=(a[i-1]+a[i]-1)%k;
    long long ans=0;
    b[0]=1;
    for(int l=0,r=1;r<=n;++r){
        if(r-l==k)
            --b[a[l++]];
        ans+=b[a[r]];
        ++b[a[r]];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  map<char,int> mp;
  for(int i=0; i<H*W; i++){
    char x;
    cin >> x;
    if(mp.count(x)){
      mp[x]++;
    }
    else{
      mp[x] = 1;
    }
  }
  
  bool flag = true;
  int two = 0;
  int one = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    int x = itr->second;
    if(x %2 != 0){
      one++;
      x--;
    }
    if(x %4 == 0){
      continue;
    }
    else if(x %2 == 0){
      two++;
    }
  }
  
  if(H %2 == 1 && W %2 == 1){
    if(one != 1){
      flag = false;
    }
  }
  else{
    if(one != 0){
      flag = false;
    }
  }
  
  int y = 0;
  if(H %2 == 1){
    y += W/2;
  }
  if(W %2 == 1){
    y += H/2;
  }
  
  if(y < two){
    flag = false;
  }
  
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  vector<ll> c(n-1);
  vector<ll> s(n-1);
  vector<ll> f(n-1);
  rep(i,n-1) cin>>c[i]>>s[i]>>f[i];
  rep(i,n) {
    ll x = 0;
    repeat(j,i,n-1) {
      ll k = (max(s[j],x)+f[j]-1)/f[j];
      x = k*f[j]+c[j];
    }
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, b, t;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> t;
  cout << b * (t/a) << endl;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);

        int billCount = sc.nextInt();
        int answerAmount = sc.nextInt();
        
        for (int i = 0; i <= billCount; i++) {
            for (int j = 0; j <= billCount - i; j++) {
                int k = billCount - i - j;
                int amount = 10000 * i + 5000 * j + 1000 * k;
                if (amount == answerAmount) {
                    System.out.println(i + " " + j + " " + k);
                    return;
                }
            }
        }
        
        System.out.println(-1 + " " + -1 + " " + -1);
    }
}

Measured memory_bytes: 23764
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long d = sc.nextLong();
        long[] x = new long[n];
        long[] y = new long[n];
        int yono = 0;
        for(int i = 0 ; i < n ;i++){
            x[i]= sc.nextLong();
            y[i] = sc.nextLong();
            if(d * d >= x[i] * x[i] + y[i] * y[i]){
                yono++;
            }
        }
        sc.close();
        System.out.println(yono);
    }
}

Measured memory_bytes: 62520
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jiglypuff
#define ld long double
#define itn int
#define pir pair<int, int> 
#define all(x) (x).begin(), (x).end()
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x1, ld y1, ld x2, ld y2)
{
	return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
	return (a * (a + 1LL)) / 2;
}
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };


const int N = 4e5 + 30;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 238;
const ld e = 74e-9;

lli bp(lli a, lli b = mod - 2LL)
{
	lli ret = 1;
	while (b)
	{
		if (b & 1) ret *= a, ret %= mod;
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return ret;
}

int n;
vector<int> g[N];
int sz[N];
lli dp[N][2], f[N];
lli c(int k, int n)
{
	lli ret = f[n];
	ret *= bp(f[k]), ret %= mod;
	ret *= bp(f[n - k]), ret %= mod;
	return ret;
}
void dfs0(int v, int par)
{
	sz[v] = 1;
	for (auto p : g[v])
	{
		if (p == par) continue;
		dfs0(p, v);
		sz[v] += sz[p];
	}
}
void dfs1(int v, int par)
{
	dp[v][0] = 1;
	itn sm = 0;
	for (auto p : g[v])
	{
		if (p == par) continue;
		dfs1(p, v);
		dp[v][0] *= dp[p][0], dp[v][0] %= mod;
		dp[v][0] *= c(sz[p], sz[v] - sm - 1), dp[v][0] %= mod;
		sm += sz[p];
	}
}
void dfs(int v, int par)
{
	for (auto p : g[v])
	{
		if (p == par) continue;
		dp[p][1] = dp[v][1];
		dp[p][1] *= dp[v][0], dp[p][1] %= mod;
		dp[p][1] *= c(n - sz[v], n - sz[p] - 1), dp[p][1] %= mod;
		//if (p == 4) cout << dp[p][1] << endl;
		dp[p][1] *= bp(dp[p][0]), dp[p][1] %= mod;
		//if (p == 4) cout << dp[p][1] << endl;
		dp[p][1] *= bp(c(sz[p], sz[v] - 1)), dp[p][1] %= mod;
		//if (p == 4) cout << dp[p][1] << endl;
		dfs(p, v);
	}
}
int main()
{
	fastio;
	cin >> n;
	f[0] = 1;
	for (lli i = 1; i <= n; i++)
	{
		f[i] = f[i - 1] * i;
		f[i] %= mod;
	}
	//cout << c(1, 2) << endl;
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dp[0][0] = dp[0][1] = 1;
	dfs0(1, 0);
	//for (int i = 0; i < n; i++) cout << sz[i + 1] << " ";
	//cout << endl;
	dfs1(1, 0);
	//for (int i = 0; i < n; i++) cout << dp[i + 1][0] << " ";
	//cout << endl;
	dp[1][1] = 1;
	dfs(1, 0);
	//for (int i = 1; i <= n; i++) cout << dp[i][1] << " ";
	//cout << endl;
	for (int i = 1; i <= n; i++)
	{
		lli ans = (dp[i][0] * dp[i][1]) % mod;
		ans *= c(sz[i] - 1, n - 1), ans %= mod;
		cout << ans << endl;
	}
	return 0;
}


/*
  __
*(><)*
  \/ /
  ||/
--||
  ||
  /\
 /  \
/    \
*/


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		


int main() {

	string s;
	cin >> s;
	int x, y;
	cin >> x >> y;
	int j = 0;
	while (true) {
		if (s[j] == 'F')j++;
		else break;
	}
	x -= j;
	j++;


	int tmp = 0;
	VI v;
	FOR(i, j, s.size()) {
		if (s[i] == 'F')tmp++;
		else {
			v.push_back(tmp);
			tmp = 0;
		}
	}
	if (tmp != 0)v.push_back(tmp);


	VI a, b;
	REP(i, v.size()) {
		if (i % 2 == 0)a.push_back(v[i]);
		else b.push_back(v[i]);
	}

	vector<bool> c(8005, false), d(8005, false);
	c[0] = true;
	d[0] = true;

	REP(i, a.size()) {
		vector<bool> e(8005, false);
		REP(j, 8004) {
			if (c[j]) {
				e[j + a[i]] = true;
				e[abs(j - a[i])] = true;
			}

		}
		c = e;
	}
	REP(i, b.size()) {
		vector<bool> e(8005, false);
		REP(j, 8005) {
			if (d[j]) {
				e[j + b[i]] = true;
				e[abs(j - b[i])] = true;
			}
		}
		d = e;
	}
	if (c[abs(y)] && d[abs(x)])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}


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

typedef long long ll;
typedef vector<ll> vll;

int main() {
    ll n, k;
    cin >> n >> k;
    vll nums(n);
    vll v(40);
    ll mask = 0;
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        for (int j = 39; j >= 0; --j) {
            mask = 1ll << j;
            if (mask & nums[i]) {
                ++v[j];
            }
        }
    }
    ll cur = 0;
    ll curX = k;
    for (int i = 39; i >= 0; --i) {
        mask = 1ll << i;
        if (mask & curX) {
            cur += (n - v[i]) * mask;
        } else {
            cur += v[i] * mask;
        }
    }
    ll ans = cur;
    ll X = curX;
    for (int i = 39; i >= 0; --i) {
        curX = k;
        cur = 0;
        mask = 1ll << i;
        curX = curX & ~(mask);
        if (curX < k) {
            for (int j = 39; j >= 0; --j) {
                mask = 1ll << j;
                if (j >= i) {
                    if (mask & curX) {
                        cur += (n - v[j]) * mask;
                    } else {
                        cur += v[j] * mask;
                    }
                } else {
                    if (v[j] > n - v[j]) {
                        curX = curX & ~(mask);
                        cur += v[j] * mask;
                    } else {
                        curX = curX | mask;
                        cur += (n - v[j]) * mask;
                    }
                }
            }
            if (cur > ans) {
                ans = cur;
                X = curX;
            }
        }
    }
    ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (X ^ nums[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int N;
    cin >> N;
    vector<int>vec(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i);
    }

    int sum_count = 0;
    bool can_mizuyari = true;
    while (can_mizuyari) {
        int count = 0;
        bool mizuyari = false;
        for (int i=0; i<N; i++) {
            if (mizuyari && vec[i] == 0) {
                count += 1;
                mizuyari = false;
            } else if (vec[i] != 0) {
                vec[i] = vec[i] -1;
                mizuyari = true;
            }
        }

        if (mizuyari)  {
            count += 1;
        }

        if (count == 0) {
            can_mizuyari = false;
        }

        sum_count += count;
    }

    cout << sum_count << endl;
    return 0;
}

Measured memory_bytes: 3600