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


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int k;
	int a,b;
	cin>>k>>a>>b;
	if(a>b) swap(a,b);
	int carr = a%k;
	if(carr==0){
	cout<<"OK";
	return 0;	
	}
	carr = k - carr;
	if(b-a>=carr) cout<<"OK";
	else cout<<"NG";

	
	
	
}

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

const int N = 3e3;

int n;
double val[N], p[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> p[i];
  
  val[0] = 1.0;
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j > 0; j--)
      val[j] = val[j-1] * p[i] + val[j] * (1.0 - p[i]);
    val[0] *= 1.0 - p[i];
  }
  
  double sum = 0.0;
  for(int i = n - (n / 2); i <= n; i++)
    sum += val[i];
  cout << setprecision(13) << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<int,int>
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//#define int unsigned long long
//#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long  
using namespace std;
//using ll = unsigned long long;
ll md=MD;
 
 
ll exp(ll a,ll b){ll r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(int a,int b){if(a<b)return a; return b;}
ll Max(int a,int b){if(a>b)return a; return b;}


int main()
{
	IOS;
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
	{
		cout<<k<<"\n";
	}
	else
	{
		if(k<=a+b) cout<<a<<"\n";
		else cout<<a-(k-a-b)<<"\n";
	}

	return 0;
}

Measured memory_bytes: 3640
N, Y = map(int, input().split())

def otoshidama():
  for i in range(min(N,Y//10000)+1):
    for j in range(min(N-i,(Y-10000*i)//5000)+1):
      k = (Y-10000*i-5000*j)//1000
      if i+j+k == N:
        return i, j, k
  return -1, -1, -1

print(*otoshidama())

Measured memory_bytes: 3060
use std::collections::HashMap;
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let n: usize = read();
  let mut s: Vec<String> = Vec::new();
  for _ in 0..n {
    s.push(read());
  }
  let mut hash = HashMap::new();
  for i in s {
    let count = hash.entry(i).or_insert(0);
    *count += 1;
  }

  let mut sorted_hash: Vec<_> = hash.iter().collect();
  sorted_hash.sort_by(|a, b| b.1.cmp(a.1));

  let max_value = sorted_hash[0].1;

  let mut keys: Vec<&str> = Vec::new();
  for (k, v) in sorted_hash {
    if max_value == v { keys.push(k); }
    if max_value != v { break; }
  }

  keys.sort();

  for i in keys {
    println!("{}", i);
  }
}

Measured memory_bytes: 28164
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    string S;
    ll w;
    cin >> S >> w;
    for (ll i = 0; i < S.size(); i++) {
        if (i % w == 0) {
            cout << S[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

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

	s1,_ := strconv.Atoi(s)
	s2,_ := strconv.Atoi(s)
	s1/=100
	s2%=100

	if s1 < 13 && s1 > 0 {
		if s2 < 13 && s2 > 0 {
			fmt.Println("AMBIGUOUS")
		} else {
			fmt.Println("MMYY")
		}
	} else {
		if s2 < 13 && s2 > 0 {
			fmt.Println("YYMM")
		} else {
			fmt.Println("NA")
		}
	}
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++)a[i]=sc.nextInt();
        int ans = 0;
        for(int i = 0;i<n;i++){
            if(a[a[i]-1]==i+1)ans++;
        }
        System.out.println(ans/2);
    }
}

Measured memory_bytes: 58844
#include <stdio.h>

int n, number[30];

void rec(int sum, int mins, int cnt)
{
	if(sum == n)
	{
		for(int i = 0; i < cnt; i++)
		{
			if(i) { printf(" "); }
			
			printf("%d", number[i]);
		}
		
		printf("\n"); return;
	}
	
	for(int i = mins; i > 0; i--)
	{
		if(sum + i > n) continue;
		
		number[cnt] = i;
		
		rec(sum + i, i, cnt + 1);
		
		number[cnt] = 0;
	}
}

int main()
{
	while(true)
	{
		scanf("%d", &n);
		
		if(n == 0) { break; }
		
		rec(0, n, 0);
	}
	
	return 0;
}

Measured memory_bytes: 2560
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0
using namespace std;
using ll = long long;

void testcase() {
    ll n, m, k; cin >> n >> m >> k;

    vector<ll> a(n), b(m);

    for (auto &it : a) cin >> it;
    for (auto &it : b) cin >> it;

    rep (i, 1, n-1) a[i] += a[i-1];

    rep (i, 1, m-1) b[i] += b[i-1];
    int res = 0;
    rep (i, -1, n-1) {
        ll val = 0;
        if (i >= 0) {
            val = a[i];
        }
        if (val > k) break;
        ll rem = k - val;

        auto it = lower_bound(b.begin(), b.end(), rem+1);
        int ct = it - b.begin();
        res = max(res, (i+1+ct));
    }
    cout << res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,k;
	cin >> n >>k;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	int dp[100001]={0};
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=2e9;	
		for(int j=i-1;j>=max(0,i-k);j--)
			dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

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

void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    bool ok = false;
    rep(i, n + 1) rep(j, m + 1)
    {
        if (i * (m - j) + j * (n - i) == k)
            ok = true;
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <vector>

using namespace std;

const bool debug = false;

vector<string> query;

vector<string> split(string s, char delim) {
    string cur = "";
    vector<string> ret;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == delim) {
            ret.push_back(cur);
            cur = "";
        } else {
            cur += s[i];
        }
    }
    ret.push_back(cur);
    return ret;
}

void get_query() {
    string query_str;
    getline(cin, query_str);
    query = split(query_str, '.');
}

int level(string s) {
    int cnt = 0;
    for (int i = 0; i < s.size() && s[i] == ' '; i++) cnt++;
    return cnt;
}

string cache = "";
bool get_input(string &s) {
    if (cache != "") {
        s = cache;
        cache = "";
        return true;
    }
    return getline(cin, s);
}

void unget_input(string s) {
    cache = s;
}

string get_key(const string &s) {
    if (debug) cout << "get_key: called with argument " << s << endl;
    string ret = "";
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == ' ') continue;
        if (s[i] == ':') return ret;
        ret.push_back(s[i]);
    }
    if (debug) cout << "ERROR in get_key" << endl;
    if (debug) cout << ret << endl;
    return "FOO";
}

string get_string_value(const string &s) {
    int colon_index = s.find(':');
    return s.substr(colon_index+2);
}

bool is_object(const string &s) {
    return s.size()-1 == s.find(':');
}

string solve() {
    string s;
    int cur_indent = 0;
    for (int i = 1; i < query.size(); i++) {
        while(get_input(s)) {
            if (debug) cout << "solve: invoke while loop with s: " << s << endl;
            if (debug) cout << "s's key: " << get_key(s) << endl;
            if (debug) cout << "cur_indent: " << cur_indent << endl;

            if (level(s) == cur_indent && query[i] == get_key(s)) {
                if (i == query.size()-1) {
                    if (is_object(s)) {
                        return "object";
                    } else {
                        return "string \"" + get_string_value(s) + "\"";
                    }
                }
                string t; get_input(t);
                cur_indent = level(t);
                unget_input(t);
                break;
            }
        }
    }
    // ここに来ればそんなプロパティは存在しなかった
    return "no such property";
}


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

Measured memory_bytes: 1320
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)

a = input()
if(len(a)==2):
   print(a)
else:
   print(a[::-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
 ll H;
 cin>>H;

 ll num =1;

 ll ans = 0;

 while(1){
   if(H<=1){
     ans += num;
     break;
   }
   H = H/2;
   ans += num;
   num *= 2; 
 }

 cout<<ans<<endl;
  
}

Measured memory_bytes: 256
x = int(input())
a =[1]
c = 1
n = 2
while c <= 33:
    n = 2
    c += 1
    while c**n<=1000:
        a.append(c**n)
        n += 1
for i in range(len(a)):
    if a[i] > x:
        a[i] = -1000
    else:
        a[i] -= x
print(a[a.index(max(a))]+x)

Measured memory_bytes: 3064
import heapq
import sys

readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    A = list(map(lambda x: -int(x), readline().split()))
    heapq.heapify(A)
    for m in range(M):
        maxA = heapq.heappop(A)
        heapq.heappush(A, -(-maxA//2))
    ans = -sum(A)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14204
A = input()
n = len(A)-1
for i in range(2**n):
  pn = ['-']*n
  for j in range(n):
    if ((i>>j)&1):
      pn[n-1-j] = '+'
  ans = A[0]+pn[0]+A[1]+pn[1]+A[2]+pn[2]+A[3]
  
  if eval(ans) == 7:
    print(ans+'=7')
    break

Measured memory_bytes: 9028
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := newIo()
	n := io.nextInt()
	X := make([]int, n)
	for i := range make([]struct{}, n) {
		X[i] = io.nextInt()
	}
	Y := make([]int, n)
	copy(Y, X)
	sort.Ints(Y)

	a := Y[(n-1)/2]
	b := Y[n/2]

	for i := 0; i < n; i++ {
		if X[i] < b {
			io.println(b)
		} else {
			io.println(a)
		}
	}
	io.flush()
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) flush() {
	_ = io.writer.Flush()
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}

func (io *io) print(a ...interface{}) {
	fmt.Fprint(io.writer, a...)
}

func (io *io) println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> P2;
typedef pair<pair<int, int>, int> P3;
typedef pair<pair<int, int>, pair<int, int>> P4;
#define PB(a) push_back(a)
#define MP(a, b) make_pair((a), (b))
#define M3P(a, b, c) make_pair(make_pair((a), (b)), (c))
#define M4P(a, b, c, d) make_pair(make_pair((a), (b)), make_pair((c), (d)))
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)

template <typename T>
struct BIT
{
    int n;
    vector<T> d;
    BIT(int n = 0) : n(n), d(n + 1) {}
    void add(int i, T x = 1)
    {
        for (i++; i <= n; i += i & -i)
        {
            d[i] += x;
        }
    }
    T sum(int i)
    {
        T x = 0;
        for (i++; i; i -= i & -i)
        {
            x += d[i];
        }
        return x;
    }
    T sum(int l, int r)
    {
        return sum(r - 1) - sum(l - 1);
    }
};
string S;
vector<int> c[26];
vector<P2> V;
BIT<int> bit(200005);

int main()
{
    cin >> S;
    int n = S.size();
    repp(i, 0, n)
    {
        c[S[i] - 'a'].PB(i);
    }
    int z = 0;
    repp(i, 0, 26)
    {
        repp(j, 0, c[i].size())
        {
            if (2 * j >= c[i].size())
                break;
            if (2 * j + 1 == c[i].size())
            {
                ++z;
                V.PB(MP(c[i][j], c[i][j]));
            }
            else
            {
                V.PB(MP(c[i][c[i].size() - 1 - j], c[i][j]));
            }
        }
    }
    if (z > 1)
        return cout << -1 << endl, 0;
    LL ans = 0;
    sort(V.begin(), V.end());
    for (auto u : V)
    {
        ans += bit.sum(u.second - 1) / (u.first == u.second ? 2 : 1);
        bit.add(u.first, 1);
        if (u.first != u.second)
            bit.add(u.second, 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define prime first
#define weight second
#define MP make_pair
#define PB push_back

using namespace std;

int main(){
	
	int student = 0, PC = 0;
	while(cin >> PC >> student && (PC != 0 || student != 0)){
		vector<vector<int> > table(student, vector<int>(720, 0));
		vector<vector<int> > logintime(PC, vector<int>(student));

		int r = 0;
		cin >> r;
		rep(i, r){
			int t, n, m, s;
			cin >> t >> n >> m >> s;

			n--;
			m--;
			t -= 540;

			if(s == 1){
				logintime[n][m] = t;
			}
			else{
				for(int i = logintime[n][m]; i < t; i++){
					if(table[m][i] == 0) table[m][i] = 1;
				}		
			}
		}

		int q = 0;
		cin >> q;
		rep(i, q){
			int t1, t2, m, count = 0;
			cin >> t1 >> t2 >> m;

			t1 -= 540;
			t2 -= 540;
			m--;

			for(int i = t1; i < t2; i++){
				if(table[m][i]) count++;
			}
			cout << count << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 58656
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  int N,A,B; cin>>N>>A>>B;
  string ans="Borys";
  if((B-A)%2==0)
    ans="Alice";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>
#include <functional>

typedef long long lint;

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()
lint* array(lint x) {
	lint *array = new lint[x];
	return array;
};
lint** array2(lint x, lint y) {
	lint **array = new lint*[x];
	rep(i, x)array[i] = new lint[y];
	rep(i, x)rep(j, y)array[i][j] = 0;
	return array;
}
int main() {
	string s;
	getline(cin, s);
	for (char c:s) {
		if ('a' <= c && c <= 'z')c = toupper(c);
		else if ('A' <= c && c <= 'Z')c = tolower(c);
		cout << c;
	}
	cout << "\n";
}


Measured memory_bytes: 3140
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;
  vi h(n);
  REP(i,n){
    cin>>h[i];
    if (h[i]>=k)ans++;
  }

  cout<<ans<<endl;
  return 0;
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B

vector<int> map[100];
int found[100];
int finish[100];
bool visit[100];

int dfs(int x, int t) {
	found[x] = t;
	visit[x] = true;
	for (int i = 0; i < map[x].size(); i++) {
		if (visit[map[x][i]]) continue;
		t = dfs(map[x][i], t + 1);
	}
	finish[x] = ++t;
	return t;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		cin >> a >> c;
		for (int j = 0; j < c; j++) {
			cin >> b;
			map[a - 1].push_back(b - 1);
		}
	}
	
	int t = 1;
	for (int i = 0; i < n; i++) 
		if (!visit[i]) t = dfs(i, t) + 1;
	
	for (int i = 0; i < n; i++)
		cout << (i + 1) << " " << found[i] << " " << finish[i] << endl;
	return 0;
}

Measured memory_bytes: 1220
import fractions
import math
import sys

fastinput = sys.stdin.readline
gcd = fractions.gcd
N,K=map(int,fastinput().split())
A = [int(i) for i in fastinput().split()]
S = sum(A)
yakusu = []
for i in range(1,math.floor(math.sqrt(S))+1):
    if not S%i:
        yakusu.append(i)
        yakusu.append(S//i)

yakusu.sort(reverse = True)
for kouho in yakusu:
    amaris =[a%kouho for a in A]
    amaris.sort()
    amarisum= sum(amaris)
    y=amarisum // kouho
    if y==0:
        print(kouho)
        break
    else:
        yakuwa = 0
        for i in range(N-y):
            yakuwa += amaris[i]
        if yakuwa <= K:
            print(kouho)
            break
    

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
  int64_t a, b;
  char op;
  cin >> a >> op >> b;

  if (op == '+') {
    cout << a + b << endl;
  } else {
    cout << a - b << endl;
  }
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int h,w;
    cin >> h >> w;

    vector<string> v(h);
    
    rep(i, h){
        cin >> v[i];
    }

    vector<vector<int>> dp(h, vector<int>(w, 10005));

    dp[0][0] = (v[0][0] == '#' ? 1 : 0);
    
    rep(i, h){
        rep(j, w){
            if(i != h - 1){
                if(v[i][j] == '.' && v[i + 1][j] == '#'){
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
                }else{
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
                }
            }

            if(j != w - 1){
                if(v[i][j] == '.' && v[i][j + 1] == '#'){
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
                }else{
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
                }
            }
        }
    }

    cout << dp[h - 1][w - 1] << endl;

    return 0;
}


Measured memory_bytes: 3656
N, Q = map(int, input().split())

tree = [[] for _ in range(N)]
result = [0]*N

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

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

for i in range(N - 1):
    for j in tree[i]:
        result[j-1] += result[i]

print(' '.join(map(str, result)))

Measured memory_bytes: 122316
#include <bits/stdc++.h>
using namespace std;
int main(){
  string o,e;
  cin >> o >> e;
  if(o.size()-e.size()==0){
    for(int i=0; i<o.size(); i++){
      cout << o.at(i) << e.at(i);
    }
  }else{
    for(int i=0; i<o.size()-1; i++){
      cout << o.at(i) << e.at(i);
    }
    cout << o.at(o.size()-1);
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#define maxn 200005
using namespace std;
struct nod
{
	int val,id;
	nod(int a,int b)
	{
		val=a;
		id=b;
	}
	nod(){}
}b[maxn];
bool operator<(nod a,nod b)
{
	return a.val!=b.val ? a.val<b.val : a.id<b.id;
}
int n,maxx=0,minn=123456789;
int a[maxn];
set<nod> s1,s2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),b[i].val=a[i],b[i].id=i;
	sort(b+1,b+1+n);
	for(int i=1;i<=n/2;i++)
		s1.insert(b[i]);
	for(int i=n/2+1;i<=n;i++)
		s2.insert(b[i]);
	maxx=b[n/2].val;
	minn=b[n/2+1].val;
	for(int i=1;i<=n;i++)
	{
		if(s1.find(nod(a[i],i))!=s1.end())
			printf("%d\n",minn);
		else
			printf("%d\n",maxx);
	}
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int MOD=1000000007;

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

    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    vector<int> ans1(n),ans2(n);
    ans1[0]=1;
    ans2[n-1]=1;
    for(int i=1;i<n;i++){
        if(a[i]>a[i-1])ans1[i]=1;
        else ans1[i]=a[i];
    }
    for(int i=n-2;i>=0;i--){
        if(b[i]>b[i+1])ans2[i]=1;
        else ans2[i]=b[i];
    }
    long long ans=1;
    for(int i=0;i<n;i++)ans=ans*min(ans1[i],ans2[i])%MOD;
    for(int i=0;i<n;i++){
        if(ans1[i]==1){
            if(a[i]>b[i])ans=0;
        }
        if(ans2[i]==1){
            if(a[i]<b[i])ans=0;
        }
    }
    cout<<ans<<endl;

}

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

int main(){
    string a, b;
    cin >> a >> b;
    if(a.at(0) == b.at(2) &&
       a.at(1) == b.at(1) &&
       a.at(2) == b.at(0) ) cout << "YES" << endl;
       else cout << "NO" << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int count_bit(int chk_bit, int bit_num){
    int count = 0;

    for(int i=0; i<bit_num; i++)
    {
        if(chk_bit & (1 << i)) count++;
    }

    return count;
}
int main(void){
    int N,M = 0;
    int pattern = 0;

    /* 標準入力 */
    cin >> N >> M;

    std::vector<int> light_flag(M);
    std::vector<int> p_i(M);

    int k = 0; //条件数
    int tmp_sij_bit = 0; //接続するスイッチビット

    /* 標準入力 */
    for(int light_i=0; light_i<M; light_i++)
    {
        cin >> k;
        light_flag[light_i] = 0;

        for(int j=0; j<k; j++)
        {
            cin >> tmp_sij_bit;
            light_flag[light_i] |= (1 << (tmp_sij_bit-1));
        }
    }

    /* 標準入力 */
    for(int i=0; i<M; i++)
    {
        cin >> p_i[i];
    }

    //debug
    // for(int light_i=0; light_i<M; light_i++)
    // {
    //     cout << "light_flag[" << light_i << "]" << light_flag[light_i] << endl;
    // }

    //スイッチN個の組み合わせを全探索
    //Nの範囲は1～10なので、計算量の目安はO(2^10)
    for(int chk_sij_bit=0; chk_sij_bit<pow(2,N); chk_sij_bit++)
    {
        //フラグリセット
        int flag = 0;

        //debug
        //cout << "chk_sij_bit" << chk_sij_bit << endl;

        //点灯するかの確認
        //p_iの値が0->ONするスイッチ数が偶数なら点灯
        //p_iの値が1->ONするスイッチ数が奇数なら点灯
        for(int light_i=0; light_i<M; light_i++)
        {
            //debug
            //cout << "count_bit:" << count_bit( (light_flag[light_i] & chk_sij_bit), N) << endl;

            if( (count_bit( (light_flag[light_i] & chk_sij_bit), N)) % 2 == p_i[light_i] )
            {
                //点灯するならフラグインクリ
                flag++;
            }
            else
            {
                //点灯しないならブレークで次のパターンに以降
                break;
            }
        }
        //全点灯するのでパターン数に追加
        if(flag == M)
        {
            //debug
            //cout << "OK:chk_sij_bit:" << chk_sij_bit << endl;

            pattern++;
        }
    }

    cout << pattern << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
/*-----------------------------------------------------------------------------------------------*/
const int N = 1e9;
int n,k,s;
int main()
{
    _SAD()
    cin>>n>>k>>s;
    rep(i,n)
    {
        if(i<k)
        {
            cout<<s<<" ";
        }
        else
        {
            cout<<(s+1)%N<<" ";
        }
    }
    cout<<nl;

    return 0;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for (int i=0; i<n; i++)
        cin>>a[i];
    vector <bool> dp(k+1);
    for (int i=0; i<=k; i++)
        for (int j=0; j<n; j++)
        {
            if (i>=a[j] && !dp[i-a[j]])
                dp[i]=true;
        }
    puts(dp[k]? "First" : "Second");
}

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

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  string s[h];
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(i,1<<h) {
    rep(j,1<<w) {
      int cnt = 0;
      rep(k,h) {
        rep(l,w) {
          if(!(i & (1<<k)) and !(j & (1<<l)) and s[k][l] == '#') cnt++;
        }
      }
      if(cnt == k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

string DoctorTableAD(char c){
	string s;
	switch( c ){
		case ' ': s = "101"; break;
		case 0x27: s = "000000"; break;
		case ',': s = "000011"; break;
		case '-': s = "10010001"; break;
		case '.': s = "010001"; break;
		case '?': s = "000001"; break;
		case 'A': s = "100101"; break;
		case 'B': s = "10011010"; break;
		case 'C': s = "0101"; break;
		case 'D': s = "0001"; break;
		case 'E': s = "110"; break;
		case 'F': s = "01001"; break;
		case 'G': s = "10011011"; break;
		case 'H': s = "010000"; break;
		case 'I': s = "0111"; break;
		case 'J': s = "10011000"; break;
		case 'K': s = "0110"; break;
		case 'L': s = "00100"; break;
		case 'M': s = "10011001"; break;
		case 'N': s = "10011110"; break;
		case 'O': s = "00101"; break;
		case 'P': s = "111"; break;
		case 'Q': s = "10011111"; break;
		case 'R': s = "1000"; break;
		case 'S': s = "00110"; break;
		case 'T': s = "00111"; break;
		case 'U': s = "10011100"; break;
		case 'V': s = "10011101"; break;
		case 'W': s = "000010"; break;
		case 'X': s = "10010010"; break;
		case 'Y': s = "10010011"; break;
		case 'Z': s = "10010000"; break;
	}
	return s;
}
int myatoi(string bin_s){
	int ret = 0;
	while( bin_s.length() > 0 ){
		ret += (int)((bin_s[0] - '0') * pow(2.0, (double)(bin_s.length() - 1)));
		bin_s.erase(0,1);
	}
	return ret;
}
char DoctorTableDA(string &s){
	int d = myatoi(s);
	char ac[] = " .,-'?";

	for(int i = 0; i < 'Z' - 'A' + 1; i++) if(d == i) return i + 'A';
	for(int i = 0; i < sizeof(ac)/sizeof(*ac); i++) if(i + 26 == d) return ac[i];
	return ' ';
}
string DoctorLovedEncode(string &raw){
	string s;
	string ret;
	for(unsigned int i = 0; i < raw.length(); i++){
		s += DoctorTableAD(raw[i]);
	}
	// padding
	while( s.length() % 5 != 0 ) s += '0';

	for(unsigned int i = 0; i < s.length() / 5; i++){
		string subs = s.substr(i*5,5);
		ret += DoctorTableDA( subs );
	}
	return ret;
}

int main(void){
	while(true){
		string s;

		while( true ){
			char c;
			c = cin.get();
			if( cin.eof() ) return 0;
			if( c == '\n') break;
			else s += c;
		}

		cout << DoctorLovedEncode( s ) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	LL k;
	scanf("%d%lld", &n, &k);
	vector<pii> v(n);
	for(int i = 0; i < n; ++i){
		scanf("%d%d", &v[i].first, &v[i].second);
	}
	sort(ALL(v));
	
	for(int i = 0; i < n; ++i){
		k -= v[i].second;
		if(k <= 0){
			printf("%d\n", v[i].first);
			break;
		}
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
	int i,n;
	long long c,d,e;
	cin >> n;
	vector<long long> a(n+4);
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	for(i=0;i<n+3;i++){
		if(a[n+3-i]==a[n+2-i]){
			c = a[n+3-i];
			d = i;
			break;
		}
	}
	for(i=0;i<n+1-d;i++){
		if(a[n+1-d-i]==a[n-d-i]){
			e = a[n+1-d-i];
			break;
		}
	}
	cout << c*e << endl;
}
	
	

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)

int main()
{
	fast;
	ll n,i,j;
	cin>>n;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n,greater<ll>());
	ll l=0;
	ll ans=a[l];
	l++;
	for(i=2;i<n;i=i+2)
	{
		if(i+1<n)
		{
			ans=ans+a[l]*2;
		}
		else
		{
			ans=ans+a[l];
		}
		l++;
	}
	cout<<ans;
	
    
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
using namespace std;

vector<int> solve(int n, vector<vector<int> > const & g) {
    vector<map<int, int> > memo(n);
    function<int (int, int, int)> count_lt = [&](int i, int parent, int d) {
        if (memo[i].count(d)) return memo[i][d];
        int cnt = 0;
        for (int j : g[i]) if (j != parent) {
            if (j < d) {
                cnt += 1 + count_lt(j, i, d);
            }
        }
        return memo[i][d] = cnt;
    };

    vector<int> c(n, -1);
    function<void (int, int, int)> go = [&](int i, int parent, int d) {
        if (parent == INT_MIN) {
            c[i] = 0;
        } else {
            if (i < d) {
                c[i] = c[parent] - count_lt(i, parent, d) + count_lt(i, parent, max(d, parent));
            } else {
                c[i] = c[parent] + 1                      + count_lt(i, parent, max(d, parent));
            }
        }
        for (int j : g[i]) if (j != parent) {
            go(j, i, max(d, parent));
        }
    };
    go(0, INT_MIN, INT_MIN);

    return c;
}

int main() {
    int n; cin >> n;
    vector<vector<int> > g(n);
    REP (i, n - 1) {
        int a, b; cin >> a >> b;
        -- a;
        -- b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto c = solve(n, g);
    REP3 (r, 1, n) {
        if (r >= 2) cout << ' ';
        cout << c[r];
    }
    cout << endl;
    return 0;
}


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

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            cin = new CommonInput();

            int Q, N;

            Q = cin.GetNextToInt();

            for (int i = 0; i < Q; i++)
            {
                N = cin.GetNextToInt();

                Console.WriteLine(Multiple(N));
            }
        }

        private int Multiple(int x)
        {
            int tmp, max, calcResult, count;
            string tmpS;

            count = 0;
            tmp = x;

            HashSet<int> checker = new HashSet<int>();

            while (tmp > 9)
            {
                if (!checker.Add(tmp))
                {
                    count = -1;
                    break;
                }
                else
                {
                    max = 0;
                    count++;
                    tmpS = tmp.ToString();
                    for (int i = 1; i < tmp.ToString().Length; i++)
                    {
                        calcResult = int.Parse(tmpS.Remove(0, i)) * int.Parse(tmpS.Remove(i, tmpS.Length - i));
                        if (max < calcResult)
                            max = calcResult;
                    }
                    tmp = max;
                }
            }

            return count;
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        public string Line { get; set; }
        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public void GetLine()
        {
            this._i = 0;
            do
            {
                this.Line = Console.ReadLine();
            } while (this.Line == "");

            if (this.Line != null)
                this._s = this.Line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);
        }

        public string GetNext()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            this.GetLine();

            return this._s[this._i++];
        }

        public int GetNextToInt()
        {
            return int.Parse(this.GetNext());
        }

        public long GetNextToLong()
        {
            return long.Parse(this.GetNext());
        }

        public double GetNextToDouble()
        {
            return double.Parse(this.GetNext());
        }
    }
}

Measured memory_bytes: 10112
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	class point{
		double x;
		double y;
		int count = 1;
		point(double x, double y){
			this.x = x;
			this.y = y;
		}
		point norm(double x1, double y1){
			return new point(x1/Math.sqrt(x1*x1+y1*y1),y1/Math.sqrt(x1*x1+y1*y1));
		}
		boolean in(point p){
			return Math.sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y)) < 1.000001 ;
		}
	}
	int overLap(int z1, int z2, point[] p){
		point a = p[z1];
		point b = p[z2];
		if((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) > 4) return Math.max(a.count, b.count);
		point mid = new point((a.x+b.x)/2,(a.y+b.y)/2);
		double r = Math.sqrt(1 - ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))/4);
		point dir = mid.norm((a.y - b.y), -(a.x - b.x));
		point center = new point(mid.x+r*dir.x,mid.y+r*dir.y); 
		point center2 = new point(mid.x-r*dir.x,mid.y-r*dir.y); 
		int cnt = a.count+b.count;
		int cnt2 = a.count+b.count;
//		System.out.println(center2.x+" "+center2.y);
//		System.out.println(center.x + " " + center.y);
//		System.out.println();
		for(int i =0;i<p.length;i++){
			if(i==z1 || i==z2) continue;
			if(center.in(p[i])){
				cnt+= p[i].count;
//				System.out.println("a "+(i+1));
			}
			if(center2.in(p[i])){
				cnt2+= p[i].count;
//				System.out.println("b "+(i+1));
			}
		}
		
		return Math.max(cnt, cnt2);
	}
	void run(){
		for(;;){
			Scanner in = new Scanner(sc.nextLine());
			int n = in.nextInt();
			if(n ==0) break;
			point[] p = new point[n];
			for(int i= 0;i< n;i++){
				in = new Scanner(sc.nextLine().replace(',', ' '));
				p[i] = new point(in.nextDouble(),in.nextDouble());
				for(int j = 0; j < i;j++){
					if(Math.abs(p[j].x- p[i].x)<0.0000001 && Math.abs(p[j].y-p[i].y)<0.0000001){
						p[j].count++;
						p[i].count =0;
						break;
					}
				}
			}
			int max = 1;
			for(int i=0;i<n;i++){
				for(int j =i+1;j<n;j++){
//					System.out.println((i+1) +" " + (1+j));
					max = Math.max(overLap(i,j,p),max);
				}
			}
			System.out.println(max);
		}
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

#define ll long long int
#define endl '\n'
#define inf 1e18
#define mod 1000000007

void testCase()
{
    //ll t; cin>>t; while(t--)
    {
     ll n;
     cin>>n;
     ll ar[n+5];
     for(int i=1;i<=n;i++)
     cin>>ar[i];
     ll sum=ar[n];
     ll ans=0;
     for(int i=n-1;i>=1;i--)
     {
         ans=(ans+(ar[i]*sum)%mod)%mod;
         sum=(sum+ar[i])%mod;
     }
     cout<<ans;




    } 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

VLL lis(200001, INFL);
VI G[200001];
VLL a;
int ans[200001];

void dfs(int idx, int prev_idx, int cnt) {
    ans[idx] = cnt;

    REP(i, G[idx].size()) {
        int next_idx = G[idx][i];
        if(next_idx == prev_idx) continue;
        auto it = lower_bound(ALL(lis), a[next_idx]);
        int change_idx = it - lis.begin();

        LL prev_num = lis[change_idx];
        lis[change_idx] = a[next_idx];
        dfs(next_idx, idx, cnt + (change_idx == cnt));
        lis[change_idx] = prev_num;
    }
}

void solve(long long N, std::vector<long long> u, std::vector<long long> v){
    REP(i, N-1) {
        G[u[i]-1].PB(v[i]-1);
        G[v[i]-1].PB(u[i]-1);
        lis[i+1] = INFL;
    }
    lis[0] = a[0];
    dfs(0, -1, 1);

    REP(i, N) {
        cout << ans[i] << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    LL tmp;
    for(int i = 0 ; i < N ; i++){
        cin >> tmp;
        a.PB(tmp);
    }
    std::vector<long long> u(N-1);
    std::vector<long long> v(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
    }
    solve(N, std::move(u), std::move(v));
    return 0;
}



Measured memory_bytes: 35428
#include <iostream>
#include <cstdlib>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
const ll mod=1000000007;
 
ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<"\n";
}

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

typedef long long ll;

const int Maxn = 505;
const int Maxm = 100000;

bool nprime[Maxm];
vector <int> pr;
int n;
ll B[Maxn][Maxn];
set <ll> S;

ll gcd(ll x, ll y) { return x? gcd(y % x, x): y; }

ll lcm(ll x, ll y) { return x / gcd(x, y) * y;  }

ll Get(ll a, ll b) { return max(a, b) % min(a, b); }

int main()
{
    for (int i = 2; i < Maxm; i++) if (!nprime[i]) {
        pr.push_back(i);
        for (int j = i + i; j < Maxm; j += i)
            nprime[j] = true;
    }
    scanf("%d", &n);
    int pnt = 2;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) if ((i + j) % 2 == 0) {
            B[i][j] = pr[(i + j) / 2] * pr[n + (i - j + n) / 2];
            S.insert(B[i][j]);
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) if ((i + j) % 2) {
            ll my = 1;
            if (i > 0) my = lcm(my, B[i - 1][j]);
            if (i + 1 < n) my = lcm(my, B[i + 1][j]);
            if (j > 0) my = lcm(my, B[i][j - 1]);
            if (j + 1 < n) my = lcm(my, B[i][j + 1]);
            ll cur = my;
            while (S.find(cur + 1) != S.end()) {
                cur += my;
            }
            B[i][j] = cur + 1;
            S.insert(B[i][j]);
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            printf("%lld%c", B[i][j], j + 1 < n? ' ': '\n');
    return 0;
}


Measured memory_bytes: 17024
<?php

while($line = trim(fgets(STDIN))) {
	$nums = array();
	for($i = 0; $i < strlen($line); $i++) {
		$nums[] = $line[$i];
	}
	$len = count($nums);
	do {
		$sums = array();
		for ($j = 0; $j <  $len - 1; $j++) {
			$n1 = $nums[$j];
			$n2 = $nums[$j + 1];
			$sums[$j] = ($n1 + $n2) % 10;
		}
		$len = count($sums);
		$nums = $sums;
	} while ($len >= 2);

	echo $sums[0] . "\n";
}

Measured memory_bytes: 6616
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	ll N, K;
	cin >> N >> K;
	vector<ll> vec(N);
	rep(i, N) cin >> vec[i];
	sort(vec.begin(), vec.end());
	ll ans = 0;
	rep(i, N - K)
	{
		ans += vec[i];
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
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 ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n;
cin >> n;
vector<int>a(n);
bool ans = true;
for(int i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)%2==0){
        if(a.at(i)%3==0)continue;
        else if(a.at(i)%5==0)continue; 
        else ans =false;
    }
}
if(ans){
    cout << "APPROVED"<<endl;
}
else {
    cout <<"DENIED"<<endl;
}
}



Measured memory_bytes: 256
def sub():
    N = int(input())
    edges = []
    for _ in range(N-1):
        ed = [int(e) for e in input().split(" ")]
        edges.append(ed)
    
    d_neighbor = {i: [] for i in range(1, N+1)} 
    d_weight = {}
    for ed in edges:
        h, t, w = ed
        d_neighbor[h].append(t)
        d_neighbor[t].append(h)
        d_weight[(h,t)] = w
    
    d_color = {i: None for i in range(1, N+1)}
    for i in range(1, N+1):
        if d_color[i] is not None:
            continue
        
        s_visit = set()
        position = i
        # s_visit.add(position)
        stack = [position]
        d_color[position] = False
        while len(stack) > 0:
            position = stack.pop()
            s_visit.add(position)
            nn = d_neighbor[position]
            nn_uv = [n for n in nn if n not in s_visit]
            cTmp = d_color[position]
            for n in nn_uv:
                t = (position, n)
                if position > n:
                    t = (n, position)
                w = d_weight[t]
                if w % 2 == 0:
                    d_color[n] = cTmp
                else:
                    d_color[n] = not cTmp
            stack.extend(nn_uv)
    
    for i in range(1, N+1):
        print(int(d_color[i]))

sub()


Measured memory_bytes: 73616
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s,t; cin>>s>>t;
	int n=s.size(),ret=0;
	for (int i=0; i<n; i++)
		if (s[i]!=t[i]) ret++;
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 3768
N = int(input())
XS = [int(i) for i in input().split()]

sxs = sorted(XS)
a1 = sxs[N//2-1]
a2 = sxs[N//2]

for i in range(N):
  x = XS[i]
  if x <= a1:
    print(a2)
  else:
    print(a1)


Measured memory_bytes: 30684