akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define int long long int
#define ss size()
using namespace std;
const int M=1e9+7,maxn=100011;
std::vector<int> adj[maxn];
std::vector<int> v1;
int ans,n,k,m,x,y,q,par[maxn],h[maxn],mach[maxn],sk[maxn];
double dp[3000][3000],ad=0,u;
bool mark[maxn];

int32_t main(){
    cin>>n;
    double a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dp[1][0]=1-a[1];
    dp[1][1]=a[1];
    for(int i=2;i<=n;i++){
        u=(1-a[i]);
        dp[i][0]=(dp[i-1][0]*u);
    }
    for(int i=2;i<=n;i++)
        for(int j=1;j<=i;j++){
            u=1-a[i];
            dp[i][j]=((dp[i-1][j-1]*a[i])+(dp[i-1][j]*u));
        }
    for(int j=(n/2)+1;j<=n;j++)
        ad+=dp[n][j];
    cout<<fixed<<setprecision(10)<<ad;
    return 0;
}


Measured memory_bytes: 74496
import sys
from collections import Counter
from string import ascii_lowercase

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10

class RollingHash:

    """ 文字列stringの部分文字列のハッシュを構築する。O(N) """
    def __init__(self, string):
        self.n = len(string)
        self.BASE = 1234
        self.MASK30 = (1 << 30) - 1
        self.MASK31 = (1 << 31) - 1
        self.MASK61 = (1 << 61) - 1
        self.MOD = self.MASK61
        self.hash = [0] * (self.n + 1)
        self.pow = [1] * (self.n + 1)
 
        for i, char in enumerate(string):
            self.hash[i + 1] = self.calc_mod(self.mul(self.hash[i], self.BASE) + ord(char))
            self.pow[i + 1] = self.calc_mod(self.mul(self.pow[i], self.BASE))
 
    def calc_mod(self, x):
        """ x mod 2^61-1 を返す """
        xu = x >> 61
        xd = x & self.MASK61
        x = xu + xd
        if x >= self.MOD:
            x -= self.MASK61
        return x
 
    def mul(self, a, b):
        """ a*b mod 2^61-1 を返す """
        au = a >> 31
        ad = a & self.MASK31
        bu = b >> 31
        bd = b & self.MASK31
        mid = ad * bu + au * bd
        midu = mid >> 30
        midd = mid & self.MASK30
        return self.calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd)
 
    def get_hash(self, l, r):
        """ string[l,r)のハッシュ値を返すO(1) """
        res = self.calc_mod(self.hash[r] - self.mul(self.hash[l], self.pow[r - l]))
        return res
 
    def merge(self, h1, h2, length2):
        """ ハッシュ値h1と長さlength2のハッシュ値h2を結合するO(1) """
        return self.calc_mod(self.mul(h1, self.pow[length2]) + h2)
 
    def get_lcp(self, l1, r1, l2, r2):
        """
            string[l1:r2]とstring[l2:r2]の長共通接頭辞(Longest Common Prefix)の
            長さを求めるO(log|string|)
        """
        ng = min(r1 - l1, r2 - l2) + 1
        ok = 0
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if self.get_hash(l1, l1 + mid) == self.get_hash(l2, l2 + mid):
                ok = mid
            else:
                ng = mid
        return ok

N = INT()
se = set()
A = []
for i in range(N):
    s = input()
    s = s[::-1]
    rh = RollingHash(s)
    A.append((s, rh))
    se.add(rh.get_hash(0, len(s)))

ch = {}
for c in ascii_lowercase:
    ch[c] = RollingHash(c).get_hash(0, 1)

ans = 0
for s, rh in A:
    C = Counter(s)
    for i in range(len(s)):
        for c in C:
            if rh.merge(rh.get_hash(0, i), ch[c], 1) in se:
                ans += 1
        C[s[i]] -= 1
        if C[s[i]] == 0:
            del C[s[i]]
ans -= N
print(ans)


Measured memory_bytes: 206404
#include<stdio.h>
int main(){
	int N,i,j;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	printf("%d",A[N-1]);
	for(j=N-2;j>=0;j--){
		printf(" %d",A[j]);
	}
	printf("\n");
}


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

