akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, L: "List[int]", R: "List[int]", D: "List[int]"):
    uf = UnionFind(N+1)
    try:
        for l, r, d in zip(L, R, D):
            uf.merge(l, r, d)
        return YES
    except MergeError:
        return NO

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    D = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
        D[i] = int(next(tokens))
    print(solve(N, M, L, R, D))
    
class MergeError(Exception):
    pass

# 参考: https://qiita.com/drken/items/cce6fc5c579051e64fab
class UnionFind:
    def __init__(self, size: int):
        self.par = list(range(size))
        self.rank = [0] * size
        self.diff_weight = [0] * size

    def root(self, x: int):
        if self.par[x] == x:
            return x
        r = self.root(self.par[x])
        self.diff_weight[x] += self.diff_weight[self.par[x]] # 累積和をとる        
        #return par[x] := r
        self.par[x] = r
        return r

    def weight(self, x: int):
        self.root(x) # 経路圧縮
        return self.diff_weight[x]

    def same(self, x: int, y: int):
        return self.root(x) == self.root(y)

    # weight(y) - weight(x) = w となるように merge する
    def merge(self, x: int, y: int, w: int):
        # x と y それぞれについて、 root との重み差分を補正
        adjusted_w = w + self.weight(x) - self.weight(y)
        x = self.root(x)
        y = self.root(y)
        if x == y:
            if adjusted_w != 0:
                raise MergeError
            return
        if self.rank[x] < self.rank[y]:
            x, y, adjusted_w = y, x, -adjusted_w
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x
        self.diff_weight[y] = adjusted_w

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 35472
<?php
list($N, $u, $v) = ints();
$G = loadTree();
dfs($u);$d1 = $distance;
dfs($v);$d2 = $distance;
$max = 0;
for($i = 1; $i <= $N; $i++){
  if($d1[$i] < $d2[$i]){
    //o($i, $d1[$i], $d2[$i]);
    chmax($max, $d2[$i] - 1);
  }
}
echo $max;

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}
function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  $G = array_fill(1, $N - 1, []);
  for($i = 0; $i < $N - 1; $i++){
    list($a, $b) = ints();
    $G[$a][] = $b;
    $G[$b][] = $a;
  }
  return $G;
}
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
signed main(){
    
    string s,t;
    cin >> s >> t; 
    int x = 300;
    
    int st[26],ts[26];
    REP(i,26){
        st[i] = x;
        ts[i] = x;
    }
    REP(i,s.size()){
        if(st[s[i] - 'a'] == x){
            st[s[i] - 'a'] = t[i] - 'a';
        }else{
            if(st[s[i] - 'a'] != t[i] - 'a'){
                cout << "No" << endl;
                return 0;
            }
        }

        if(ts[t[i] - 'a'] == x){
            ts[t[i] - 'a'] = s[i] - 'a';
        }else{
            if(ts[t[i] - 'a'] != s[i] - 'a'){
                cout << "No" << endl;
                return 0;
            }
        }

    }
    cout << "Yes" << endl;
    
    return 0;
}
//g++ -std=c++14 code1.cpp



Measured memory_bytes: 776
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
using namespace std;
 

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; ++i)
#define int long long

 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

 
const int MAXN = 3e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = INT64_MAX;


random_device rd;
mt19937 rnd(rd());


signed main() {
	FAST_IO;
	int n;
	cin >> n;
	int ans = 0;
	forn(i, n) {
		int val;
		cin >> val;
		if ((i + 1) % 2 == 1 && val % 2 == 1) {
			ans++;
		}
	}
	cout << ans << "\n";
 	return 0;
}

Measured memory_bytes: 3656
//テスト
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

//減少のことは考えないで最大をとる

