akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<random>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n, m;
    cin >> n >> m;
    vector<ll> r;

    for (int i = 1; i * i <= m; i++) {
        if (m % i == 0) {
            r.push_back(i);
            if (i * i != m) {
                r.push_back(m / i);
            }
        }
    }
    
    rSORT(r, [](int a, int b) {return a > b; });
    for (ll i : r) {
        if (i * n <= m) {
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
while True:
    nums = raw_input().strip()
    if nums == '0':
        break

    nums = list(nums)
    nums.reverse()

    minus = False
    if nums[-1] == '-':
        minus = True
        nums.pop()
        nums = [0] + nums

    nums = map(int, nums)

    for i in range(len(nums)):
        if i % 2 != 0:
            nums[i] = -nums[i]

    for i in range(len(nums) + 1):
        try:
            if nums[i] < 0:
                nums[i] += 10
                if i == len(nums) - 1:
                    nums = nums + [0]
                nums[i + 1] += 1
            elif nums[i] == 10:
                nums[i] = 0
                if i == len(nums) - 1:
                    nums = nums + [0]
                nums[i + 1] -= 1
        except IndexError:
            pass

    if minus:
        del nums[0]

    print ''.join(map(str, reversed(nums)))

Measured memory_bytes: 4264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;


int main(){
	int a[26];
	for (int i = 0;i < 26;++i) {
		a[i] = 0;
	}
	char c;
	while (cin >> c) {
		char b = tolower(c);
		if ('a' <= b&&b <= 'z')   a[b - 'a']++;
	}
	for (int i = 0;i < 26;i++) {
		cout << (char)('a' + i) << " : " << a[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
package main

import (
	"fmt"
)

func main() {
	var b, ans string
	fmt.Scanln(&b)
	switch b {
	case "A":
		ans = "T"
	case "T":
		ans = "A"
	case "C":
		ans = "G"
	case "G":
		ans = "C"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>

#define INF 1000000007
using namespace std;
signed main(){
    int n,k;
    int h[114514];
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>h[i];
    int dp[114514];
    for(int i=0;i<114514;i++)dp[i]=INF;
    dp[0]=0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            dp[i]=min(dp[max(i-j,0)]+abs(h[i]-h[max(i-j,0)]),dp[i]);
        }
    }
    
    
    cout<<dp[n-1]<<endl;
    return 0;
}





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

struct Node{
	long key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(long k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL){
		y = x;
		if (z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;

	if (y == NIL) root = z;
	else {
		if (z->key < y->key) y->left = z;
		else y->right = z;
	}
}

void inorder(Node *u){
	if (u == NIL) return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preorder(Node *u){
	if (u == NIL) return;
	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

long find(Node *u, long x){
	if (u == NIL) return 0;
	else if (u->key == x) return 1;
	else if (u->key > x) return find(u->left, x);
	else return find(u->right, x);
}

int main(){
	long n, x;
	string com;
	cin >> n;
	for (long i = 0; i < n; i++){
		cin >> com;
		if (com == "insert"){
			cin >> x;
			insert(x);
		}
		else if (com == "print"){
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
		else {
			cin >> x;
			if (find(root, x)) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 19960
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
MOD = 10 ** 9 + 7


# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % MOD)
    inverse.append(pow(factorial[-1], MOD - 2, MOD))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % MOD


ans = 0
for i in range(N - K + 1):
    ans -= A[i] * nCr(N - i - 1, K - 1) % MOD
    ans %= MOD

A = A[::-1]
for i in range(N - K + 1):
    ans += A[i] * nCr(N - i - 1, K - 1) % MOD
    ans %= MOD

print(ans % MOD)


Measured memory_bytes: 16144
import java.math.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    static final int modnum = 1000000007;

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

        UnionFindTree unionfind = new UnionFindTree(N);

        for (int i = 0; i < M; i++) {
            int p1 = sc.nextInt();
            int p2 = sc.nextInt();
            int length = sc.nextInt() % 2;
            unionfind.union(p1 - 1, p2 - 1);
        }

        HashMap<Integer,Integer> roots = new HashMap<Integer,Integer>();
        for (int i = 0; i < N; i++) {
            roots.put(unionfind.find(i), 1);
        }

        System.out.println(roots.size());
    }
}

class UnionFindTree {

    int[] parent; // インデックスにとノードを対応させ、そのルートノードのインデックスを格納
    int[] rank; // parentと同様に、木の高さを格納

    public UnionFindTree(int size) {
        this.parent = new int[size];
        this.rank = new int[size];

        for (int i = 0; i < size; i++) {
            makeSet(i);
        }
    }

    public void makeSet(int i) {
        parent[i] = i;
        rank[i] = 0; // 集合の高さ
    }

    public void union(int x, int y) {
        int xRoot = find(x);
        int yRoot = find(y);

        // xが属する木の方が大きい場合
        if (rank[xRoot] > rank[yRoot]) {
            parent[yRoot] = xRoot; // yの親をxに更新

        } else if (rank[xRoot] < rank[yRoot]) {
            parent[xRoot] = yRoot;

        } else if (xRoot != yRoot) {
            parent[yRoot] = xRoot;
            rank[xRoot]++; // 同じ高さの木がルートの子として着くから大きさ++;
        }
    }

    // 引数の属する木のルートのidを返す
    public int find(int i) {
        if (i != parent[i]) {
            parent[i] = find(parent[i]);
        }
        return parent[i];
    }

    // 同じ木に属しているか
    public boolean same(int x, int y) {
        return find(x) == find(y);
    }
}

Measured memory_bytes: 93496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    rep(i,n){
        ll v=a[i];
        ll j=i-1;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            a[j]=v;
            j--;
        }
        a[j+1]=v;
        rep(k,n){
            cout<<a[k];
            if(k<n-1) cout<<' ';
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3116
N=int(input())
S=input()
t=0
for i in range(1,N):
    if S[i]=="E":
        t+=1
a=t
for i in range(1,N):
    if S[i-1]=="W":
        t+=1
    if S[i]=="E":
        t-=1
        a=min(a,t)
print(a)

Measured memory_bytes: 3700
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    char now=S[0];
    int place=0;
    int center;
    if(S.size()%2==1){
        center=(S.size()+1)/2;//真ん中がcenter番目
    }else{
        center=-1;
    }
    int ans=S.size();
    for(int i=1; i<S.size(); i++){
        if(now!=S[i]){
            now=S[i];
            if(center!=-1){
                if(i+1<=center) ans=min(ans, (int)S.size()-i);
                else ans=min(ans, i);
            }else{
                if(i+1<=S.size()/2) ans=min(ans, (int)S.size()-i);
                else ans=min(ans, i);
            }
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

const int N = 2e5+5;
ll a[N];
ll suf[N];

int main()
{
   IOS;
   int n;
   cin >> n;
   rep(i,1,n)cin >> a[i];
   suf[n+1] = 0;
   suf[n] = a[n];
   per(i,n-1,1)suf[i] = (suf[i+1]+a[i])%mod;
   //rep(i,1,n)cout << suf[i] << endl;
   ll sum = 0;
   rep(i,1,n)
   {
       sum = (sum + a[i]*suf[i+1]%mod)%mod;
   }
   cout << sum;
}


Measured memory_bytes: 6688
#include <stdio.h>

/*
	ax + by = c
	dx + ey = f

	ax = c - by
	x = (c - by) / a

	dx = f - ey
	x = (f - ey) / d

	(c - by) / a = (f - ey) / d
	d(c - by) = a(f - ey)
	dc - bdy = af - aey
	aey - bdy = af - dc
	y(ae - bd) = af - dc
	y = (af - dc) / (ae - bd)
*/

int main() {
	double a, b, c, d, e, f, x, y;
	while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
		y = (a * f - d * c) / (a * e - b * d);
//		x = (f - e * y) / d;
		x = (c - b * y) / a;

		if (x > (double)-0.001 && x <= (double)0) x = 0;
		if (y > (double)-0.001 && y <= (double)0) y = 0;

		printf("%.3lf %.3lf\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] as = br.readLine().split(" ");
		boolean flag = true;
		for(int i = 0 ; i< n ;i++) {
			int a = Integer.parseInt(as[i]);
			if(a % 2 == 0) {
				if(a % 3 != 0 &&  a%5 != 0 ) {
					flag = false;
					break;
				}
			}
		}
		if(flag ) {
			System.out.println("APPROVED");
		}else {
			System.out.println("DENIED");
		}
		
	}

}


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

    step = list(input().split())
    pos = 0     # 0:bottom, 1:top
    lu, ru, ld, rd = [0] * 4
    cnt = 0

    for s in step:
        if pos == 0:
            if s == "lu":
                lu = 1
            elif s == "ru":
                ru = 1
            elif s == "ld":
                lu = 0
            elif s == "rd":
                ru = 0

            if lu == 1 and ru == 1:
                cnt += 1
                pos = 1
                lu, ru = 0, 0

        elif pos == 1:
            if s == "ld":
                ld = 1
            elif s == "rd":
                rd = 1
            elif s == "lu":
                ld = 0
            elif s == "ru":
                rd = 0

            if ld == 1 and rd == 1:
                cnt += 1
                pos = 0
                ld, rd = 0, 0

    print(cnt)


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

const ll inf = 1e9+5;

int main(){
	int n;
    cin>>n;
    ll a[n][3];
    for(ll i = 0;i < n;i++) {
        for(ll j = 0;j < 3;j++) cin>>a[i][j];
    }
    ll dp[n][3];
    memset(dp,0,sizeof dp);
    for(ll i = 0;i < 3;i++) dp[0][i] = a[0][i];
    for(ll i = 1;i < n;i++) {
        // decide to do jth task on ith day
        for(ll j = 0;j < 3;j++) {
            ll ans = 0;
            for(ll k = 0;k < 3;k++) {
                if(j == k) continue;
                ans = max(ans, dp[i-1][k] + a[i][j]);
            }
            dp[i][j] = ans;
        }
    }
    cout<<*max_element(dp[n-1], dp[n-1]+3);
}


Measured memory_bytes: 4992
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    if m % 2 == 1 {
        println!("-1");
        return;
    }
    let mut graph = vec![vec![]; n];
    for i in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push((b, i));
        graph[b].push((a, i));
    }

    let mut vis = vec![false; n];
    let mut edges: Vec<Option<(usize, usize)>> = vec![None; m];
    vis[0] = true;
    dfs(0, 0, &graph, &mut edges, &mut vis);
    for e in edges.into_iter() {
        let (from, to) = e.unwrap();
        sc.write(format!("{} {}\n", from + 1, to + 1));
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<(usize, usize)>>,
    edges: &mut Vec<Option<(usize, usize)>>,
    vis: &mut Vec<bool>,
) {
    for &(next, _) in graph[v].iter() {
        if vis[next] {
            continue;
        }
        vis[next] = true;
        dfs(next, v, graph, edges, vis);
    }

    let mut out = 0;
    for &(next, edge_id) in graph[v].iter() {
        if next == p {
            continue;
        }
        if edges[edge_id].is_none() {
            edges[edge_id] = Some((v, next));
        }
        let (from, _) = edges[edge_id].unwrap();
        if from == v {
            out += 1;
        }
    }
    for &(next, edge_id) in graph[v].iter() {
        if next == p {
            assert!(edges[edge_id].is_none());
            if out % 2 == 0 {
                edges[edge_id] = Some((next, v));
            } else {
                edges[edge_id] = Some((v, next));
            }
        }
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 081_arc_b / Link: https://abc071.contest.atcoder.jp/tasks/arc081_b?lang=en  ----- */
/* ------問題------

2×N のマス目があります． すぬけ君は，このマス目に N 個のドミノを，重ならないように敷き詰めました． ここで，ドミノは，1×2 または 2×1 のマス目を覆うことができます．
すぬけ君は，赤色，水色，緑色の 3 色を使って，これらのドミノを塗ることにしました． このとき，辺で接しているドミノは異なる色で塗るようにします． ここで，必ずしも 3 色すべてを使う必要はありません．
このような塗り方が何通りあるかを mod 1000000007 で求めてください．
ただし，ドミノの敷き詰め方は，文字列 S1,S2 を用いて，次のようにして与えられます．
各ドミノは，それぞれ異なる英小文字または英大文字で表される．
Si の j 文字目は，マス目の上から i 番目，左から j 番目のマスにどのドミノがあるかを表す．

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	string s1, s2;
	cin >> s1 >> s2;
	ans = 1;
	int mode = -1;
	FOR(i, 0, N) {
		if (mode == -1) {//init
			if (s1[i] == s2[i]) {
				mode = 0; ans = 3;
			}
			else {
				mode = 1; ans = 6;
			}
		}
		else if (mode == 0) {// :
			if (s1[i] == s2[i]) {
				mode = 0; ans *= 2;
			}
			else {
				mode = 1; ans *= 2;
			}
		}
		else if (mode == 1) {// =L

			mode = 2;
		}
		else if (mode == 2) {// =R
			if (s1[i] == s2[i]) {
				mode = 0; ans *= 1;
			}
			else {
				mode = 1; ans *= 3;
			}
		}

		ans %= MOD;
	}
	cout << ans << "\n";

	return 0;
}


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

using namespace std;

int main(){
    int k;
    cin >> k;
    vector<int64_t> A, prev;
    for (int i = 1; i < 10; i++){
        A.push_back(i);
        prev.push_back(i);
    }

    while (A.size() < 100000){
        vector<int64_t> next;
        for (const auto &p: prev){
            int64_t a = p % 10;
            next.push_back(p * 10 + a);
            if (a < 9)
                next.push_back(p * 10 + a + 1);
            if (a > 0)
                next.push_back(p * 10 + a - 1);
        }
        for (const auto &n: next)
            A.push_back(n);
        prev = next;
    }

    sort(A.begin(), A.end());
    cout << A[k - 1] << endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin>>n;
    int arr[n][3];
    int dp[n][3] = {0};
    for(int i = 0; i<n; i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    for(int i = 0; i<3; i++){
        dp[0][i] = arr[0][i];
    }
    for(int i = 1; i<n; i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + arr[i][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + arr[i][1];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + arr[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
}


Measured memory_bytes: 5900
#include <stdio.h>
int main(void){
    // Your code here!
    int n, x, i, j, k, c;
    c=0;
    while(1){
        scanf("%d %d", &n, &x);
        if(n==0 && x==0)break;
        for(i=1; i<n+1; i++){
            for(j=1; j<n+1; j++){
                for(k=1; k<n+1; k++){
                    if(j!=k && i!=j && i!=k && i+j+k==x){
                        c=c+1;
                    }
                }
            }
        }
        printf("%d\n",c/6);
        c=0;
    }
    return 0;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
        int n;
        cin>>n;
        int a,mxa=0;
        map<int,int>mp;
        for(int i=0;i<n;i++){
             cin>>a;mxa=max(a,mxa);
             mp[a]++;
        }
        int ans=0;
        for(auto&& i:mp){
             if(i.second==0)continue;
               if(i.second==1)ans++;
               for(int j=i.first;j<=mxa;j+=i.first){
                    mp[j]=0;
               }
        }
        cout<<ans<<endl;

     }


 


 






    





      

        


Measured memory_bytes: 66024
import java.util.Scanner;
class Main {
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		// TODO Auto-generated method stub
		int W = scanner.nextInt();
		int H = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int r = scanner.nextInt();
				
		if(W >= x + r && x - r >= 0 && H >= y + r && y - r >= 0){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
	}

}

Measured memory_bytes: 26304
s,K = open(0).read().split()
K = int(K)
dista = [(123 - ord(x)) % 26 for x in s]
sa = sum(dista)
if K >= sa:
    print('a'*(len(s)-1)+chr(97+(K-sa)%26))
else:
    ans = []
    count = K
    for i in range(len(s)):
        if count >= dista[i]:
            ans.append('a')
            count -= dista[i]
        else:
            ans.append(s[i])
    if ans[-1] == 'a':
        ans[-1] = chr(97+(count%26))
    else:
        ans[-1] = chr(ord(ans[-1])+count)
    print(''.join(ans))

Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 105;

struct mf{
	struct edg{ int pos; lint cap; int rev; };
	vector<edg> gph[MAXN];
	void clear(){ for(int i=0; i<MAXN; i++) gph[i].clear(); }
	void add_edge(int s, int e, lint x){
		gph[s].push_back({e, x, (int)gph[e].size()});
		gph[e].push_back({s, 0, (int)gph[s].size()-1});
	}
	int dis[MAXN], pnt[MAXN];
	bool bfs(int src, int sink){
		memset(dis, 0, sizeof(dis));
		memset(pnt, 0, sizeof(pnt));
		queue<int> que;
		que.push(src);
		dis[src] = 1;
		while(!que.empty()){
			int x = que.front();
			que.pop();
			for(auto &e : gph[x]){
				if(e.cap > 0 && !dis[e.pos]){
					dis[e.pos] = dis[x] + 1;
					que.push(e.pos);
				}
			}
		}
		return dis[sink] > 0;
	}
	lint dfs(int x, int sink, lint f){
		if(x == sink) return f;
		for(; pnt[x] < gph[x].size(); pnt[x]++){
			edg e = gph[x][pnt[x]];
			if(e.cap > 0 && dis[e.pos] == dis[x] + 1){
				lint w = dfs(e.pos, sink, min(f, e.cap));
				if(w){
					gph[x][pnt[x]].cap -= w;
					gph[e.pos][e.rev].cap += w;
					return w;
				}
			}
		}
		return 0;
	}
	lint match(int src, int sink){
		lint ret = 0;
		while(bfs(src, sink)){
			lint r;
			while((r = dfs(src, sink, 1e15))) ret += r;
		}
		return ret;
	}
}mf;

int n, a[MAXN];

int main(){
	cin >> n;
	lint ret = 0;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(a[i] < 0) mf.add_edge(0, i, -a[i]);
		else mf.add_edge(i, n+1, a[i]), ret += a[i];
		for(int j=2*i; j<=n; j+=i) mf.add_edge(i, j, 1e15);
	}
	cout <<ret - mf.match(0, n + 1) << endl;
}


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

#define LEN 4

string WordCut(char *S, int length){
    char result[length] = {0};
    for(int i = 0; i < length ;i++){
        result[i] = S[i];
    }
    string str(result,length);
    return str;
}

int main(void){
    string S;
    cin >> S;

    string T[LEN] = {"dream","dreamer","erase","eraser"};
    string tmp;
    bool CheckFlg = true;
    for(int i = S.length(); i > 0 ; i--){
        for(int j = 0; j < LEN; j++){
            if((i - T[j].length()) >= 0 ) { //アクセス違反防止
                tmp = WordCut(&S[i - T[j].length()],T[j].length());
            }
            if(tmp == T[j]){
                CheckFlg = true;
                i = (i+1) - T[j].length();
                break;
            }else{
                CheckFlg = false;
            }
        }

        if(!CheckFlg){
            cout << "NO" <<endl;
            return 0;
        }  
    }

    cout << "YES" <<endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String str = sc.next();
			int len = str.length();
			int ans = 0;
			int temp = 0;
			for (int i = 0; i < len; i++) {
				char c = str.charAt(i);
				if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
					temp++;
				} else {
					ans = Math.max(ans, temp);
					temp = 0;
				}
			}
			System.out.print(Math.max(ans, temp));
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;


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


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

    int res = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]){
            res++;
        }
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
#include<algorithm>



class Card{
public:
  char c;
  int num;
  int default_index;
  Card(int c,int num,int di){this->c = c;this->num = num;this->default_index=di;}
};



int main(){
  int n;
  std::cin >> n;
  std::cin.ignore();
  
  std::string input;
  getline(std::cin,input);
  
  std::stringstream ss(input);
  std::vector<Card> card;
  for(int i=0;i<n;i++){
    std::string tmp;
    getline(ss,tmp,' ');
    card.push_back(Card(tmp[0],std::stoi(tmp.substr(1)),i));
  }
  
  //bubble
  int not_sort = 1;
  while(not_sort){
    not_sort = 0;
    for(int i=0;i<n-1;++i){
      if(card[i].num>card[i+1].num){
        std::swap(card[i],card[i+1]);
        not_sort = 1;
      }
    }
  }
  
  for(int i=0;i<card.size();++i){
    std::cout << card[i].c << card[i].num;
  	if(i==card.size()-1){
  		std::cout << std::endl;
  	}else{
  		std::cout << " ";
  	}
  }
	
  for(int i=1;i<card.size();++i){
  	if(card[i-1].num==card[i].num && card[i-1].default_index > card[i].default_index){
  		std::cout << "Not stable" << std::endl;
  		break;
  	}
  	if(i==card.size()-1){
    	std::cout << "Stable" << std::endl;
    }
  }
  
  //もとに戻す
  not_sort = 1;
  while(not_sort){
    not_sort = 0;
    for(int i=0;i<n-1;++i){
      if(card[i].default_index>card[i+1].default_index){
        std::swap(card[i],card[i+1]);
        not_sort = 1;
      }
    }
  }

  //selection
  int change = 0;
	
	for(int i=0;i<card.size();i++){
		int min_num=i;
		for(int j=i+1;j<card.size();++j){
			if(card[min_num].num > card[j].num){
				min_num = j;
			}
		}
		
		if(i!=min_num){
			change++;
			std::swap(card[i],card[min_num]);
		}
	}
  
	
  for(int i=0;i<card.size();++i){
    std::cout << card[i].c << card[i].num;
  	if(i==card.size()-1){
  		std::cout << std::endl;
  	}else{
  		std::cout << " ";
  	}
  }
  
  for(int i=1;i<card.size();++i){
  	if(card[i-1].num==card[i].num && card[i-1].default_index > card[i].default_index){
  		std::cout << "Not stable" << std::endl;
  		break;
  	}
  	if(i==card.size()-1){
    	std::cout << "Stable" << std::endl;
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}



int main() {
    int n,m,k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if(i*(m-j)+j*(n-i) == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = j
	pq[j].index = i
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}



Measured memory_bytes: 1244
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


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



int main() {
	
	int n, k;
	cin >> n >> k;
	vector<int> l(n);

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

	SORT(l);

	int sum = 0;
	FOR(i,n-k,n) {
		sum += l[i];
	}

	ANS(sum);

	return 0;
}



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

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

    ll ans = 0;

    rep(i,n-1){
        if(a[i]>x){
            ans += a[i]-x;
            a[i] = x;
        }
        ll sum = a[i]+a[i+1];
        if(sum>x){
            ll d = sum - x;
            ans += d;
            a[i+1] -= d;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4000
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;

queue<pair<string,int>> ps;

int main(void){
  int n;
  cin>>n;
  int q;
  cin>>q;
  string name;
  int time;
  for(int i=0;i<n;i++){
    cin>>name>>time;
    ps.push(make_pair(name,time));
  }
  int g_time=0;
  while(!ps.empty()){
    pair<string,int> tmp=ps.front();
    ps.pop();
    if (tmp.second<=q){
      g_time+=tmp.second;
      cout<<tmp.first<<" "<<g_time<<endl;
    }else{
      g_time+=q;
      ps.push(make_pair(tmp.first,tmp.second-q));
    }
  }
  return 0;
}



Measured memory_bytes: 6284
#include <stdio.h>

int n, s, cnt;

void dfs(int i, int sum, int n){
    if(sum==s&&!n){
        cnt++;
        return;
    }
    if(i==10||!n) return;
    dfs(i+1,sum,n);
    dfs(i+1,sum+i,n-1);
}

int main(){
	while(1){
		scanf("%d%d",&n,&s);
		if(n==0&&s==0){
			break;
		}
		cnt=0;
		dfs(0,0,n);
		printf("%d\n",cnt);
	}

    return 0;
}

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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384


int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}


typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

 
/*CODE START HERE*/
int main() {
  int n;
  string s;
  cin >> n >> s;
  int count_max =0;
  forr(i,1,n){ //iは2番目始めの文字のat(i)
    int count = 0;
    string c = s ;
    forr(j,0,i){
      bool alp = false ;
      forr(k,i,n){
       if( c.at(j)==c.at(k)){
         alp = true ;
         c.at(k) = 'A' ;
       }
      }
        if (alp){
          count ++ ;
        }
    } 
    count_max =  max(count_max , count);
  }
  cout << count_max << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
multiset<int> s;
set<int> si;
int main()
{
    int n,m,x,last;
    cin >> n >> m;
    last=0;
    s.insert(0);
    for(int i=1;i<=n;i++)
    {
        cin >> x;
        x=(last+x)%m;
        last=x;
        s.insert(x);
        si.insert(x);
    }
    set<int>::iterator it;
    ll ans=0;
    for(it=si.begin();it!=si.end();it++)
    {
        int t=s.count(*it);
        ans+=1ll*(t-1)*t/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7936
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	cnt := map[int]int{}
	cnt[a]++
	cnt[b]++
	cnt[c]++
	fmt.Println(len(cnt))
}

func intMax(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func intMin(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func intSum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func intAbs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = newScanner()
}

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
vvi in;
vector<bool>d;
int n;
int coa,cob;
bool f(int a,int b){
	if(coa==cob&&coa==n/2)return true;
	rep(i,in[a].size()){
		if(d[in[a][i]])continue;
		d[in[a][i]]=true;
		coa++;
		rep(j,in[b].size()){
			if(d[in[b][j]])continue;
			d[in[b][j]]=true;
			cob++;
			if(f(in[a][i],in[b][j]))return true;
			d[in[b][j]]=false;
			cob--;
		}
		d[in[a][i]]=false;
		coa--;
	}
	return false;
}
int main(){
	int a,b;
	coa=cob=1;
	cin>>n>>a>>b;
	d=vector<bool>(n,false);
	a--;b--;
	d[a]=d[b]=true;
	vvi tmp(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		tmp[a].pb(b);
		tmp[b].pb(a);	
	}
	if(n%2){
		cout<<"No"<<endl;
		return 0;
	}
	in=tmp;
	int q=0;
	rep(i,n)if(in[i].size()>3)q++;
	if(q){
		cout<<"No"<<endl;
		return 0;
	}
	q=0;
	rep(i,n)if(in[i].size()==3)q++;
	if(q>2){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<(f(a,b)?"Yes":"No")<<endl;
}

Measured memory_bytes: 16056
import java.util.Scanner;

class Main
{
    public static int Partition(int[]A, int p, int r)
    {
	int x = A[r];
	int i = p - 1;

	for(int j = p; j < r; j++)
	    {
		if(A[j] <= x)
		    {
			i++;
			int a = A[j];
			A[j] = A[i];
			A[i] = a;
		    }
	
	    }	
	int b = A[r];
	A[r] = A[i + 1];
	A[i + 1] = b;
	
	return i + 1;
    }

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

	int n = In.nextInt();

	int[] A = new int[n];

	for(int i = 0; i < n; i++)
	    A[i] = In.nextInt();

	int c = Partition(A,0,n-1);

	for(int i = 0; i < n; i++)
	    {
		if(i == c) System.out.print("[" + A[i] + "]");
		else System.out.print(A[i]);

		if(i == n - 1) System.out.println();
		else System.out.print(" ");
	    }
    }
}

Measured memory_bytes: 71316
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define all(v) (v).begin(),(v).end()
using ll = long long;
constexpr ll INF = 1e9;

int main(void) {
    ll N, K;
    cin >> N >> K;
    vector<vector<ll>> A(N, vector<ll>(N));
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    mcf_graph<ll, ll> graph(2*N+2);
    ll s = 2*N, t = 2*N+1;
    graph.add_edge(s, t, N*K, INF);
    for (ll i = 0; i < N; i++) {
        graph.add_edge(s, i, K, 0);
        graph.add_edge(i+N, t, K, 0);
    }
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            graph.add_edge(i, j+N, 1, INF-A[i][j]);
        }
    }

    graph.flow(s, t, N*K);
    ll sum = 0;
    vector<string> ans(N, string(N, '.'));
    for (auto&& e : graph.edges()) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        ll i = e.from, j = e.to - N;
        sum += A[i][j];
        ans[i][j] = 'X';
    }
    cout << sum << endl;
    for (auto&& a : ans) {
        cout << a << endl;
    }

    return 0;
}


Measured memory_bytes: 3512
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    ll lcm = N * M / __gcd(N, M);
    if(N > M) {
        swap(N, M);
        swap(S, T);
    }
    ll c = lcm / N, d = lcm / M;

    bool ok = 1;
    rep(i, N) {
        if((i * c) % d == 0) {
            if(S[i] != T[(i * c) / d])
                ok = 0;
        }
    }
    cout << (ok ? lcm : -1) << endl;
    return 0;
}

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


int main(){
  char c;
  
  cin >> c;
  
  if(c == 'a'){
    cout << "vowel" << endl;
  }else if(c == 'i'){
    cout << "vowel" << endl;
  }else if(c == 'u'){
    cout << "vowel" << endl;
  }else if(c == 'e'){
    cout << "vowel" << endl;
  }else if(c == 'o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
  
}

Measured memory_bytes: 3632
n = int(input())
s = input()
sum = s.count("R") * s.count("G") * s.count("B")
for i in range(1, n-1):
  for j in range(i+1, n):
    k = 2*j-i-1
    if(k >= n):
      break
    if(len({s[i-1], s[j-1], s[k]}) == 3):
        sum -= 1
print(sum)

Measured memory_bytes: 9212
from math import gcd
from collections import Counter, defaultdict, deque

(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]


ACounter = Counter(A)

# has i, j duplicate with gcd not 1
hasPair = any(v > 1 for k, v in ACounter.items() if k != 1)
if not hasPair:
    # check any i j pair has same prime factor
    seenCount = defaultdict(set)

    def sieve(n):
        ret = [-1] * n
        for i in range(2, n):
            if ret[i] == -1:
                for j in range(i, n, i):
                    # each cell is rewritten once for each of its unique prime factors so total cost is O(n loglog n)
                    ret[j] = i
                    if ACounter[j]:
                        seenCount[i].add(j)
        return ret

    sieve(10 ** 6 + 1)

    # print({k: v for k, v in seenCount.items() if v})
    hasPair = any(len(v) > 1 for k, v in seenCount.items())

if hasPair:
    g = 0
    for x in A:
        g = gcd(g, x)
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")
else:
    print("pairwise coprime")



Measured memory_bytes: 276768
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,M,C;
cin>>N>>M>>C;
int B[M];
for(int i=0;i<M;i++){
    cin>>B[i];
}
int A[N][M],t=0,cnt=0;
for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
        cin>>A[i][j];
        t=t+(A[i][j]*B[j]);
    }
    if(t+C>0)cnt++;
    t=0;
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 256
s= input()
n = len(s) - 1


import itertools
li = list(itertools.product({0, 1}, repeat=n))
for i in range(len(li)):
    total = int(s[0])
    shiki = s[0]
    for j in range(n):
        if li[i][j] == 0:
            total += int(s[j+1])
            shiki += "+"+s[j+1]
        else:
            total -= int(s[j+1])
            shiki += "-"+s[j+1]
    if total == 7:
        shiki += "="+str(7)
        print(shiki)
        break
    else:
        pass


Measured memory_bytes: 3064
k = int(input())
ans = 0
mod = 7
flag = 0
for i in range(10 ** 6 + 1):
    ans += 1
    if mod % k == 0:
        flag = 1
        break
    else:
        mod = (mod % k) * 10 + 7

if flag == 1:
    print(ans)
else:
    print(-1)

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

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

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

bool is_triangle(int a, int b, int c)
{
	int arr[] = {a, b, c};
	sort(arr, arr+3);
	if (arr[0] != arr[1] && arr[0] != arr[2] && arr[1] != arr[2])
		return (arr[0]+arr[1] > arr[2]);
	return false;
}

int main()
{
	int n;
	cin >> n;
	int a[n];
	int ans = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (is_triangle(a[i], a[j], a[k]))
					ans++;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    map<int, int> mp;
    akari<int> as(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
        mp[as[i]]++;
    }
    //sort(as.begin(), as.end());
    if (mp[1])
    {
        if (mp[1] == 1)
        {
            cout << 1 << endl;
            return;
        }
        else
        {
            cout << 0 << endl;
            return;
        }
    }
    int ans = 0;
    for (int a : as)
    {
        bool ok = mp[a] == 1;
        for (int f = 2; f * f <= a; f++)
        {
            if (a % f == 0 && (mp[a / f] || mp[f]))
            {
                ok = 0;
            }
        }
        ans += ok;
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 32592