akhauriyash/Code-Regression huggingface dataset:
#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 per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  ll N; cin>>N;
  if(N%10==3) cout<<"bon"<<endl;
  else if(N%10==0) cout<<"pon"<<endl;
  else if(N%10==1) cout<<"pon"<<endl;
  else if(N%10==6) cout<<"pon"<<endl;
  else if(N%10==8) cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
}

Measured memory_bytes: 3636
def get_data():
    data = int(input())
    return data

def get_data_list():
    data_list = input().split()
    for i, v in enumerate(data_list):
        data_list[i] = int(v)
    return data_list

class MakePositionEasy:

    def __init__(self, data):
        self.w = data[0]
        self.h = data[1]

def get_all_persimmon_coordinate(persimmon_num):
    all_persimmon_coordinate = [None] * persimmon_num
    for i in range(persimmon_num):
        all_persimmon_coordinate[i] = tuple(get_data_list())
    all_persimmon_coordinate = set(all_persimmon_coordinate)
    return all_persimmon_coordinate

def make_persimmon_map(area_size, all_persimmon_coordinate):
    persimmon_map = [[0] * (area_size.w + 1) for i in range(area_size.h + 1)]
    for w in range(1, area_size.w+1):
        current_line_count = 0
        for h in range(1, area_size.h+1):
            if (w,h) in all_persimmon_coordinate:
                current_line_count += 1
            bef_num = persimmon_map[h][w-1]
            persimmon_map[h][w] = (bef_num + current_line_count)
    return persimmon_map

def get_max_num(persimmon_map,area_size, given_size):
    max_num = 0
    for w in range(given_size.w, area_size.w+1):
        for h in range(given_size.h, area_size.h+1):
            persimmon_num = calculate_persiommon_num(persimmon_map, given_size, w, h)
            if persimmon_num > max_num:
                max_num = persimmon_num
    return max_num

def calculate_persiommon_num(persimmon_map , given_size, w, h):
    persimmon_num = persimmon_map[h][w]
    persimmon_num -= persimmon_map[h-given_size.h][w]
    persimmon_num -= persimmon_map[h][w-given_size.w]
    persimmon_num += persimmon_map[h-given_size.h][w-given_size.w]
    return persimmon_num


if __name__ == "__main__":
    while True:
        persimmon_num = get_data()
        if persimmon_num == 0:
            break
        area_size = MakePositionEasy(get_data_list())
        all_persimmon_coordinate = get_all_persimmon_coordinate(persimmon_num)
        given_size = MakePositionEasy(get_data_list())
        persimmon_map = make_persimmon_map(area_size, all_persimmon_coordinate)
        max_num = get_max_num(persimmon_map,area_size, given_size)
        print(max_num)


Measured memory_bytes: 5848
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int n=0;
	int x=0;
	int z=0;
	
	while(1){
		x=b*n+c;
		if(x%a==0){
			z=1;
			break;
		}
		if(x>=a*b)break;
		n++;
	}
	if(z==0){
		cout<<"NO"<<endl;
	}else if(z==1){
		cout<<"YES"<<endl;
	}
	return 0;
}


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

#define MAX_N 100
#define MAX_K 100000

int n, k, a[MAX_N];

bool dp[MAX_K + 1];

int main() {
  std::cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }

  dp[0] = false;
  for(int i = 1; i <= k; ++i) {
    for(int j = 0; j < n; ++j) {
      if(i - a[j] >= 0 && !dp[i - a[j]]) {
        dp[i] = true;
      }
    }
  }

  std::cout << (dp[k] ? "First" : "Second") << std::endl;
}


Measured memory_bytes: 384
#include <cstdio>

int a[15000];

int main()
{
	int N, min = 99999999, max = -99999999;
	long long int sum = 0;

	scanf(" %d", &N);

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

	for (int i = 0; i < N; ++i)
	{
		sum += a[i];
		if (max < a[i]) {
			max = a[i];
		}
		if (min > a[i]) {
			min = a[i];
		}
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 1064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();


			int n = int.Parse(Console.ReadLine());
			int ans;
			if (n % 1000 == 0) {
				ans = 0;
			} else {
				ans = 1000 - n % 1000;
			}
			Console.WriteLine(ans);

		}
	}
}


Measured memory_bytes: 27548
fun main(args: Array<String>) {
    var (n, p) = readLine()!!.split(' ').map(String::toLong)
    val factors = calcFactors(p)
    var filterd = factors.filter { it.value >= n }

    if (filterd.isEmpty()) {
        println(1)
    } else {
        var total = 1L
        var x = 2L
        while (filterd.isNotEmpty()) {
            filterd.forEach { total *= it.key }
            filterd = filterd.filter { it.value >= n * x }
            x++
        }
        println(total)
    }
}