int main(){
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<pair<int,int>>> s(d,vector<pair<int,int>>(26));
    rep(i,d){
        rep(j,26){
            int input;
            cin >> input;
            s[i][j] = make_pair(input,j);
        }
    }
    rep(i,d){
        sort(s[i].begin(),s[i].end(),greater<pair<int,int>>());
    }
    vector<int> ans(d);
    rep(i,d){
        ans[i] = s[i][0].second+1;
    }
    rep(i,d){
        cout << ans[i] << endl;
    }
	return 0;   
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int mod=1e9+7;
int32_t main()
{
   int n,k;
   cin>>n>>k;
   int ans1=0,ans2=0;
   int pre[n+5];
   for(int i=0;i<=n;i++)
   {
       ans1+=i;
       pre[i+1]=ans1;
   }
    for(int i=n;i>=0;i--)
    {
        ans2+=i;
        pre[n-i+1]=(ans2-pre[n-i+1]+1)%mod;
    }
    int ans=0;
    for(int i=k;i<=n+1;i++)
    {    ans+=pre[i];
        ans%=mod;}
    cout<<ans<<endl;    
}

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

int main(){
    int n,y;
    cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=i+1;j<=n+1;j++){
            int a=i;
            int b=j-i-1;
            int c=n-a-b;
            if(10000*a+5000*b+1000*c==y){
                cout<<a<<" "<<b<<" "<<c<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long

using namespace std;

int n;
char vvc[300][600];

bool checkc(int ii){
    REP(i,n){
        REP(j,n){
            if(vvc[i][j+ii] != vvc[j][i+ii]) return false;
        }
    }
    return true;
}

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

    cin >> n;
    REP(i,n){
        REP(j,n){
            char c;
            cin >> c;
            vvc[i][j] = vvc[i][j+n] = c;
        }
    }

    ll ans=0;
    REP(i,n) if(checkc(i)) ans += n;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int x,y;
  scanf("%d%d",&x,&y);
  for(int i=0;i<=x;i++){ 	
	if(2*i+4*(x-i)==y){
		printf("Yes") ;
        return 0;
		}
	}
  printf("No") ;
  return 0;
}

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

using namespace std;

int d[4];

int main()
{
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    n *= 4;
    h = min(2 * q, h);
    s = min(2 * h, s);
    d = min(2 * s, d);
    cout << (n / 8) * d + ((n % 8) / 4) * s + ((n % 4) / 2) * h + (n % 2) * q;
    return 0;
}


Measured memory_bytes: 256
import math
 
def volume(a,b,t):
    if  b>a*t :#台形パターン
        v =  a*a*b-(0.5*(a**3))*t
    else:#三角形パターン
        v =0.5*b*b*a/t
    return v
  
a, b, x = map(int, input().split())
LR = [0,9*(10**9)]
if x == 0:
    print(0)
else:
    while LR[1]-LR[0]>1:
        mid = 0.5*(LR[0]+LR[1])
        v= volume(a,b,math.tan(math.radians(mid/10**8)))
        if v >x:
            LR[0]=mid
        else:
            LR[1]=mid
    #     print("v==={}\nx==={}\ntan==={}\n{}\n".format(v,x,math.tan(math.radians(mid/10**7)),LR))
    #     time.sleep(1)
    print(LR[0]/10**8)

Measured memory_bytes: 3188
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B

from sys import stdin
input = lambda: stdin.readline().rstrip()

N = int(input())
A = list(map(int, input().split()))

cnt = 0
for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
        if A[j] < A[minj]:
            minj = j

    if i != minj:
        w = A[i]
        A[i] = A[minj]
        A[minj] = w
        cnt = cnt + 1

print(' '.join(map(str,A)))
print(cnt)


Measured memory_bytes: 5600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        foreach (var input in Enumerable.Range(0, int.MaxValue).Select(x => Console.ReadLine()).TakeWhile(x => !string.IsNullOrEmpty(x)))
        {
            var values = input.Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine("{0} {1}", Gcd(values[0], values[1]), Lcm(values[0], values[1]));
        }
    }
    private static int Gcd(int m, int n)
    {
        if (m < n)
        {
            return Gcd(n, m);
        }
        else if (n == 0)
        {
            return m;
        }
        else
        {
            return Gcd(n, m % n);
        }
    }
    private static int Lcm(int m, int n)
    {
        return m / Gcd(m, n) * n;
    }
}

Measured memory_bytes: 6020
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#define int long long
#define rep(i, n) for (int i=0; i<n; i++)
#define REP(n) rep(i, n)
using namespace std;

int n;
string snake, head, tail, body;

