akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//<(") 
#define ll long long 
using namespace std;
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
 
const ll mod = 1e9 + 7;
const ll siz = 50 + 10;
const ll base = 32;
const ll MAXX = 1e18;
ll maCo = 0;

ll n, m, s;
ll dist[siz][5010];
ii exCha[siz];
vector<iii> graph[siz];

void djs() {
	priority_queue<iii, vector<iii>, greater<iii>> nxt;
	for (ll i = 1; i <= n; i++) {
		for (ll j = 0; j < maCo + 10; j++) {
			dist[i][j] = MAXX;
		}
	}
	ll curVal = min(s, maCo);
	dist[1][curVal] = 0;
	nxt.push(iii(0, ii(1, curVal)));
	while (!nxt.empty()) {
		ll d = nxt.top().first;
		ll u = nxt.top().second.first;
		ll mon = nxt.top().second.second;
		nxt.pop();
		if (dist[u][mon] != d) {
			continue;
		}
		//cerr << u << ' ' << d << ' ' << mon << '\n'; 
		for (ll i = 0; i < (int)graph[u].size(); i++) {
			ll v = graph[u][i].first;
			ii need = graph[u][i].second;
			for (ll j = 0;; j++) {
				ll nCost = mon + exCha[u].first * j - need.first;
				if (mon >= maCo) {
					nCost;
				}
				if (nCost < 0) {
					continue;
				}
				if (dist[v][nCost] > dist[u][mon] + need.second + exCha[u].second * j) {
					dist[v][nCost] = dist[u][mon] + need.second + exCha[u].second * j;
					nxt.push(iii(dist[v][nCost], ii(v, nCost)));
				}
				if (nCost > maCo) {
					break;
				}                                                                     
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	cin >> n >> m >> s;
	for (ll i = 0; i < m; i++) {
		ll a, b, x, y;
		cin >> a >> b >> x >> y;
		graph[a].push_back(iii(b, ii(x, y)));
		graph[b].push_back(iii(a, ii(x, y)));
		maCo = max(maCo, x);
	}
	maCo *= m;
	for (ll i = 1; i <= n; i++) {
		cin >> exCha[i].first >> exCha[i].second;
	}	
	djs();
	for (ll i = 2; i <= n; i++) {
		ll ans = MAXX;
		for (ll j = 0; j <= maCo; j++) {
			//cerr << dist[i][j] << ' ';
			ans = min(ans, dist[i][j]);
		}
		//cerr << '\n';
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 201888
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

#define rep(i, n) for(int i=0;i<n;i++)

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

signed main() {
	string S, T;
	cin >> S >> T;

	map<char, char> m1, m2;

	rep(i, S.size()) {
		char c1 = S[i];
		char c2 = T[i];
		if (m1.count(c1) && m1[c1] != c2) {
			cout << "No" << endl;
			return 0;
		}
		m1[c1] = c2;

		if (m2.count(c2) && m2[c2] != c1) {
			cout << "No" << endl;
			return 0;
		}
		m2[c2] = c1;
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  double a,b,c,d;
  cin>>a>>b>>c>>d;
  printf("%12.10lf ",a*b/2);
  if(((int)a)%2==0&&((int)b)%2==0&&((int)a)/2==c&&((int)b)/2==d){
    cout<<1;
  }else{
    cout<<0;
  }
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

vector<int> Prime(int num) {
	vector<int>ret;
	ret.push_back(2);
	ret.push_back(3);
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (int j = 2; j < ret.size(); j++) {
			if (ret[j] * ret[j] > i)break;
			if (i%ret[j] == 0) {
				flag = false;
				break;
			}
		}
		if (flag)ret.push_back(i);
		flag = true;
		for (int j = 2; j < ret.size(); j++) {
			if (ret[j] * ret[j] > i + 2)break;
			if ((i + 2) % ret[j] == 0) {
				flag = false;
				break;
			}
		}
		if (flag)ret.push_back(i + 2);
	}
	return ret;
}

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

	auto P = Prime(100000);
	while (cin >> N >> M >> K, N) {
		int a = 0, b = 0;
		for (int i = 0; i < P.size() && P[i] * P[i] <= N; i++) {
			for (int j = i; j < P.size() && P[i] * P[j] <= N; j++) {
				if (P[i] * K >= P[j] * M) {
					if (P[a] * P[b] < P[i] * P[j]) {
						a = i, b = j;
					}
				}
			}
		}
		cout << P[a] << " " << P[b] << endl;
	}
}


Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
// ascending order
#define asort(array, N) sort(array, array + N)
// descending order
#define asort_r(array, N) sort(array, array + N, greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> d;
	for(int i = 0; i < N; i++) {
		int x;
		cin >> x;
		d.push_back(x);
	}
	vsort(d);
	vunique(d);
	cout << d.size() << endl;


}


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

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

    int oddc = 1;
    rep(i, n){
        int cnt = 0;
        int a;
        cin >> a;
        for(int j = -1; j <= 1; j++){
            if((a+j)%2 == 1) cnt++;
        }
        oddc *= cnt;
    }
    int ans = 1;
    rep(i, n) ans *= 3;
    cout << ans - oddc << endl;
    return 0;
}   

/*

2 3
1 2 3, 2 3 4

all:3*3=9
odd:2*1=2
9-2
*/

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;



class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();
		 String[] aaa = str.split(" ");
	
		 int count = aaa.length;
		 int[] bbb = new int[count];
		 
		 for(int i = 0; i < bbb.length;i++) {
			 bbb[i] = Integer.parseInt(aaa[i]);
		 }
		 

	    Arrays.sort(bbb);

	    System.out.println(bbb[0] +" "+ bbb[1] + " " + bbb[2]);

	    
	}
}

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

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

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


int main(){
	int N; cin >> N;
	vector<int> v(N);
	rep(i,N) cin >> v[i];
	sort(v.begin(),v.end());
	vector<double> after(N);
	after[0] = v[0];
	rep(i,N-1){
		after[i+1] = (after[i] + v[i+1])/2.0;
	}
	cout << fixed;
	cout << setprecision(6) << after[N-1] << endl;
    
}


Measured memory_bytes: 256
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let _ = lines.next().unwrap().unwrap();
    let a_line = lines.next().unwrap().unwrap();
    let splited = a_line.trim().split_whitespace();
    let mut a: Vec<i32> = splited.map(|s| s.parse().unwrap()).collect();
    a.sort_by(|a, b| b.cmp(a));

    let alice: i32 = a.iter().enumerate().filter(|&(i, &_)| i % 2 == 0).map(|(_, &x)| x).sum();
    let bob: i32 = a.iter().enumerate().filter(|&(i, &_)| i % 2 == 1).map(|(_, &x)| x).sum();

    writeln!(&mut writer, "{}", alice - bob).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2
3 1", br"2
",
        ),
        (
            br"3
2 7 4", br"5
",
        ),
        (
            br"4
20 18 2 18", br"18
",
        ),
    ];

    #[test]
    fn test_b() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


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

