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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll dp[N][4][4][4] = {};
    for(int i = 0; i < 4; i++)
        for(int j = 0; j < 4; j++)
            for(int k = 0; k < 4; k++)
                if(!((i == 0 && j == 2 && k == 1)
                     || (i == 0 && j == 1 && k == 2)
                     || (i == 2 && j == 0 && k == 1)))
                    dp[2][i][j][k] = 1;
    for(int n = 3; n < N; n++) {
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 4; j++) {
                for(int k = 0; k < 4; k++) {
                    for(int l = 0; l < 4; l++) {
                        if(i == 0 && j == 2 && l == 1)
                            continue;
                        if(j == 0 && k == 2 && l == 1)
                            continue;
                        if(i == 0 && k == 2 && l == 1)
                            continue;
                        if(j == 2 && k == 0 && l == 1)
                            continue;
                        if(j == 0 && k == 1 && l == 2)
                            continue;
                        dp[n][j][k][l] += dp[n - 1][i][j][k];
                        if(dp[n][j][k][l] > MOD)
                            dp[n][j][k][l] -= MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < 4; i++)
        for(int j = 0; j < 4; j++)
            for(int k = 0; k < 4; k++)
                ans = (ans + dp[N - 1][i][j][k]) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def sol(score,hand):
    if hand=="r":
        return score["p"]
    elif hand=="p":
        return score["s"]
    elif hand=="s":
        return score["r"]
    return 0
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
win=""
for num,val in enumerate(t):
    if num<k or win[num-k]!=val:
        win+=val
    else:
        win+="n"
score={"r":r,"p":p,"s":s}
ans=0
for val in win:
    ans+=sol(score,val)

print(ans)


Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<map>
#include<functional>

using namespace std;

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

int N, K;
P sushi[100000];

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> sushi[i].second >> sushi[i].first;
	}
	sort(sushi, sushi + N, greater<P>());

	map<int, int> M;
	ll ans = 0;
	ll kind = 0;
	for (int i = 0; i < K; i++) {
		ans += sushi[i].first;
		M[sushi[i].second]++;
		if (M[sushi[i].second] == 1)kind++;
	}
	ans += kind * kind;
	ll now = ans;
	int lpointer = K - 1, rpointer = K;
	while (1) {
		if (rpointer == N|| lpointer == -1)break;

		if (M[sushi[rpointer].second] != 0) {
			rpointer++;
			continue;
		}
		ll ad = sushi[rpointer].first;

		while (M[sushi[lpointer].second] == 1 && lpointer >= 0)lpointer--;
		if (lpointer == -1)break;
		ll er = sushi[lpointer].first;

		//if (ans <= now - (kind * kind) + (kind + 1) * (kind + 1) -er + ad) {
		now = now - (kind * kind) + (kind + 1) * (kind + 1) - er + ad;
		ans = max(ans, now);
		M[sushi[rpointer].second]++;
		M[sushi[lpointer].second]--;
		rpointer++, lpointer--;
		kind++;
		//}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}

#[fastout]
fn main() {
  input! {
     N:usize,
     XYP:[(i64,i64,i64);N]
  }
  let N: usize = N;
  let mut XYP: Vec<(i64, i64, i64)> = XYP;
  let inf = std::i64::MAX;
  let mut xkyori = vec![vec![inf; N]; 2usize.pow(N as u32)];
  let mut ykyori = vec![vec![inf; N]; 2usize.pow(N as u32)];

  for pat_i in 0..2usize.pow(N as u32) {
    for i in 0..N {
      if pat_i >> i & 1 == 1 {
        // 都市 i に鉄道が引かれている場合の距離は0。
        xkyori[pat_i][i] = 0;
        ykyori[pat_i][i] = 0;
      } else {
        // そうでない場合、すべての路線への距離の最小値を求める。
        let (x, y, p) = XYP[i];
        xkyori[pat_i][i] = x.abs();
        ykyori[pat_i][i] = y.abs();
        for j in 0..N {
          if pat_i >> j & 1 == 1 {
            xkyori[pat_i][i] = min(xkyori[pat_i][i], (x - XYP[j].0).abs());
            ykyori[pat_i][i] = min(ykyori[pat_i][i], (y - XYP[j].1).abs());
          }
        }
      }
      debug!(pat_i, i, xkyori[pat_i]);
    }
  }
  debug!(xkyori);
  debug!(ykyori);
  // ここまでで前処理。xkyoriとykyoriが計算できた。
  let mut ans = vec![inf; N + 1];
  // 3進数を計算。0=線路なし,1=X路線, 2=Y路線
  for pat_i in 0..3usize.pow(N as u32) {
    // pat_xとpat_yの作成
    let mut k = N;
    let mut pat = pat_i;
    let mut pat_x = 0;
    let mut pat_y = 0;
    for i in 0..N {
      match pat % 3 {
        1 => pat_x += 2usize.pow(i as u32),
        2 => pat_y += 2usize.pow(i as u32),
        _ => k -= 1,
      }
      pat /= 3;
    }
    let mut t_ans = 0;
    for i in 0..N {
      t_ans += min(xkyori[pat_x][i], ykyori[pat_y][i]) * XYP[i].2;
    }
    ans[k] = min(ans[k], t_ans);
  }
  for a in ans {
    println!("{}", a);
  }
}


Measured memory_bytes: 11792
import scala.io.StdIn

object Main {
  def main(args: Array[String]) = {
    val a = StdIn.readInt
    val b = StdIn.readInt
    val c = StdIn.readInt
    val x = StdIn.readInt
    var count = 0;
    for(i <- 0 to a; j <- 0 to b; k <- 0 to c){
      if(i * 500 + j * 100 + k *50 == x) count += 1
    }
    println(count)
  }
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    else return gcd(b, a % b);
}

vector<pair<ll,ll>> pfact(ll n)
{
    vector<pair<ll,ll>> P;
    ll cnt;

    for(ll i=2; i*i<=n; ++i) {
        cnt = 0;
        if(n % i != 0) continue;
        while(n % i == 0) {
            n /= i;
            ++cnt;
        }
        P.pb({i, cnt});
    }
    if(n > 1) P.pb({n, 1});

    return P;
}

int main()
{
    ll A, B;
    cin >> A >> B;

    ll G = gcd(A, B);
    auto P = pfact(G);
    PR(SZ(P)+1);

    return 0;
}

/*

a b c d e f g


*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cfloat>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;

#define ll long long
#define rep(i, n) for (long double i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)


int main()
{
    ll a;
    float b;
    ll ans;
    cin >> a >> b;
    int c;
    c = 100 * b + 0.1;
    ans = a*c/100;
    cout << ans << endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
bool con[10][10];
int n,a[10]={1,2,3,4,5,6,7,8,9,10};
bool check(){
	rep(k,n-1)if(!con[a[k]][a[k+1]])return false;
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	int m,x,y,ans=0;
	cin>>n>>m;
	rep(k,m){
		cin>>x>>y;
		con[x][y]=con[y][x]=true;
	}
	do{
		if(check())ans++;
	}while(next_permutation(a+1,a+n));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int main(){

	int a,b;
	cin>>a>>b;
	if(a!=1&&b!=1)cout<<"1"<<endl;
	if(a!=2&&b!=2)cout<<"2"<<endl;
	if(a!=3&&b!=3)cout<<"3"<<endl;

	return 0;

}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
string x;
cin >>x;
if(x.find("a") ==std::string::npos){
cout << "a";
}
else if(x.find("b") ==std::string::npos){
cout <<"b";
}
else if(x.find("c") ==std::string::npos){
cout <<"c";
}else if(x.find("d") ==std::string::npos){
cout <<"d";
}else if(x.find("e") ==std::string::npos){
cout <<"e";
}else if(x.find("f") ==std::string::npos){
cout <<"f";
}else if(x.find("g") ==std::string::npos){
cout <<"g";
}else if(x.find("h") ==std::string::npos){
cout <<"h";
}else if(x.find("i") ==std::string::npos){
cout <<"i";
}else if(x.find("j") ==std::string::npos){
cout <<"j";
}else if(x.find("k") ==std::string::npos){
cout <<"k";
}else if(x.find("l") ==std::string::npos){
cout <<"l";
}else if(x.find("m") ==std::string::npos){
cout <<"m";
}else if(x.find("n") ==std::string::npos){
cout <<"n";
}else if(x.find("o") ==std::string::npos){
cout <<"o";
}else if(x.find("p") ==std::string::npos){
cout <<"p";
}else if(x.find("q") ==std::string::npos){
cout <<"q";
}else if(x.find("r") ==std::string::npos){
cout <<"r";
}else if(x.find("s") ==std::string::npos){
cout <<"s";
}else if(x.find("t") ==std::string::npos){
cout <<"t";
}else if(x.find("u") ==std::string::npos){
cout <<"u";
}else if(x.find("v") ==std::string::npos){
cout <<"v";
}else if(x.find("w") ==std::string::npos){
cout <<"w";
}else if(x.find("x") ==std::string::npos){
cout <<"x";
}else if(x.find("y") ==std::string::npos){
cout <<"y";
}else if(x.find("z") ==std::string::npos){
cout <<"z";
}
else{
cout <<"None";
}
return 0;}

Measured memory_bytes: 512
from functools import reduce
def dfs(num):
    global count
    if len(str(num)) != len(set(str(num))):
        return

    if len(str(num)) == N:
        if len(set(str(num))) == len(str(num)):
            count += 1
        if num == P:
            ans.append(count)
        if num == Q:
            ans.append(count)
        return

    else:
        for i in range(1, N + 1):
            dfs(num * 10 + i)


N = int(input())
P = int("".join(list(input().split())))
Q = int("".join(list(input().split())))
ans = []
count = 0

dfs(0)
print(abs(ans[0] - ans[1]))


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x,t;
  cin >> x >> t;
  cout << max(0, x-t) << endl;
}

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

const ll mod =  998244353;
int main() {
    int K;
    cin >> K;
    string ans;
    rep(i,K){
        ans += "ACL";
    }
    cout << ans << endl;
}


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

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        var count = 0;
        foreach (var c in S)
        {
            if (c == 'o') count++;
        }

        var rem = 15 - S.Length;
        if (count + rem >= 8)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}



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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ');
            var n = int.Parse(a[0]);
            var m = int.Parse(a[1]);


            var node = new List<int[]>();
            for (int i = 0; i < m; i++)
            {
                node.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToArray());
            }

            var result = 0;
            nxt:
            var cnt = node.SelectMany(_ => _).GroupBy(_ => _);
            foreach (var item in cnt)
            {
                if (item.Count() == 1)
                {
                    result++;
                    node = node.Where(_ => _[0] != item.Key && _[1] != item.Key).ToList();
                    goto nxt;
                }
            }

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 13536
<?php
fscanf(STDIN, "%d%d%d%d", $N, $M, $F, $T);
$d1 = new Di($N);
$d2 = new Di($N);
for($i = 0; $i < $M; $i++){
    fscanf(STDIN, "%d%d%d%d", $f, $t, $a, $b);
    $d1->connect($f, $t, $a);
    $d1->connect($t, $f, $a);
    $d2->connect($f, $t, $b);
    $d2->connect($t, $f, $b);
}
$d1->solve($F);
$d2->solve($T);
$left[$N+1] = 0;
for($i = $N; $i >= 1; $i--){
    $left[$i] = max(10**15 - $d1->distance[$i] - $d2->distance[$i], $left[$i+1]);
}
unset($left[$N+1]);
echo implode("\n", array_reverse($left));

/**
 * Dijkstra
 * Attention: 1-origin
 **/
class Di{
  public $pq;
  public $distance;
  public $graph;
  public $from;
  public $inf = 10**18;
  function __construct($n) {
    $this->pq = new SplPriorityQueue();
    for($i = 1; $i <= $n; $i++){
      $this->distance[$i] = $this->inf;
      $this->from[$i] = 0;
    }
  }
  function connect($from, $to, $cost){
    $this->graph[$from][] = [$to, $cost];
  }
  function solve($from){
    $this->pq->insert($from, 0);
    $this->distance[$from] = 0;
    while($this->pq->count()){
      $f = $this->pq->extract();
      if(!isset($this->graph[$f]))continue;
      foreach($this->graph[$f] as list($t, $dist)){
        $new = $this->distance[$f] + $dist;
        if($this->distance[$t] > $new){
          $this->distance[$t] = $new;
          $this->from[$t] = $f;
          $this->pq->insert($t, -$new);
        }
      }
    }
  }
}

Measured memory_bytes: 277996
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
  string k,d;
  cin>>k>>d;
  int ans=0;
  for (int i = 0; i < k.size(); ++i)
  {
  	if(k[i]==d[i])ans++;
  }
  cout<<ans;
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

bool solve() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    if (N == 0) return false;

    alias Edge = Tuple!(int, "to", int, "dist", int, "cost");
    auto G = new Edge[][](N);

    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= Edge(s[1]-1, s[2], s[3]);
        G[s[1]-1] ~= Edge(s[0]-1, s[2], s[3]);
    }

    auto D = new int[](N);
    D[] = 10^^9 + 10;

    auto pq = new BinaryHeap!(Array!Edge, "a.dist == b.dist ? a.cost > b.cost : a.dist > b.dist");
    pq.insert(Edge(0, 0, 0));

    int ans = 0;

    while (!pq.empty) {
        auto n = pq.front.to;
        auto d = pq.front.dist;
        auto c = pq.front.cost;
        pq.removeFront;
        if (D[n] <= d) continue;
        D[n] = d;
        ans += c;
        foreach (e; G[n]) {
            auto m = e.to;
            auto nd = e.dist + d;
            auto nc = e.cost;
            if (D[m] <= nd) continue;
            pq.insert(Edge(m, nd, nc));
        }
    }

    ans.writeln;

    return true;
}