int a[110],b[110],n,t;

int main()
{
    scanf("%d%d",&n,&t);
    for(int i=0;i<n;i++)
        scanf("%d%d",&a[i],&b[i]);
    int m=1000000;
    for(int i=0;i<n;i++)
        if(b[i]<=t&&a[i]<m)m=a[i];
    if(m==1000000)printf("TLE");
    else printf("%d",m);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#define PI 3.1415926535897932384626433832795028841971
using namespace std;

int main(){
    
    int a,b;
    char op;
    while(true){
        int ans;
        cin >> a >> op >> b;
        
        if(op == '?'){
            break;
        }
        
        switch(op){
            case '+':
                ans = a + b;
                break;
            case '-':
                ans = a - b;
                break;
            case '*':
                ans = a * b;
                break;
            case '/':
                ans = a / b;
                break;
                
        }
        
        cout << ans << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);double[]a=new double[8];for(int t=s.nextInt(),i;t-->0;System.out.println(((a[7]-a[5])*(a[2]-a[0]))-((a[3]-a[1])*(a[6]-a[4]))==0.0?"YES":"NO"))for(i=8;i-->0;)a[i]=s.nextDouble();}}

Measured memory_bytes: 12000
use proconio::input;
fn main() {
    input! {
        a:usize,
        b:usize,
    }
    let mut cnt = 0;
    for i in a..=b {
        let i_5 = i / 10 / 10 / 10 / 10;
        let i_4 = i / 10 / 10 / 10 - i_5 * 10;
        let i_3 = i / 10 / 10 - i_4 * 10 - i_5 * 100;
        let i_2 = i / 10 - i_3 * 10 - i_4 * 100 - i_5 * 1000;
        let i_1 = i - i_2 * 10 - i_3 * 100 - i_4 * 1000 - i_5 * 10000;
        if i_5 == i_1 && i_4 == i_2 {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 2116
con = 0;
mm = 0;

n = int(input())
a = [input().split() for l in range(n)]
b = [None]*n

for i in range(n):
    if a[i][0] == a[i][1]:
        con = con +1
    else:
        con = 0
    if con == 3:
        mm = 1;
        break;

if mm == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
//#define debug 1

int main() {
	int n,h,w;
	cin>>n>>h>>w;
	cout<<max(0,(n-h+1)*(n-w+1))<<endl;
#ifdef debug
	cout<<"Don't forget ndefine debug!"<<endl;
#endif
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        O: chars,
        E: chars,
    }
    let mut ans = String::new();
    let mut ito = O.into_iter().peekable();
    let mut ite = E.into_iter().peekable();

    loop {
        if let Some(o) = ito.next() {
            ans.push(o);
        }
        if let Some(e) = ite.next() {
            ans.push(e);
        }
        if ite.peek().is_none() && ito.peek().is_none() {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.math.BigInteger;
import java.util.*;
import java.util.TreeMap;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int shopNum = sc.nextInt();
		int drinkNum = sc.nextInt();
		Map<Integer, Integer> drinks = new TreeMap<>();
		for(int i = 0; i < shopNum; i++){
			int key = sc.nextInt();
			try {
				int prev = drinks.get(key);
				drinks.put(key, sc.nextInt()+prev);
			}catch(Exception e) {
				drinks.put(key, sc.nextInt());
			}
		}

		BigInteger ans = BigInteger.ZERO;
		for(Map.Entry<Integer, Integer> entry : drinks.entrySet()) {
			if(drinkNum > entry.getValue()) {
				drinkNum -= entry.getValue();
				ans = ans.add(new BigInteger(entry.getKey().toString()).multiply(new BigInteger(entry.getValue().toString())));
			}else {
				ans = ans.add(new BigInteger(String.valueOf(drinkNum)).multiply(new BigInteger(entry.getKey().toString())));
				break;
			}
		}
		System.out.println(ans);
	}
}




Measured memory_bytes: 95188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int x;
    cin>>x;
    if(x) cout<<0<<endl;
    else cout<<1<<endl;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
	
#define WHATS(var)//cout<<__LINE__<<' '<<#var<<"="<<var<<endl;
	
template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
	os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
	int i=0;
	for(auto it:v){
		if(i > 0){os << ' ';}
		os << it;
		i++;
	} 
	return os;
}

map<long long int, int>soinnsuu(long long int a) {
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;


	return ans;
}
	
int main() {
	ios::sync_with_stdio(false);
	long long  N;cin>>N;
	auto sos=soinnsuu(N);
	int amin=-1;
	amin=sos.size();
	int amax=1;
	for(auto m:sos)amax*=m.second+1;

	cout<<amin<<' '<<amax-1<<endl;
	return 0;	
}


Measured memory_bytes: 3208
while(True):
    ans = 0
    R, N = map(int, input().split())
    R = float(R)
    if R == 0 and N == 0:
        break
    d = []
    for _ in range(N):
        d.append(list(map(float, input().split())))
    for i in range(len(d)-1,-1,-1):
        x,y = d[i][0],d[i][1]
        d[i][0] = (x**2+y**2)**0.5
        d[i].append(x/d[i][0])
        d[i].append(y/d[i][0])
        if d[i][0] <= R:
            ans += 1
            del d[i]
    while(True):
        if not len(d): print(ans); break
        for i in range(len(d)-1,-1,-1):
            d[i][0] -= d[i][3]
            if d[i][0] <= R:
                ans += 1
                del d[i]
        if not len(d): print(ans); break
        d.sort(key=lambda x: x[0])
        for j in range(len(d)-1,0,-1):
            X = d[j][0]*d[j][4]
            Y = d[j][0]*d[j][5]
            if (d[j][4]*d[0][4]+d[j][5]*d[0][5] ) < 0:
                xv = R*d[0][4]
                yv = R*d[0][5]
                if ((X-xv)**2+(Y-yv)**2)**0.5 < d[j][2]:
                    del d[j]
                continue
            if ( abs((d[0][5]*X-d[0][4]*Y)) < d[j][2] ):
                del d[j]
        del d[0]




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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    string s;
    cin >> s;
    int n = s.size() + 1;
    vi lb(n), rb(n);
    for1(i, n - 1) lb[i] = s[i - 1] == '<' ? lb[i - 1] + 1 : 0;
    ford(i, n - 1) rb[i] = s[i] == '>' ? rb[i + 1] + 1 : 0;

    i64 sum = 0;
    forn(i, n) sum += max(lb[i], rb[i]);
    cout << sum << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 4764
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)3e5 + 1;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N], pr[N];
int main (){
  scanf ("%d", &n);
  forn (i, 1, n) scanf ("%d", a + i);
  int sum = 0;
  a[0] = 0, a[n + 1] = 0;
  forn (i, 0, n){
    sum += abs(a[i] - a[i + 1]);
  }
  forn (i, 1, n) pr[i] = sum + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]));
  forn (i, 1, n){
    printf ("%d\n", pr[i]);
  }
  return 0;
}