int main(){
  vector<int> A(5);
  for(int i=0; i<5; i++) cin >> A[i];

  int ans = 99999;
  for(int i=0; i<5; i++){
    int sum = 0;
    for(int j=0; j<5; j++){
      if(j != i) {
        if(A[j] % 10 == 0) sum += (A[j]/10)*10;
        else sum += (A[j]/10+1)*10;
      } else {
        sum += A[j];
      }
    }
    ans = min(sum, ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, X, Y;
    cin >> N >> X >> Y;

    ll count[N];
    REP(i, N) count[i] = 0;

    FOR(i, 1, N) {
        FOR(j, i + 1, N + 1) {
            int d = min(j - i, abs(i - X) + 1 + abs(j - Y));
            count[d]++;
        }
    }

    FOR(i, 1, N) cout << count[i] << endl;

    return 0;
}


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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int n;
    int[] a;
    scan(n);
    a = readln.split.to!(int[]);
    yes(solve(n, a));
}

bool solve(int n, int[] a) {
    auto mx = a.reduce!max;
    auto mn = a.reduce!min;

    if (mx - mn > 1) {
        return false;
    }

    if (mx - mn == 0) {
        if (mx == n - 1) {
            return true;
        }

        return 1 <= mx && mx <= n / 2;
    }

    int cntmn, cntmx;

    foreach (i ; 0 .. n) {
        if (a[i] == mn) cntmn++;
        else cntmx++;
    }

    auto cmin = cntmn + 1;
    auto cmax = cntmn + (cntmx / 2);

    debug {
        writeln(cmin, " ", cmax);
    }

    return cmin <= mx && mx <= cmax;
}





















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 4476
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val s = in.readLine
  val Array(x, y) = in.readLine.split(" ").map(_.toInt)
  val bufX = mu.ArrayBuffer.empty[Int]
  val bufY = mu.ArrayBuffer.empty[Int]
  val (coordX, coordY) = {
    var cnt = 0
    var isEven = true
    bufX += 0
    s.foreach(ch => {
      if(ch == 'T') {
        isEven = isEven ^ true
        if(isEven) {
          bufX += 0
          cnt += 1
        }
        else {
          bufY += 0
        }
      }
      else {
        if(isEven) bufX(cnt) += 1
        else bufY(cnt) += 1
      }
    })
    (bufX.sum, bufY.sum)
  }
  // debug("x:", bufX.mkString(" "))
  // debug("y:", bufY.mkString(" "))

  val corr = (coordX + coordY) * 2 + 10 //座標のマイナスを補正する
  val coordMax = 2 * corr + 10
  // debug("corr", corr)
  val x2 = x + corr
  val y2 = y + corr
  // テーブル構築 : dp(i)(j)でi回目の操作で座標軸上の n + corr に居られるか
  val dpx = Array.ofDim[Boolean](bufX.size + 1, coordMax)
  val dpy = Array.ofDim[Boolean](bufY.size + 1, coordMax)
  dpx(0)(corr) = true
  dpy(0)(corr) = true

  // 最初の向きは固定
  if(dpx.size > 1) {
    dpx(1)(corr + bufX(0)) = true
    // debug("dpx:", 1, bufX(0))
  }

  for{
    i <- 1 until bufX.size
    j <- 0 until coordMax
  } {
    if(dpx(i)(j)) {
      // debug("dpx:", i+1,j-bufX(i),j+bufX(i))
      if(j - bufX(i) >= 0) dpx(i+1)(j-bufX(i)) = true
      if(j + bufX(i) >= 0) dpx(i+1)(j+bufX(i)) = true
    }
  }
  for{
    i <- 0 until bufY.size
    j <- 0 until coordMax
  } {
    if(dpy(i)(j)) {
      // debug("dpy:", i, j, i+1,j-bufY(i),j+bufY(i))
      if(j - bufY(i) >= 0) dpy(i+1)(j-bufY(i)) = true
      if(j + bufY(i) >= 0) dpy(i+1)(j+bufY(i)) = true
    }
  }

  // debug(dpx.size, dpy.size)
  // debug(bufX.size, x2, bufY.size, y2)
  val ans = if(dpx(bufX.size)(x2) && dpy(bufY.size)(y2)) "Yes" else "No"
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString == "class Main$") return
    println(any.mkString(" "))
  }
}