void main() {
    while (solve()) {}
}



Measured memory_bytes: 22872
from collections import deque
N=int(input())
A=list(map(int,input().split()))

A.sort(reverse=True)
Aq=deque(A)

ans=Aq.popleft()
a=0
for i in range(1,N):
    if i%2==0:
        a=Aq.popleft()
    ans+=a

print(ans)

Measured memory_bytes: 33268
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000;
//#define PI 3.14159265359

ll ans = 0;
ll H, W, K;

int check_sum(vector<vector<int>> c) {
    int a = 0;
    rep(i, H) {
        a += accumulate(c[i].begin(), c[i].end(), 0);
    }
    return a;
}

void operation(vector<vector<int>> c, int x) {
    rep(i, W + H) {
        if (((x >> i) % 2) == 1) {
            if (i < W) {
                rep(j, H) {
                    c[j][i] = 0;
                }
            } else {
                rep(j, W) {
                    c[i - W][j] = 0;
                }
            }
        }
    }

    if (check_sum(c) == K) {
        ans++;
    }
}

int main() {
    // input
    cin >> H >> W >> K;
    vector<vector<int>> c(H);
    rep(i, H) {
        rep(j, W) {
            char cc;
            cin >> cc;
            if (cc == '.') {
                c[i].emplace_back(0);
            } else if (cc == '#') {
                c[i].emplace_back(1);
            }
        }
    }

    // process
    rep(i, pow(2, H + W)) {
        operation(c, i);
    }

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


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main()
{
  while(true)
    {
      int n,x;
      int count=0;
      cin>>n>>x;
      if(n==0 && x==0)break;
      for(int i=1;i<=n;i++)
	{
	  for(int k=1;k<=n;k++)
	    {
	      for(int j=1;j<=n;j++)
		{
		  if(i+j+k==x && i<k && k<j)
		    {
		      count++;
		    }
		}
	    }
	}
      cout<<count<<endl;
    }
  return 0;
  }


Measured memory_bytes: 3076
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  ll n,t;
  cin >> n >> t;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll count = t;
  
  for(int i = 1; i < n;i++){
    if(a[i]-a[i-1] < t){
      count = count + a[i] - a[i-1];
    }else{
      count += t;
    }
  }
  
  cout << count;  
  
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

int main(){
  int n;
  std::cin >> n;
  std::vector<int> piyo;
  std::vector<std::pair<int, int>> a;
  std::pair<int, int> hoge;
  int fuga;
  for(int i = 0; i < n - 1; i++){
    std::cin >> hoge.first;
    std::cin >> hoge.second;
    a.push_back(hoge);
  }

  for(int i = 0; i < n; i++){
    std::cin >> fuga;
    piyo.push_back(fuga);
  }

  std::sort(piyo.begin(), piyo.end(), std::greater<int>());
  int sum = 0;
  for(int i = 1; i < n; i++){
    sum += piyo[i];
  }

  int now;
  std::vector<int> stac, ans(10000);
  stac.push_back(1);
  while(!stac.empty()){
    now = stac[0];
    for(int i = 0; i < n - 1; i++){
      if(a[i].first == now || a[i].second == now){
        stac.push_back(a[i].first + a[i].second - now);
        a[i].first = -1;
        a[i].second = -1;
      }
    }
    ans[now - 1] = piyo[0];
    piyo.erase(piyo.begin());
    stac.erase(stac.begin());
  }

  std::cout << sum << std::endl;
  for(int i = 0; i < n; i++){
    std::cout << ans[i] << " ";
  }
}

Measured memory_bytes: 640
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 

class Main{ 

	static void solve(){ 
		int a = ni();
		int b = ni();
		if(a+b==15)out.println("+");
		else if(a*b==15)out.println("*");
		else out.println("x");
	} 
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
} 



Measured memory_bytes: 21332
//abc103_b.cpp
//Sat Jul 21 20:49:21 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INF 100000000
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	if (s==t){
		cout << "Yes" << endl;
	}else{
		int flag = 0;
		for (int i=1;i<s.size();i++){
			string tempa = s.substr(i,s.size()-i);
			string tempb = s.substr(0,i);
			string temp = tempa+tempb;
//			cout << temp << endl;
			if (temp == t){
				flag = 1;
				break;
			}
		}
		if (flag == 1){
			cout << "Yes" << endl;
		}else {
			cout << "No" << endl;
		}
	}	
}

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