fun calcFactors(n: Long): Map<Long, Long> {//素因数分解
    val factors = mutableMapOf<Long, Long>()
    var tmp = n
    var i = 2L
    while (i * i <= tmp) {
        while (tmp % i == 0L) {
            factors[i] = factors.getOrElse(i) { 0L } + 1L
            tmp /= i
        }
        i++
    }
    if (tmp > 1L) factors[tmp] = 1L
    return factors
}

Measured memory_bytes: 36508
#include <stdio.h>

int main(void){
  char b[1];
  
  scanf("%s", b);
  
  if(b[0] == 'A'){
    printf("T");
  }else if(b[0] == 'C'){
    printf("G");
  }else if(b[0] == 'G'){
    printf("C");
  }else if(b[0] == 'T'){
    printf("A");
  }
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1000000000;

class UF {
 private:
  vi parent_, vrank_;
  vl setcnt_;

 public:
  UF(int N) : parent_(N), vrank_(N, 0), setcnt_(N, 1) {
    for (int i = 0; i < N; ++i) {
      parent_[i] = i;
    }
  }

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

  int setcnt(int x) { return setcnt_[find(x)]; }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    ll cnt = setcnt_[x] + setcnt_[y];
    // cout << "+" << cnt << endl;
    if (vrank_[x] < vrank_[y]) {
      parent_[x] = y;
      setcnt_[y] = cnt;
    } else {
      parent_[y] = x;
      setcnt_[x] = cnt;
      if (vrank_[x] == vrank_[y]) vrank_[x]++;
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }
};

int main() {
  //
  ll n;
  cin >> n;
  vl x(n), y(n);
  rep(i, n) { cin >> x[i] >> y[i]; }

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  set<pll> pqlist;
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      pqlist.insert(make_pair(x[i] - x[j], y[i] - y[j]));
      pqlist.insert(make_pair(x[j] - x[i], y[j] - y[i]));
    }
  }
  ll ans = INF;
  for (auto& pq : pqlist) {
    ll p = pq.first, q = pq.second;
    UF uf(n);
    rep(i, n) {
      rep(j, n) {
        if (i == j) continue;
        if (x[i] - x[j] == p && y[i] - y[j] == q) uf.unite(i, j);
      }
    }
    set<int> r;
    rep(i, n) { r.insert(uf.find(i)); }
    ans = min(ans, (ll)r.size());
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
l = gets.chomp
n = l.size
M = 10 ** 9 + 7

def pow(x, n)
    n == 0 ? 1 : (n.odd? ? x : 1) * pow(x ** 2 % M, n / 2) % M
end

ans = 0
t = 1
n.times do |i|
    next if l[i] == ?0
    ans = (ans + pow(3, n-i-1) * t) % M
    t = t * 2 % M
end

p (ans + t) % M

Measured memory_bytes: 2044
import java.util.Scanner

object Main {
  def main(args:Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val cell0 = sc.nextLine()
    val cell1 = sc.nextLine()

    if (cell0 == cell1.reverse && cell0.reverse == cell1) {
      println("YES")
    } else {
      println("NO")
    }
  }
}

Measured memory_bytes: 25676
// AOJ - ALDS1
// ALDS1_3_C - Doubly linked list
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_C
package main

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

// node, list 構造体とメソッドはALDS1_3_A/Bで使ったものをそのまま使う
// この課題ではdelete(v int)を追加する
type node struct {
	v          int
	prev, next *node
}
type list struct {
	head, tail node
}

func newList() *list {
	nl := new(list)
	nl.head.next = &nl.tail
	nl.tail.prev = &nl.head
	return nl
}
func (ll *list) pushBack(v int) {
	nn := new(node)
	nn.v = v
	nn.next = &ll.tail
	nn.prev = ll.tail.prev
	ll.tail.prev.next = nn
	ll.tail.prev = nn
}
func (ll *list) pushFront(v int) {
	nn := new(node)
	nn.v = v
	nn.prev = &ll.head
	nn.next = ll.head.next
	ll.head.next.prev = nn
	ll.head.next = nn
}
func (ll *list) popBack(v *int) (ret bool) {
	if ll.head.next == &ll.tail {
		ret = false
		return
	}
	ret = true
	*v = ll.tail.prev.v
	ll.tail.prev = ll.tail.prev.prev
	ll.tail.prev.next = &ll.tail
	return
}
func (ll *list) popFront(v *int) (ret bool) {
	if ll.head.next == &ll.tail {
		ret = false
		return
	}
	ret = true
	*v = ll.head.next.v
	ll.head.next = ll.head.next.next
	ll.head.next.prev = &ll.head
	return
}
func (ll *list) deleteFirst() {
	var v int
	ll.popFront(&v)
}
func (ll *list) deleteLast() {
	var v int
	ll.popBack(&v)
}
func (ll *list) delete(v int) {
	for lp := ll.head.next; lp != nil; lp = lp.next {
		if lp != &ll.tail && lp.v == v {
			lp.next.prev = lp.prev
			lp.prev.next = lp.next
			break // 最初の要素のみ削除する
		}
	}
}
func (ll *list) showList() {
	cnt := 0
	wtr := bufio.NewWriter(os.Stdout)
	for lp := ll.head.next; lp != nil && lp != &ll.tail; lp = lp.next {
		if cnt > 0 {
			fmt.Fprint(wtr, " ")
		}
		fmt.Fprint(wtr, lp.v)
		cnt++
	}
	fmt.Fprintln(wtr)
	wtr.Flush()
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	dl := newList()
	for i := 0; i < n; i++ {
		sc.Scan()
		cmd := sc.Text()
		if cmd == "insert" || cmd == "delete" {
			v := nextInt(sc)
			if cmd == "insert" {
				dl.pushFront(v)
			} else {
				dl.delete(v)
			}
		} else if cmd == "deleteFirst" {
			dl.deleteFirst()
		} else if cmd == "deleteLast" {
			dl.deleteLast()
		}
		// dl.showList() // debug
	}
	dl.showList()
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}



Measured memory_bytes: 42988
n = int(input())
s = [input() for i in range(n)]
dict_s = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
str_s = "MARCH"
ans = 0

import re
for item in dict_s.keys():
    for word in s:
        if(re.match(item, word) != None):
            dict_s[item] += 1

for i in range(3):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += dict_s[str_s[i]] * dict_s[str_s[j]] * dict_s[str_s[k]]
            # print("[%d] [%d] [%d]" %(i,j,k))
print(ans)


Measured memory_bytes: 9880
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long num = sc.nextLong();

		long min = num;
		long max = num;
		long sum = num;

		for (int i = 1; i < N; i++) {
			num = sc.nextLong();
			if (min > num) {
				min = num;
			}
			if (max < num) {
				max = num;
			}
			sum += num;
		}

		System.out.println(min + " " + max + " " + sum);

	}
}



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