Measured memory_bytes: 111564
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type pos struct {
	x, y int
}

const inf = int(1e15)

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	p := make([]pos, N)
	for i := 0; i < N; i++ {
		x, y := getInt(), getInt()
		p[i] = pos{x - y, x + y}
	}
	ma0 := -inf
	mi0 := inf
	ma1 := -inf
	mi1 := inf
	for i := 0; i < N; i++ {
		ma0 = max(ma0, p[i].x)
		ma1 = max(ma1, p[i].y)
		mi0 = min(mi0, p[i].x)
		mi1 = min(mi1, p[i].y)
	}
	ans := max(ma0-mi0, ma1-mi1)
	out(ans)
}


Measured memory_bytes: 8296
n = int(input())
status = 0

for i in range(1,10):
    if n % i == 0 and 1 <= n/i <= 9:
        status = 1
#        print(i)
#        print(n/i)
        break
    else:
        pass


if status == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int dp[410][410];
int main(){
    int n,ma,mb;cin >> n >> ma >> mb;
    vi a(n),b(n),c(n);
    rep(i,n) cin >> a[i] >> b[i] >> c[i];
    rep(i,410){
        rep(j,410){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    rep(it,n){
        set<P> ng;
        rep(i,401){
            rep(j,401){
                if(i-a[it]>=0&&j-b[it]>=0){
                    if(!ng.count({i-a[it],j-b[it]})){
                        if(chmin(dp[i][j],dp[i-a[it]][j-b[it]]+c[it])){
                            ng.insert({i,j});
                        }
                    }
                }
            }
        }
    }
    int ans=INF;
    rrep(i,400){
        rrep(j,400){
            if(dp[i][j]!=INF&&i*mb==j*ma){
                chmin(ans,dp[i][j]);
            }
        }
    }
    if(ans==INF){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
//GCD,LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
    int n;
    cin>>n;
    vector<ll> t;
    for(int i=0;i<n;++i){
        ll time;cin>>time;
        t.push_back(time);
    }
    ll ans=1;
    for(int i=0;i<n;++i){
        ans=lcm(ans,t[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <vector>

int N;
std::vector<int> d;
int tmp;
int ans = 0;

int main()
{
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &tmp);
        d.push_back(tmp);
    }
    if (N % 2 != 0) {
        ans = 0;

    } else {
        std::sort(d.begin(), d.end());
        ans = d.at(N / 2) - d.at(N / 2 - 1);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;

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

		int n = sc.nextInt();

		if (n == 0) {
			System.out.println(0);
			return;
		}

		int rem = 0;
		String ans = "";
		while(n != 0) {
			rem = n % -2;
			n /= -2;
			if (rem == -1) {
				n++;
				rem = 1;
			}
			ans = rem + ans;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
from functools import reduce

def main():
    def nCk(n, k, mod=10 ** 9 + 7):
        if n < k:
            return 0
        k = min(k, n - k)
        mod_mul = lambda a, b: a * b % mod
        numer = reduce(mod_mul, range(n - k + 1, n + 1), 1)
        denom = reduce(mod_mul, range(1, k + 1), 1)
        return numer * pow(denom, mod - 2, mod) % mod

    X, Y = map(int, input().split())

    b = (2 * X - Y) // 3
    a = (-X + 2 * Y) // 3

    if (X + Y) % 3 != 0 or a < 0 or b < 0:
        print(0)
    else:
        print(nCk(a + b, a))

main()


Measured memory_bytes: 3572
def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N:
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,1)
    distance += tmp_dist
    tmps = [tmp_x,tmp_y]
    for k in range(N-1):
        tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
        distance += tmp_dist
        tmps = [tmp_x,tmp_y]
    print(distance)

if __name__=='__main__':
    main()

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <climits>
using namespace std; 
#define ll long long int


int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    map<pair<ll, ll>, ll> m;
    ll a, b, x, y;
    vector<int> px = {0, 0, 0, -1, -1, -1, -2, -2, -2},
                py = {0, -1, -2, 0, -1, -2, 0, -1, -2};
    for(int i = 0; i < n; ++i){
        cin >> x >> y;
        for(int j = 0; j < 9; ++j){
            a = x + px[j], b = y + py[j];
            if(a >= 1 && a + 2 <= h && b >= 1 && b + 2 <= w) m[{a, b}]++;
        }
    }
    vector<ll> ans(10);
    ans[0] = (w - 2) * (h - 2) - m.size();
    for(auto an: m){
        ans[an.second]++;
    }
    for(int i = 0; i < 10; ++i) cout << ans[i] << endl;
}


Measured memory_bytes: 56448
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
##############################

S = input().rstrip()
K = int(input())

N = len(S)

ret = []
for nums in range(1, K+1):
    for i in range(N):
        s = S[i:i+nums]
        ret.append(s)

ret = sorted(set(ret))
print(ret[K-1])


Measured memory_bytes: 5068
def solve(i,m,a)
  if m==0
    return TRUE
  end
  if i >= @n
    return FALSE
  end
  res= solve(i+1,m,a) || solve(i+1,m-a[i],a)
  return res
end
@n=gets.to_i
a=gets.split.map(&:to_i)
q=gets.to_i
m=gets.split.map(&:to_i)
m.each do |mi|
  if solve(0,mi,a)
    puts "yes"
  else
    puts "no"
  end
end

Measured memory_bytes: 8692
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
using namespace std;

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

    int h[n];
    REP(i,n){
        cin >> h[i];
    }

    int a,b;
    int highest[100100]={0}; // hightst[i]: 灯台iから一本の道でたとどれる灯台のうち、最大の高さを保持
    REP(i,m){
        cin >> a >> b;
        a--;
        b--;
        highest[a] = max(highest[a], h[b]);
        highest[b] = max(highest[b], h[a]);
    }

    int ans = 0;
    REP(i,n){
        if(h[i] > highest[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4372
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In,' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            /*            
            var ans = 0;
            for(int i=1; i<=N; i++){
                var sum = i.ToString().Select(x => (int)(x - '0')).Sum();
                if(A <= sum && sum <= B)
                    ans += i;
            }
            */

            var ans = Enumerable.Range(1,N).Where(n => {
                var sum = n.ToString().Sum(c => (int)(c-'0'));
                return A <= sum && sum <= B;
            }).Sum();

            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream,char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0;i < tmp.Length;i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }

}

Measured memory_bytes: 11476
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  vector<tuple<int,int,int>> p(n);
  int qw,er,ty;
  rep(i,0,n){
    cin >> qw >> er >> ty;
    p[i] = make_tuple(qw,er,ty);
  }
  tuple<int,int,int> ans;
  
  rep(i,0,101){
    rep(j,0,101){
      
      vector<int> h(0);
      vector<int> zero(1,INF);
      set<int> kind;
      rep(k,0,n){
        if(get<2>(p[k])==0) {
          qw = 0;
          qw += abs(i-get<0>(p[k]));
          qw += abs(j-get<1>(p[k]));
          qw += get<2>(p[k]);
          zero.pb(qw);
        }
        else {
          qw = 0;
          qw += abs(i-get<0>(p[k]));
          qw += abs(j-get<1>(p[k]));
          qw += get<2>(p[k]);
          h.pb(qw);
          kind.insert(qw);
        }
      }
      if(kind.size()!=1) continue;
      else if(h[0] > *min_element(ALL(zero))) continue;
      else {
        cout << i << ' ' << j << ' ' << h[0] << endl;
        return 0;
      }
    }
  }
  
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  std::string c1, c2;

  std::cin >> c1 >> c2;
  if (c1[0] == c2[2] &&
      c1[1] == c2[1] &&
      c1[2] == c2[0]) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int cnt = 0;
    for (int i = 0; i < N - 2; i++) {
      if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
    }
    System.out.println(cnt);
  }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i  <= n; ++i)
        if (i % 3 == 0 || i % 5 == 0)   ;
        else    ans += i;
    cout << ans << endl;
    return 0;
}


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

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

  int hundred = x / 100;
  int have = hundred * 5;
  int need = x - hundred * 100;

  if(have >= need) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        class CountedHashSet
        {
            public class Counter
            {
                public Counter()
                {
                    count = 1;
                }

                public int count { get; set; }
            }


            public Dictionary<int, Counter> keySet;

            public CountedHashSet()
            {
                keySet = new Dictionary<int, Counter>();
            }

            public void Add(int key)
            {
                Counter c;

                if (keySet.TryGetValue(key, out c))
                {
                    c.count++;
                }
                else
                {
                    keySet.Add(key, new Counter());
                }
            }

            public int GetKeyCount(int key)
            {
                Counter c;

                if (keySet.TryGetValue(key, out c))
                {
                    return c.count;
                }

                return 0;
            }
        }
        public static List<int> PrimeFactors(int n)
        {
            int i = 2;
            List<int> result = new List<int>();

            while (i * i <= n)
            {
                if (n % i == 0)
                {
                    n /= i;
                    result.Add(i);
                }
                else
                {
                    i++;
                }
            }

            if (n != 1)
            {
                result.Add(n);
            }

            return result;
        }

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            CountedHashSet hs = new CountedHashSet();

            for (int i = N; i > 0; i--)
            {
                List<int> pf = PrimeFactors(i);
                foreach(int e in pf)
                {
                    hs.Add(e);
                }
            }

            int ans = 1;
            foreach(KeyValuePair<int,CountedHashSet.Counter> ks in hs.keySet)
            {
                ans = (int)(Math.BigMul(ans, ks.Value.count + 1) % 1000000007);
            }

            Console.WriteLine(ans);
        }
    }
}


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

map <long long , long long> frequency;

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

  long long sum = 0;
  long long num = 0;
  long long ans = 0; 

	frequency[0] = 1; 
  for(int i = 0; i < n; i++){
    cin >> num;
		sum += num; // Frequency index
		ans += frequency[sum];
		frequency[sum]++;
  }
	cout << ans << endl;
	exit(0);
}