int main(){
	string S;
	cin >> S;
	
	for(int i=0;i<55;i++){
		if(S[2*i]=='L' || S[2*i+1]=='R'){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
def check(x,y,n):
	for i in range(n):
		if x[i] != '?' and y[i] != x[i]:
			return False
	return True
			
S = list(input())
T = list(input())
S_len = len(S)
T_len = len(T)

if T_len > S_len:
	print('UNRESTORABLE')
	quit()
	
answer = []

for i in range(S_len - T_len + 1):
	S_dush = S[i:i+T_len]
	if check(S_dush,T,T_len):
		ans = S[:]
		ans[i:i+T_len] = T
		for j in range(S_len):
			if ans[j] == '?':
				ans[j] = 'a'
		answer.append(''.join(ans))
if answer:
	answer.sort()
	print (answer[0])
else:
	print('UNRESTORABLE')

Measured memory_bytes: 3064
N, M = map(int, input().split())
height = list(map(int,input().split()))
def loadmake(a, b, load):
    if a in load.keys():
        load[a].append(b)
    else:
        load[a] = [b]
load = {}
for m in range(M):
    a, b = map(int, input().split())
    loadmake(a-1, b-1, load)
    loadmake(b-1,a-1,load)
oklist = [1]*N
for n in range(N):
    if n in load.keys():
        for l in load[n]:
            if height[l] >= height[n]:
                oklist[n] = 0
print(sum(oklist))

Measured memory_bytes: 34780
fn main(){
    let q = get_line::<i32>();
    let mut i = 0;
    let mut xs: Vec<i32> = Vec::new();
    while i < q {
      let v = read_vec::<i32>();
      match  v[0] {
        0 => xs.push(v[1]),
        1 => println!("{}", xs[v[1] as usize]),
        2 => {xs.pop(); ()},
        _ => ()
      }
      i = i + 1
    }
}

fn get_line<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


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

using namespace std;

const int N = 1e5 + 5;

int n, m, a[N];

long long lcm (long long x, long long y) {
    return x * y / __gcd(x, y);
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long curlcm = 1;
    for (int i = 1; i <= n; i++) {
        curlcm = lcm(curlcm, a[i]);
        if (curlcm > 2e9) return cout << 0, 0;
    }
    
    long long start = curlcm / 2;
    for (int i = 1; i <= n; i++) {
        if ((start - a[i] / 2) % a[i]) {
            return cout << 0, 0;
        }
    }
    long long step = (m - start) / curlcm;
    long long end = start + step * curlcm;
    
    if (start > m) return cout << 0, 0;
    
    cout << (end - start) / curlcm + 1;
    return 0;
}

Measured memory_bytes: 640
N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))

flag = True
c = 0
while flag:
    flag = False
    for j in reversed(range(1, N)):
        if  A[j - 1] > A[j]:
            A[j - 1],    A[j] = A[j], A[j - 1]
            c += 1
            flag = True
    
print(' '.join(map(str, A)))
print(c)

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

int main(){
  long long n;
  cin >> n;
  long long s;
  long long x;
  x = n;
  s += x*(x+1)/2;
  x = n/3;
  s -= 3*x*(x+1)/2;
  x = n/5;
  s -= 5*x*(x+1)/2;
  x = n/15;
  s += 15*x*(x+1)/2;
  cout << s;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using tiii = tuple<int,int,int>;

ll solve() {
    ll N, M, a, b;
    cin >> N >> M;
    vector<tiii> ps; // 0:b, 1:a
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        ps.push_back(tiii(a,1,i));
        ps.push_back(tiii(b,0,i));
    }
    sort(ps.begin(), ps.end());
    vector<int> f(M), c;
    ll ans = 0;
    for ( auto p : ps) {
        int a,k,i;
        tie(a,k,i) = p;
        if ( k == 1 ) {
            c.push_back(i);
        } else {
            if ( f[i] == 1 ) continue;
            bool br = false;
            for ( auto j : c ) {
                br = true;
                f[j] = 1;
            }
            c.clear();
            if ( br ) {
                ans++;
            }
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4980
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();

			List<Restaurant> list = new ArrayList<Main.Restaurant>(N);
			for (int i = 0; i < N; i++) {
				list.add(new Restaurant(i + 1, s.next(), s.nextInt()));
			}

			list.stream().sorted(
					Comparator.comparing(Restaurant::getName).thenComparing(
							Comparator.comparingInt(Restaurant::getPoint).reversed()))
					.map(Restaurant::getNo)
					.forEach(System.out::println);
		}
	}

	static class Restaurant {
		final int no;
		final String name;
		final int point;

		public Restaurant(int no, String name, int point) {
			this.no = no;
			this.name = name;
			this.point = point;
		}

		public int getNo() {
			return no;
		}

		public String getName() {
			return name;
		}

		public int getPoint() {
			return point;
		}
	}
}


Measured memory_bytes: 27856
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 1e6+10
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll magic[101][101];
vector<ll>primes;
bool prime[1000001];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll a,b,c,d,e,f,x,y,k,t,A=0,mod,B=0,L,j,i,l,r,m,n,C=0,ans=0,sum=0,sum1=0;
    vector<ll>v,v1;
    queue<ll>qu;
    map<string,int>mp;
    cin>>n;
    ll ac=0,tle=0,wa=0,re=0;
    for(i=0;i<n;i++)
    {
        cin>>str;
        if(str=="AC")
            ac++;
        else if(str=="WA")
            wa++;
        else if(str=="TLE")
            tle ++;
        else if(str=="RE")
            re++;
    }
    cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<re<<endl;


    return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N;
  M=0;
  for (int i = 0; i < N; i++) {
    string color;
    cin >> color;
    if (color == "Y"){
      M=1;
      break;
    }
  }
  if (M==0){
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 3540
def Getinv(n):
    inv=[0]*(n+1)
    inv[0]=1
    inv[1]=1
    for i in range(2,n+1):
        inv[i] = (-(Q//i)*inv[Q%i]) % Q
    return inv

Q=10**9+7


def main():
    n,a,b,c=map(int,input().split(' '))
    modinv=Getinv(max(2*n+1,100))
    A=a*modinv[a+b]%Q
    B=b*modinv[a+b]%Q
    powa=[1]*(n+1)
    powb=[1]*(n+1)
    for i in range(n):
        powa[i+1]=powa[i]*A%Q
        powb[i+1]=powb[i]*B%Q
    C=100*modinv[100-c]%Q
    ans = 0
    nowc =1
    for i in range(n,2*n):
        nowc *=i*modinv[i-n]
        nowc %=Q
        ans +=nowc*(powa[n]*powb[i-n]+powa[i-n]*powb[n])
        ans %=Q
    print(ans*C%Q)

main()

Measured memory_bytes: 18804
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: usize = read_as_vec()[0];
    let mut a= read_as_vec::<usize>();
    a.sort();
    let mut left_acc_power = a.iter().sum::<usize>() - a[n-1];
    let mut ans = 1;
    for i in (0..n-1).rev(){
        if a[i+1] <= left_acc_power*2{
            ans += 1;
            left_acc_power -= a[i];
        }else{
            break;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<iostream>
#include<algorithm>
const int INF=(1<<22);
int dp[1000000],d[20],n,m;
int main(){
    std::cin>>n>>m;
    std::fill(dp,dp+n+1,INF);dp[0]=0;
    for(int i(0);i<m;++i)std::cin>>d[i];
    for(int i(0);i<m;++i)for(int j(d[i]);j<=n;++j){
        dp[j]=std::min(dp[j],dp[j-d[i]]+1);
    }std::cout<<dp[n]<<std::endl;
}

Measured memory_bytes: 1356
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


int n,cnt,cnt2;
ll a[N],b[N],c[N];
char s[N];

void work() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%lld",a+i);
	scanf("%s",s+1);
	if (s[n]=='1') return puts("1"),void();
	cnt = 0;
	int ok = 0;
	REP(i,1,n) if (s[i]=='0') {
		ll x = a[i];
		REP(j,1,cnt) x=min(x,x^b[j]);
		if (x) b[++cnt]=x;
		else ok = 1;
	}
	REP(i,1,n) if (s[i]=='1') {
		ll x = a[i];
		REP(j,1,cnt) x=min(x,x^b[j]);
		if (x) return puts("1"),void();
	}
	cnt=0;
	int p=n;
	while (p) {
		ll x=a[p];
		REP(j,1,cnt) x=min(x,x^b[j]);
		if (s[p]=='0') {
			if (x) b[++cnt]=x;
		}
		else {
			if (x) return puts("1"),void();
		}
		--p;
	}
	puts("0");
}

int main() {
	int t;
	scanf("%d", &t);
	while (t--) work();
}










Measured memory_bytes: 3672
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		
		int sum = 0;
		for (int i = 1; i < 5000; i++) {
			sum += i;
			if (sum > n) {
				int dif = sum - n;
				for (int j = 1; j <= i; j++) {
					if (j == dif) continue;
					out.println(j);
				}
				break;
			}
		}
		
		out.flush();
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 8836
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        long ans = 1;
        
        for(int i=1; i<=N; i++){
            ans =(ans * i) % 1000000007;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    ll n,a,b; cin >> n >> a >> b;
    ll x=n/(a+b);
    n-=x*(a+b);
    ll ans=x*a;
    if(n>a) ans+=a;
    else ans+=n;
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int n;
	static char[] s;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		s = sc.next().toCharArray();
		sc.close();

		char[] ans = new char[n + 2];
		ans[0] = 'S';
		ans[1] = 'S';
		exec(ans);
		if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
			System.out.println(new String(ans).substring(0, n));
			return;
		}

		ans[1] = 'W';
		exec(ans);
		if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
			System.out.println(new String(ans).substring(0, n));
			return;
		}

		ans[0] = 'W';
		ans[1] = 'S';
		exec(ans);
		if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
			System.out.println(new String(ans).substring(0, n));
			return;
		}

		ans[1] = 'W';
		exec(ans);
		if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
			System.out.println(new String(ans).substring(0, n));
			return;
		}
		System.out.println(-1);
	}

	static void exec(char[] a) {
		for (int i = 2; i < n + 2; i++) {
			if ((a[i - 1] == 'S') ^ (s[(i - 1) % n] == 'o')) {
				a[i] = other(a[i - 2]);
			} else {
				a[i] = a[i - 2];
			}
		}
	}

	static char other(char c) {
		if (c == 'S') {
			return 'W';
		} else {
			return 'S';
		}
	}
}