signed main()
{
    cin >> n;

    REP(n)
    {   
        cin >> snake;

        if (snake.length() < 6)
        {   
            cout << "NA" << endl;
            continue;
        }   

        head = snake.substr(0, 2); 
        if (head == ">'")
        {   
            tail = snake.substr(snake.length() - 1, 1); 
            if (tail != "~")
            {   
                cout << "NA" << endl;
                continue;
            }   
            body = string((snake.length() - 4) / 2, '=') + "#" + string((snake.length() - 4) / 2, '=');
            if (snake.substr(2, snake.length() - 3) == body)
            {   
                cout << "A" << endl;
                continue;
            } else {
                cout << "NA" << endl;
                continue;
            }   
        } else if (head == ">^") {
            tail = snake.substr(snake.length() - 2, 2); 
            if (tail != "~~")
            {   
                cout << "NA" << endl;
                continue;
            }   
            body = ""; 
            int cnt = (snake.length() - 4) / 2;
            while (cnt--) body += "Q=";
            if (snake.substr(2, snake.length() - 4) == body)
            {
                cout << "B" << endl;
                continue;
            } else {
                cout << "NA" << endl;
                continue;
            }
        } else {
            cout << "NA" << endl;
            continue;
        }
    }

    return 0;
}

Measured memory_bytes: 1224
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (H, W) = read!(usize, usize);
    let A = read![[i32]; H];

    let mut ops = vec![];
    let mut prev = None;

    for y in 0..H {
        for x in 0..W {
            let x = if y % 2 == 0 { x } else { W - 1 - x };
            let mut a = A[y][x];

            if let Some((y1, x1)) = prev {
                a += 1;
                ops.push((y1, x1, y, x));
                prev = None;
            }

            if a % 2 != 0 {
                prev = Some((y, x));
            }
        }
    }

    println!("{}", ops.len());
    for (y1, x1, y2, x2) in ops {
        println!("{} {} {} {}", 1 + y1, 1 + x1, 1 + y2, 1 + x2)
    }
}


Measured memory_bytes: 13044
#include<stdio.h>

int main(void) {
  int n, a[200], c=0, owari=0;
  
  scanf("%d",&n);
  for(int i = 0; i < n; i++) {
    scanf("%d",&a[i]);
  }
  
  while(1) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 == 1)
        owari = 1;
    }
    if (owari == 1)
      break;
    
  	c ++;
    
    for (int i = 0; i < n; i++) {
      a[i] /= 2;
    }
  }
  printf("%d",c);
  
  return 0;
}


Measured memory_bytes: 128
if __name__ == "__main__":
    n = int(input())
    s = input()

    ans = s[0]
    tmp = s[0]

    for i in range(n):
        if s[i] == tmp:
            continue
        else:
            tmp = s[i]
            ans += s[i]

    print(str(len(ans)))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define INF 1000000000

using namespace std;

int dp[1000001][10][3];
int special[10][3];
string n="";

int main()
{
	cin >> n;
	for (int i=0; i<=n.size(); i++)
		for (int j=0; j<10; j++)
			for (int k=0; k<3; k++)
				dp[i][j][k] = INF;
	for (int j=0; j<10; j++)
		for (int k=0; k<3; k++)
			special[j][k] = INF;
	dp[n.size()][0][0] = 0;	
	for (int i=n.size()-1; i>=0; i--)
	{
		for (int j=0; j<10; j++)
		{
			for (int j1=0; j1<10; j1++){
				int diff = 0;
				if (j>=n[i]-'0'){
					diff = j+(j-(n[i]-'0'));
					dp[i][j][0] = min(dp[i][j][0], dp[i+1][j1][0]+diff);	
				}
				if (j>n[i]-'0'){
					diff = j+(j-1-(n[i]-'0'));
					dp[i][j][0] = min(dp[i][j][0], dp[i+1][j1][1]+diff);
					dp[i][j][0] = min(dp[i][j][0], dp[i+1][j1][2]+diff);
				}
				if (j<=n[i]-'0'){
					diff = j+(9+j-(n[i]-'0'));
					dp[i][j][1] = min(dp[i][j][1], dp[i+1][j1][1]+diff);
					dp[i][j][1] = min(dp[i][j][1], dp[i+1][j1][2]+diff);
				}
				if (j<n[i]-'0'){
					diff = j+(10+j-(n[i]-'0'));
					dp[i][j][2] = min(dp[i][j][2], dp[i+1][j1][0]+diff);
				}
			}
		}
	}
	for (int j=1; j<10; j++)
	{
		for (int j1=0; j1<10; j1++){
			int diff = 0;
			if (j>=1){
				diff = j+(j-0);
				special[j][0] = min(special[j][0], dp[0][j1][0]+diff);	
			}
			if (j>0){
				diff = j+(j-1-0);
				special[j][0] = min(special[j][0], dp[0][j1][1]+diff);
				special[j][0] = min(special[j][0], dp[0][j1][2]+diff);
			}
		}
	}
	int Min=INT_MAX;
	for (int j=1; j<10; j++){
		Min = min(Min, dp[0][j][0]);
		Min = min(Min, special[j][0]);
	}
	cout << Min;
	return 0;
}


