akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int i, j;
int flag;
int n;
int m;
int atari;
int d;
char amida[31][11];
int temp[10], keep[10];

int check_amida(void){
	int k, l;
	for (k = 0; k < d; k++){
		for (l = 0; l < n - 1; l++){
			if (amida[k][l] == '1'){
				temp[l] += temp[l + 1];
				temp[l + 1] = temp[l] - temp[l + 1];
				temp[l] -= temp[l + 1];
			}
		}
	}
	if (temp[atari - 1] == m){
		return (1);
	}
	else {
		return (0);
	}
}

int ins_amida(int a, int b){
	int res;
	amida[a][b] = '1';
	res = check_amida();
	amida[a][b] = '0';
	
	return (res);
}

int main(void)
{
	while (1){
		scanf("%d", &n);
		
		if (!n){
			break;
		}
		
		for (i = 0; i < n; i++){
			temp[i] = i + 1;
			keep[i] = i + 1;
		}
		
		scanf("%d", &m);
		scanf("%d", &atari);
		scanf("%d", &d);
		
		for (i = 0; i < d; i++){
			scanf("%s", amida[i]);
			getchar();
		}
		
		flag = 0;
		
		if (check_amida() == 1){
			printf("0\n");
			flag = 1;
		}
		if (flag == 0){
			for (i = 0; i < d; i++){
				for (j = 0; j < n - 1; j++){
					memcpy(temp, keep, sizeof(keep));
					if (amida[i][j] == '1'){
						continue;
					}
					if (j > 0){
						if (amida[i][j - 1] == '1'){
							continue;
						}
					}
					if (j != n - 2){
						if (amida[i][j + 1] == '1'){
							continue;
						}
					}
					if (ins_amida(i, j) == 1){
						printf("%d %d\n", i + 1, j + 1);
						flag = 1;
						break;
					}
				}
				if (flag == 1){
					break;
				}
			}
		}
		if (flag == 0){
			printf("1\n");
		}
	}
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(){
  int N;
  string S;
  cin >> N;
  map<string, int> word;
  for(int s=0;s<N;s++){
    cin >> S;
    word[S]+=1; 
  }
  int max=0;
  for(auto w : word){
    if(w.second>max) max=w.second;
  }
  //vector<string> max_word;
  //max_word.clear();
  for(auto w : word){
    if(w.second==max) {
      cout << w.first << endl;
      //max_word.push_back(w.first);
    }
  }

  return 0;
}

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

using namespace std;

pair<long, long> s[111111];
long m1[111111], m2[111111];
int main()
{
	long n, c;
	cin >> n >> c;
	for (int i = 1; i <= n; i++)
		scanf("%ld%ld", &s[i].first, &s[i].second);
	s[n + 1].first = c;
	sort(s + 1, s + n + 1);
	long e = 0, ee = 0, m = 0, mm = 0;
	for (int i = 0; i <= n; i++) {
		m1[i] = m;
		m2[n - i] = mm;
		e += s[i + 1].second - s[i + 1].first + s[i].first;
		ee += s[n - i].second + s[n - i].first * 2 - s[n - i + 1].first * 2;
		m = max(m, e);
		mm = max(mm, ee);
	}
	long M = 0;
	for (int i = 0; i <= n; i++)
		M = max(M, m1[i] + m2[i]);
	e = 0, ee = 0, m = 0, mm = 0;
	fill(m1, m1 + n + 1, 0);
	fill(m2, m2 + n + 1, 0);
	for (int i = 0; i <= n; i++) {
		m1[i] = m;
		m2[n - i] = mm;
		e += s[i + 1].second - s[i + 1].first * 2 + s[i].first * 2;
		ee += s[n - i].second + s[n - i].first - s[n - i + 1].first;
		m = max(m, e);
		mm = max(mm, ee);
	}
	for (int i = 0; i <= n; i++)
		M = max(M, m1[i] + m2[i]);
	cout << M << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
int const MOD = 1e9 + 7;
i64 const INF = 1e18 + 42;
/***********************************************************************/
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  const long double pi = acos((long double)-1);
  long double ang1 = 2 * pi * (m + h * 60) / (12 * 60);
  long double ang2 = 2 * pi * m / 60;
  long double ang = abs(ang1 - ang2);
  long double c = sqrt(a * a + b * b - 2 * a * b * cos(ang));
  cout.precision(10);
  cout << fixed << c << endl;
}


Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;
  int ans=0,com=200001;
  cin>>n;
  vector<int>p(n);
  rep(i,n) cin>>p[i];
  rep(i,n){
    if(com>p[i]){
      ans++;
    }
    com=min(com,p[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let abc: Vec<Vec<i64>> = (0..n).map(|_| (0..3).map(|_| input()).collect()).collect();

    let mut v = vec![vec![0; 3]; n + 1];
    for i in 1..n + 1 {
        v[i][0] = abc[i - 1][0] + std::cmp::max(v[i - 1][1], v[i - 1][2]);
        v[i][1] = abc[i - 1][1] + std::cmp::max(v[i - 1][2], v[i - 1][0]);
        v[i][2] = abc[i - 1][2] + std::cmp::max(v[i - 1][0], v[i - 1][1]);
    }

    println!("{}", v[n].iter().max().unwrap());
}


Measured memory_bytes: 18684
import java.util.*

fun main(args: Array<String>) {
    data class Node(
            val to: MutableList<Int> = mutableListOf(),
            var visited: MutableMap<Int, Boolean> = mutableMapOf(0 to false, 1 to false, 2 to false),
            var min: MutableMap<Int, Int> = mutableMapOf(0 to Int.MAX_VALUE, 1 to Int.MAX_VALUE, 2 to Int.MAX_VALUE)
    )

    data class Value(
            val index: Int,
            var num: Int,
            var ken: Int
    )
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val nodes = mutableMapOf<Int, Node>()
    for (i in 1..n) {
        nodes[i] = Node()
    }
    for (i in 1..m) {
        val (u, v) = readLine()!!.split(' ').map(String::toInt)
        nodes[u]!!.to.add(v)
    }
    val (s, t) = readLine()!!.split(' ').map(String::toInt)
    val queue = ArrayDeque<Value>()
    nodes[s]!!.to.forEach {
        queue.addLast(Value(it, 0, 1))
    }

    while (queue.isNotEmpty()) {
        val value = queue.pollFirst()
        val (index, num, ken) = Triple(value.index, value.num, value.ken)
        val node = nodes[index]!!

        if (node.visited[num]!!) {
            if (node.min[num]!! <= ken) {
                continue
            } else {
                node.min[num] = ken
                if (num == 2) {
                    node.to.forEach { queue.addLast(Value(it, 0, ken + 1)) }
                } else {
                    node.to.forEach { queue.addLast(Value(it, num + 1, ken)) }
                }
            }
        } else {
            node.visited[num] = true
            node.min[num] = ken
            if (num == 2) {
                node.to.forEach { queue.addLast(Value(it, 0, ken + 1)) }
            } else {
                node.to.forEach { queue.addLast(Value(it, num + 1, ken)) }
            }
        }

    }
    if (nodes[t]!!.visited[2]!!) {
        println(nodes[t]!!.min[2])

    } else {
        println(-1)
    }
}



Measured memory_bytes: 182724
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	vi X(N);
	rep(i, N)
		cin >> X[i];
	ll ans = InfLL;
	for (int P = 1; P <= 100; P++) {
		ll anstmp = 0;
		rep(i, N) {
			anstmp += (X[i] - P) * (X[i] - P);
		}
		ans = min(ans, anstmp);
	}


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

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut N = String::new();
    let mut astring = String::new();

    io::stdin().read_line(&mut N).expect("fail");
    io::stdin().read_line(&mut astring).expect("fail");

    let N: u32 = N.trim().parse().unwrap();
    let mut sum: u64 = 0;

    for n in astring.split_whitespace() {
        let n: u64= n.parse().unwrap();
        sum = sum + (n - 1);
    }

    //println!("{}{:?}", N, a);
    println!("{}", sum);
}

Measured memory_bytes: 4476
#include<stdio.h>
int main(void) 
{
	int n = 0,count1 = 0,count2 = 0;
	char str1[110], str2[110];

	scanf("%d%s%s", &n,str1,str2);

	for (int i = 0; i < n * 2; i++) {
		if (i % 2 == 0) {
			printf("%c", str1[count1++]);
		}
		else {
			printf("%c", str2[count2++]);
		}
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 128
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, w = list(map(int, input().rstrip('\n').split()))
    dp = [0] * (w + 1)
    for i in range(n):
        wv, vv = list(map(int, input().rstrip('\n').split()))
        for j in range(w-wv, -1, -1):
            dp[j+wv] = max(dp[j+wv], dp[j] + vv)
    print(dp[-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 40432
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[] {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        System.out.println(arr[sc.nextInt()-1]);
    }
}

Measured memory_bytes: 21844
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    P = [None] * M
    X = [None] * M
    for i in range(M):
        P[i], X[i] = map(int, input().split())

    sum_T = sum(T)
    for i in range(M):
        ans = sum_T - T[P[i] - 1] + X[i]
        print(ans)


if __name__ == "__main__":
    main()


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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 1e5 + 100;
const int maxN = 1e16;
const int oo = 1e18;
const int mod  = 1e9 + 7;

int n, k, sum;
int f[N];

int add(int x, int y) { return (x + y + 4 * mod) % mod; }
int mul(int x, int y) { return x * y % mod; }
int pw(int x, int y) {
    int res = 1;
    while(y) {
        if(y & 1) res = mul(res, x);
        x = x * x % mod;
        y >>= 1;
    }
    return res;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    FORW(i, k, 1) {
        int cnt = (k - i) / i + 1;
        f[i] = add(f[i], pw(cnt, n));
        FOR(j, 1, sqrt(i)) if(i % j == 0) {
            if(i > 1) f[j] = add(f[j], -f[i]);
            if(j > 1 && j * j < i) f[i/j] = add(f[i/j], -f[i]);
        }
        sum = add(sum, mul(i, f[i]));
    }
    cout << sum;
}


Measured memory_bytes: 4380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long x = in.nextLong();
			long k = x / 11;

			long sa = x - 11*k;
			if (sa == 0) {
				out.println(2*k);
			} else if (sa > 0) {
				if (sa <= 6) {
					out.println(2L*k + 1L);
				} else {
					out.println(2L*k + 2L);
				}
			}

		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

	static long max(long... n) {
		long ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.max(ret, n[i]);
		}
		return ret;
	}

	static int max(int... n) {
		int ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.max(ret, n[i]);
		}
		return ret;
	}

	static long min(long... n) {
		long ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.min(ret, n[i]);
		}
		return ret;
	}

	static int min(int... n) {
		int ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.min(ret, n[i]);
		}
		return ret;
	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll h, w;
    cin >> h >> w;

    vector<string> board(h);
    rep(i, h) {
        cin >> board[i];
    }

    vvl matrix(h, vl(w));
    rep(i, h) {
        ll ok = 1;
        rep(j, w) {
            if(board[i][j] == '#') {
                ok = 0;
            }
        }
        if(ok) {
            rep(j, w) {
                matrix[i][j] = 1;
            }
        }
    }

    rep(j, w) {
        ll ok = 1;
        rep(i, h) {
            if(board[i][j] == '#') {
                ok = 0;
            }
        }
        if(ok) {
            rep(i, h) {
                matrix[i][j] = 1;
            }
        }
    }

    rep(i, h) {
        ll ok = 0;
        rep(j, w) {
            if(!matrix[i][j]) {
                cout << board[i][j];
                ok = 1;
            }
        }
        if(ok || i == h-1) {
            cout << "\n";
        }
    }

    re0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back
#define eps 1e-10

int main() {
    int n, x; cin >> n >> x;
    int l[n + 1]; rrep(i, 1, n + 1) cin >> l[i];
    int ans = 0;
    int d[n + 2]; d[1] = 0;
    rrep(i, 1, n + 1) {
        d[i + 1] = d[i] + l[i];
    }
    //rep(i, n + 2) cout << d[i] << " "; cout << endl;
    rrep(i, 1, n + 2) if (d[i] <= x) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define rREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define rFOR(i, a, b) for (ll i = a; i >= b; --i)
#define aFOR(i, V) for (auto i : V)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
#define INF 1'000'000'007 // 10^9 + 7
#define MOD 1'000'000'007 // 10^9 + 7
#define lINF 1'000'000'000'000'000'007 // 10^18 + 7
// ------------------------------

int main() {
    int N;
    cin >> N;
    int ans = 0;
    FOR(C, 1, N) {
        for (int A = 1; A * A <= N - C; ++A) {
            if ((N - C) % A == 0) {
                if (A * A == N - C) {
                    ans += 1;
                }
                else ans += 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

template<int MOD> struct Fp{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD){ if(val<0) v += MOD; }
    constexpr int getmod(){ return MOD; }
    constexpr Fp operator - () const noexcept{ return val ? MOD - val : 0; }
    constexpr Fp operator + (const Fp& r) const noexcept{ return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept{ return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept{ return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept{ return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept{ val += r.val; if(val>=MOD) val -= MOD; return *this; }
    constexpr Fp& operator -= (const Fp& r) noexcept{ val -= r.val; if(val<0) val += MOD; return *this; }
    constexpr Fp& operator *= (const Fp& r) noexcept{ val = val*r.val%MOD; return *this; }
    constexpr Fp& operator /= (const Fp& r) noexcept{
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) { long long t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        val = val*u%MOD; if(val<0) val += MOD; return *this; }
    constexpr bool operator == (const Fp& r) const noexcept{ return this->val == r.val; }
    constexpr bool operator != (const Fp& r) const noexcept{ return this->val != r.val; }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept{ return os << x.val; }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept{ return is >> x.val; }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept{
        if (n == 0) return 1; auto t = modpow(a, n/2); t = t*t; if(n & 1) t = t*a; return t; }
};
const int MOD = MODV;
using mint = Fp<MOD>;

int main(){
    Init();
    ll n, k; cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    // cnt[i](a, b); aは[i+1, n)に含まれるa[i]の転倒数、bは[0, i+1)に含まれるa[i]の転倒数
    vector<pair<ll, ll>> cnt(n);
    rep(i, n){
        for(ll j=i+1; j<n; j++) if(a[j] < a[i]) cnt[i].first++;
        for(ll j=0; j<i; j++) if(a[j] < a[i]) cnt[i].second++;
    }

    // cnt[i].f+sは1~(k-1)回出現し、cnt[i].fはk回出現する
    ll ans = 0;
    rep(i, n){
        ans += (k*(k-1)/2)%MODV*(cnt[i].first+cnt[i].second)+k*cnt[i].first;
        ans %= MODV;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <random>
#include <set>
#include <sstream>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 100005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
bool is_palin(const string& s) {
    int sz = s.size();
    int l = sz / 2 - 1, r = sz / 2;
    if (sz & 1) {
        r++;
    }
    while (l >= 0 && r < sz) {
        if (s[l] != s[r]) return false;
        l--, r++;
    }
    return true;
}
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int x;
    cin >> x;
    double y = x / 3.0;
    printf("%lf", y * y * y);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
const double eps = 1e-9;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int lim = 100;
    ll n, k;
    cin >> n >> k;
    V<ll> a(n);
    read(a);
    ll ok = INF, ng = 0;
    while (ok - ng > 1LL) {
        ll co = 0;
        ll mid = (ok + ng) / 2LL;
        for (int i = 0; i < n; i++) {
            co += a[i] / mid;
            if (a[i] > 0 && a[i] % mid == 0) co--;
        }
        if (co <= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << newl;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    double A,B,H,M;
    cin>>A>>B>>H>>M;
    double alpha=(60*H+M)/720*(2*acos(-1.0));
    double beta=M/60*(2*acos(-1.0));
    double theta=alpha-beta;
    double res=0;
    res=sqrt(A*A+B*B-2.0*A*B*cos(theta));
    cout<<fixed<<setprecision(10)<<res;
}

Measured memory_bytes: 4204
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-19 07:29:05
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;
  map<string, int> mp;

  char pre = '$';

  for (int i = 0; i < n; ++i) {
    string w; cin >> w;
    if (mp.find(w) != mp.end()) {
      cout << "No" << endl; return 0;
    } else {
      ++mp[w];
    }
    char beg = w[0], end = w.back();
    if (i == 0) {
      pre = end;
    } else {
      if (beg != pre) {
        cout << "No" << endl; return 0;
      } else {
        pre = end;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}

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

using namespace std;
# define M_PI 3.14159265358979323846
# define epsi 1e-9
# define F first
# define S second
# define REP(i,a,b) for(int i=a;i<=b;i++)
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
using ll = long long int;
const int MOD = 1e9 + 7;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++)
    {
        int temp;
        cin>>temp;
        p[i]=temp;
    }
    sort(p,p+n);
    int ans=0;
    for(int i=0;i<k;i++)
    {
        ans+=p[i];
    }
    cout<<ans;
    
}

Measured memory_bytes: 3656
n, x, m = map(int, input().split())

s = set()
l = [x]
while x ** 2 % m not in s:
    v = x ** 2 % m
    s.add(v)
    l.append(v)
    x = v

idx = l.index(x ** 2 % m)
loop = len(l) - idx

if n < len(l):
    print(sum(l[:n]))
elif (n - idx) % loop == 0:
    print(sum(l[:idx]) + ((n - idx) // loop) * sum(l[idx:]))
else:
    print(sum(l[:idx]) + ((n - idx) // loop) * sum(l[idx:]) + sum(l[idx:idx+(n-idx)%loop]))

Measured memory_bytes: 77136
import java.math.BigInteger;
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		

		int n = sc.nextInt();
		int l = sc.nextInt();
		
		
		int[] tastes = new int[n];
	
		
		for(int i=0; i<n ;i++) {
			tastes[i] = l + i;
		}
		
		int min = tastes[0];
		int minabs = Math.abs(tastes[0]);
		int sum = 0;
		
		for(int i=0;i<n;i++) {
			sum += tastes[i];
			if (minabs > Math.abs(tastes[i])) {
				min = tastes[i];
				minabs = Math.abs(tastes[i]);
			}
		}
		
		System.out.println(sum - min);

		
		
	}
	
}



Measured memory_bytes: 22356
//
//  main.cpp
//  CP
//
//  Created by Shiv Pavan Raj on 22/02/20.
//  Copyright © 2020 Shiv Pavan Raj. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

#define SZ(x) ((int)(x).size())
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
using namespace std;
typedef pair<int,int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())

using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
const int MX = 2e5+10;
const int MX2 = 1e6+5;

ll INF= 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;

struct node {
    int to;
    int next;
}edge[MX];
int head[MX];
int cnt,mxx,ans;
void add(int x,int y) {
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt++;
}
void dfs(int v,int par,int step) {
    mxx++;
    if (step == 0) return ;
    for (int i = head[v] ; ~i; i = edge[i].next) {
        if (edge[i].to == par) continue;
        dfs(edge[i].to,v,step-1);
    }
}
int main(int argc, const char * argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); // insert code here...
    int n,k;
    cin >> n >> k;
    for (int i = 0; i <= n; ++i) head[i] = -1;
    for (int i = 0; i < n -1; i++) {
        int a,b;
        cin >> a >> b;
        add(a,b);
        add(b,a);
    }
    ans=0;
    if (k%2) {
        for (int i = 1;i <= n; i++) {
            for (int j= head[i]; ~j; j = edge[j].next) {
                mxx = 0;
                int t = edge[j].to;
                dfs(t,i,k/2);
                dfs(i,t,k/2);
                ans = max(ans,mxx);
            }
        }
    }
    else {
        for (int i = 1; i <= n;i++) {
            mxx = 0;
            dfs(i,0,k/2);
            ans = max(ans,mxx);
        }
    }
    cout << n - ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <utility> //pairを使う
using namespace std;

typedef unsigned long long ll;

const ll inf = 1000000000000;
const ll mod = 100000;

int main(){
	string s;
	cin >> s;
	bool flag = false;
	for(int i = 0; i < s.size(); i++){
		if(i >= 2){
			string t1 = s.substr(i, 1);
			string t2 = s.substr(i - 1, 1);
			string t3 = s.substr(i - 2, 1);
			if(t1 == t2 && t2 == t3){
				flag = true;
			}
		}
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#define N 250000000

int str[N];
int count = 0;

int getChar(char );

int main()
{
  long long p, sum;
  int i, j, n;
  char com[9], s[13];

  scanf("%d", &n);

  for( i = 0; i < n; i++)
    {
      scanf("%s%s",com,s);
      
	  sum = 0; p = 1;
	  str[count] = 0;
	  for( j = 0; j < strlen(s); j++)
	    {
	      sum += p*(getChar(s[j]));
	      p*=5;
	    }

	  if( com[0] == 'i')
	    {	  
	      str[sum] = 1;
	    }
	  else
	    {
	      if (str[sum]==1)printf("yes\n");
	      else printf("no\n");
	    }
    }
	  
      return 0;
}
  
int getChar(char ch)
{
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}



Measured memory_bytes: 18628
#include <bits/stdc++.h>
using namespace std;
int A, B, C, dp[101][101][101];

int func(int a, int b, int c){
    if(a == b && b == c)    return 0;
    if(a > 100 || b > 100 || c > 100)   return 1e9;
    int &ret = dp[a][b][c];
    if(ret != -1)   return ret;
    ret = func(a + 2, b, c) + 1;
    ret = min(ret, func(a, b + 2, c) + 1);
    ret = min(ret, func(a, b, c + 2) + 1);
    ret = min(ret, func(a + 1, b + 1, c) + 1);
    ret = min(ret, func(a + 1, b, c + 1) + 1);
    ret = min(ret, func(a, b + 1, c + 1) + 1);
    return ret;
}

int main(){
    memset(dp, -1, sizeof(dp));
    cin >> A >> B >> C;
    printf("%d\n", func(A, B, C));
    return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;
public class Main {
    public static void main(final String[] args) {
     Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
         int[] array = new int[n];
        int i=0;
        for(i=0;i<n;i++){
            array[i]=sc.nextInt();
        }
        for(i=n-1;i>=1;i--){
            System.out.print(array[i]+" ");          
        }
        if(i==0){
            System.out.print(array[0]);
        }
        System.out.println();
    }
}


Measured memory_bytes: 26352
S = [input() for i in range(3)]
s = S[0][0]
a,b,c = 1,0,0
while True:
    if s == 'a':
        if a==len(S[0]):
            print('A')
            break
        s = S[0][a]
        a += 1
    elif s == 'b':
        if b==len(S[1]):
            print('B')
            break
        s = S[1][b]
        b += 1
    elif s == 'c':
        if c==len(S[2]):
            print('C')
            break
        s = S[2][c]
        c += 1


Measured memory_bytes: 38384
#include<iostream>

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		int ans = 0;

		while( n != 1 )
		{
			if( n & 1 )
				n = n * 3 + 1;
			else
				n >>= 1;

			++ans;
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#input

c = str(raw_input())

#judge

if c == 'a':
    print 'vowel'
elif c == 'i':
    print 'vowel'
elif c == 'u':
    print 'vowel'
elif c == 'e':
    print 'vowel'
elif c == 'o':
    print 'vowel'
else:
    print 'consonant'


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

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int bill;
    cin >> bill;
    if(bill%1000 == 0)
        cout << 0;
    else
        cout << 1000-bill%1000;
}

Measured memory_bytes: 3648
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#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()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

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); }

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

ll cnt[30];
signed main(void)
{
  string s;
  cin >> s;
  ll n = s.size();

  ll ret = 0;
  REP(i, n) {
    ret += cnt[s[i]-'a'];
    cnt[s[i]-'a']++;
  }

  cout << n*(n-1)/2-ret+1 << endl;

  return 0;
}


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

int main()
{
    int X, Y, Z, TMP;
    cin >> X >> Y >> Z;
    TMP = X;
    X = Y;
    Y = TMP;
    TMP = Z;
    Z = X;
    X = TMP;

    cout << X << " " << Y << " " << Z << endl;
    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int N,K;
	cin >> N >> K;
	map<ll, ll> mp;
	vector<ll> A(N);
	rep(i,N) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	ll sa = 1e18, sa_prev = 1e18;
	rep(i,N-1) {
		if(A[i+1] - A[i] > 0) chmin(sa, A[i+1] - A[i]);
	}
	while(1) {
		rep(i,N) {
			ll a = A[i] % sa;
			if(a != 0) chmin(sa, a);
		}
		if(sa == sa_prev) {
			break;
		}
		sa_prev = sa;
	}
	rep(i,N) {
		if(A[i] < K) continue;
		if((A[i] - K) % sa == 0) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b>>c;
	int s=a+b+c;
	if(s>=22) cout <<"bust";
	else cout <<"win" ; 
	return 0;
} 

Measured memory_bytes: 888
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


int main(int argc, char* argv[])
{
    int a,b;
    scanf("%d%d", &a, &b);
    int i;
    if(a<b) {
        for(i=0; i<b; i++) {
            printf("%d", a);
        }
        printf("\n");
    }
    else {
        for(i=0; i<a; i++) {
            printf("%d", b);
        }
        printf("\n");
    }


    return 0;
}


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

const char SPACE = 'C';

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> map(H);
	for (int i = 0; i < H; i++)
		cin >> map[i];

	for (int i = 0; i < H; i++) {
		bool flag = true; 
		for (int j = 0; j < W; j++) {
			if (map[i][j] == '#') {
				flag = false;
				break;
			}
		}
		if (flag)
			for (int j = 0; j < W; j++)
				map[i][j] = SPACE;
	}

	for (int i = 0; i < W; i++) {
		bool flag = true;
		for (int j = 0; j < H; j++) {
			if (map[j][i] == '#') {
				flag = false;
				break;
			}
		}
		if (flag)
			for (int j = 0; j < H; j++)
				map[j][i] = SPACE;
	}
	for (int i = 0; i < H; i++) {
		bool f = true;
		for (int j = 0; j < W; j++) {
			if (map[i][j] != SPACE) {
				cout << map[i][j];
				f = false;
			}
		}
		if (!f)
			cout << endl;
	}
		

}


Measured memory_bytes: 256
n=int(input())
sum=0
a=0
b=0
ab=0
for i in range(n):
    x=input()
    m=len(x)
    if x[0]=='B' and x[m-1]=='A':
        ab+=1
    elif x[0]=='B':
        b+=1
    elif x[m-1]=='A':
        a+=1
    
    for j in range(m-1):
        if x[j]=='A' and x[j+1]=='B':
            sum+=1
    
if ab==0:
    print(sum+min(a,b))
else:
    if a==0 and b==0:
        print(sum+ab-1)
    elif a==0 or b==0:
        print(sum+ab)
    else:
        print(sum+ab+1+min(a-1,b-1))

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

vector<P> g[101010];
ll root;
ll V;

ll parent[22][101010];
ll depth[101010],dist[101010];

void dfs(int v,int p,ll d,ll dt){
  parent[0][v]=p;
  depth[v]=d;
  dist[v]=dt;
  for(int i=0;i<g[v].size();i++){
    if(g[v][i].fi!=p)dfs(g[v][i].fi,v,d+1,dt+g[v][i].se);
  }
}

void init(){
  dfs(root,-1,0,0);
  for(int k=0;k+1<22;k++){
    for(int v=0;v<V;v++){
      if(parent[k][v]<0)parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
    }
  }
}

int lca(int u,int v){
  if(depth[u]>depth[v])swap(u,v);
  for(ll k=0;k<22;k++){
    if((depth[v]-depth[u])>>k&1){
      v=parent[k][v];
    }
  }
  if(u==v)return u;
  for(ll k=22-1;k>=0;k--){
    if(parent[k][u]!=parent[k][v]){
      u=parent[k][u];
      v=parent[k][v];
    }
  }
  return parent[0][u];
}

int main(){
	cin.sync_with_stdio(false);
  cin>>V;
  rep(i,V-1){
    ll a,b,c;
    cin>>a>>b>>c;
    a--; b--;
    g[a].push_back(P(b,c));
    g[b].push_back(P(a,c));
  }
  init();
  ll q,k;
  cin>>q>>k;
  k--;
  rep(i,q){
    ll x,y;
    cin>>x>>y;
    x--; y--;
    ll da=dist[x]+dist[k]-dist[lca(x,k)]*2;
    ll db=dist[y]+dist[k]-dist[lca(y,k)]*2;
    cout<<da+db<<endl;
  }
	return 0;
}


Measured memory_bytes: 35584
// 計６パターン？

package main

import "fmt"

func main() {
	var X, Y int
	fmt.Scan(&X, &Y)
	if X <= 0 && Y <= 0 {
		if Y < X {
			fmt.Println(min(1+abs(X)+abs(Y), 2+abs(abs(X)-abs(Y))))
		} else {
			fmt.Println(abs(abs(Y) - abs(X)))
		}
	} else if 0 <= X && 0 <= Y {
		if X <= Y {
			fmt.Println(Y - X)
		} else if Y < X {
			fmt.Println(min(Y+X+1, 2+abs(abs(Y)-abs(X))))
		}
	} else {
		fmt.Println(1 + abs(abs(Y)-abs(X)))
	}
}

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

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

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int main()
{
	int n,m=1;
	cin>>n;
	string s;
	map <string,int> q;
	for(int i=0;i<n;i++){
        cin>>s;
        if(q.find(s)!=q.end()){
            q[s]++;
            m=max(m,q[s]);
        }
        else q[s]=1;
	}
	map<string,int>::iterator it;
	for(it=q.begin();it!=q.end();it++){
        if((*it).second==m) cout<<it->first<<endl;
        //cout<<(*it).second<<" "<<it->first<<endl;
	}
	return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    
    string a, b;
    rep(dx) {
        a += 'R';
        b += 'L';
    }
    rep(dy) {
        a += 'U';
        b += 'D';
    }

    cout << a << b;
    cout << "DR" << a << "UL";
    cout << "UL" << b << "DR";
    cout << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int n;
    cin >> n;
    int ans=0;
    int a;
    rep(i,n) {
        cin >> a;
        while (a%2==0) {
            a/=2;
            ++ans;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
patterns = ["S", "H", "C", "D"]
cards = dict([(i, [str(j) for j in range(1, 14)]) for i in patterns])

for i in range(n):
    p, n = input().strip().split()
    cards[p].remove(n)
for i in patterns:
    if cards[i]:
        for j in cards[i]:
            print(i, j, sep=" ")


Measured memory_bytes: 5608
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        long[] sum = new long[N];
        long[] a = new long[N];
        long[] abssum = new long[N+1];
        List<Integer> minusIndex = new ArrayList<>();
        for(int i=0;i<N;++i){
            if(i==0){
                a[i] = scan.nextLong();
                sum[i]=a[i];
            }else{
                boolean minus = (scan.next().equals("-"));
                a[i] = scan.nextLong();
                sum[i] = sum[i-1] + a[i]*(minus ? -1:1);
                if(minus)minusIndex.add(i-1);
            }
        }
        for(int i=N-1;i>=0;--i)abssum[i] = abssum[i+1]+a[i];

        long ans = sum[N-1];
        for(int i=0;i<minusIndex.size()-1;++i){
            ans = Math.max(ans, sum[minusIndex.get(i)] - abssum[minusIndex.get(i)+1] + 2*abssum[minusIndex.get(i+1)+1]);
        }
        System.out.println(ans);
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int ar[20][20];

int main(){
  FASTER;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++){
    string num = to_string(i);
    int d = num.size();
    int f = num[0] - '0';
    int l = num[d - 1] - '0';
    ar[f][l]++;
  }
  int ans = 0;
  for (int f = 1; f < 10; f++){
    for (int l = 1; l < 10; l++){
      int a = ar[f][l];
      int b = ar[l][f];
      ans += (a * b);      
    }
  } 
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256