akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
#include<time.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n,k;
int r,s,p;
string t;
int ta[111111];

int score[3];
int dp[111111][3];//r,s,p

vector<int> te[111111];

bool can_win(int a,int b){
  return (a+1==b) || (a==2&&b==0);
}


int query(int pos){

    int tmpn=te[pos].size();

    for(int i=0;i<tmpn;i++){
      for(int now=0;now<3;now++){
        for(int next=0;next<3;next++){
          if(now==next)continue;
          if(can_win(next,te[pos][i])){
            dp[i+1][next]=max(dp[i+1][next],dp[i][now]+score[next]);
          }
          else{
            dp[i+1][next]=max(dp[i+1][next],dp[i][now]);
          }
        }
      }
    }

  int ans=0;
  rep(i,3)ans=max(ans,dp[tmpn][i]);

  rep(i,tmpn+1)rep(j,3)dp[i][j]=0;
  //rep(i,n)rep(j,3)dp[i][j]=0;
  return ans;
}

int main(){
  cin>>n>>k>>score[0]>>score[1]>>score[2]>>t;
  int ans=0;

  rep(i,n){
    if(t[i]=='r')ta[i]=0;
    if(t[i]=='s')ta[i]=1;
    if(t[i]=='p')ta[i]=2;
  }
  rep(i,n){
    te[i%k].pb(ta[i]);
  }

  rep(i,k)
    ans+=query(i);

  //for(int pos=0;pos<k;pos++){
  //  int last;[]j

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


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)
  {
    cin >> a[i];
  }

  bool is_odd = n % 2 == 1;

  int index = n - 1;
  while (index > -1)
  {
    cout << a[index] << " ";
    index -= 2;
  }

  if (is_odd)
    index = 1;
  else
    index = 0;

  while (index < n)
  {
    cout << a[index] << " ";
    index += 2;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2944
package main
 
import(
  "fmt"
	"bufio"
	"os"
	"strings"
	"log"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}
 
func abc148a(a int, b int){
	if a+b == 3{
		fmt.Println(3)
	}else if a+b == 4{
		fmt.Println(2)
	}else{
		fmt.Println(1)
	}
}
 
func main(){
	a := 0
	b := 0
	fmt.Scan(&a)
	fmt.Scan(&b)
	abc148a(a,b)
}

//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {

        int a, b, d, r;

        double f;

        

        scanf("%d%d", &a, &b);

        

            //a/b(整数)

            d = a / b;

            //a/bの余り

            r = a % b;

            //a/b(浮動小数点数)

            f = (double)a / b;

            

            printf("%d %d %lf\n", d, r, f);

        return 0;

}


Measured memory_bytes: 2124
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>

using namespace std;

int main() {
	string ans, res;

	while (cin >> ans >> res, ans != "0" || res != "0") {
		int hit = 0;
		for (int i = 0; i < 4; ++i)
			if (ans[i] == res[i])
				++hit;

		cout << hit << " ";

		int blow = 0;
		map<int, bool> m;
		for (int i = 0; i < 4; ++i)
			m[ans[i]] = true;

		for (int i = 0; i < 4; ++i)
			if (m[res[i]])
				++blow;

		cout << (blow - hit) << endl;
	}
/*
	vector<int> nums;
	for (int i = 0; i < 10000; ++i) {
		char str[5];
		sscanf(str, "%04d", i);

		bool is_ng = true;
		for (int j = 0; j < 4; ++j)
			for (int k = 0; k < 4; ++k)
				if (str[j] == str[k])
					is_ng = false;

		if (is_ng) continue;

		nums.push_back(i);
	}

	int ans, res;

	while (cin >> ans >> res, ans || res) {
		int 
		cout << (int)( lower_bound( nums.begin(), nums.end(), res ) - lower_bound() ) << endl;
	}
*/
}

Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    int n,k;
    cin>>n>>k;
    cin>>s;
    k--;
    s[k]+=32;
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 3612
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*A)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if h<=0:break
    elif i>=a:
        count +=1
        h -=i

if h>0:
    count +=(h-1)//a+1

print(count)

Measured memory_bytes: 25304
#include<iostream>
#include<string>
#include <cctype>
#include <algorithm>

bool check_int(std::string str)
{
    if (std::all_of(str.cbegin(), str.cend(), isdigit))
    {
        
        return true;
    }
   
    return false;
}
int main(){
using std::string;
int a,b;
string s;
std::cin >>a>>b;
std::cin >>s;
string a1,b1;
a1=s.substr(0, a);
b1=s.substr(a+1,b);
int flag=1;
if(s[a]=='-'){
if( check_int(a1)){
if( check_int(b1)){
flag=0;
}
}
}
if(flag==0)
std::cout << "Yes";
else
std::cout << "No";
return 0;
}

Measured memory_bytes: 256
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

memo = [0 for i in range(65)]
AA = [i for i in A]
for i in AA:
	r = 0
	while i > 0:
		if((i & 1) == 1):
			memo[r] = memo[r] + 1
		i = i // 2
		r = r + 1