Measured memory_bytes: 118532
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int L = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();

    int l = -1;
    for (int i = 0; i < N - 1; i++) {
      if (a[i] + a[i + 1] >= L) {
        l = i;
        break;
      }
    }
    if (l < 0) {
      System.out.println("Impossible");
      return;
    }
    System.out.println("Possible");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < l; i++) sb.append(i + 1).append('\n');
    for (int i = N - 2; i > l; i--) sb.append(i + 1).append('\n');
    sb.append(l + 1);
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 51064
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();

    if a <= 8 && b <= 8 {
        println!("Yay!");
    } else {
        println!(":(");
    }
}


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

int main(){
  ll n;cin>>n;
  vector<ll> v(n);
  vector<ll> w(n,0);
  rep(i,n) cin>>v[i];
  for(ll i=n-1;i>=0;i--){
      ll tmp=0;
      rep(j,n/(i+1)){
        if(j==0) tmp+=v[(i+1)*(j+1)-1];
        else tmp+=w[(i+1)*(j+1)-1];
      }
      if(v[i]==1){
        if(tmp%2==0) w[i]=0;
        if(tmp%2==1) w[i]=1;
      }else if(v[i]==0){
        if(tmp%2==0) w[i]=0;
        if(tmp%2==1) w[i]=1;
      }
  }
  ll ans=0;
  rep(i,n) if(w[i]==1) ans++;
  cout<<ans<<endl;
  rep(i,n) if(w[i]==1) cout<<i+1<<' ';
  cout<<endl;
  
}



Measured memory_bytes: 3968
def main():
    N = int(input())
    s = list(input())
    K = int(input())
    
    base = s[K-1]
    for i in range(N):
        if s[i] != base:
            s[i] = "*"
            
    print(*s,sep="")
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
def dfs(i, s, ex):
    if i == 4:
        if s == 7:
            return ex + "=7"
        else:
            return ""

    if i == 0:
        return dfs(i + 1, int(S[i]), S[i])

    return dfs(i + 1, s + int(S[i]), ex + "+" + S[i]) or dfs(
        i + 1, s - int(S[i]), ex + "-" + S[i]
    )


S = input()
print(dfs(0, 0, ""))


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

const int MOD = 1e9 + 7;

typedef long long int ll;
typedef pair<ll, ll> Pl;

ll N, last;
map<Pl, ll> MAP;

// || (X == 0 && S == 1) || (X == 1 && S == 0)
ll func(ll S, ll X) {
  if (MAP[Pl(S, X)] > 0) return MAP[Pl(S, X)];
  if (X == 0 && S == 0) {MAP[Pl(S, X)] = 1; return MAP[Pl(S, X)];}
  ll ans = 0;
  ans = (ans + func(S / 2, X / 2)) % MOD;
  if (X >= 1 && S >= 1) {ans = (ans + func((S - 1) / 2, (X - 1) / 2)) % MOD;}
  if (S >= 2) ans = (ans + func((S - 2) / 2, X / 2)) % MOD;
  MAP[Pl(S, X)] = ans;
  return ans;
}

int main(void){
    // Here your code !
    scanf("%lld", &N);
    last = func(N, N);
    printf("%lld\n", last);
    return 0;
}

Measured memory_bytes: 256
// @samaranand
//
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define int64 long long
#define VI vector < int >
#define VII vector < vector < int > >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define pii pair < int , int >
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define sz(v) v.size()
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
//const long long biGinf = 9e+18;
const char nwl = '\n';