Measured memory_bytes: 2048
N, M = map(int, input().split())

field = [] 
for i in range(M):
    field.append([False] * N)

for n in range(N):
    row = list(map(int, input().split()))
    row.pop(0)
    for i in row:
        field[i-1][n] = True

cnt = 0
for m in range(M):
    if all(field[m]):
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    
    String a=sc.next();
    String b=sc.next();
    boolean ans=true;
    if(a.length()>b.length()){
      System.out.println("GREATER");
    }else if(a.length()<b.length()){
      System.out.println("LESS");
    }else{
      for(int i=0;i<a.length();i++){
        char aa=a.charAt(i);
        char bb=b.charAt(i);
        if (aa>bb){
          System.out.println("GREATER");
          ans=false;
          break;
        }
        else if(aa<bb){
          System.out.println("LESS");
          ans=false;
          break;
        }
      }
      if(ans==true)System.out.println("EQUAL");
    }
    
  }
}

Measured memory_bytes: 23124
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int a;
	cin >> a;

	cout << a * a * 3 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  string O,E;
  cin >> O;
  cin >> E;
  for(int i=0;i<(int)E.size();i++){
    cout << (char)O[i] << (char)E[i];
  }
  if((int)O.size()!=(int)E.size()){
    cout << (char)O[(int)O.size()-1];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
/**************************
  * Writer : Leo101
  * Problem : AT2396 Infinite Sequence
  * Tags : Dp，递推
**************************/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define File(s) freopen(#s".in", "r", stdin); freopen(#s".out", "w", stdout)
#define gi get_int()
const int Max_N = 2e6, Mod = 1e9 + 7;
int get_int()
{
	int x = 0, y = 1; char ch = getchar();
	while ((ch < '0' || ch > '9') && ch != '-')
		ch = getchar();
	if (ch == '-') y = -1,ch = getchar();
	while (ch <= '9' && ch >= '0') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * y;
}

long long Dp[Max_N];

int main()
{
	int n = gi;
	long long Sum = 0;
	Dp[n] = n; Dp[n - 1] = 1ll * n * n % Mod;
	for (int i = n - 2; i > 0; i--) 
		Sum = (Sum + Dp[i + 3]) % Mod,
		Dp[i] = (Sum + i + 1 + Dp[i + 1] + 1ll * (n - 1) * (n - 1)) % Mod;
	printf("%lld", Dp[1]);

	return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll n, a, b;
    ll f, l;
    cin >> n >> a >> b;

    f = a * (n - 1) + b;
    l = a + b * (n - 1);

    if(l - f + 1 < 0) put(0);
    else put(l - f + 1);
}

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

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main()
{
   int N, K;
   cin >> N >> K;
   if (K == 1)
   {
      cout << 0 << endl;
      return;
   }
   cout << (N - K) << endl;
   return;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


Measured memory_bytes: 256
S = input()

ml = [str(i).zfill(2) for i in range(1, 13)]

if S[:2] in ml:
    if S[2:] in ml:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if S[2:] in ml:
        print("YYMM")
    else:
        print("NA")

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

int main(){
  int h,i,sum=0;
  char s;
  i=0;
  h=0;
  while(cin>>s){
    if(s=='S'&&h==1&&i<0){
      sum+=i*-1;
      i=1;
      h=0;
    }else if (s=='T'){
      i--;
      h=1;
    }else if(s=='S'){
      i++;
      h=0;
    }
  }
  if(i>=0)sum+=i;
  else sum+=i*-1;
  cout<<sum<<endl;
  return 0;
}


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

using namespace std;

struct crop{
  double inc;
  string name;

  bool operator < (const crop &c)const{
    if(c.inc != inc){
      return c.inc < inc;
    }else{
      return c.name > name;
    }
  }

};

int main(){
  int n,P,A,B,C,D,E,F,S,M;
  string L;

  while(cin >> n, n){
    crop data[n];

    for(int i = 0 ; i < n ; i++){
      cin >> L >> P >> A >> B >> C 
	  >> D >> E >> F >> S >> M;

      int Time = A + B + C + D + E;
      Time += (M-1) * (D + E);
      S = S*M*F;

      data[i].name = L;
      data[i].inc = (double)(S-P) / Time;
    }

    sort(data,data+n);

    for(int i = 0 ; i < n ; i++){
      cout << data[i].name << endl;
    }

    cout << "#" << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

void solve(int n,int m){
  int a,b;
  bool p[n+5][n+5],ans[n+5];
  rep(i,n+5)rep(j,n+5){p[i][j]=ans[j]=false;}
  rep(i,m){
    cin>>a>>b;
    p[a][b]=p[b][a]=true;
  }
  REP(i,1,n+1){
    REP(j,1,n+1){
      ans[i]+=p[1][i];
      if(p[1][i]==true&&p[i][j]==true)ans[j]=true;
    }
  }
  int cnt=0;
  REP(i,2,n+1)cnt+=ans[i];
  cout<<cnt<<endl;
}

int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0)break;
    solve(n,m);
  }
  
  return 0;
}



Measured memory_bytes: 3316
#include<iostream>
#include<complex>

using namespace std;

typedef complex<int> C;

int dice[6][4] = {{3, 2, 4, 5}, {1, 3, 6, 4}, {1, 5, 6, 2},
                    {1, 2, 6, 5}, {1, 4, 6, 3}, {2, 3, 5, 4}};

C transfer(int t, int f, int d) {
    if (t == d || t+d == 7) {
        return C(0, 0);
    }
    else if (f == d) {
        return C(0, -1);
    }
    else if (f+d == 7) {
        return C(0, 1);
    }
    else {
        for (int i=0; i<3; i++) {
            if (t == dice[d-1][i] && f == dice[d-1][i+1]) {
                return C(-1, 0);
            }
        }
        if (t == dice[d-1][3] && f == dice[d-1][0]) {
            return C(-1, 0);
        }
        else {
            return C(1, 0);
        }
    }
}

int main() {
    int n, t, f;
    while (true) {
        cin >> n;
        if (n == 0) {
            break;
        }
        int top[400][400] = {};
        int height[400][400] = {};
        for (int i=0; i<n; i++) {
            cin >> t >> f;
            C pos = C(200, 200);
            bool is_transferred = true;
            while (is_transferred) {
                is_transferred = false;
                for (int d=6; d>3; d--) {
                    C moved = pos+transfer(t, f, d);
                    if (height[pos.real()][pos.imag()] > height[moved.real()][moved.imag()]) {
                        is_transferred = true;
                        pos = moved;
                        if (f == d) {
                            f = t;
                        }
                        else if (f+d == 7) {
                            f = 7-t;
                        }
                        t = 7-d;
                        break;
                    }
                }
            }
            top[pos.real()][pos.imag()] = t;
            height[pos.real()][pos.imag()]++;
            //cout << "pos=" << pos << ", t=" << t << ", f=" << f << ", h=" << height[pos.real()][pos.imag()] << endl;
        }
        int count[7] = {};
        for (int i=0; i<400; i++) {
            for (int j=0; j<400; j++) {
                count[top[i][j]]++;
            }
        }
        for (int i=1; i<=6; i++) {
            cout << count[i];
            if (i == 6) {
                cout << endl;
            }
            else {
                cout << ' ';
            }
        }
    }
    return 0;
}

Measured memory_bytes: 2416
N=int(input())
mns=list(map(int,input().split()))
atk=min(mns)
while 1:
    mns=list(filter(lambda x: x!=0, map(lambda x: x%atk, mns)))
    if not mns:
        break
    mns+=[atk]
    atk=min(mns)
print(atk)

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

inline void print(){return;} 
template <typename T, typename... Types> 
inline void print(T var1,Types... var2){cout<<var1<<" ";print(var2...);} 

inline void println(){cout<<"\n";} 
template <typename T, typename... Types> 
inline void println(T var1,Types... var2){cout<<var1<<" ";println(var2...);}

int mod=1e9+7;

main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    
    int n,l;
    cin>>n>>l;

    int s=0,m=mod,k;
    for(int i=0;i<n;i++)
    {
        s+=l+i;
        if(m>abs(l+i))
        {
            m=abs(l+i);
            k=l+i;
        }
    }

    print(s-k);
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    string w; cin >>w;
    vector<int> count(26,0);
    
    for (auto c: w)
        count[c-'a']++;

    Yes(all_of(ALL(count), [](int x){ return x%2==0; }));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
int arr[100004],dp[100006];

int dp_na_pari(int ind)
{
    if(ind==n-1) return 0;
    if(ind>=n) return INT_MAX;

    int ans=INT_MAX;
    if(dp[ind]!=-1)
        return dp[ind];

    for(int i=1;i<=2;i++)
    {
        if(ind+i<n)
          ans=min(ans,abs(arr[ind]-arr[ind+i])+ dp_na_pari(ind+i));
    }
    return dp[ind]=ans;

}

int main()
{

    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<dp_na_pari(0)<<endl;

}


Measured memory_bytes: 9080
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[100];
    for(int i=0;i<n;i++)
        cin >> a[i];
    int als = 0, bb = 0;
    int nokori = n;
    int max, num;
    while(nokori>0){
        max = a[0];
        for(int i=0;i<n;i++){
            if(max <= a[i]){
                max = a[i];
                num = i;
            }
        }
        als = als + max;
        a[num] = 0;
        nokori--;
        max = a[0];
        for(int i=0;i<n;i++){
            if(max <= a[i]){
                max = a[i];
                num = i;
            }
        }
        bb = bb + max;
        a[num] = 0;
        nokori--;
    }

    cout << als - bb << '\n';
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long int64;

class DPredictionAndRestriction {
 public:
  void solve(std::istream &in, std::ostream &out) {
    int n, k, r, s, p;
    string t;
    in >> n >> k >> r >> s >> p;
    in >> t;

    map<char, int> price;
    price['r'] = r;
    price['s'] = s;
    price['p'] = p;

    int64 ans = 0;
    string g = t;
    forn(i, n) {
      char w = getWin(t[i]);
      char prev = '?';
      if (i >= k) {
        prev = g[i - k];
      }
      if (prev == w)g[i] = '?';
      else {
        g[i] = w;
        ans += price[w];
      }
    }
    out << ans << endl;
  }
  char getWin(char c) {
    if (c == 'r')return 'p';
    if (c == 'p')return 's';
    if (c == 's')return 'r';

  }

};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  DPredictionAndRestriction solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define MI          map<int, int>
#define PI          pair<int, int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
ll a[N], BIT[N], b[N], pp[N];
ll maxx(int idx){
    ll ret=-1;
    while(idx){
        ret= max(BIT[idx], ret);
        idx -= (idx&(-idx));
    }
    return ret;
}
void upd(int idx, ll val){
    while(idx<N){
        BIT[idx] = max(BIT[idx], val);
        idx += (idx&(-idx));
    }
}
int main(){
    int n;sc(n);
    fr(i, 1, n) lsc(a[i]);
    fr(i, 1, n) lsc(b[i]);
    ll ans=0;
    fr(i,1,n){
        ll mx = maxx(a[i]);
        if (mx<1) {
//            trace(i, a[i], 0);
            ans = max(ans, b[i]);
            upd(a[i], b[i]);
            //pp[a[i]] = b[i];
        }
        else {
  //          trace(i, a[i], mx);
            ans = max(ans, mx+b[i]);
            upd(a[i], mx+b[i]-pp[a[i]]);
            //pp[a[i]] = mx+b[i];
        }
        //trace(ans);
    }
    lpr(ans);n_l;
    return 0;
}



Measured memory_bytes: 14592
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		ArrayList<Integer> list = new ArrayList<>();
		long N = scan.nextLong();
		double R = Math.sqrt(N);
		int num = 0;
		int ans = 0;

		if(N == 1) {

			System.out.println(0);

		} else {

			for (int i = 2; i <= R; i++) {
				num = power(N, i);
				list.add(num);
				for (int j = 0; j < num; j++) {
					N /= i;
				}
			}
			if (N != 1) {
				ans++;
			}
			for (int i = 0; i < list.size(); i++) {
				ans += times(list.get(i));
			}

			System.out.println(ans);
		}
	}

	public static int power(long N, int i){
		int num = 0;
		while (N % i == 0) {
				N /= i;
				num++;
		}
		return num;
	}

	public static int times(int a) {
		int b = 0;
		if (a == 0) {

		} else if (a < 3) {
			b = 1;
		} else if (a < 6){
			b = 2;
		} else if (a < 10){
			b = 3;
		} else if (a < 15){
			b = 4;
		} else if (a < 21){
			b = 5;
		} else if (a < 28){
			b = 6;
		} else if (a < 36){
			b = 7;
		} else {
			b = 8;
		}
		return b;
	}

}