res = 0
for i in range(50):
	if 2*memo[i] < N:
		res = res + (1 << i)
d = 51
while res > K:
	if ((res >> d) & 1) == 1 and ((K >> d) & 1) == 0:
		res = res ^ (1 << d)
	d = d - 1
    
ans = 0
for i in A:
	ans = ans + (res ^ i)
print(ans)
  

Measured memory_bytes: 14620
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        p: [chars],
    }
    let mut c = true;
    for p in p {
        c = !c;
        c |= &['T'][..] == &p[..];
    }
    puts!("{}\n", if c { "T" } else { "F" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <cmath>

using namespace std;
 
template<class T>
T read()
{
    T value;
    std::cin >> value;
    return value;
}
 
template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}

int main()
{
    double a,b;
    cin >> a >> b;
    cout << (int)ceil((a+b)/2) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<list>
using namespace std;
int main()
{
    int n;
    cin>>n;
    list<int>nil;
    for(int i=0; i<n; i++)
    {
        char s[100];
        int x;
        scanf("%s",s);
        if(s[0]=='i')
            scanf("%d",&x),nil.push_front(x);
        else if(s[6]=='L')
            nil.pop_back();
        else if(s[6]=='F')
            nil.pop_front();
        else if(s[0]=='d')
        {
            scanf("%d",&x);
            for(list<int>::iterator it=nil.begin(); it!=nil.end(); it++)
                if(*it==x)
                {
                    nil.erase(it);
                    break;
                }
        }
    }
    int flag=0;
    //for(auto i:nil)
    for(list<int>::iterator it=nil.begin(); it!=nil.end(); it++)
    {
        if(flag++)
            cout<<' ';
        cout<<*it;
    }
    cout<<'\n';
    return 0;
}
/*
9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteLirst
deleteFast

*/



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

int main() {
    int N;
    cin >> N;
    int A[N], B[N], C[N];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);

    ll ans = 0;
    rep(j, N) {
        auto itrA = lower_bound(A, A+N, B[j]);
        auto itrC = upper_bound(C, C+N, B[j]);
        ll numA = (int)(itrA-A);
        ll numC = N-(int)(itrC-C);
        ans += numA * numC;
    }

    cout << ans << endl;

    return 0;
}



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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define _GLIBCXX_DEBUG

void chmaxl(ll &a,ll b){
	if(a<b){
		a=b;
	}
	return;
}

void chminl(ll &a,ll b){
	if(a>b){
		a=b;
	}
	return;
}

void chmaxi(int &a,int b){
	if(a<b){
		a=b;
	}
	return;
}

void chmini(int &a,int b){
	if(a>b){
		a = b;
	}
	return;
}



int main() {
  int a,b;
  cin >> a >> b;
  if(a<=b){
    cout << a;
  }
  else{
    cout << a-1;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long next357(long n) {
  	for(int i = 1; i <= 10;i++) {
  		if( (n%(int)(pow(10.0,i))) / (int)(pow(10.0,i-1)) !=7) {
			if(n/pow(10.0, i-1)>1)
	          	n +=2*pow(10.0, i-1);
          	else
              	n +=3*pow(10.0, i-1);
            n /= (int)(pow(10.0,i-1));
	  	   	n *= (int)(pow(10.0,i-1));
	      	for(int j = 1; j < i; j++) {
              	n+= 3*(int)(pow(10.0,j-1));
	        }
          	return n;
        }
    }
  	return -1;
}
int main(){
	long n,t=357,count=0;
  	cin >> n;	
  	string s;
  	int ch=0;
  	bool ok;
  	while(t<=n) {
      	s = to_string(t);
      	ch = 0;
      	ok = false;
      	for(int i = 0; i < s.size(); i++) {
        	if(s[i] == '3')
            	ch |= 1;
          	if(s[i] == '5')
              	ch |= 2;
          	if(s[i] == '7')
              	ch |= 4;
          	if(ch == 7) {
            	ok = true;
              	break;
            }  	
        }
      	if(ok) {
          	count++;
        }
    	t = next357(t);
      	if(t==-1)
          	break;
    }
 	cout << count << endl;
}

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

int main(void){
    int a, b, c;
    int i;
    int count = 0;
    
    cin >> a >> b >> c;
    
    for(i = a; i <= b; i++){
        if(!(c % i)) count ++;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, K;
vector<int> u, v;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    string s;
    cin >> s;
    ll a = 0, k = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'B')
            k++;
        else
            a += k;
    }
    cout << a << endl;
}

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

int main() {
	long long d, n, a = 0, x, y, z, b;
	cin >> d >> n;
	/*
	for(int i = 0; i < n; i++){
		for(int j = 0; i < d; i++){
			
		}
	}
	
	while(n > 0){
		a++;
		x = d;
		b = a;
		while(x >= 0){
			if(b % 100 == 0){
				if(x == 1){
					n--;
				}
				x--;
				b / 100;
			}else{
				break;
			}
				
		}

	}
	cout << a << endl;
	*/
	if(d == 0){
		if(n < 100){
			cout << n << endl;
		}else{
			cout << 101 << endl;
		}
	}else if(d == 1){
		if(n < 100){
			cout << 100 * n << endl;
		}else{
			cout << 100 * 100 + 100<< endl;
		}
	
	}else{
		if(n < 100){
			cout << 100 * 100 * n << endl;
		}else{
			cout << 10000 * 100 + 10000<< endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
vector<int>tas(200001);
vector<int>visited(200001);
vector<vector<int>>chi(200001,vector<int>(0));
void dfs(int k){
  visited[k]=1;
  rep(i,chi[k].size()){
    if(!visited[chi[k][i]]){tas[chi[k][i]]+=tas[k];
    dfs(chi[k][i]);
  }
  }
}
signed main() {
  int n, q;
  cin>>n>>q;
  vector<int>par(n);
rep(i,n-1){
  int t1,t2;
  cin>>t1>>t2;
    chi[t2-1].push_back(t1-1);
    chi[t1-1].push_back(t2-1);
}
rep(i,q){
  int num,tmp;
  cin>>num>>tmp;
  tas[num-1]+=tmp;
}

dfs(0);
rep(i,n){
  cout<<tas[i]<<endl;
}
}


Measured memory_bytes: 24320
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	cout << (h - a) * (w - b) << endl;
}

Measured memory_bytes: 256
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let () =
  let max_b = 4 in
  let max_f = 3 in
  let max_r = 10 in
  let ary = Array.make (max_b * max_f * max_r) 0 in
  let n = read_int () in
  for _ = 1 to n do
    let l = read_line () in
    match List.map int_of_string (split l ' ') with
    | [] | [_] | _::_::[] | _::_::_::[] -> exit 1
    | b :: f :: r :: v :: _ ->
        ary.(max_f*max_r*(b-1) + max_r*(f-1) + (r-1)) <- ary.(max_f*max_r*(b-1) + max_r*(f-1) + (r-1)) + v
  done;
  for b = 1 to max_b do
    for f = 1 to max_f do
      for r = 1 to max_r do
        Printf.printf " %d" ary.(max_f*max_r*(b-1) + max_r*(f-1) + (r-1))
      done;
      print_newline ()
    done;
    if b <> max_b then Printf.printf "####################\n"
  done

Measured memory_bytes: 2392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    if(n==1){
        cout<<"Hello World"<<endl;
    }else{
        int a,b;cin>>a>>b;
        cout<<a+b<<endl;
    }
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

//https://qiita.com/drken/items/4a7869c5e304883f539b#2-%E8%A8%88%E7%AE%97%E6%A9%9F%E4%B8%8A%E3%81%A7%E3%81%AE%E3%82%B0%E3%83%A9%E3%83%95%E3%81%AE%E8%A1%A8%E3%81%97%E6%96%B9

int main() {
  // 頂点数と辺数
  int N, M; cin >> N >> M;

  // グラフ
  Graph G(N+1); // 0 to N
  for (int i = 0; i < M; ++i) {
      int a, b;
      cin >> a >> b;
      G[a].push_back(b);
      G[b].push_back(a);
  }

  vector<int> from(N+1, -1); // 0 to N
  queue<int> que;

  que.push(1);

  while(!que.empty()){
    int v = que.front();
    que.pop();

    for(int nv : G[v]){
      if (from[nv] != -1) continue;

      from[nv] = v;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  for (int v = 2; v <= N; ++v) cout << from[v] << endl;
}

Measured memory_bytes: 10104
// ITP2_1_C List
import java.util.Scanner;

class Node {
  int x;
  Node next;
  Node prev;
}

public class Main {
  public static void main(String[] args) {
    Node sentinel = new Node();
    Node curr = sentinel;
    Scanner sc = new Scanner(System.in);
    int q = sc.nextInt();
    for (int i = 0; i < q; ++i) {
      switch (sc.nextInt()) {
        case 0: // insert
          Node tmp = new Node();
          tmp.x = sc.nextInt();
          tmp.next = curr;
          tmp.prev = curr.prev;
          if (curr.prev != null) curr.prev.next = tmp;
          curr.prev = tmp;
          curr = tmp;
          break;
        case 1: // seek
          int d = sc.nextInt();
          if (d > 0) {
            while (d != 0 && curr.next != null) {
              curr = curr.next;
              d--;
            }
          } else {
            while (d != 0 && curr.prev != null) {
              curr = curr.prev;
              d++;
            }
          }
          break;
        case 2: // delete
          curr.next.prev = curr.prev;
          if (curr.prev != null) curr.prev.next = curr.next;
          curr = curr.next;
      }
    }
    while (curr.prev != null) curr = curr.prev;
    while (curr != sentinel) {
      System.out.println(curr.x);
      curr = curr.next;
    }
  }
}



Measured memory_bytes: 307576
/**
 * @author yuzining
**/
#ifdef local
#include "D:\vscode\acm\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

const int MOD = 1e9 + 7;

void Main() {
  int n, k; cin >> n >> k;
  vector<int> a(n);
  bool havePositive = false;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i] > 0) havePositive = true;
  }
  if(n == k) {
    int ans = 1;
    for(int i = 0; i < n; i++) {
      if(a[i] < 0) a[i] += MOD;
      ans = 1ll * ans * a[i] % MOD;
    }
    cout << ans << '\n';
    return;
  }
  sort(a.begin(), a.end(), [&](const int &x, const int &y) {
    return abs(x) > abs(y);
  });
  if((k & 1) && !havePositive) {
    int ans = 1;
    reverse(a.begin(), a.end());
    for(int i = 0; i < k; i++) {
      ans = 1ll * ans * (MOD + a[i]) % MOD;
    }
    cout << ans << '\n';
    return;
  }
  int ans = 1;
  if(k & 1) {
    for(int i = 0; i < n; i++) {
      if(a[i] > 0) {
        ans = 1ll * ans * a[i] % MOD;
        a.erase(a.begin() + i);
        n--, k--;
        break;
      }
    }
  }
  vector<long long> tmp;
  int t1 = INT_MIN, t2 = INT_MIN;
  for(int i = 0; i < n; i++) {
    if(a[i] < 0) {
      if(t1 == INT_MIN) {
        t1 = a[i];
      } else {
        tmp.push_back(1ll * t1 * a[i]);
        t1 = INT_MIN;
      }
    } else if(a[i] > 0) {
      if(t2 == INT_MIN) {
        t2 = a[i];
      } else {
        tmp.push_back(1ll * t2 * a[i]);
        t2 = INT_MIN;
      }
    }
  }
  k >>= 1;
  if(k <= int(tmp.size())) {
    sort(tmp.begin(), tmp.end());
    reverse(tmp.begin(), tmp.end());
    for(int i = 0; i < k; i++) {
      ans = 1ll * ans * (tmp[i] % MOD) % MOD;
    }
    cout << ans << '\n';
  } else {
    cout << 0 << '\n';
  }
}

Measured memory_bytes: 5068
#include <cstdio>
#include <bitset>

using namespace std;

int main( int argc, char *argv[] ){

  int W,H,N ;

  scanf("%d%d%d",&W,&H,&N) ;

  int x,y,a ;
  int Wl,Hl,Wu,Hu ;
  Wl = 0;
  Hl = 0;
  Wu = W;
  Hu = H;

  for(int i=0; i<N; i++){
    scanf("%d%d%d",&x,&y,&a) ;
    if     (a==1&x>Wl){Wl=x;}
    else if(a==2&x<Wu){Wu=x;}
    else if(a==3&y>Hl){Hl=y;}
    else if(a==4&y<Hu){Hu=y;}
  }

  if((Wu-Wl)<0|(Hu-Hl)<0){printf("%d",0);}
  else   {printf("%d",(Wu-Wl)*(Hu-Hl));}
}


Measured memory_bytes: 128
import Data.List

data RecItem = RecItem {
    riStart :: Int
  , riEnd :: Int
  , riChannel :: Int
  } deriving (Show)

data EventType = ETStart | ETEnd
                           deriving (Eq, Ord)

data Event = Event {
    evTime :: Int
  , evType :: EventType
} deriving (Eq, Ord)

calc :: [RecItem] -> Int -> Int
calc ris numC =
  countPara $ sort $ concat [eventList ris c | c <- [1 .. numC]]

eventList :: [RecItem] -> Int -> [Event]
eventList ris c = 
  concat [[Event s ETStart, Event e ETEnd] |
          RecItem s e _ <- paste $ sortOn riStart $ filter ffilt ris]
  where 
    ffilt (RecItem s e c') = c == c'
    paste = paste2 []
    paste2 acc [] = reverse acc
    paste2 [] (ri : ris) = paste2 [ri] ris
    paste2 acc@((RecItem sA eA c) : risA) (riB@(RecItem sB eB _) : ris)
      | eA == sB  = paste2 ((RecItem sA eB c) : risA) ris
      | otherwise = paste2 (riB : acc) ris

--    paste = foldr gen []
--    gen ri [] = [ri]
--    gen ri1@(RecItem s1 e1 _) ris2@((RecItem s2 e2 c) : ris)
--      | e1 == s2  = RecItem s1 e2 c : ris
--      | otherwise = ri1 : ris2

countPara :: [Event] -> Int
countPara evs = f 0 0 evs
  where f cur vMax [] = vMax
        f cur vMax ((Event t ETStart) : evs) = f (cur + 1) vMax' evs
          where vMax' = if cur == vMax then vMax + 1 else vMax
        f cur vMax ((Event t ETEnd)   : evs) = f (cur - 1) vMax evs

main :: IO ()
main = do
  x <- getLine
  let [numRI, numC] = [read w | w <- words x]
  ris <- readData numRI
  putStrLn $ show $ calc ris numC

readData :: Int -> IO [RecItem]
readData n = do
  ris <- f n []
  return $ reverse ris
  where
    f :: Int -> [RecItem] -> IO [RecItem]
    f n acc | n == 0 = return acc
            | otherwise = do
                    x <- getLine
                    let [s, e, c] = [read w | w <- words x]
                    f (n - 1) (RecItem s e c : acc)


Measured memory_bytes: 139644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
  ll n;
  cin >> n;
  ll ans = 1, mx = 0;
  rep(i, 1, n+1){
    ll cur = i;
    ll tmp = 0;
    while(cur % 2 ==0){
      tmp++;
      cur /= 2;
    }
    if(mx < tmp){
      ans = i;
      mx = tmp;
    }
  }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================




int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	ll N, K, C;
	cin >> N >> K >> C;

	string S;
	cin >> S;


	vll L, R; // i日目の左端、右端


	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'o' && L.size() < K)
		{
			L.emplace_back(i);
			i += C;
		}
	}

	for (int i = N - 1; i >= 0; i--)
	{
		if (S[i] == 'o' && R.size() < K)
		{
			R.emplace_back(i);
			i -= C;
		}
	}

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

	for (int i = 0; i < K; i++)
	{
		if (L[i] == R[i])
		{
			cout << R[i] + 1 << endl;
		}
	}





}





Measured memory_bytes: 5128
object Main extends App {
  import scala.io.StdIn._
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val arms = Array.tabulate(m){_ ⇒
    val Array(x, y) = readLine.trim.split(' ').map(_.toInt - 1)
    (x, y)
  }.sortBy(_._1).map(_._2)
  val min = Array.tabulate(n){i ⇒ i}
  val max = Array.tabulate(n){i ⇒ i}
  for (y ← arms){
    min(y) = Math.min(min(y), min(y + 1))
    min(y + 1) = min(y)
    max(y) = Math.max(max(y), max(y + 1))
    max(y + 1) = max(y)
  }
  println((0 until n).map{i ⇒ max(i) - min(i) + 1}.mkString(" "))
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int n,x,y;
    cin>>n>>x>>y;
    cout<<min(x,y)<<" "<<max(0ll,x+y-n)<<endl;
    return 0;
}


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

typedef long long ll;
const int N = 300300;
int n;
ll a[N];
int b[N];
ll ans = 0;
int par[N], sz[N];
int l[N], r[N];

int getPar(int v)
{
	return (par[v] == -1 ? v : par[v] = getPar(par[v]));
}
bool unite(int v, int u)
{
	v = getPar(v);
	u = getPar(u);
	if (v == u) return false;
	if (sz[v] < sz[u]) swap(v, u);
	sz[v] += sz[u];
	par[u] = v;
	l[v] = min(l[v], l[u]);
	r[v] = max(r[v], r[u]);
	return true;
}

void on(int p)
{
	sz[p] = 1;
	if (p > 0 && sz[p - 1] > 0)
		unite(p - 1, p);
	if (p < n - 1 && sz[p + 1] > 0)
		unite(p, p + 1);
	int v = getPar(p);
	ans += a[p] * (r[v] - p + 1) * (p - l[v] + 1);
	return;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &a[i]);
		b[n - a[i]] = i;
	}
	for (int i = 0; i < n; i++)
	{
		sz[i] = 0;
		par[i] = -1;
		l[i] = r[i] = i;
	}
	for (int i = 0; i < n; i++)
		on(b[i]);
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 5760
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        FastReader in  = new FastReader(); 
        Solver s = new Solver();
        int t = 1;
        while(t-- > 0) s.solve(in, out);
        out.close();
    }

    static class Solver {
        public void solve(FastReader in, PrintWriter out) throws IOException {
            // solve
            int n=in.nextInt();
            int k=in.nextInt();
            int[] a=new int[n];
            for(int i=0;i<n;i++) a[i]=in.nextInt();
            int[] dp=new int[n];
            Arrays.fill(dp, Integer.MAX_VALUE);
            dp[0]=0;
            for(int i=1;i<n;i++){
                for(int j=1;j<=k;j++){
                    if(i-j>=0) dp[i]=Math.min(dp[i], dp[i-j]+Math.abs(a[i]-a[i-j]));
                }
            }
            out.println(dp[n-1]);
        } 
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

#define llint long long int

using namespace std;

int main(){
    int N, X, Y;

    cin >> N >> X >> Y;

    vector<int> ans(N - 1, 0);

    for(int i = 0; i < N; i ++){
        vector<int> v(N, 0);

        int d = 1;

        for(int j = i - 1; j >= 0; j --){
            v[j] = d;
            d ++;
        }
        d = 1;

        for(int j = i + 1; j < N; j ++){
            v[j] = d;
            d ++;
        }
        if(v[X - 1] + 1 < v[Y - 1]){
            v[Y - 1] = v[X - 1] + 1;
        }else if(v[Y - 1] + 1 < v[X - 1]){
            v[X - 1] = v[Y - 1] + 1;
        }
        for(int j = X - 2; j >= 0; j --){
            if(v[j + 1] + 1 < v[j]){
                v[j] = v[j + 1] + 1;
            }else{
                break;
            }
        }
        for(int j = X; j < N; j ++){
            if(v[j - 1] + 1 < v[j]){
                v[j] = v[j - 1] + 1;
            }else{
                break;
            }
        }
        for(int j = Y - 2; j >= 0; j --){
            if(v[j + 1] + 1 < v[j]){
                v[j] = v[j + 1] + 1;
            }else{
                break;
            }
        }
        for(int j = Y; j < N; j ++){
            if(v[j - 1] + 1 < v[j]){
                v[j] = v[j - 1] + 1;
            }else{
                break;
            }
        }
        for(int j = 0; j < i; j ++){
            ans[v[j] - 1] ++;
        }
    }
    for(int i = 0; i < N - 1; i ++){
        cout << ans[i] << endl;
    }
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(std::string S){
    if(S <= "2019/04/30") {
        cout << "Heisei" << endl;
    }else {
        cout << "TBD" << endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
from collections import deque

H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
rows_list=[]
upper=0
for i in range(H):
  for j in range(W):
    if cake[i][j]=="#":
      rows_list.append([upper, i])
      upper=i+1
      break
rows_list[-1][-1]=H-1
ans_list=[]
for rows in rows_list:
  for i in range(rows[0], rows[1]+1):
    left=0
    for j in range(W):
      if cake[i][j]=="#":
        ans_list.append([rows[0], rows[1], left, j])
        left=j+1
    if ans_list:
      ans_list[-1][-1]=W-1
ans=[[0 for _ in range(W)] for _ in range(H)]
key=1
for l in ans_list:
  for i in range(l[0], l[1]+1):
    for j in range(l[2], l[3]+1):
      ans[i][j]=key
  key+=1
for a in ans:
  print(*a)

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

#[allow(dead_code)]
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")
}

#[allow(dead_code)]
struct UnionFind {
    parent: Vec<i32>,
}

#[allow(dead_code)]
impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: vec![-1; n],
        }
    }
    fn root(&mut self, x: usize) -> usize {
        let p = self.parent[x];
        return if p < 0 {
            x
        } else {
            self.parent[x] = self.root(p as usize) as i32;
            self.parent[x] as usize
        };
    }
    fn union_set(&mut self, x: usize, y: usize) -> bool {
        let mut x = self.root(x);
        let mut y = self.root(y);
        if x == y {
            return false;
        }
        if self.parent[y] < self.parent[x] {
            std::mem::swap(&mut x, &mut y);
        }
        self.parent[x] += self.parent[y];
        self.parent[y] = x as i32;
        true
    }
    fn find_set(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }
    fn size(&mut self, x: usize) -> usize {
        let r = self.root(x);
        -self.parent[r] as usize
    }
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut union_find = UnionFind::new(n);
    let mut edges = vec![];
    for _ in 0..m {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        edges.push((a, b));
    }
    edges.reverse();
    let mut sum = n * (n - 1) / 2;
    let mut anss = vec![0; m];
    for i in 0..m {
        anss[i] = sum;
        let a = edges[i].0;
        let b = edges[i].1;
        if !union_find.find_set(a, b) {
            sum -= union_find.size(a) * union_find.size(b);
            union_find.union_set(a, b);
        }
    }
    anss.reverse();
    for i in 0..m {
        println!("{}", anss[i]);
    }
}


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