int main() {
	//ur code

	int n;
	cin >> n;
	int s0 = 0, s1 = 0, s2 = 0;
	for0(i, n) {
		int x, y, z;
		cin >> x >> y >> z;
		int t0 = s0, t1 = s1, t2 = s2;
		s0 = x + max(t1, t2);
		s1 = y + max(t0, t2);
		s2 = z + max(t1, t0);
		//cout << s0 << " " << s1 << " " << s2 << nwl;
	}
	cout << max(s0, max(s1, s2));
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var P = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var min = P[0];
        var count = 0;
        for (int i = 0; i < N; i++)
        {
            if (min >= P[i])
            {
                count++;
            }
            min = Math.Min(min, P[i]);
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 34012
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	ll ans = 0;
	makei(N);
	makei(K);
	rep(N) {
		int x;
		cin >> x;
		ans += 2*min(x, K - x);
	}
	say(ans);
}

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

using namespace std;

int main()
{
	int n;
	double num;
	int list[100]={};
	cin >> n;
	while(n--)
	{
		cin >> num;

		if(num<165)list[0]++;
		else if(num<170)list[1]++;
		else if(num<175)list[2]++;
		else if(num<180)list[3]++;
		else if(num<185)list[4]++;
		else list[5]++;
	}    

	for(int i=0;i<6;i++)
	{
		cout << i+1 << ":";
		for(int j=0;j<list[i];j++)cout << "*";
		cout << endl; 
	}
    return 0;
}

Measured memory_bytes: 1232
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
ans = 0
divs = make_divisors(N)
divs = [x for x in divs if x > 1]
for k in divs:
    x = N
    while x % k == 0:
        x //= k
    if x % k == 1:
        ans += 1

divs = make_divisors(N - 1)
divs = [x for x in divs if x > 1]
ans += len(divs)
print(ans)


Measured memory_bytes: 39280
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TripleDots solver = new TripleDots();
        solver.solve(1, in, out);
        out.close();
    }

    static class TripleDots {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            String s = in.next();

            if (s.length() <= k) {
                out.append(s);
                return;
            }

            out.append(s.substring(0, k) + "...");

        }

    }
}



Measured memory_bytes: 38660
N = int(input())
SP = []
for i in range(N):
  S, P = map(str, input().split())
  SP.append([S, int(P), i + 1])

A = sorted(SP, key = lambda x : x[1], reverse = True)
A = sorted(A, key = lambda x : x[0])

for a in A:
  print(a[2])

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);i++)
int main() {
	bool isprime[100001];
	rep(i,100001) isprime[i]=true;
	isprime[0]=isprime[1]=false;
	for(int i=0 ; i*i<100001; i++){
		if(isprime[i]){
			for(int j=2;i*j<100001;j++){
				isprime[i*j]=false;
			}
		}
	}
	int cnt[100000];
	cnt[0]=0;
	rep(i,100001){
		if(isprime[i+1]&&isprime[(i+2)/2]){
			cnt[i+1]=cnt[i]+1;
		}
		else cnt[i+1]=cnt[i];
	}
	int Q;
	cin>>Q;
	rep(i,Q){
		int l,r;
		cin>>l>>r;
		cout<<cnt[r]-cnt[l-1]<<endl;
	}
	return 0;

}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;

namespace V0046{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var ml = new List<decimal>();
            while(Console.In.Peek() != -1) ml.Add(sr.Next<decimal>());
            Console.WriteLine(ml.Max() - ml.Min());
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }
    }
}

Measured memory_bytes: 9572
/*   In The Name Of God   */
// Hunt...
/*
ID: alimora2
LANG: C++11
TASK: PROB
*/
#include <bits/stdc++.h>

#define sqr(A) (A) * (A)
using namespace std;
typedef long long ll;

const string P = "Positive", N = "Negative", Z = "Zero";

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	ll a, b;
	cin >> a >> b;
	if (a > 0 && b > 0)
		return cout << P << endl, 0;
	if (a <= 0 && b >= 0)
		return cout << Z << endl, 0;
	if (a < 0 && b < 0)
		if ((abs(a) - abs(b) + 1) % 2 == 0)
			return cout << P << endl, 0;
		else
			return cout << N << endl, 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X): 
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

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

bool comp(pair<ll, ll> a, pair<ll, ll> b){
    return a.first * b.second < a.second * b.first;
}

int main(){
    ll q, h, s, d, n; cin >> q >> h >> s >> d >> n;
    vector<pair<ll, ll> >v;
    v.push_back(pair<ll, ll>(q, 1));
    v.push_back(pair<ll, ll>(h, 2));
    v.push_back(pair<ll, ll>(s, 4));
    v.push_back(pair<ll, ll>(d, 8));
    n *= 4;
    sort(v.begin(), v.end(), comp);
    ll ans = 0;
    for(ll i = 0; i < 4; ++i){
        ans += (n / v[i].second) * v[i].first;
        n %= v[i].second;
    }
    cout << ans << endl;
    return 0;
}

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