public class Main {
  Scanner sc;

  boolean[][] field;
  boolean[][] done;

  int[][] ofs = new int[][] { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 },
      { 1, 1 }, { 1, -1 }, { -1, 1 }, { -1, -1 } };

  void dfs(int x, int y) {
    if ( done[ y ][ x ] )
      return;

    done[ y ][ x ] = true;
    for ( int[] d : ofs ) {
      int dx = d[ 0 ];
      int dy = d[ 1 ];
      // debug(field[y][x], y, x, dx, dy);
      if ( field[ y + dy ][ x + dx ] ) {
        dfs( x + dx, y + dy );
      }
    }
  }

  void run() {
    for ( ;; ) {
      int w = ni();
      int h = ni();

      if ( ( w | h ) == 0 ) {
        break;
      }

      field = new boolean[h + 2][w + 2];
      for ( int i = 1; i <= h; ++i ) {
        for ( int j = 1; j <= w; ++j ) {
          field[ i ][ j ] = ni() == 1;
        }
      }

      done = new boolean[h + 2][w + 2];

      int cnt = 0;
      for ( int i = 1; i <= h; ++i ) {
        for ( int j = 1; j <= w; ++j ) {
          if ( field[ i ][ j ] && !done[ i ][ j ] ) {
            ++cnt;
            // debug(i, j);
            dfs( j, i );
          }
        }
      }

      System.out.println( cnt );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

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

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

Measured memory_bytes: 43104
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long int
//map<pair<ll, ll>, ll> pos;
vector<ll>Iraq;
vector<ll>Seria;
vector<ll>Afgan;
vector<ll>temp;
ll arrra[100008];
map<ll,ll>vis;
map<ll,ll>tmp_vis;
map<ll,ll>exact_pos;
ll F[200009];
ll tF[200009];
vector<ll>sub_s[29];
vector<ll>siz;
ll check=1;


int main() {
    
    ll t, i, h, c, big, end, mid,n,m=0,x,y=1,j,k,p,q,r,s=0,sum,tot=100;
    cin>>p;
    for(i=1;i<=p;i++)
    {
      cin>>q;
      if(q%2==1&&i%2==1)
       m++;	
    }
    cout<<m;
    
     
 
}

Measured memory_bytes: 3600
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize
    }
    println!("{}", (n + 1) / 2);
}