int main() {
    int N; cin >> N;
    int hp = 0;
    int hn = 0;
    int ansp = 0;
    int ansn = -1;
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        cin >> hn;
        if (hn <= hp) {
            ansn++;
        } else {
            if (ansn > ansp) ansp = ansn;
            ansn = 0;
        }
        hp = hn;
    }

    if (ansn > ansp) {
        ans = ansn;
    } else {
        ans = ansp;
    }

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

Measured memory_bytes: 256
N, M, *XYZ = map(int, open(0).read().split())

A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    A[0].append(sum((x, y, z)))
    A[1].append(sum((x, y, -z)))
    A[2].append(sum((x, -y, z)))
    A[3].append(sum((x, -y, -z)))
    A[4].append(sum((-x, y, z)))
    A[5].append(sum((-x, y, -z)))
    A[6].append(sum((-x, -y, z)))
    A[7].append(sum((-x, -y, -z)))

cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))

print(max(cand))


Measured memory_bytes: 3572
#include <stdio.h>
char b[10][10];
void solve(int x,int y){
	int c,i,j;
	b[y][x]='0';
	for(c=0,i=y+1,j=x;c<3&&i<8;c++,i++){
		if(b[i][j]=='1'){
			solve(j,i);
		}
	}
	for(c=0,i=y,j=x+1;c<3&&j<8;c++,j++){
		if(b[i][j]=='1'){
			solve(j,i);
		}
	}
	for(c=0,i=y-1,j=x;c<3&&i>=0;c++,i--){
		if(b[i][j]=='1'){
			solve(j,i);
		}
	}
	for(c=0,i=y,j=x-1;c<3&&j>=0;c++,j--){
		if(b[i][j]=='1'){
			solve(j,i);
		}
	}
}
int main(void){
	int n,c=1,i,j,x,y;
	scanf("%d",&n);
	while(n--){
		for(i=0;i<8;i++){
			scanf("%s",b[i]);
		}
		scanf("%d %d",&x,&y);
		solve(x-1,y-1);
		printf("Data %d:\n",c++);
		for(i=0;i<8;i++){
			printf("%s\n",b[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 608
#include "bits/stdc++.h"
using namespace std;
int main(){
    int N,i;
    long long int ans,tmp;
    cin >> N;
    vector<int> A(N);
    for(i=0;i<N;i++) cin >> A.at(i);
    sort(A.begin(),A.end());
    if(N%2){
        ans = 0;
        for(i=0;i<N/2;i++) ans -= A.at(i);
        for(i=N/2;i<N;i++) ans += A.at(i);
        ans *= 2;
        ans -= A.at(N/2) + A.at(N/2+1);
        tmp = 0;
        for(i=0;i<N/2+1;i++) tmp -= A.at(i);
        for(i=N/2+1;i<N;i++) tmp += A.at(i);
        tmp *= 2;
        tmp += A.at(N/2)+A.at(N/2-1);
        ans = max(ans,tmp);
    }else{
        ans = 0;
        for(i=0;i<N/2;i++) ans -= A.at(i);
        for(i=N/2;i<N;i++) ans += A.at(i);
        ans *= 2;
        ans += A.at(N/2-1) - A.at(N/2);
        tmp = 0;
        for(i=0;i<N/2;i++) tmp -= A.at(i);
        for(i=N/2;i<N;i++) tmp += A.at(i);
        tmp *= 2;
        tmp += A.at(N/2-1)-A.at(N/2);
        ans = max(ans,tmp);   
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0;i<n;i++) {
    cin>>a.at(i);
  }
  int count=0;
  for(int i=0;i<n;i++) {
    while(i+1<n && a.at(i) == a.at(i+1)) ++i;
    if(i+1<n && a.at(i)<a.at(i+1)) {
      while(i+1<n && a.at(i) <= a.at(i+1)) ++i;
    } else if(i+1<n && a.at(i) > a.at(i+1)) {
      while(i+1<n && a.at(i) >= a.at(i + 1)) ++i;
    }
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t x, y;
    cin >> x >> y;

    int64_t n = 1;
    while (2 * x <= y) {
        ++n;
        x *= 2;
    }
    cout << n << endl;
}


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

int main(void){
    int n, y;
    scanf("%d %d", &n, &y);
    if(y/n > 10000 || y/n < 1000){
        printf("-1 -1 -1");
        return 0;
    }
    int fu=y/10000;
    y -= fu*10000;
    int hi=y/5000;
    y -= hi*5000;
    int no=y/1000;
    for(;;){
        int m = fu+hi+no;
        if(n<m){
            printf("-1 -1 -1");
            return 0;
        }else if(m==n){
            printf("%d %d %d", fu, hi, no);
            return 0;
        }else if(n-m>=4 && hi>0){
            hi--;
            no+=5;
        }else if(n-m>0 && fu>0){
            fu--;
            hi+=2;
        }else{
            printf("-1 -1 -1");
            return 0;
        }
    }
}


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

int gcd(int a, int b)
{
     return(b ? gcd(b, a % b):a);
}

int main()
{
    int a, b;
    while(cin >> a >> b)
    {
        cout << gcd(a, b) << " " << (long long) a * b /gcd(a, b) << endl;
    }
}

Measured memory_bytes: 2972
/*#### bits/stdc++.h */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<deque>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
/*####*/
int main(){
	int A = 1, B = 1,n,x;
	for(scanf("%d",&n); n--;){
		A *= 3;
		scanf("%d",&x);
		if(x%2==0)B *= 2;
	}
	printf("%d\n",A-B);
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    col[x] = c
    for v,w in e[x]:
        if col[v] == -1:
            dfs(v , c+w)

dfs(1,0)



for i in range(1,N+1):
    print(col[i] % 2)


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

long long dp[1002][1002];
long long MOD  = 1e9 + 7;
string a[1002];
int main() {
	int n, m;
	cin >> n >> m;
	int i, j;
	for(i=0;i<n;i++)
	    cin>>a[i];
	 dp[n-1][m-1] = 1;
	for(i=n-1;i>=0;i--)
	    for(j=m-1;j>=0;j--)
	        if(a[i][j]=='.')
	            dp[i][j] += dp[i+1][j] + dp[i][j+1], dp[i][j]%=MOD;
	 cout<<dp[0][0];
	
	return 0;
}

Measured memory_bytes: 9088
N,D = map(int,input().split())
position = []
for i in range(N):
    position.append(input().split())

import math
def distance(vector1,vector2):
    sum = 0
    for i in range(D):
        sum += (float(vector1[i])-float(vector2[i]))**2
    return math.sqrt(sum)

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if distance(position[i],position[j]).is_integer():
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct{
  int p,l,r;
    }Node;
Node T[MAX];

int depht(int);
void print_degree(int);

int main(){

  int n,i,j,node,degree,child,left;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }
  for(i = 0; i < n; i++){
    scanf("%d%d",&node,&degree);
    for(j = 0; j < degree; j++){
      scanf("%d",&child);
      T[child].p = node;
      if(j == 0)
        T[node].l = child;
      else
        T[left].r = child;
      left = child;
    }
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,depth(i)\
);
    if(T[i].p == NIL)
      printf("root, [");
    else if(T[i].l == NIL)
      printf("leaf, [");
    else
      printf("internal node, [");
    print_degree(T[i].l);
    printf("]\n");
  }

  return 0;
}

int depth(int node){

  int count=0;

  while(T[node].p != NIL){
    count++;
    node = T[node].p;
  }
  return count;
}

void print_degree(int i){

  if(i != NIL){
    if(T[i].r == NIL)
      printf("%d",i);
    else printf("%d, ",i);
  print_degree(T[i].r);
  }
}

Measured memory_bytes: 1784
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = (int)n-1; i >= 0; i--)
#define ll long long int
#define pb push_back
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int N, b, c, d, ans = 0, t;
  int c_100 = 0;
  string s;
  cin >> N >> s;
  vector<bool> flag(10, false);
  vector<int> a(1000, 0);
  vector<vector<int> > sum(N);
  vector<int> info(10, 0);

  for(char c: s){
    b = (int)c - '0';
    info[b]++;
  }

  rep(i, N){
    b = s[i] - '0';
    info[b]--;
    sum[i] = info;
  }


  rep(j, N){
    b = s[j] - '0';
    if(flag[b]) continue;
    else { // 最大でも10回
      c_100++; flag[b] = true;
      vector<bool> f2(10, false); int c_10 = 0;
      for(int i = j+1; i < N; i++){ // 二桁目を探す
        c = s[i] - '0';
        if(f2[c]) continue;
        else {
          c_10++; f2[c] = true;
          rep(k, 10){ // 三桁目を探す
            if (sum[i][k] > 0) {
              t = b*100 + c*10 + k;
              ans++;
            }            
          }
        }
        if(c_10 == 10) break;
      }
    }
    if(c_100 == 10) break; 
  }
  print(ans);
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int n = sc.nextInt();
		char[] ch = sc.next().toCharArray();
		
		int[] l = new int[n+1];
		for(int i = 0; i < n;i++) {
			l[i+1] = l[i] + (ch[i]=='#'?1:0);
		}
		
		int min = n;
		
		for(int i = 0; i <= n ; i++) {
			int blackToWhite = l[i];
			int whiteToBlack = (n - l[n]) - (i - l[i]);
			min = Math.min(min, blackToWhite + whiteToBlack);
		}
		
		System.out.println(min);
	}
}


Measured memory_bytes: 30276
#include <iostream>

using namespace std;
int main() {
    int X;
    cin >> X;
    int i = 0;
    int j = 0;
    for (i=1; i<360; i++) {
        j += X;
        if (j % 360 == 0) break;
    }
    cout << i << endl;
    return 0;
}

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

int main(){
	int n,q;
	cin>>n>>q;
	
	vector<char> s(n);
	vector<int> sum(n,0);//累積和.
	cin>>s[0];
	sum[0]=0;
	for(int i=1;i<n;++i){
		cin>>s[i];
		if(s[i]=='C'&&s[i-1]=='A') sum[i]=sum[i-1]+1;
		else sum[i]=sum[i-1];
	}
	
	REP(i,q){
		int l,r;
		cin>>l>>r;
		
		cout<<sum[r-1]-sum[l-1]<<endl;
	}
	
	return 0;
}//abc122_c.復習.参考.

Measured memory_bytes: 1280
while 1:
    n = int(input())
    if n == 0:
        break

    array = []
    for _ in range(n):
        a = int(input())
        array.append(a)
    k = int(input())

    n -= 1
    l = 0
    cnt = 0
    while l <= n:
        cnt += 1
        m = (l+n) // 2
        if array[m] == k:
            break

        if array[m] < k:
            l = m + 1
        else:
            n = m - 1
    print(cnt)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> x(5);
  int k;
  for(int i=0;i<5;i++){
    cin>>x.at(i);
  }
  cin>>k;
   int y=0;
  for(int m=0;m<5;m++){
    for(int j=0;j<5;j++){
      if(x.at(m)-x.at(j)>k){
        y++;
      }
    }
  }
  if(y==0){
    cout<<"Yay!"<<endl;
  }
  else{
    cout<<":("<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		
		for (int i=0; i<s.length(); i++){
			char c = s.charAt(i);
			if (i % 2 == 0){
				if (c != 'R' && c != 'U' && c != 'D' ){
					System.out.println("No");
					return;
				}
			} else {
				if (c != 'L' && c != 'U' && c != 'D' ){
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23636