ll f(ll n) {
	if (n <= 1) return 0;
	return n * (n-1) / 2;
}

ll cnt[200010] = {0};
ll ans[200010] = {0};

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n; cin >> n;
	vector<ll> v(n);
	for (auto &i : v) {
		cin >> i;
		cnt[i]++;
	}
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		ans[i] = f(cnt[i]);
		sum += ans[i];
	}
	for (int i = 0; i < n; i++) {
		cout << sum - ans[v[i]] + f(cnt[v[i]] - 1) << '\n';
	}
}

Measured memory_bytes: 6272
import java.util.Scanner;


public class Main
{
	static int[][] map = new int[8][8];
	
	static int[][][] peace =
		{
			{
				{1,1,0,0},
				{1,1,0,0},
				{0,0,0,0},
				{0,0,0,0},
			},
			{
				{1,0,0,0},
				{1,0,0,0},
				{1,0,0,0},
				{1,0,0,0},
			},
			{
				{1,1,1,1},
				{0,0,0,0},
				{0,0,0,0},
				{0,0,0,0},
			},
			{
				{0,1,0,0},
				{1,1,0,0},
				{1,0,0,0},
				{0,0,0,0},
			},
			{
				{1,1,0,0},
				{0,1,1,0},
				{0,0,0,0},
				{0,0,0,0},
			},
			{
				{1,0,0,0},
				{1,1,0,0},
				{0,1,0,0},
				{0,0,0,0},
			},
			{
				{0,1,1,0},
				{1,1,0,0},
				{0,0,0,0},
				{0,0,0,0},
			},
		};
	
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{
			for(int i=0; i<8; i++)
			{
				String s = scanner.next();
				
				for(int j=0; j<8; j++)
				{
					map[i][j] = Integer.parseInt(s.substring(j, j+1));
				}
			}
			
			int id = -1;
			for(int i=0; i<8 && id<0; i++)
			{
				for(int j=0; j<8; j++)
				{					
					if(getPeace(i, j) >= 0)
					{
						id = getPeace(i, j);
						break;
					}
				}
			}
			
			String[] output = {"A", "B", "C", "D", "E", "F", "G"};
			System.out.println(output[id]);
		}
	}
	
	static int getPeace(int h, int w)
	{
		for(int k=0; k<7; k++)
		{
			int sum = 0;
			boolean is = true;
			for(int i=0; i<4; i++)
			{
				for(int j=0; j<4; j++)
				{
					if(h+i>=8 || w+j>=8)
					{
						break;
					}
					if(peace[k][i][j] != map[h+i][w+j])
					{
						is = false;
					}
					else if(map[h+i][w+j]==1 && peace[k][i][j]==1)
					{
						sum ++;
					}
					
				}
			}
			if(is && sum==4)
			{
				return k;
			}
		}
		return -1;
	}
}

Measured memory_bytes: 27760
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line.split(" ")[0]);
int wmax=Integer.parseInt(line.split(" ")[1]);
int[] v=new int[n];
int[] w=new int[n];
for(int i=0;i<n;i++){
line=br.readLine();
v[i]=Integer.parseInt(line.split(" ")[0]);
w[i]=Integer.parseInt(line.split(" ")[1]);
}
int[][] dp=new int[n+1][wmax+1];
for(int j=n-1;j>=0;j--){
for(int i=0;i<=wmax;i++){
if(i<w[j]) dp[j][i]=dp[j+1][i];
else dp[j][i]=Math.max(dp[j+1][i],dp[j][i-w[j]]+v[j]);
}
}
out.println(dp[0][wmax]);
}
out.flush();
}
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
};

ll N;
Vertex V[105];
pll ans[105];

void dfs(ll idx, ll &time) {
    ans[idx].first = time++;
    for (auto &nxt:V[idx].node) {
        if (ans[nxt].first > 0)
            continue;
        dfs(nxt, time);
    }
    ans[idx].second = time++;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        ll n, k;
        cin >> n >> k;
        n--;
        REP(j, k) {
            ll v;
            cin >> v;
            v--;
            V[n].node.push_back(v);
        }
    }
    REP(i, N) {
        ans[i] = pll(0, 0);
    }
    ll time = 1;
    REP(i, N) {
        if (ans[i].first > 0)
            continue;
        dfs(i, time);
    }
    REP(i, N) {
        cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
}

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