Measured memory_bytes: 4352
n = int(input())
pre_t, pre_x, pre_y = [0, 0, 0]
ok = True
for i in range(n):
  t, x, y = map(int, input().split())
  if (((t-pre_t) - abs(x-pre_x) - abs(y-pre_y)) < 0
      or ((t-pre_t) - abs(x-pre_x) - abs(y-pre_y)) % 2 != 0):
    ok = False
    break
  pre_t, pre_x, pre_y = [t, x, y]
  
if ok:
  print("Yes")
else:
  print("No")

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

// 1なら1, 2なら11, 3なら111...を返す
/*
ll countunit(ll n){
	ll res = 0;
	rep(i,n){
		res += pow(10,i);
	}
	return res;
}
*/
int main(){
	
	ll n;
	cin >> n;
	if(n%2==1){
		cout << 0 << endl;
		return 0;
	}
	
	/*
	vector<ll> cu(18);
	rep(i,18){
		cu[i] = countunit(i+1);
	}
	*/
	
	// nは偶数
	ll res = 0;
	while(n > 0){
		res += n/10;
		n /= 5;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int cmp(int a,int b){
	return a>b;
}
int main(){
	int n,m; int sum=0;
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n,cmp);
	for(int i=0;i<m;i++){
		sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <random>
#include <iomanip>
  
#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++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main() {
  string s;
  cin >> s;
  int N;
  cin >> N;
  for(int i = 0; i < s.size(); i += N) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;
const ll max_n = 1e5+5;
vc g[max_n], cd[max_n], ra[max_n], rb[max_n];
ll m, ans[max_n]={0}, dp[max_n]={0}, od[max_n], pj[max_n];

void dfs1(ll now, ll pr){
	dp[now] = 1;
	for(auto to: g[now]){
		if(to == pr) continue;
		dfs1(to, now);
		dp[now] = dp[now] * (dp[to] + 1) % m;
	}
}

void dfs2(ll now, ll pr){
	pj[now] = (pj[now] + 1) % m;
	ans[now] = dp[now] * pj[now] % m;
	cd[now].pb(1);
	ll s = 0;
	for(auto to: g[now]){
		if(to == pr) continue;
		s++;
		od[to] = s; 
		cd[now].pb(dp[to]);
	}
	rep(i,0,s+1){
		ra[now].pb(1);
		rb[now].pb(1);
	}
	rep(i,1,s) ra[now][i] = ra[now][i-1] * (cd[now][i] + 1) % m;
	repr(i,s,1) rb[now][i] = rb[now][i+1] * (cd[now][i] + 1) % m;
	for(auto to: g[now]){
		if(to == pr) continue;
		pj[to] = (pj[now] * ra[now][od[to]-1] % m) * rb[now][od[to]+1] % m;
		dfs2(to, now);
	}
}

int main() {
    // your code goes here
    ll n, x, y;
    cin >> n >> m;
    rep(i,1,n-1){
    	cin >> x >> y;
    	g[x].pb(y);
    	g[y].pb(x);
    }
    dfs1(1, 0);
    pj[1] = 0;
    dfs2(1, 0);
    rep(i,1,n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 38144
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    string x, y;
    cin >> x >> y;
    map<char, char> pp;
    map<char, char> pp2;
    bool is = true;
    for (int i = 0; i < x.size(); i++) {
        if(pp.count(x[i]) == 0 && pp2.count(y[i]) == 0){
            pp[x[i]] = y[i];
            pp2[y[i]] = x[i];
        }else if(pp.count(x[i]) == 0 || pp2.count(y[i]) == 0){
            is = false;
            break;
        }else if(pp[x[i]] !=  y[i] || pp2[y[i]] != x[i]){
            is = false;
            break;
        }
    }
    if (is)
        cout << "Yes" << endl;
    else cout << "No" << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 916
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstring>	// require memset
//#include <fstream>	// require freopen

using namespace std;

typedef pair<int, int> P; // row, col order

int scene[100][100];
int pic[50][50];
int n, m;

P check_pic (int row, int col )
{
	P res(-1,-1);
	for (int i = 0; i < m; ++i ){
		for (int j = 0; j < m; ++j ){
			if (pic[i][j] == -1 ){
				continue;
			}else{
				if (pic[i][j] == scene[row + i][col + j] ){
					if (res.first == -1 && res.second == -1){
						res.first = row + i;
						res.second = col + j;
					} // end if
					continue;
				}else{
					return P(-1,-1);
				} // end if
			} // end if
		} // end for
	} // end for

	return res;
}

void rotate90 (void )
{
	int res[m][m];
	
	memset (res, 0, sizeof(res ) );
	
	for (int i = 0; i < m; ++i ){
		for (int j = 0; j < m; ++j ){
			res[j][m - 1 - i] = pic[i][j];
		} // end for
	} // end for

	for (int i = 0; i < m; ++i ){
		for (int j = 0; j < m; ++j ){
			pic[i][j] = res[i][j];
		} // end for
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.sip", "r", stdin );

	while (cin >> n >> m && n && m ){
		memset (scene, 0, sizeof (scene ) );
		memset (pic, 0, sizeof (pic ) );
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n; ++j ){
				cin >> scene[i][j];
			} // end for
		} // end for

		for (int i = 0; i < m; ++i ){
			for (int j = 0; j < m; ++j ){
				cin >> pic[i][j];
			} // end for
		} // end for

		vector <P> res;

		for (int k = 0; k < 4; ++k ) {
			for (int i = 0; i < n - m + 1; ++i ){
				for (int j = 0; j < n - m + 1; ++j ){
					P r = check_pic (i,j );
					if (r.first != -1 || r.second != -1 ){
						res.push_back(r);
					} // end if
				} // end for
			} // end for
			rotate90();
		} // end for

		if (res.empty() ){
			cout << "NA" << endl;
		}else{
			sort (res.begin(), res.end() );
			cout << (res[0].second + 1 ) << ' ' << (res[0].first + 1) << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1100
#include <iostream>

using namespace std;

int main() {
    int x,y;
    cin >> x >> y;
    if(4*x < y || y % 2 != 0 || y == 0 || x > y/2) {
        cout << "No";
    }
    else {
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
using namespace std;
template<class _T>inline void read(_T &_a)
{
	bool f=0; char _c=getchar(); _a=0;
	while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
	while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
	if(f) _a=-_a;
}

int n,ans[200001];

int main()
{
	read(n);
	for (int i=2,t;i<=n;++i)
	{
		read(t);
		++ans[t];
	}
	for (register int i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4528
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,w;
 cin>>n>>w;
 int a[n+1][2];
 int i;
 memset(a,0,sizeof(a));
 for(i=1;i<=n;i++)
 cin>>a[i][0]>>a[i][1];
 long long int dp[n+1][w+1];
 memset(dp,0,sizeof(dp));
 for(i=1;i<=n;i++)
 {
 	for(int j=1;j<=w;j++)
 	dp[i][j]=max(dp[i-1][j],(j-a[i][0]>=0)?(dp[i-1][j-a[i][0]]+a[i][1]):0);
 }
 cout<<dp[n][w]<<endl;
 return 0;
}


Measured memory_bytes: 79104
#include "bits/stdc++.h"

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

  int count = 0;
  for (auto i = a; i <= b; i++)
  {
    if (c % i == 0)
      count++;
  }

  std::cout << count << std::endl;

  return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=2005;
int n,sum[N],dep[N],sz[N];
char s[N];
int pp,lnk[N],nxt[N*2],to[N*2];
void ae(int k1,int k2){to[++pp]=k2,nxt[pp]=lnk[k1],lnk[k1]=pp;}
void pre(int k1,int k2){
	sz[k1]=s[k1],sum[k1]=0;
	for(int i=lnk[k1];i;i=nxt[i])if(to[i]!=k2)dep[to[i]]=dep[k1]+1,pre(to[i],k1),sz[k1]+=sz[to[i]],sum[k1]+=sum[to[i]]+sz[to[i]];
}
int dfs(int k1,int k2){
	int v=-1;
	for(int i=lnk[k1];i;i=nxt[i])if(to[i]!=k2){
		if(v==-1||sum[to[i]]>sum[v])v=to[i];
	}
	if(v==-1)return 0;
	int k=dfs(v,k1)+sz[v];
	if(sum[k1]-sum[v]-sz[v]>=k)return sum[k1]&1;
	else return k-(sum[k1]-sum[v]-sz[v]);
}
int main(){
	scanf("%d%s",&n,s+1);
	rep(i,1,n)s[i]&=1;
	rep(i,2,n){
		int k1,k2;
		scanf("%d%d",&k1,&k2);
		ae(k1,k2),ae(k2,k1);
	}
	int ans=1e9;
	rep(k1,1,n){
		pre(k1,0);
		if(dfs(k1,0)==0)ans=min(ans,sum[k1]/2);
	}
	if(ans==1e9)ans=-1;
	printf("%d\n",ans);
	return 0;
}


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

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

  // import
  vector <int> btn(n);
  for (int i = 0; i < n; i++)
    cin >> btn.at(i);

  // check
  int btn_next = 0;
  int count = 0;
  while (btn.at(btn_next) > 0) {
    int btn_current = btn_next;
    count++;
    btn_next = btn.at(btn_current) - 1;
    btn.at(btn_current) = 0;
    if (btn_next == 1)
      break;
  }

  // output
  if (btn_next == 1)
    cout << count << endl;
  else
    cout << -1    << endl;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll dp[100001],h[100001];
int n,k;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n)
	cin>>h[i];
	dp[0]=0;
	forn(i,1,n){
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		rep(j,k){
			if(i<=j)
			break;
			dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]));
		}
	}
	cout<<dp[n-1];
	re 0;
}


Measured memory_bytes: 1792
#!/bin/env python
  
class Monster():
  def __init__(self, hp):
    self.hitpoint = hp

  def damage(self, damage):
    return -(-self.hitpoint // damage)

def main():
  input_string = raw_input()
  monster = Monster(int(input_string.split(' ')[0]))
  print(monster.damage(int(input_string.split(' ')[1])))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
def solve():
    N = int(input())
    T = [[] for _ in range(N+1)]
    searched = [False]*(N+1)
    for _ in range(N-1):
        a,b,c = map(int, input().split())
        T[a].append((b,c))
        T[b].append((a,c))
        
    Q,K = map(int, input().split())
    distance = [10**9]*(N+1)
    distance[K] = 0
    
    # K から始める
    queue = [K]
    while queue:
        dom = queue.pop()
        if searched[dom]:
            continue
        searched[dom] = True
        for cod, d in T[dom]:
            if searched[cod]:
                continue
            queue.append(cod)
            distance[cod] = distance[dom]+d
            
        # print(dom, distance)
        
    # print(distance)
    
    for _ in range(Q):
        x,y = map(int, input().split())
        print(distance[x]+distance[y])
        
solve()

Measured memory_bytes: 44692
#include<bits/stdc++.h>
using namespace std;
bool comp(string a,string b)
{
    return a<b;
}
vector<string> alpSort(vector<string> a){
	int n=a.size();
	sort(a.begin(),a.end(),comp);
	return a;
}
int main()
{
    int n,cn;
    string s;
    cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    v=alpSort(v);
    cn=0;
    for(int i=0;i<v.size()-1;i++)
    {
        if(v[i]!=v[i+1])
        {
            cn++;
        }
    }
    cout<<cn+1<<endl;
}


Measured memory_bytes: 15828
A,B,C=map(int,input().split())
coin=0
for day in range(1,1+C): #1日からC日まで繰り返す
    coin=coin+A
    if day%7==0: 
        coin=coin+B #七日経ったらB枚のコインも追加
    if coin>=C:
        break #coinがC枚より多くなったら繰り返し終了
print(day)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 50;
ll ans[N];
ll k;

int main() {
    cin >> k;
    ll a = k / N;
    ll b = k % N;
    ll c = N - b;
    fill(ans, ans + N, N + a - 1);
    for (int i = 0; i < b; ++i) {
        ++ans[i];
    }
    for (int i = b; i < N; ++i) {
        ans[i] -= b;
    }
    cout << N << endl;
    for (int i = 0; i < N; ++i) {
        cout << ans[i] << ' ';
    }
    cout << endl;
    return 0;
}


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

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


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

int N;

int main() {
    scanf("%d", &N);

    int pt = 0, px = 0, py = 0, ok = 1;
    for(int i = 0; i < N; i++) {
        int t, x, y; scanf("%d %d %d", &t, &x, &y);

        int tmp = abs(x - px) + abs(y - py);
        if(tmp <= t - pt && tmp % 2 == (t - pt) % 2) {

        }
        else {
            ok = 0;
        }

        pt = t;
        px = x;
        py = y;
    }

    if(ok) printf("Yes");
    else printf("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=998244353;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main() {
    ll n;cin>>n;n--;
    ll ans=0;
    REP(i,1,n+1)ans+=n/i;
    out(ans);
}

Measured memory_bytes: 3632
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
using namespace std;
using ll = long long;
typedef pair <int, int> pii;
int main()
{

	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	string s, t;
	//long long n, A[1000000000];
	int n, m, q;
	//int   y[100001], z[100001], x[10001] = {};
	//pii y[100001];
	//pair<int, float> pii[100001];
	int A[501][501] = {};
	int B[501][501] = {};
	cin >> n;
	cin >> m;
	m -= n * 1000;
	for ( a = 0; a <= n; a++)
	{
		for ( b = 0; b <= n-a; b++)
		{
			if (m-a*9000-b*4000==0)
			{
				cout << a << endl;
				cout << b << endl;
				cout << n-a-b << endl;
				return 0;
			}
		}
	}
	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	cout << "-1 -1 -1" << endl;


	return 0;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> s(n);
    vector <bool> d(k+1);
    for(int i=0 ; i<n ; i++)
        cin >> s[i];

    for(int i=0 ; i<=k ; i++)
        for(int j:s)
            if(i>=j && !d[i-j])
                d[i] = true;

    if(d[k]) cout<<"First";
    else cout << "Second";
    return 0;
}

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

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

int main() {
    int a, b, c, k, m;
    cin >> a >> b >> c >> k;
    cout << a + b + c + max(max(a, b), c) * ((1 << k) - 1) << endl;
    return 0;
}

Measured memory_bytes: 3548
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
	char s[210][210];
	int H, W;
	cin >> H >> W;

	for (int i = 1; i < H + 1; i++)
		for (int j = 1; j < W + 1; j++)
			cin >> s[i][j];

	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			if (i == 0 || j == 0 || i == H + 1 || j == W + 1)
				cout << "#";
			else
				cout << s[i][j];
		}
		cout << endl;
	}
	return 0;
}


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

int main() {
	int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
  if(f >= e-a)
    cout<<"Yay!"<<endl;
  else
    cout<<":("<<endl;
 
 
    
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
suma = []
sumb = 0
for i in range(N):
    sumb = sum([A1[j] for j in range(len(A1)) if j <= i]) + sum([A2[k] for k in range(len(A2)) if k >= i])

    suma.append(sumb)

print(max(suma))

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

bool comp(P x, P y) {
    return x.second < y.second;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> pp(n);
    rep(i, n) {
        int s, t;
        cin >> s >> t;
        pp[i] = make_pair(s, t);
    }

    sort(all(pp), comp);

    int ans = 0;
    int now = -1;
    rep(i, n) {
        if(now < pp[i].first) {
            now = pp[i].second;
            ans++;
        }
    }

    cout <<  ans << endl;
}


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

bool ok(vector< tuple< int, int > >& obj)
{
  int now = 0;
  for(auto v : obj) {
    if(now + get< 0 >(v) < 0) return(false);
    now += get< 1 >(v);
  }
  return(true);
}

int main()
{
  int N;
  cin >> N;
  
  vector< tuple< int, int > > curr, revv;
  while(N--) {
    string S;
    cin >> S;

    int height = 0, cnt = 0;
    for(char c : S) {
      if(c == '(') ++cnt;
      else         --cnt;
      height = min(height, cnt);
    }
    int revheight = 0, revcnt = 0;
    reverse(S.begin(), S.end());
    for(char c : S) {
      if(c == ')') ++revcnt;
      else         --revcnt;
      revheight = min(revheight, revcnt);
    }
    if(cnt >= 0) {
      curr.emplace_back(height, cnt);
    } else {
      revv.emplace_back(revheight, revcnt);
    }
  }
  sort(curr.rbegin(), curr.rend());
  sort(revv.rbegin(), revv.rend());

  bool flag = ok(curr) & ok(revv);
  int csum = 0, rsum = 0;
  for(auto v : curr) csum += get< 1 >(v);
  for(auto v : revv) rsum += get< 1 >(v);
  flag &= csum == rsum;
  if(flag) cout << "Yes" << endl;
  else     cout << "No"  << endl;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c, k; cin >> a >> b >> c >> k;
    while(k > 0){
        if(a >= b) b *= 2;
        else if (b >= c) c *= 2;
        k--;
    }
    if(a < b and b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3644
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
 {
	public static void main (String[] args)
	 {
            Scanner sc=new Scanner(System.in);
            String s=sc.next(),str="";char ch[]=s.toCharArray();
            int i,j,n=s.length(),min=1000000;
            for(i=0;(i+2)<n;i++) {
            	char ch1=ch[i],ch2=ch[i+1],ch3=ch[i+2];
            	int num=(ch1-'0')*100+(ch2-'0')*10+(ch3-'0');
            	int diff=Math.abs(num-753);
            	min=Math.min(diff,min);
            }
            System.out.println(min);
	 }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
 
#define endl "\n"
#define ioss ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
//#define int long long
 
typedef  long long ll;
 
using namespace std;
ll ans=0;ll nm=1;
void kill(ll h)
{
    if(h==1){ans=ans+nm;}
  else
  {
    ans=ans+nm;nm=nm*2;
     kill(h/2);
     //<<ans<<endl;
  }
}
 
int main()
{
    ioss
    ll h;cin>>h;
  //kill(h);
    ll answ=0;ll i=0;
    for( i=0;;i++)
    {
        if(pow(ll(2),i)>h)break;
    }
    i--;
    cout<<ll(pow(ll(2),i))*2-1<<endl;
 // cout<<answ<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int,int> pp;

int N;
const int MAX_N = 100010;
const int MAX_M = 26;
const int INF = 1e9;

char a[MAX_N];
int min_v[MAX_M], min_i[MAX_M], cnt[MAX_M];

pp solve(int L,int R){
    if(L==R)return pp(-1,-1);
    int mid = (L+R)/2;
    pp ret = solve(L, mid);
    if(ret.first>=0)return ret;
    ret = solve(mid+1, R);
    if(ret.first>=0)return ret;

    for(int i=L;i<=mid;i++){
        int x = a[i]-'a';
        if(min_v[x] > cnt[x]*2-i+1){
            min_v[x] = cnt[x]*2-i+1;
            min_i[x] = i;
        }
        cnt[x]++;
    }
    for(int i=mid+1;i<=R;i++){
        int x = a[i]-'a';
        cnt[x]++;
        if(2*cnt[x]-i > min_v[x]){
            return pp(min_i[x], i);
        }
    }

    for(int i=L;i<=mid;i++){
        int x = a[i]-'a';
        min_v[x] = INF;
        cnt[x] = 0;
    }
    return pp(-1,-1);
}

int main(){
    scanf("%s",a+1);
    N = strlen(a+1);

    for(int i=0;i<MAX_M;i++){
        min_v[i] = INF;
    }
    pp ans = solve(1,N);

    printf("%d %d\n",ans.first, ans.second);
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<ll> A(N);
  ll a;
  cin >> a;
  A.at(0) = a;
  REPI(i, 1, N) {
    cin >> a;
    A.at(i) = A.at(i - 1) + a;
  }

  ll ans = 1e10;
  REP(i, N) {
    ll tmp1 = A.at(i);
    ll tmp2 = A.at(N - 1) - A.at(i);
    ans = min(ans, abs(tmp2 - tmp1));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}
///////////////////////////

ll beki(ll n) {
	if (n == 0) { return 1;}
	return 10 * beki(n - 1);
}



int main() {

	ll X, Y;
	cin >> X >> Y;
	cout << X + Y / 2;
	
	system("PAUSE");
}

Measured memory_bytes: 504
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace AtcoderExpress
{


    class Program
    {

        static void Main(string[] args)
        {
            //var W = long.Parse(Console.ReadLine());
            var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var H = HW[0];
            var W = HW[1];
            //Array.Sort(A);
            if(H == 1 || W ==1){
              Console.WriteLine(1);
            }
            else if((H%2 == 1 && W % 2 == 0) || (H % 2 == 0 && W % 2 == 1))
            {
                Console.WriteLine((H*W)/2);
            }
            else
            {
                Console.WriteLine((H * W+1) / 2);
            }
            
        }
    }
}


Measured memory_bytes: 13396
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    S = IS()
    if S[2] == S[3] and S[4] == S[5]:
        print('Yes')
    else: print('No')
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
	ll N,K; cin >> N >> K;
	vector<ll> A(N);
	rep(i,N){
		cin >> A[i];
	}
    ll ans = 0;
	rep(i,N){
        ll cnt1 = 0;
        ll cnt2 = 0;
		repr(j,i+1,N){
			if(A[i] > A[j]){
				cnt1++;
			}
		}
		rep(j,i){
			if(A[i] > A[j]){
            	cnt2++;
            }
		}
		if(K % 2 == 0){
			cnt1 *= (K/2);
			cnt1 %= MOD;
			cnt1 *= (K+1);
			cnt1 %= MOD;
			cnt2 *= K/2;
			cnt2 %= MOD;
			cnt2 *= K-1;
			cnt2 %= MOD;
		}
		else{
			cnt1 *= (K+1)/2;
			cnt1 %= MOD;
			cnt1 *= K;
			cnt1 %= MOD;
			cnt2 *= (K-1)/2;
			cnt2 %= MOD;
			cnt2 *= K;
			cnt2 %= MOD;
		}
    	ans += cnt1 + cnt2;
        ans %= MOD;
		
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

void reset(vector<int> &v) {
  rep(i, v.size()) { v[i] = 0; }
}

int main(void) {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<bool>> s(h, vector<bool>(w, false));
  rep(i, h) {
    string tmp;
    cin >> tmp;
    rep(j, w) {
      if (tmp[j] == '1') s[i][j] = true;
    }
  }
  int ans = h + w;
  rep(c, 1 << (h - 1)) {
    bitset<9> b(c);
    int cut = b.count();
    vector<int> blocks(cut + 1, 0);
    int wc = 0;
    int hc = 0;
    int bc = 0;
    bool cutted = true;
    while (1) {
      blocks[bc] += s[hc][wc];
      if (blocks[bc] > k) {
        if (cutted) {
          cut = h + w;
          break;
        }
        cut++;
        cutted = true;
        bc = 0;
        hc = -1;
        reset(blocks);
      } else if (hc == h - 1) {
        bc = 0;
        hc = -1;
        wc++;
        cutted = false;
        if (wc == w) break;
      } else if (b.test(hc)) {
        bc++;
      }
      hc++;
    }
    ans = min(ans, cut);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256