Measured memory_bytes: 15660
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

typedef long long lli;

const lli N = 1000;
const lli M = 1000000;

lli n, dp[N+1], t[1001];
string data[N];
string pat[4][4] = {
  {"0xxxxxxx", "", "", ""},
  {"110yyyyx", "10xxxxxx", "", ""},
  {"1110yyyy", "10yxxxxx", "10xxxxxx", ""},
  {"11110yyy", "10yyxxxx", "10xxxxxx", "10xxxxxx"},
};

main(){
  t[0] = 1;
  for(lli i=1;i<1001;i++) t[i] = (t[i-1] * 2) % M;
  while(cin >> n && n){
    for(lli i=0;i<n;i++) cin >> data[i];
    fill(dp, dp+n+1, 0);
    dp[0] = 1;
    for(lli i=0;i<n;i++){
      for(lli j=0;j<4&&i+j<n;j++){
        bool f = true;
        bool f_y = false;
        bool f_y2 = false;
        if(j == 0) f_y = true;
        lli cnt[2] = {0, 0};
        for(lli k=0;k<=j;k++){
          for(lli l=0;l<8;l++){
            if(data[i+k][l] != 'x' && pat[j][k][l] != 'x' && pat[j][k][l] != 'y' && data[i+k][l] != pat[j][k][l]){
              //cout << "# " << j << ' ' << k << ' ' << l << endl;
f = false;
            }
            if(data[i+k][l] == '1' && pat[j][k][l] == 'y') f_y = f_y2 = true;
            if(data[i+k][l] == 'x'){
              if(pat[j][k][l] == 'x') cnt[0]++;
              if(pat[j][k][l] == 'y'){
                cnt[1]++;
                f_y = true;
              }
            }
          }
        }
        //cout << i << ' ' << j << ' ' << f << endl;
        if(!f_y) f = false;
        if(f){
          lli val = t[cnt[0]];;
          //cout << cnt[0] << ' ' << cnt[1] << endl;
          if(cnt[1]){
            if(f_y2) val = (val * t[cnt[1]]) % M;
            else val = (val * ((t[cnt[1]] - 1 + M) % M)) % M;
          }
          //cout << val << endl;
          dp[i+j+1] = (dp[i+j+1] + dp[i] * val) % M;
        }
      }
    }
    cout << dp[n] << endl;
  }
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <tuple>
#include <unordered_map>
#include <map>
#include <cmath>

#define endl "\n"
#define eb emplace_back
#define ll long long

using namespace std;

int n;
int grid[100000][3];
int dp[100000][3];

int memoization(int day, int take) {

    if (day >= n)
        return 0;

    if (dp[day][take] != -1)
        return dp[day][take];

    int maxim = -1;
    for (int i = 0; i < 3; i++) {
        if (i == take)
            continue;

        int bruh = grid[day][i] + memoization(day+1, i);
        if (bruh > maxim)
            maxim = bruh;
    }

    return dp[day][take] = maxim;
}

int main() {

    cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> grid[i][j];
            dp[i][j] = -1;
        }
    }

    cout << max(grid[0][0] + memoization(1, 0), max(grid[0][1] + memoization(1, 1) , grid[0][2] + memoization(1,2))) << endl;

    return 0;

}

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