Measured memory_bytes: 50140
#import numpy as np
import math
n = int(input())
a= list(map(int,input().split()))
a.sort(reverse=1)

ans = a[0]

for i in range(1,n):
    if a[-1] == 0:
        print("0")
        exit()
    elif a[i] > 10**18:
        print("-1")
        exit()
    elif ans > 10**18:
        print("-1")
        exit()
    else:
        ans *= a[i]

if ans > 10**18:
    ans = -1
print(ans)
    
    

Measured memory_bytes: 22660
s=input()
n=len(s)
ans=0
if n%2==0:
    for i in range(0,n//2):
        if s[i]!=s[n-1-i]:
            ans+=1
elif n%2==1:
    for i in range(0,n//2):
        if s[i]!=s[n-1-i]:
            ans+=1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>

using namespace std;

#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)

#define DEB(X) if(mode==1)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(mode==1)cout<< X <<" ";
#define ARDEB(i,X) if(mode==1)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define FORDEB(n,X) if(mode==1)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(mode==1)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};

const int INF=100000000;
int mode=1;

int main(){
	int n,k,x,y,ans=0;
	cin>>n>>k>>x>>y;
	if(n<k){
		cout<<n*x<<endl;
	}
	else cout<<x*k+(n-k)*y<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
// Union Find

template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	vector<T> sizes;
	UnionFind(T n):par(n),rank(n,0),sizes(n,1){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}

	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  sizes[x]=sizes[x]+sizes[y];
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
	T size(T x){
	  return sizes[root(x)];
	}
};
int main(){
  ll n,m;
  cin>>n>>m;
  UnionFind<ll> uf(m+n);
  rep(i,n){
    ll a;
    cin>>a;
    rep(j,a){
      ll b;
      cin>>b;
      b--;
      b+=n;
      uf.unite(i,b);
    }
  }
  ll k=uf.root(0);
  rep(i,n){
    if(i==0) continue;
    if(k!=uf.root(i)){
      COUT("NO");
      return 0;
    }
  }
  COUT("YES");
}

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

// inputで受け取り配列化する
const input = Number(fs.readFileSync("/dev/stdin", "utf8"));

let num = 1;
while (true) {
  const _num = Math.pow(num, 2) + 1 + 1 + 1 + num + num;
  if (_num > input) {
    break;
  }
  num++;
}

const map = new Map();

for (let x = 1; x <= num; x++) {
  for (let y = 1; y <= num; y++) {
    for (let z = 1; z <= num; z++) {
      const sum =
        Math.pow(x, 2) +
        Math.pow(y, 2) +
        Math.pow(z, 2) +
        x * y +
        y * z +
        x * z;
      if (map.has(sum)) {
        const cnt = map.get(sum);
        map.set(sum, cnt + 1);
      } else {
        map.set(sum, 1);
      }
    }
  }
}

for (let index = 1; index <= input; index++) {
  if (map.has(index)) {
    console.log(map.get(index));
  } else {
    console.log(0);
  }
}


Measured memory_bytes: 41236
n, t = map(int, input().split())
tl = list(map(int, input().split()))
ans = 0
tl.append(100000000000)
tmp = 0
for i in range(n):
    if tl[i+1] - tl[i] > t:
        ans += tl[i] - tmp + t
        tmp = tl[i+1]
    else:
        pass
print(ans)

Measured memory_bytes: 30812
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
 
int32_t main()
{
	fast;

	int n, k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.begin(), v.end());
	vector<int> v1(100001, 1);
	vector<int> v2(100001, 1);
	for(int i=1;i<100001;i++)
	{
		v1[i]=(v1[i-1]*i)%mod;
		v2[i]=pow1(v1[i], mod-2);
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int x=i;
		int y=n-i-1;
		if(x>=k-1)
		{
			int w=(v1[x]*v2[x-k+1])%mod;
			w=(w*v2[k-1])%mod;
			w=w*v[i];
			ans=(ans+w)%mod;
		}
		if(y>=k-1)
		{
			int w=(v1[y]*v2[y-k+1])%mod;
			w=(w*v2[k-1])%mod;
			w=w*v[i];
			ans=(ans-w)%mod;
		}
	}
	ans=(ans+2*mod)%mod;
	cout<<ans<<endl;

	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;

  vector<vector<int>> E(N + 1);
  for (int i = 1; i < N; i++) {
    int a, b;
    cin >> a >> b;
    E.at(a).push_back(b), E.at(b).push_back(a);
  }

  vector<int> V(N + 1);
  for (int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    V.at(p) += x;
  }

  function<void(int, int)> dfs = [&](int v, int p) {
    V.at(v) += V.at(p);
    for (int e : E.at(v)) if (p != e) dfs(e, v);
  };

  dfs(1, 0);

  for (int i = 1; i <= N; i++) cout << V.at(i) << "\n";
}

Measured memory_bytes: 26624
N = int(input())
A = list(map(int,input().split()))
ans = 0
r = 0
XOR = 0
SUM = 0
for l in range(N):
  while r < N and XOR^A[r] == SUM+A[r]:
    XOR ^= A[r]
    SUM += A[r]
    r += 1  
  ans += r-l
  XOR ^= A[l]
  SUM -= A[l] 
print(ans)

Measured memory_bytes: 23560
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Greedy Takahashi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll a, b, k;
  scanf("%lld%lld%lld", &a, &b, &k);

  ll d = min(a, k);
  a -= d, k -= d;
  ll e = min(b, k);
  b -= e, k -= e;

  printf("%lld %lld\n", a, b);
  return 0;
}