void solve(int N, int x) {
    if (x <= 1 || x >= N*2-1) {
        cout << "No" << endl;
        return;
    }

    cout << "Yes" << endl;
    vector<int> res(N*2-1, -1);
    res[N-2] = 1;
    res[N-1] = x;
    res[N] = N*2-1;
    int iter = 0;
    for (int v = 2; v < N*2-1; ++v) {
        if (v == x) continue;
        while (res[iter] != -1) ++iter;
        res[iter] = v;
    }
    for (auto v : res) cout << v << endl;
}

int main() {
    int N, x;
    cin >> N >> x;
    solve(N, x);
}

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

int main()
{
	string s;
	cin >> s;
	if(s.size() == 2)
	{
		if(s[0] == s[1]) return puts("1 2"), 0;
		else return puts("-1 -1"), 0;
	}
	for(int i = 0; i < s.size()-2; i++)
	{
		if(s[i] == s[i+1] or s[i] == s[i+2])
			return printf("%d %d\n", i+1, i+3), 0;
	}
	puts("-1 -1");
	return 0;
}

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

int main() {
  int X,N;
  cin >> X >> N;
  int num=0;
  bool frag =true;
  vector <int> b(N);
  if(N==0){
    cout << X <<endl;
    return 0;
  }

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

  sort(b.begin(),b.end());

  if (b.at(0)>X){
    cout << X << endl;
    return 0;
  }
  else if(b.at(N-1)<X){
    cout << X << endl;
    return 0;
  }

  for(int i=0;i<N;i++){
    //cout << b.at(i);
    if(b.at(i)==X){
      frag =false;
      num=i;
      break;
    }
  }
  //cout << num << endl;

  int tmp1=0,tmp2=0;
  int num1,num2;
  num1=num;num2=num;

  tmp1 = X; tmp2=X;
  if(frag){
    cout << X <<endl;
    return 0;
  }
  else{
    while(true){
      tmp1++;tmp2--;
      num1--;num2++;
      if((num1>-1 && b.at(num1)!=tmp2)||num1<0){
        //cout << tmp2 <<"A"<<endl;
        cout << tmp2 <<endl;
        return 0;
      }
      if((num2<N && b.at(num2)!=tmp1)||num2>N-1){
        //cout << tmp1<<"B" <<endl;
        cout << tmp1 <<endl;
        return 0;
      }
    }

  }

}


Measured memory_bytes: 3628
#coding:utf-8
n = int(input())
numbers = list(map(int,input().split()))

for i in range(n):
    tmp = numbers[i]
    j = i - 1

    while j >= 0 and numbers[j] > tmp:
        numbers[j+1] = numbers[j]
        j -= 1
    numbers[j+1] = tmp

    print(*numbers)

Measured memory_bytes: 6752
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	
	if a + b > c + d {
		fmt.Println("Left")
	} else if  a + b < c + d {
		fmt.Println("Right")
	} else {
		fmt.Println("Balanced")
	}
}

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