#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
typedef long long ll;
const ll inf = 1ll<<62;

ll digitsum(ll a){
  int res = 0;
  while(a){
    res += a%10;
    a /= 10;
  }
  return res;
}

int main(){
#define int ll
  int n; cin >> n;

  int ans = inf;
  FOR(i,1,n/2+1)
    ans = min(ans, digitsum(i)+digitsum(n-i));
  cout << ans << endl;
}

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

int main() {
    int N;  cin >> N;
    string S;  cin >> S;
    int ans = 0, j = N - 1;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'W') {
            while (i < j) {
                if (S[j] == 'R') {
                    --j;
                    ++ans;
                    break;
                }
                else --j;
            }
        }
    }
    cout << ans << endl;
}


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

int gcd(int x, int y){
	if (y != 0)	gcd(y, x%y);
	else return x;
}

int main(void){
	int x, y;

	cin >> x >> y;

	cout << gcd(x, y) << "\n";

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b; cin>>a>>b;
    a--; b--;
    vector <vector<int>> g(100 ,vector <int>(100 ));
    int col = 0;//0白1黒
    for(int i=0;i<100;i++){
        if(i==100/2) col = 1;
        for(int j=0;j<100;j++){
            g[i][j] = col;
        }
    }
    /*cout<<a<<endl;
    cout<<b<<endl;*/
    for(int i=0;i<50;i+=2){
        for(int j=(i%2);j<100;j+=2){
            if(a&&j<100) {g[i][j]=1; a--;}
        }
    }
    int cnt = 0;
    for(int i=99;i>=50;i-=2){
        for(int j=1-(i%2);j<100;j+=2){
            if(b&&j<100) {g[i][j]=0; b--; cnt++;}
        }
    }
    //cout<<cnt<<endl;
    cout<<100<<' '<<100<<endl;
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            if(g[i][j]) cout<<'.';
            else cout<<'#';
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
loop{
  n=gets.to_i
  break if n==0

  mat=Array.new
  n.times{
    arr=gets.split.map(&:to_i)
    arr.push(arr.inject(:+))
    mat.push arr
  }

   colsum=mat.transpose.map{|r|
      r.inject(:+)
   }
   mat.push(colsum)
   
  mat.each do |x|
    x.each do |y|
      print "%5d" % y
    end
    puts
  end
}

Measured memory_bytes: 8768
package main

import "fmt"

func main() {
  	var n int
  	fmt.Scan(&n)
    in := make([]int, n)
    for i := range in {
    	fmt.Scan(&in[i])
    }
    fmt.Println(frog(in))
}

func frog(in []int) int {
	dp := make([]int, len(in))
	dp[1] = abs(in[0] - in[1])

	for i := 2; i < len(in); i++ {
		dp[i] = min(dp[i-1]+abs(in[i]-in[i-1]), dp[i-2]+abs(in[i]-in[i-2]))
	}

	return dp[len(in)-1]
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}


Measured memory_bytes: 6308
#include <stdio.h>

#define MAX 1000000

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

	int tmp[MAX];
	int i, j, flag = 0;
	for (i = 0; i < MAX; i++)
		tmp[i] = 0;

	for (i = 0; i < MAX; i++) {
		if (i == 0) {
			tmp[i] = s;
		} else {
			if (tmp[i-1] % 2 == 0) {
				tmp[i] = tmp[i-1] / 2;
			} else {
				tmp[i] = 3 * tmp[i-1] + 1;
			}
		}
	}

	for (i = 0; i < MAX; i++) {
		for (j = i + 1; j < MAX; j++) {
			if (tmp[i] == tmp[j]) {
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			break;
		}
	}

	printf("%d\n", j+1);

	return 0;
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


void bfs(int s, vector<vector<int>>& g, vector<int>& visited){
	queue<int> q;
	q.push(s);
	visited[s] = s;
	while (!q.empty()){
		int u = q.front(); q.pop();
		for (int v : g[u]){
			if (visited[v] < 0){
				visited[v] = s;
				q.push(v);
			}
		}
	}
}

signed main(){

	int N, K, L;
	vector<vector<int>> road, train;
	cin >> N >> K >> L;
	road.assign(N, vector<int>());
	train.assign(N, vector<int>());
	for (int i = 0; i < K; i++){
		int p, q;
		cin >> p >> q; p--; q--;
		road[p].push_back(q);
		road[q].push_back(p);
	}
	for (int i = 0; i < L; i++){
		int p, q;
		cin >> p >> q; p--; q--;
		train[p].push_back(q);
		train[q].push_back(p);
	}

	vector<int> visited_road(N), visited_train(N);
	visited_road.assign(N, -1);
	visited_train.assign(N, -1);

	for (int i = 0; i < N; i++){
		if (visited_road[i] < 0) bfs(i, road, visited_road);
		if (visited_train[i] < 0) bfs(i, train, visited_train);
	}

	map<pair<int, int>, int> cnt;
	for (int i = 0; i < N; i++){
		cnt[pair<int, int>(visited_road[i], visited_train[i])]++;
	}

	for (int i = 0; i < N; i++){
		cout << cnt[pair<int, int>(visited_road[i], visited_train[i])] << " ";
	}


	return 0;
}

Measured memory_bytes: 30312
#include <stdio.h>
#include <iostream>

int main() {
	int K;
	std::cin >> K;
	int odd, even;
	even = K / 2;
	if ((K % 2) == 0)odd = even;
	else odd = even + 1;
 
	int pair_num = odd * even;
	std::cout << pair_num <<std:: endl;
	return 0;
}

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

int dist(int x1, int y1, int x2, int y2) {
	return abs(x1 - x2) + abs(y1 - y2);
}

int main() {
    
	int n; cin >> n;
	vector<int> t(n + 1, 0), x(n + 1, 0), y(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	bool can = true;
	for (int i = 1; i <= n; i++) {
		int dt = t[i] - t[i - 1];
		int ddist = dist(x[i], y[i], x[i - 1], y[i - 1]);
		if (dt < ddist) {
			can = false;
		}
		if ((dt % 2) != (ddist % 2)) {
			can = false;
		}
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 4196
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int map[101];
int n;
int main(void)
{
	scanf("%d",&n);
	for (int i = 0; i<n; i++)
	{
		scanf("%d", &map[i]);
	}
	int cnt = 0;
	int cnt2 = 0;
	for (int i = 0; i<n; i++)
	{
		
		if (map[i] % 2 == 0)
		{
			cnt++;
			//printf("%d\n",map[i]);
			if (map[i] % 3 == 0 || map[i] % 5 == 0)
			{
				cnt2++;
				//printf("%d %d",cnt,cnt2);
				//printf("%d\n", map[i]);
			}
		}
	}
	if (cnt == cnt2) printf("APPROVED");
	else printf("DENIED");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int A,B,C,D;
const int Mod=998244353;
#define Maxn 3005
int dp[Maxn][Maxn][2];

int main(){
	scanf("%d%d%d%d",&A,&B,&C,&D);
    dp[A][B][1]=1;
    for(int i=A;i<=C;++i)
        for(int j=B;j<=D;++j){
        	dp[i+1][j][0]=(dp[i+1][j][0]+1ll*j*dp[i][j][0])%Mod;
        	dp[i][j+1][1]+=dp[i][j][0];if(dp[i][j+1][1]>=Mod)dp[i][j+1][1]-=Mod;
        	dp[i+1][j][0]=(dp[i+1][j][0]+1ll*j*dp[i][j][1])%Mod;
        	dp[i][j+1][1]=(dp[i][j+1][1]+1ll*i*dp[i][j][1])%Mod;
		}
	printf("%d\n",(dp[C][D][0]+dp[C][D][1])%Mod);
	return 0;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

ll n;
int main() {
    scanf("%lld",&n);
    ll i = 1;
    while((ll)pow(i,2) <= n){
        i++;
    }
    printf("%lld\n",(ll)pow(i-1,2));
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto &y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
#define INDEX(x, xs) &x - &xs[0]

void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = long long int;
using ull = unsigned long long;

signed main() {
  async_io();
  int n;
  while (true) {
    cin >> n;
    if (n == 0) return 0;
    auto sum = 0;
    for (int i = 2;; i++) {
      auto base = i * (i + 1) / 2;
      if (base > n) break;
      if ((base - n) % i == 0) sum++;
    }
    cout << sum << "\n";
  }
}
// aoj submit / --language cpp11 --page 0001 --tweet

Measured memory_bytes: 3152
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    unsigned long long n,k,a,b,x;
    cin >> n >> k;

    if((n-k)%(k-1)==0){
        x=(n-k)/(k-1);
    }else{
        x=(n-k)/(k-1)+1;
    } 
    
    cout << 1+x << endl;
    
}

Measured memory_bytes: 256
h,w=map(int, input().split())
w1=['.'*(w+2)]
s=w1+['.'+input()+'.' for _ in range(h)]+w1

for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=='.':
      t=s[i-1][j-1:j+2]+s[i][j-1:j+2]+s[i+1][j-1:j+2]
      s[i]=s[i][:j]+str(t.count('#'))+s[i][j+1:]
  print(s[i][1:-1])

Measured memory_bytes: 9044
conv1 = {' ':"101","'":"000000",",":"000011","-":"10010001",".":"010001","?":"000001","A":"100101","B":"10011010","C":"0101","D":"0001","E":"110","F":"01001","G":"10011011","H":"010000","I":"0111","J":"10011000","K":"0110","L":"00100","M":"10011001","N":"10011110","O":"00101","P":"111","Q":"10011111","R":"1000","S":"00110","T":"00111","U":"10011100","V":"10011101","W":"000010","X":"10010010","Y":"10010011","Z":"10010000"}
conv2 = {"00000":"A","00001":"B","00010":"C","00011":"D","00100":"E","00101":"F","00110":"G","00111":"H","01000":"I","01001":"J","01010":"K","01011":"L","01100":"M","01101":"N","01110":"O","01111":"P","10000":"Q","10001":"R","10010":"S","10011":"T","10100":"U","10101":"V","10110":"W","10111":"X","11000":"Y","11001":"Z","11010":" ","11011":".","11100":",","11101":"-","11110":"'","11111":"?"}
while 1:
    try:
        s = raw_input()
        s1 = ""; s2 = "";
        for c in s:
            s1 += conv1[c]
        if len(s1)%5>0 :s1 += "0"*(5-(len(s1)%5))
        for i in xrange(len(s1)/5):
            s2 += conv2[s1[:5]]
            s1 = s1[5:]
        print s2
    except EOFError:
        break

Measured memory_bytes: 4328
#include <iostream>
#include <vector>

using namespace std;

int main(){
	while(1){
		int n, p; cin >> n >> p;
		if(!n && !p)break;
		
		int i=0, num=p;
		vector <int> count(n);
		while(1){
			if(num==0){
				num = count[i];
				count[i] = 0;
			} else{
				count[i]++;
				num--;
				if(count[i] == p) break;
			}
			i++;
			if(i >= n) i=0;
		}
		cout << i << endl;
	}
	return 0;
}


Measured memory_bytes: 3080