Measured memory_bytes: 256
//....SARANSH GUPTA....\\  

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(p,n) for(int i=p;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007

int main()
{
    FIO
    string s;
    cin>>s;
    ll sum=0;
    fo(0,s.length())
    {
        sum=sum+(s[i]-'0');
    }
    if(sum%9==0)
    cout<<"Yes";
    else 
    cout<<"No";
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

ll f(ll n){
    if(n == 0) return 0;
    ll bcnt = __builtin_popcountll(n);
    return 1 + f(n % bcnt);
}

ll mod_pow(ll x, ll n, ll m){
    ll res = 1, a = x;
    for(; n>0;a=a*a%m, n>>=1)
        if(n & 1) (res *= a) %= m;
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    string s; cin >> s;

    int bitcnt = count(s.cbegin(), s.cend(), '1');
    vi modx(2, 0);

    rep(i,n){
        if(s[i] == '1'){
            rep(j,2){
                int d = bitcnt + ((j == 0) ? -1 : 1);
                if(d != 0){
                    modx[j] += mod_pow(2, n-i-1, d);
                    modx[j] %= d;
                }
            }
        }
    }
    rep(i,n){
        int x, d;
        if(s[i] == '1'){
            x = modx[0];
            d = bitcnt - 1;
            if(d != 0){
                x += d - mod_pow(2, n-i-1, d);
                x %= d;
            }
        }else{
            x = modx[1];
            d = bitcnt + 1;
            x += mod_pow(2, n-i-1, d);
            x %= d;
        }
        if(d == 0) cout << 0 << endl;
        else cout << f(x) + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3792
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N,M,K = map(int, readline().split())

    F = [[] for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, readline().split())
        F[a].append(b)
        F[b].append(a)
    
    B = [[] for _ in range(N+1)]
    for _ in range(K):
        c,d = map(int, readline().split())
        B[c].append(d)
        B[d].append(c)


    seen = [-1]*(N+1)
    group = 0
    def dfs(G, s):
        stack = [s]
        seen[s] = group
        n_connection = 1 
        
        while stack:
            u = stack.pop()
            for v in G[u]:
                if seen[v] == -1:
                    n_connection += 1
                    seen[v] = group
                    stack.append(v)
    
        return n_connection


    union = {}
    for i in range(1,N+1):
        if seen[i] == -1:
            n = dfs(F, i)
            union[group] = n
            group += 1
            
    ans = []
    for i in range(1,N+1):
        tmp = 0
        tmp += union[seen[i]] - 1
        tmp -= len(F[i])
        for j in B[i]:
            if seen[j] == seen[i]:
                tmp -= 1
        ans.append(tmp)
    
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 51728