int main()
{
    int N, K;
    int i;
    cin >> N >> K;
    vector<int> A(N);
    for(i = 0; i < N;i++){
      cin >> A.at(i);
    }
    long int max;
    long int sum;

    int j;
    for(j = 0; j < K; j++){
      sum += A.at(j);
    }
    max = sum;

    for(j = 0; j < N-K; j++){
      sum = sum - A.at(j) + A.at(j+K);
      if(sum > max){
        max = sum;
      }
    }
    long int a = (max + K) / 2;
    cout << a;
    if((max + K) % 2 == 1){
      cout << ".5";
    }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    vector<string> w(n);
    char c;
    bool f = true;
    rep(i, n)
    {
        string s; cin >> s;
        if (i != 0)
        {
            if (c != s[0] || find(ALL(w), s) != w.end()) f = false;
        }
        w[i] = s;
        c = s[s.size() - 1];
    }
    if (!f) puts("No");
    else puts("Yes");
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define acc(v) accumulate(v.begin(), v.end(),0);
#define MOD 1e+7;
#define inf 1e9;
#define fi first;
#define se second;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, res = 0;
  cin >> n >> m;
  vector<int> p(m);
  vector<vector<int>> s(m,vector<int>(0));
  rep(i,m) {
    int k;
    cin >> k;
    rep(j,k) {
      int a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }
  rep(i,m) cin >> p[i];
  for (int bit = 0; bit < (1 << n); bit++) {
    bool ok = true;
    rep(i,m) {
      int con = 0;
      for (auto v : s[i]) if (bit & (1 << v)) ++con;
      if (con % 2 != p[i]) ok = false;
    }
    if (ok) res++;
  }
  cout << res << endl;
  return 0;
}
//templete by private_yusuke

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1')
      cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>

int main(){
  int N,c=1;
  char S[102];
  scanf("%d\n%s",&N,S);
  if(N%2==0){
    int T=N/2;
    for(int i=0;i<T;i++){
      if(S[i]!=S[i+T]) c=0;
    }
  }else{
    c=0;
  }
  if(c) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
 
int main()
{
    int i,x1,x2,x3,m;
    while(~scanf("%d",&m))
    {
        x1=0;
        x2=0;
        for(i=1; i<=m; i++)
        {
            //cin>>a[i];
            scanf("%lld",a+i);
            if(a[i]%2==0) x1++;
            if(a[i]%4==0) x2++;
        }
        //cout<<x1<<' '<<x2<<endl;
        x1-=x2;
        x3=m-x1-x2;
        if(x3<=x2||(x1==0&&x2+1==x3))
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.Iterator;

class Depth {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Depth() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}

	private int time;
	private Integer[][] table;
	public void depthSearch() {
		table = new Integer[totalVertex][3];
		for(Integer[] i : table)
		{
			i[0] = -1; 
		}
		time = 0;
		depthSearchHelper(0);
		for(int i = 0; i < table.length - 1 ; i++)
		{
			if(table[i][0] == -1)
			{
				depthSearchHelper(i);
			}
			System.out.println(table[i][0] + 1 + " " + table[i][1] + " " + table[i][2]);
		}
		if(table[table.length-1][0] == -1)
		{
			depthSearchHelper(table.length-1);
		}
		System.out.println(table[table.length-1][0] + 1 + " " + table[table.length-1][1] + " " + table[table.length-1][2]);
		
	}

	public void depthSearchHelper(int n) {
		time++;
		table[n][0] = n;
		table[n][1] = time;
		LinkedList<Integer> paths = adjList.get(n);
		if(paths.size() == 0)
		{
			table[n][2] = ++time;
		}else
		{
			for(int i: paths)
			{
				boolean test = true;
				for(Integer[] j : table)
				{
					if(j[0] == i)
					{
						test = false;
					}
				}
			
				if(test == true)
				{
					depthSearchHelper(i);
				}
			}
			table[n][2] = ++time;
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main{
	public static void main(String argv[]) {
		Depth g = new Depth();
		g.loadAdjList();
		g.depthSearch();
	}
}


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

int main(void)
{
    int n;
    cin >> n;
    deque<int> dq;
    for (size_t i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        int position = lower_bound(dq.begin(), dq.end(), a) - dq.begin();
        if(0 == position){
            dq.push_front(a);
        }else{
            dq[position - 1] = a;
        }
    }

    cout << dq.size() << endl; 
    return 0;
}

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

int main(){
  int e;
  while(cin >> e, e){
    int limz, ret = ( 1 << 30 );
    for(int z = 0 ; ( limz = z * z * z) <= e ; z++ ){
      for(int y = 0 ; limz + y * y <= e; y++){
        int x = e - limz - y * y;
        ret = min( x + y + z, ret);
      }
    }
    cout << ret << endl;
  }
}

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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

int roundUp(int n) {
    if(n % 10 == 0)
        return n;
    else 
        return (10 - n%10) + n;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    vector<int> arr(5);

    for(int i = 0; i < 5; i++)
        cin >> arr[i];

    int res = 10e5;
    do {
        int t = 0;
        int i;
        for(i = 0; i < 5; i++) {
            if(i == 0)
                t += roundUp(arr[i]);
            else {
                if(i != 4)
                    t += roundUp(arr[i]);
                else 
                    t += arr[i];
            }
        }
        res = min(res, t);
    } while(next_permutation(arr.begin(), arr.end()));


    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256