Measured memory_bytes: 26660
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,d = map(int, input().split())
    if n%(1+2*d) == 0:
        print(n//(1+2*d))
    else:
        print(n//(1+2*d)+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
h,w = [int(i) for i in input().split()]

pic = []

for i in range(h):
	pic.append(input())


for i in range(w+2):
	print('#', sep='',end='')
print()

for i in range(h):
	print('#', sep='',end='')
	print(pic[i],end='')
	print('#')


for i in range(w+2):
	print('#', sep='',end='')
print()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

std::vector<std::vector<int>> dp;
std::vector<std::string> s;
int h, n;

int check(int i, int j){
	if(s[i][j] == '#') return 0;
	if(s[i + 1][j] == '#') return 0;
	if(s[i][j + 1] == '#') return 0;
	if(s[i + 1][j + 1] == '#') return 0;
	return 1;
}

int dfs(int p, int q){
	if(p >= h - 1) return 0;
	if(~dp[p][q]) return dp[p][q];
	
	int ret = 0;
	if(q == 0){ //xxxx
		ret = std::max({dfs(p + 1, 0), dfs(p + 1, 1), dfs(p + 1, 2), dfs(p + 1, 3), dfs(p + 1, 4)});
	}else if(q == 1){ //ooxx
		int count = check(p, 0);
		ret = std::max(count + dfs(p + 1, 0), count + dfs(p + 1, 3));
	}else if(q == 2){ //xoox
		int count = check(p, 1);
		ret = count + dfs(p + 1, 0);
	}else if(q == 3){ //xxoo
		int count = check(p, 2);
		ret = std::max(count + dfs(p + 1, 0), count + dfs(p + 1, 1));
	}else if(q == 4){ //oooo
		int count = check(p, 0) + check(p, 2);
		ret = count + dfs(p + 1, 0);
	}
	
	return dp[p][q] = ret;
}

int main(){
	cin >> h >> n; s.resize(h, std::string(4, '.'));
	for(int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		
		s[b][a] = '#';
	}
	reverse(begin(s), end(s));
	dp.resize(h - 1, std::vector<int>(5, -1));
	
	cout << std::max({dfs(0, 0), dfs(0, 1), dfs(0, 2), dfs(0, 3), dfs(0, 4)}) << endl;
	return 0;
}



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

int s(int n)
{
  int r(0);
  for (int i = 0; i < 10; i++) {
    r += n % 10;
    n /= 10;
  }
  return r;
}

int main()
{
  int n;
  cin >> n;
  cout << (n % s(n) == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
#define ll long long
#define ar array

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

	int a,b;
	cin >> a >> b;

	if (a+b==15) {
		cout << '+' << endl;
	} else if (a*b==15) {
		cout << '*' << endl;
	} else {
		cout << 'x' << endl;
	}
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
using namespace std;
 
int main()
{
    long N;
  	long sum;
 
  	cin>>N;
 
 	sum=((1+N)*N - ((N/3)*3)*(N/3+1)- ((N/5)*5)*(N/5+1)+ ((N/15)*15)*(N/15+1))/2;
	
  	cout<<sum<<endl;
  
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
int a[40];
LL l[40],r[40],b[40];
int main()
{
    int i,j,n;
    LL x,y,k;
    k=1;
    x=0;
    y=0;
    for(i=0;i<32;i++)
    {
        if(i%2==0)
        {
            y=y+k;
            b[i]=k;
        }
        else
        {
            x=x-k;
            b[i]=-k;
        }
        l[i]=x;
        r[i]=y;
        k=k*2;
    }
    scanf("%d",&n);
    if(n==0)
    {
        printf("0\n");
        return 0;
    }
    while(n!=0)
    {
        for(i=0;;i++)
        if(l[i]<=n&&n<=r[i])
            break;
        a[i]=1;
        n=n-b[i];
    }
    i=35;
    while(i>0&&a[i]==0)
        i--;
    for(;i>=0;i--)
        printf("%d",a[i]);
    printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
 
 
int main() {
  ll N,D;
  cin>>N>>D;
  ll x[N][D];
  rep(i,N){
    rep(j,D){
      cin>>x[i][j];
    }
  }
  ll ans=0;
  ll dist=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=0;k<D;k++){
        dist+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      for(int k=1;k<=dist;k++){
        if(k*k==dist){
          ans++;
          dist=0;
          break;
        }
      }
      dist=0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
 
int main() {
	int M1, D1; cin >> M1 >> D1;
	int M2, D2; cin >> M2 >> D2;
	if (D2 == 1) cout << "1" << endl;
	else cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define BUGO(x) cerr << #x << " = " << (x) << '\n';
#define BUGOARR(a) {cerr << #a << ": "; for (auto i: a) cerr << i << ' '; cerr << '\n';}
#ifndef MANSON
#define BUGO(x)
#define BUGOARR(x)
#endif

int main()
{
    const int maxn = 128;
    string alph;
    for (char i = 'a'; i <= 'z'; ++i) alph += i;
    for (char i = 'A'; i <= 'Z'; ++i) alph += i;
    for (char i = '0'; i <= '9'; ++i) alph += i;
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> cnt(alph.size());
    int n = 0;
    for (int i = 0; i < alph.size(); ++i)
    {
        cout << "? " << string(maxn, alph[i]) << endl;
        cin >> cnt[i];
        n += cnt[i] = maxn - cnt[i];
    }
    string ans = "";
    for (int i = 0; i < alph.size(); ++i)
    {
        int l = 0, r = (int)ans.size() - 1;
        while (cnt[i]--)
        {
            int j = r + 1;
            while (l <= r)
            {
                int m = (l + r) / 2;
                cout << "? ";
                int printed = 1;
                for (int k = 0; k < m; ++k)
                    if (ans[k] == alph[i])
                        cout << ans[k], ++printed;
                cout << alph[i];
                for (int k = m; k < ans.size(); ++k)
                    cout << ans[k], ++printed;
                cout << endl;
                int x;
                cin >> x;
                if (x == n - printed)
                {
                    j = m;
                    r = m - 1;
                }
                else
                    l = m + 1;
            }
            ans.insert(ans.begin() + j, alph[i]);
            l = j + 1, r = (int)ans.size() - 1;
        }
    }
    cout << "! " << ans << flush;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
#pragma GCC optimize ("O2")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
	double n,m,i,j;
	bool ans;
	cin>>n>>m>>i>>j;
	cout<<fixed<<setprecision(6)<<n*m/2.000000<<" ";
	if(i*2==n&&j*2==m){
		cout<<1;
	}
	else{
		cout<<0;
	}
	return 0;
}


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

#dcount = 0 #
while True:
    for n in str(N):
        if int(n) in D:
            N+=1
                # print(n,N,count) #
                #count += 1 #
            break
    else:
        print(N)
        break



Measured memory_bytes: 2940
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N>3) {
			System.out.println(N/3);
		}else {
			System.out.println(0);
		}
		sc.close();
	}

}

Measured memory_bytes: 22740
n=int(input())
slist=[]
for i in range(n):
    slist.append(input())
slist.sort()
anslist=[]
anslist.append([slist[0],1])
kosulist=[]
for i in range(1,n):
    if slist[i]!=slist[i-1]:
        kosulist.append(anslist[-1][1])
        anslist.append([slist[i],1])
    else:
        anslist[-1][1]+=1
        if i==n-1:
            kosulist.append(anslist[-1][1])
maxkosu=max(kosulist)
answer=[]
for i in range(len(anslist)):
    if anslist[i][1]==maxkosu:
        answer.append(anslist[i][0])
for i in range(len(answer)):
    print(answer[i])

Measured memory_bytes: 42812