akhauriyash/Code-Regression huggingface dataset:
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  if (a < b) {
    return b - a;
  } else {
    return a - b;
  }
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b) {
    a = b;
  }
}
template <class F> class fix_point : private F {
public:
  explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};
template <class F> constexpr decltype(auto) make_fix(F &&f) {
  return fix_point<F>(std::forward<F>(f));
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

u64 cnt2(u64 n) {
  if (n % 2 == 1) {
    return 0;
  }
  u64 ret = 0;
  while (n != 0) {
    ret += n / 2;
    n /= 2;
  }
  return ret;
}

u64 cnt5(u64 n) {
  if (n % 2 == 1) {
    u64 ret = -cnt5(n - 1);
    while (n != 0) {
      n /= 5;
      ret += n;
    }
    return ret;
  }
  n /= 2;
  u64 ret = 0;
  while (n != 0) {
    n /= 5;
    ret += n;
  }
  return ret;
}

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const u64 n = scan<u64>();
  std::cout << std::min(cnt2(n), cnt5(n)) << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
#include <chrono>
#include <random>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-8;
long double pi = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ifstream in("input.txt");
ofstream out("output.txt");

void solve()
{
	int x, n, t;
	cin >> n >> x >> t;
	cout << (n / x + (n % x > 0)) * t;
}

int main()
{
	cout << setprecision(20) << fixed;
	cin.tie();
	cout.tie();
	clock_t t1 = clock();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
		//test();
	}
	//cout << (clock() - t1) * 1.0 / CLOCKS_PER_SEC;
	gg;
}

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

int main(){
  long N, K;
  cin >> N >> K;
  vector<long> H(N);
  for(int i=0; i<N; i++)cin >> H[i];
  sort(H.begin(), H.end(), greater <int>());
  long ans=0;
  for(int i=0; i<N; i++){
    if(K>0){K--; continue;}
    ans+=H[i];
  }
  cout << ans << endl;
  return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();


		for(int i=0;i<input.length();i++){
			if(Character.isUpperCase(input.charAt(i))){
				System.out.print(Character.toLowerCase(input.charAt(i)));
			}else{
				System.out.print(Character.toUpperCase(input.charAt(i)));


			}



		}System.out.println();



		//??????


	}

}

Measured memory_bytes: 24728
use std::io::{BufRead, Read};

pub struct Scanner<R>
where
    R: BufRead,
{
    reader: R,
}

impl<R> Scanner<R>
where
    R: BufRead,
{
    pub fn new(reader: R) -> Self {
        Scanner { reader: reader }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: ::std::str::FromStr,
        <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
    {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .unwrap()
    }
}

use std::cmp::min;

fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut sc = Scanner::new(stdin);

    let n: usize = sc.next();
    let mut a: Vec<u64> = (0..n + 1).map(|_| sc.next()).collect();
    let mut b: Vec<u64> = (0..n).map(|_| sc.next()).collect();

    let mut kills: u64 = 0;

    for i in 0..n {
        let kill = min(a[i], b[i]);
        kills += kill;
        b[i] -= kill;

        let next_kill = min( a[i + 1], b[i]);
        kills += next_kill;
        a[i + 1] -= next_kill;
    }
    println!("{}", kills);
}


Measured memory_bytes: 6396
using System;
using System.Linq;

// AtCoder Educational DP -A Frog


public class Program{

	public static void Main(){
	
		var len = int.Parse(Console.ReadLine());
		
		var stage = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

		var dp = new int[len];
		dp[0] = 0;
		dp[1] = Math.Abs(stage[1]-stage[0]);
		
		int from1, from2;
		for(int x = 2; x < len; x++){
			
			from1 = dp[x-1] + (Math.Abs(stage[x] - stage[x-1]));
			from2 = dp[x-2] + (Math.Abs(stage[x] - stage[x-2]));
			dp[x] = (from1 > from2) ? from2 : from1;	
			
		}
		
		//foreach(var a in dp) Console.WriteLine(a);
		Console.WriteLine(dp[len-1]);
		
	
	
	}
	
	




}

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

int main(){
  int x,t;
  cin >>x >>t;
  if(x-t>=0) cout << x-t << endl;
  if(x-t<0) cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

ret = 0
(0..a).each do |ai|
  (0..b).each do |bi|
    (0..c).each do |ci|
      next if 500 * ai + 100 * bi + 50 * ci != x
      ret += 1
    end
  end
end
puts ret


Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;


int main(void) {
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < s.length(); i++) {
    if (i%2==0 && s[i] == '1') a++;
    if (i%2==1 && s[i] == '0') a++;
    if (i%2==0 && s[i] == '0') b++;
    if (i%2==1 && s[i] == '1') b++;
  }
  cout << min(a, b) << endl;

  return 0;
}

Measured memory_bytes: 512
x1, y1, x2, y2 = map(int, input().split())
vector = (x2-x1, y2-y1)
ten3 = (x2 - vector[1], y2 + vector[0])
ten4 = (x1-vector[1], y1 + vector[0])
ans = []
ans.append(ten3[0])
ans.append(ten3[1])
ans.append(ten4[0])
ans.append(ten4[1])
print(*ans)

Measured memory_bytes: 38256
N = gets.to_i
p = gets.chomp.split.map(&:to_i)
a = p == p.sort ? "YES" : "NO"

[*0...N].combination(2){|i, j|
    q = p.dup
    q[i], q[j] = q[j], q[i]
    a = "YES" if q == p.sort
}

puts a

Measured memory_bytes: 3836
import scala.io.StdIn.{readInt, readLine}
class IntTree(size: Int) {
    val tree: Array[Array[Int]] = new Array[Array[Int]](size)
    var root: Int = -1
    
    def add(target: Int, c: Array[Int]): Unit = {
        tree(target) = c
        if (root == -1 || c.contains(root)) root = target
    }
    def toPrintableArray(): Array[String] = {
        val ret = new Array[String](size)
        def go(ptr: Int, children: Array[Int], parent: Int, depth: Int): Unit = {
            if (ptr < children.length) {
                val target = children(ptr)
                val nodeType = if (tree(target).length == 0) "leaf" else "internal node"
                val c = tree(target).mkString(", ")
                ret(target) = s"node ${target}: parent = ${parent}, depth = ${depth}, ${nodeType}, [${c}]"
                go(0, tree(target), target, depth + 1)
                go(ptr + 1, children, parent, depth)
            }
        }
        val c = tree(root).mkString(", ")
        ret(root) = s"node ${root}: parent = -1, depth = 0, root, [${c}]"
        go(0, tree(root), root, 1)
        ret
    }
}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val t = new IntTree(len)
        (0 until len).foreach { i =>
            val line = readLine.split(" ").map(_.toInt)
            t.add(line.head, line.slice(2, line.length))
        }
        println(t.toPrintableArray.mkString("\n"))
    }
}


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

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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a.at(i);
  int ans = a.at(0);
  REP(i,1,n) ans = gcd(ans, a.at(i));
  cout << ans << endl;
}


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

#define ff                   first
#define ss                   second
#define ll                   long long int
#define pii                  pair<int,int>
#define pb                   push_back
#define rep(i,a,b)           for(int i=a;i<b;i++)
#define t(x)                 int t; cin>>t; while(t--)
#define vi                   vector<int>
#define mii                  map<int,int>
#define min3(a, b, c)        min(min(a, b), c)
#define min4(a, b, c, d)     min(min(a, b), min(c, d))
#define max3(a, b, c)        max(max(a, b), c)
#define max4(a, b, c, d)     max(max(a, b), max(c, d))
#define ps(x,y)              fixed<<setprecision(y)<<x
#define setbits(x)           __builtin_popcountll(x)
#define zrobits(x)           __builtin_ctzll(x)
#define mod                  1000000007
#define all(x)               x.begin(),x.end()
#define FIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                      rng(chrono::steady_clock::now().time_since_epoch().count());

ll w, h, n;

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()
{
    FIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin>>n;
    if(n==0)
        cout<<1<<endl;
    else
        cout<<0<<endl;
}

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

using namespace std;

const int maxN = 700;

struct DisjointSets {
	static const int maxn = maxN;

	int n;
	int p[maxn];
	int f[maxn];

	DisjointSets() : n(0) {

	}

	void resize(const int & n) {
		this->n = n;
		memset(p, -1, sizeof p[0] * n);
		memset(f, 0, sizeof f[0] * n);
	}

	int root(const int & u) {
		if (p[u] < 0)
			return u;
		else {
			int r = root(p[u]);
			f[u] ^= f[p[u]];
			return p[u] = r;
		}
	}

	bool union_sets(const int & u, const int & v, const int & x) {
		int ur = root(u), vr = root(v);
		if (ur == vr)
			return x == (f[u] ^ f[v]);
		else {
			if (p[ur] > p[vr])
				swap(ur, vr);
			p[ur] += p[vr];
			p[vr] = ur;
			f[vr] = f[u] ^ f[v] ^ x;
			return true;
		}
	}
};

int N, M;
bool E[maxN][maxN];
DisjointSets DS;
int deg[maxN][2];
bool vis[maxN + 1];

int answer() {
	DS.resize(N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (!E[i][j]) {
				if (!DS.union_sets(i, j, 1))
					return -1;
			}
		}
	}
	for (int u = 0; u < N; u++) {
		int r = DS.root(u);
		deg[r][DS.f[u]]++;
	}

	vector<int> dff;
	for (int u = 0; u < N; u++)
		dff.push_back(abs(deg[u][0] - deg[u][1]));
	int ttl = accumulate(dff.begin(), dff.end(), 0);
	int lmt = ttl / 2;
	vis[0] = true;
	for (const auto & x : dff) {
		for (int i = lmt - x; i >= 0; i--)
			vis[i + x] |= vis[i];
	}
	int lwr = lmt;
	for (; !vis[lwr]; lwr--);
	int lhs = lwr + (N - ttl) / 2, rhs = N - lhs;
	return (lhs * (lhs - 1) + rhs * (rhs - 1)) / 2;
}

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

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		E[u][v] = E[v][u] = true;
	}

	cout << answer() << '\n';

	return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
    string S;
    int n = 0;
    int e = 0;
    int w = 0;
    int s = 0;
    cin >> S;

    for ( int i = 0; i < S.length(); i++ ) {
	switch( S[i] ) {
	case 'N': 
	    n++;
	    break;
	case 'E': 
	    e++;
	    break;
	case 'W': 
	    w++;
	    break;
	case 'S': 
	    s++;
	    break;
	default:
	    break;
	}
    }

    bool result = false;
    if ( ( n == 0 && s == 0 ) && ( e == 0 && w == 0 ) ) {
	result = true;
    }
    else if ( ( e == 0 && w == 0 ) && (n > 0 && s > 0) ) {
	result = true;
    }
    else if ( ( n == 0 && s == 0 ) && (e > 0 && w > 0) ) {
	result = true;
    }
    else if ( ( n > 0 && s > 0 ) && (e > 0 && w > 0) ) {
	result = true;
    }
    
    if ( result ) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

int N, M;
int A[101][101];
int B[101];
int C;

bool solve(int i) {
	int sum = C;
	for (int j = 0; j < M; j++) {
		sum += A[i][j] * B[j];
	}
	if (sum > 0) return true;
	else return false;
}

int main() {
	cin >> N >> M >> C;
	for (int j = 0; j < M; j++) cin >> B[j];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) cin >> A[i][j];
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (solve(i)) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int count=0;
    for(int i=0;i<a.length();i++)
    {
        if(a[i]!=b[i])
        count++;
    }
    cout<<count<<endl;
}


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

class Program
{
	static void Main(string[] args)
	{
		while (true)
		{
			var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var m = input[0];
			var f = input[1];
			var r = input[2];

			if (m == -1 && f == -1 && r == -1) break;
			var total = m + f;
			if (m == -1 || f == -1)
			{
				System.Console.WriteLine("F");
			}
			else if (m + f >= 80)
			{
				System.Console.WriteLine("A");
			}
			else if (total >= 65 && total < 80)
			{
				System.Console.WriteLine("B");
			}
			else if (total >= 50 && total < 65)
			{
				System.Console.WriteLine("C");
			}
			else if (total >= 30 && total < 50)
			{
				if (r >= 50)
				{
					System.Console.WriteLine("C");
				}
				else
				{
					System.Console.WriteLine("D");
				}
			}
			else
			{
				System.Console.WriteLine("F");
			}
		}
	}
}


Measured memory_bytes: 16364
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;

signed main() {
	int N,K;
	cin >> N >> K;
	vector<int> vec(K);
	for(int i = 0;i < K;i++) {
		cin >> vec.at(i);
	}
	for(int i = N;i < 100000;i++) {
		int W = i;
		bool A = true;
		while(W != 0) {
			for(int j = 0;j < K;j++) {
				if(vec.at(j) == W % 10) {
					A = false;
				}
			}
			W = W / 10;
		}
		if(A == true) {
			cout << i << endl;
          break;
		}
	}
}

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

using namespace std;
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; }

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};

int n, m;
P req[100010];
bool cmp(P a, P b) { return a.second < b.second;}

int main(void){
	cin>>n>>m;
	for(int i=0;i<m;i++) cin>>req[i].first>>req[i].second;

	sort(req, req + m, cmp);

	/*
	cout<<endl;
	for(int i=0;i<m;i++) {
		cout<< req[i].first << " " <<req[i].second <<endl;
	}
	*/
	
	int res = 0, endtime = 0;
	for(int i=0;i<m;i++) {
		if(endtime <= req[i].first) {
			endtime = req[i].second;
			res++;
		}
	}

	cout<< res <<endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,M;
  cin>>N>>M;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  vector<pii> B(M);
  rep(i,0,M){
    cin>>B[i].second>>B[i].first;
    }
  sort(ALL(B));
  int memo=M-1;
  int ans=0;
  rep(i,0,N){
    if(A[i]<B[memo].first){
      ans+=B[memo].first;
      B[memo].second--;
      if(B[memo].second==0)
        memo--;
      }
    else
      ans+=A[i];
    }
  cout<<ans;
  }


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

using namespace std;

const int N = 1e6 + 5, inf = 1e8;

char s[N];

map<int, int> dp;

int main() {
  scanf("%s", s);
  int n = strlen(s);
  int now = 0, ans;
  for (int i = 0; i < n; i++) {
    int c = s[i] -'a';
    now ^= 1 << c;
    ans = inf;
    if (__builtin_popcount(now) <= 1)
      ans = 1;
    for (int j = 0; j < 26; j++) {
      int b = now ^ (1 << j);
      auto bef = dp.find(b);
      if (bef != dp.end()) {
        ans = min(ans, bef->second + 1);
      }
    }
    auto it = dp.find(now);
    if (it != dp.end())
      ans = min(ans, it->second+1);
    int cur = ans;
    if (it != dp.end())
      cur = min(cur, it->second);
    if (cur < inf)
      dp[now] = cur;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 9856
import java.util.Scanner;

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

        int n = 10;
		int m = K;
		String s = Integer.toString(Integer.parseInt(String.valueOf(N) ,n),m);



        int A = s.length();
        System.out.println(A);
    }
}


Measured memory_bytes: 35832
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

int main()
{
	int max_s = 0;
	map<string, int> n;
	string s1, s2 = "", s3;
	while(cin >> s1){
		n[s1]++;
		if (s1.size() > s2.size())
		{
			s2 = s1;
		}
		if(max_s < n[s1]){
			s3 = s1;
			max_s = n[s1];
		}
	}
	cout << s3 << " " << s2 << endl;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll a,b;
	string s,t,u;
	cin>>s>>t>>a>>b>>u;
	if(u==s)--a;
	else
		if(u==t)--b;
	cout<<a<<' '<<b<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

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

int main(){
    long long n;
    cin >> n;
    vector<long long> ans(n+1);
    ans[0] = 2;
    ans[1] = 1;
    for (int i = 2; i < n+1; i++){
        ans[i] = ans[i-1] + ans[i-2];
    }
    cout << setprecision(18) << ans[n] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 1e5+233;
vector<pair<int,int> > ans;
int d[maxn],w[maxn],a[maxn];
int del,n;
bool cmp(int x,int y){
	return d[x] < d[y];
}
int query(int l,int r,int need){
	int pos = -1;
	while(l<=r){
		int mid =(l+r)>>1;
		if(d[a[mid]] - del < need) l = mid + 1; else
		if(d[a[mid]] - del > need) r = mid - 1; else
		return a[mid];
	}
	return -1;
}
signed main(){
	n = rd();
	Rep(i,1,n) d[i] = rd();
	Rep(i,1,n) w[i] = 1;
	Rep(i,1,n) a[i] = i;
	sort(a+1,a+1+n,cmp);//从小到大排序 
	del = 0;
	Dep(i,n,2){
		/*当前是a[i] - del，权重为w[i]
		移动一步
		对于所有(n-w[i])个点，都要减少1*/
		ll need = d[a[i]] - del - (n - w[a[i]]) + w[a[i]]; 
		int pos = query(1,i-1,need);//找到标号
		if(pos == -1){
			puts("-1");
			return 0;
		}
		del += w[a[i]];
		w[pos] += w[a[i]];
		ans . push_back(pii(a[i],pos));
	}
	if(d[a[1]] != del){
		puts("-1");
		return 0;
	}
	for(auto i:ans){
		printf("%lld %lld\n",i.fi,i.se);
	}
	return 0;
}


Measured memory_bytes: 5488
let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split() |> Array.map int

//メモ化
let memoize fn =
    let cache = new System.Collections.Generic.Dictionary<_,_>()
    (fun x ->
        match cache.TryGetValue x with
        | true, v -> v
        | false, _ -> 
            let v = fn (x)
            cache.Add(x,v)
            v)

// 最大公約数
let rec gcd = 
    let f (x,y) =
        let (x,y) = if y > x then (y,x) else (x,y)
        match x % y with
        | 0 -> y
        | z -> gcd (y, z)
    memoize f

// 左から順に最大公約数を求める
let rec memFromLeftGcd =
    let f i =
        match i with
        | 0 -> a.[0]
        | _ -> gcd ((memFromLeftGcd (i-1)), a.[i])
    memoize f

// 右から順に最大公約数を求める
let rec memFromRightGcd =
    let f i =
        match n - 1 - i with
        | 0 -> a.[n-1]
        | _ -> gcd ((memFromRightGcd (i+1)), a.[i])
    memoize f

seq{0..n-1}
|> Seq.map(fun i ->
    match i with
    | 0 -> memFromRightGcd <| i+1
    | i when i = n-1 -> memFromLeftGcd <| i-1
    | _ -> gcd ((memFromLeftGcd <| i-1),(memFromRightGcd <| i+1))
    )
|> Seq.max
|> stdout.WriteLine


Measured memory_bytes: 44868
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int a[3];
    rep(i, 3) { cin >> a[i]; }
    sort(a, a + 3);

    int diff = (a[2] - a[0]) + (a[2] - a[1]);
    int ans = 0;
    if (diff % 2 == 0) {
        ans = diff / 2;
    } else {
        ans = diff / 2 + 2;
    }

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

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define swap(a,b) (a+=b,b=a-b,a-=b)
const int MOD=1e9+7;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void Radix32(int *a,const int sz)
{
  int temp[sz],shift=0b1000,mask=0xff;
  rep(j,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz){u[(a[i]>>(j*shift))&mask]++;}rep(i,mask){u[i+1]+=u[i];}
    rep(i,sz){temp[--u[(a[sz-1-i]>>(j*shift))&mask]]=a[sz-1-i];}j++;
    rep(i,sz){v[(temp[i]>>(j*shift))&mask]++;}rep(i,mask){v[i+1]+=v[i];}
    rep(i,sz)a[--v[(temp[sz-1-i]>>(j*shift))&mask]]=temp[sz-1-i];
  }
}
int main()
{
  int N=IN(),K=IN(),l,m=0,r,accum=1,sign=1,A[N];long x,y;
  rep(i,N)A[i]=IN(),m+=A[i]<0?1:0;
  Radix32(A,N);
  rep(i,m/2)swap(A[N-m+i],A[N-1-i]);
  rep(i,(N-m)/2)swap(A[i],A[N-m-1-i]);
  rep(i,N/2)swap(A[i],A[N-1-i]);
  if(K&1)accum=A[N-1],sign=(A[N-1]<0?-1:1),N--,K--;
  l=0,r=N-1;
  while(K)
  {
    x=1l*A[l]*A[l+1],y=1l*A[r]*A[r-1];
    if(x*sign>y*sign)x%=MOD,accum=1l*accum*x%MOD,l+=2;
    else y%=MOD,accum=1l*accum*y%MOD,r-=2;
    K-=2;
  }
  return printf("%ld\n",(1l*accum%MOD+MOD)%MOD),0;
}

Measured memory_bytes: 3160
// GCD(x,y)
#include<iostream>
int main(){
  int x, y;
  std::cin >> x >> y;
  while(1){
    if(x > y){
      if(x % y == 0){
        std::cout << y << "\n";
        break;
      }
      x = x % y;
    }
    else{
      if(y % x == 0){
        std::cout << x << "\n";
        break;
      }
      y = y % x;
    }
  }
  return 0;
}

Measured memory_bytes: 3096
S = list(input())
N = len(S)
flag = True

for i in range((N-1)//4):
    if S[i] == S[(N-1)//2-1-i] and S[(N+3)//2-1+i] == S[N-1-i]:
        continue
    else:
        flag = False
        break

for i in range((N-1)//2):
    if S[i] != S[N-1-i]:
        flag = False
        break

print("Yes" if flag else "No")

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

using namespace std;

const int maxn = 1e5 + 7;

int n;
char s[maxn];
int main(){
	scanf("%s",s + 1);n = strlen(s + 1);
	if(s[1] != '1' || s[n] != '0')return !puts("-1");
	for(int i = 1; i < n; ++i)if(s[i] ^ s[n - i])return !puts("-1");
	int cur = 1;
	for(int i = 2; i <= n; ++i){
		printf("%d %d\n",cur,i);
		if(s[i - 1] == '1')cur = i;
	}
	return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

int gcd(int x, int y)
{
    return (x % y) ? gcd(y, x % y) : y;
}

int gcd3(int a, int b, int c)
{
    return gcd(gcd(a, b), c);
}

int main()
{
    int k;
    int a, b, c;
    int sum = 0;

    scanf("%d", &k);

    for (a = 1; a <= k; a++) {
        for (b = 1; b <= k; b++) {
            for (c = 1; c <= k; c++) {
                sum += gcd3(a, b, c);
            }
        }
    }

    printf("%d\n", sum);

    return 0;
}

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

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

  if (((A * 100 + B * 10 + C) % 4) == 0)
  {
    cout << "YES" << endl; 
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
 
public class Main
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) 
	{
        //code by sushant kumar
        FastReader in=new FastReader();
        int a=in.nextInt();
        System.out.println(a+a*a+a*a*a);
        
       
    }
}

Measured memory_bytes: 25360
// B - 石落としゲーム

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int S[30][30];

class Stone {
public:
	int number;
	bool vanish = false;

	Stone(int number) {
		this->number = number;
	}
};

class Pazzle {
public:
	int H, W, K;
	Stone *stone[30][30];

	// コンストラクタ
	Pazzle(int H, int W, int K) {
		this->H = H;
		this->W = W;
		this->K = K;

		// nullptrで初期化
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				stone[i][j] = nullptr;
			}
		}
	}

	// 石を落下させる
	void move_stones() {
		for (int i=H-2; i>=0; i--) {
			for (int j=0; j<W; j++) {
				if (stone[i][j] == nullptr) continue;

				// 石を下へ移動
				int h = i;
				while(h<=H-2 && stone[h+1][j] == nullptr) {
					stone[h+1][j] = stone[h][j];
					stone[h][j] = nullptr;
					h++;
				}

			}
		}
	}

	// 石が消えるかどうかを判定し、vanishフラグを立てる
	// 一つでも消えるならtrueを返す
	bool check_vanish() {
		bool result = false;

		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				//cout << "  " << i << " " << j << endl; // **** debug ****
				if (stone[i][j] == nullptr) continue;
				int same = 0;
				for (int k=j; k<W; k++) {
					if (stone[i][k] == nullptr) break;
					if (stone[i][k]->number == stone[i][j]->number) {
						same++;
					} else {
						break;
					}
				}

				if (same >= K) {
					for (int k=j; k<W; k++) {
						if (stone[i][k] == nullptr) break;
						if (stone[i][k]->number == stone[i][j]->number) {
							stone[i][k]->vanish = true;
						} else {
							break;
						}
					}
					result = true;
				}
			}
		}

		return result;
	}

	// 消える石のスコアを計算
	int count_score(int i) {
		int total_num = 0;

		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				if (stone[i][j] == nullptr) continue;

				if (stone[i][j]->vanish == true) {
					total_num += stone[i][j]->number;
				}
			}
		}

		return pow(2, i) * total_num;
	}

	// vanishフラグの立っている石をメモリから消去
	void delete_stones() {
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				if (stone[i][j] == nullptr) continue;

				if (stone[i][j]->vanish == true) {
					delete stone[i][j];
					stone[i][j] = nullptr;
				}
			}
		}
	}

	int execute(int sh, int sw) {
		stone[sh][sw]->vanish = true;
		delete_stones();
		move_stones();

		int score = 0;
		for (int i=0;;i++) {
			if (check_vanish() == false) break;
			score += count_score(i);
			delete_stones();
			move_stones();
		}
		//cout << score << endl; // **** debug ****
		return score;
	}

	void reset() {
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				stone[i][j] = new Stone(S[i][j]);
			}
		}
	}
};



int main() {
	int H, W, K;
	cin >> H >> W >> K;

	Pazzle pazzle(H, W, K);

	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			char c;
			cin >> c;
			S[i][j] = c - '0';
		}
	}

	int ans = 0;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			//cout << i << " " << j << endl; // **** debug ****
			pazzle.reset();
			ans = max(ans, pazzle.execute(i, j));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 25472
//ABC 164 D
#include<bits/stdc++.h>
using namespace std;
int k[2020],f[2000005],a[2000005],g[2000005];
long long sum;
int main() {
string s;
cin>>s;
int n=s.size();
for(int i=0;i<n;i++){
a[i+1]=s[i]-'0';
}
int l=1; 
for(int i=n;i>=1;i--){ 
g[i]=l;
l*=10;
l%=2019;
}
for(int i=n;i>=1;i--){ 
f[i]=(f[i+1]+a[i]*g[i])%2019;
k[f[i]]++;
}
sum=k[0];
sum+=(k[0]*(k[0]-1)/2);
for(int i=1;i<=2018;i++){
sum+=(k[i]*(k[i]-1)/2);
}
cout<<sum;
return 0;
}

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  b = a;
  sort(b.begin(), b.end());
  rep(i, n) {
    if (a[i] != b[b.size() - 1]) {
      cout << b[b.size() - 1] << endl;
    } else {
      cout << b[b.size() - 2] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int grid[n][2];
	for(int i = 0; i < n;++i){
		cin >> grid[i][0] >> grid[i][1];
	}
	for(int i = 0; i < n-2;++i){
		if(grid[i][0] == grid[i][1] && grid[i+1][0] == grid[i+1][1] && grid[i+2][0] == grid[i+2][1]){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
typedef struct Element
{
    long number;
}ElementType;
typedef struct dqueuelist
{
    ElementType item;
    struct dqueuelist *pri;
    struct dqueuelist *next;
}dqueuelist,*dqp;
typedef struct kk
{
    dqp front;
    dqp rear;
}*LinkQueue;
LinkQueue creat()
{
    LinkQueue head=(LinkQueue)malloc(sizeof(struct kk));
    dqp new_p;
    head->front=head->rear=(dqp)malloc(sizeof(struct dqueuelist));
    head->front->item.number=-1;
    head->front->next=NULL;
    head->rear->next=NULL;
    return head;
}
LinkQueue Enter(LinkQueue q,ElementType item,int end)
{
    dqp ptr=NULL;
    dqp temp=NULL;
    if(end==1)
    {
        ptr =(dqp)malloc(sizeof(struct dqueuelist));
        ptr->item=item;
        temp=q->front->next;
        q->front->next=ptr;
        ptr->next=temp;
        if(temp!=NULL)
        temp->pri=ptr;
        ptr->pri=q->front;
    }else{
        ptr=(dqp)malloc(sizeof(struct dqueuelist));
        ptr->item=item;
        ptr->next=NULL;
        q->rear->next=ptr;
        ptr->pri=q->rear;
        q->rear=ptr;
    }
    return q;
}
ElementType Out(LinkQueue q,int end)
{
    dqp ptr,t;
    ElementType temp;
    if(end==1)
    {
        if(q->front->next==NULL)
        {
            temp.number=-1;
            return temp;
        }
        ptr=q->front->next;
        temp=ptr->item;
        q->front->next=ptr->next;
        if(ptr->next!=NULL)
        ptr->next->pri=q->front;
        if(q->rear==ptr)
            q->rear=q->front;
        free(ptr);
    }else{
        if(q->rear==NULL)
        {
            temp.number=-1;
            return temp;
        }
        ptr=q->rear->pri;
        t=q->rear;
        temp=t->item;
        ptr->next=NULL;
        q->rear=ptr;
        if(q->front==ptr)
            q->front=q->rear;
        free(t);
    }
    return temp;
}
long number[200001];
void Out_all(LinkQueue q,long n,long round)
{
    ElementType k;
    dqp p,temp;
    long i,count=0;
    while((q->rear!=NULL)&&(q->rear->item.number!=-1))
    {
        p=NULL;
        temp=NULL;
        p=q->rear->pri;
        temp=q->rear;
        k=temp->item;
        number[count]=k.number;
        p->next=NULL;
        q->rear=p;
        if(q->front==p)
            q->rear=q->front;
        count++;
    }
    if(round==1)
    for(i=0;i<n;i++)
        printf("%ld ",number[i]);
    else{
        for(i=n-1;i>=0;i--)
        printf("%ld ",number[i]);
    }
}
void deal()
{
    long i,j,n,round;
    ElementType temp;
    LinkQueue Deque;
    Deque=creat();
    while(scanf("%ld",&n)!=EOF)
    {
        round=2;
        for(i=0;i<n;i++)
        {
            scanf("%ld",&temp.number);
            if(round==1)
            {
                Deque=Enter(Deque,temp,round);
                round=2;
            }else{
                Deque=Enter(Deque,temp,round);
                round=1;
            }
        }
        Out_all(Deque,n,round);
        printf("\n");
    }
}
int main()
{
    deal();
    return 0;
}

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

ll factrial[MAX_N], inverse[MAX_N];  //階乗と逆元を保持

ll power(ll x, ll n) {  //繰り返し二乗法
    ll ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return ans;
}

void init(ll n) {
    factrial[0] = 1;
    inverse[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factrial[i] = (factrial[i - 1] * i) % MOD;  //階乗を求める
        inverse[i] = power(factrial[i], MOD - 2) % MOD;  //オイラーの定理で逆元を求める
    }
}

ll nCk(ll n, ll k) {
    return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}


ll N,a[MAX_N]{},b[MAX_N]{},c[MAX_N]{},ab[MAX_N]{},bc[MAX_N]{},q[MAX_N];

int main() {
    string s;
    cin >> s;
    N = s.size();
    REP(i,N){
        if(s[i]=='A')a[i+1]++;
        a[i+1] += a[i];
        if(s[i]=='B')b[i+1]++;
        b[i+1] += b[i];
        if(s[i]=='C')c[i+1]++;
        c[i+1] += c[i];
        if(s[i]=='?')q[i+1]++;
        q[i+1] += q[i];
    }
    /*
    REP(i,N){
        if(s[i]=='B')ab[i+1]+=a[i];
        ab[i+1] += ab[i];
        ab[i+1] %= MOD;
        if(s[i]=='C')bc[i+1]+=b[i];
        bc[i+1] += bc[i];
        bc[i+1] %= MOD;
    }
    */
    init(q[N]);
    ll ans = 0;
    REP(i,N){
        if(s[i]=='B'){
            if(i<N-1 && i>0){
                ans += (a[i])*(c[N]-c[i+1])%MOD*power(3,q[N])%MOD;
                ans %= MOD;
                ans += (q[i])*(c[N]-c[i+1])%MOD*power(3,q[N]-1)%MOD;
                ans %= MOD;
                ans += (a[i])*(q[N]-q[i+1])%MOD*power(3,q[N]-1)%MOD;
                ans %= MOD;
                ans += (q[i])*(q[N]-q[i+1])%MOD*power(3,q[N]-2)%MOD;
                ans %= MOD;
            }
        }
        if(s[i]=='?'){
            if(i<N-1 && i>0){
                ans += (a[i])*(c[N]-c[i+1])%MOD*power(3,q[N]-1)%MOD;
                ans %= MOD;
                ans += (q[i])*(c[N]-c[i+1])%MOD*power(3,q[N]-2)%MOD;
                ans %= MOD;
                ans += (a[i])*(q[N]-q[i+1])%MOD*power(3,q[N]-2)%MOD;
                ans %= MOD;
                ans += (q[i])*(q[N]-q[i+1])%MOD*power(3,q[N]-3)%MOD;
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;

string s;
llint dp[200005][3][3][2];
set<char> S;

int main(void)
{
	cin >> s;
	llint n = s.size(), p = 0;
	for(int i = 0; i < n; i++){
		p += s[i]-'a';
		S.insert(s[i]);
	}
	p %= 3;
	
	if(S.size() == 1){
		cout << 1 << endl;
		return 0;
	}
	if(n == 2){
		cout << 2 << endl;
		return 0;
	}
	if(n == 3 && S.size() == 3){
		cout << 3 << endl;
		return 0;
	}
	
	dp[0][0][0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				for(int l = 0; l < 2; l++){
					for(int m = 0; m < 3; m++){
						llint nl = l;
						if(i > 0 && k == m) nl = 1;
						(dp[i+1][(j+m)%3][m][nl] += dp[i][j][k][l]) %= mod;
					}
				}
			}
		}
	}
	llint ans = 0;
	for(int k = 0; k < 3; k++) ans += dp[n][p][k][1], ans %= mod;
	
	bool flag = false;
	for(int i = 1; i < n; i++){
		if(s[i-1] == s[i]){
			flag = true;
			break;
		}
	}
	if(!flag) ans++, ans %= mod;
	
	cout << ans << endl;

	return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

pair<int, int> heavy(auto& adj, vb& alive, vi& save, int loc, int par) {
    int tot = 0, pa = 0, pb = 0;
    for (int nbr : adj[loc]) if (nbr != par && alive[nbr]) {
        int ctot, cpath;
        tie(ctot, cpath) = heavy(adj, alive, save, nbr, loc);

        tot = max(tot, ctot);
        if (cpath >= pa) { pb = pa; pa = cpath; }
        else if (cpath > pb) pb = cpath;
    }
    return { max(tot, pa + pb + save[loc]), max(0, save[loc] + max(pa, pb)) };
}

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

    int N;
    cin >> N;

    vvi adj(N);
    for (int i = 0, u, v; i < N - 1; i++) {
        cin >> u >> v;
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
    }

    string color;
    cin >> color;

    queue<int> rem;

    vi deg(N);
    for (int i = 0; i < N; i++) {
        deg[i] = adj[i].size();
        if (deg[i] <= 1 && color[i] == 'B')
            rem.push(i);
    }

    vb alive(N, true);
    for (; !rem.empty(); rem.pop()) {
        int v = rem.front();
        alive[v] = false;
        for (int nbr : adj[v]) if (--deg[nbr] == 1 && color[nbr] == 'B') {
            rem.push(nbr);
        }
    }

    int ans = 0, root = -1;
    vi save(N);
    for (int i = 0; i < N; i++) if (alive[i]) {
        root = i;
        ans += deg[i];
        if ((deg[i]&1) == (color[i] == 'B')) {
            ans++;
            save[i] = 2;
        }
    }

    if (root != -1 && deg[root] != 0) ans -= heavy(adj, alive, save, root, root).first;
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 17104
n = int(input())

from collections import defaultdict

d = defaultdict(int)

for _ in range(n):
    s = input()
    d[s] += 1

a = list(d.keys())
b = list(d.values())

l = len(a)
val = max(b)

ans = []

for i in range(l):
    if b[i] == val:
        ans.append(a[i])

ans = sorted(ans)
l = len(ans)

for i in range(l):
    print(ans[i])

Measured memory_bytes: 101888
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

bool isPrime(int x) {
    if (x == 2) return true;
    if (x < 2  || x % 2 == 0) return false;
    int i = 3;
    double sqrtX = sqrt(x);
    while (i <= sqrtX) {
        if (x % i == 0) {
            return false;
        }
        i += 2;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    int result = 0;
    rep(i, N) {
        int x;
        cin >> x;
        if (isPrime(x)) result++;
    }
    cout << result << endl;
}


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

int main() {
  int N;
  cin >> N;
 
  bool flg = true;
  char S[N];
  
  for(int i = 0; i < N; i++){
    cin >> S[i];
    if(S[i] == 'Y' ) {
      cout << "Four" <<endl;
      flg = false;
      break;
    }
  }
  
  if(flg == true){
    cout << "Three" <<endl;
  }
}
  
    
   
 

  

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int w,h,x,y; cin>>w>>h>>x>>y;
	cout<<double(w)*h/2<<" "<<(x+x==w&&y+y==h)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=10000+10,maxlen=13;
char s[maxn][maxlen];
int len[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%s",s[i]+1);
        len[i]=strlen(s[i]+1);
    }
    int cntA=0,cntB=0,cntBA=0,ans=0;
    for(int i=1;i<=n;++i)
    {
        if(s[i][1]=='B'&&s[i][len[i]]=='A') ++cntBA;
        else if(s[i][1]=='B') ++cntB;
        else if(s[i][len[i]]=='A') ++cntA;
        for(int j=1;j<len[i];++j) if(s[i][j]=='A'&&s[i][j+1]=='B') ++ans;
    }
    if(cntBA>0)
    {
        ans+=cntBA-1;
        cntBA=1;
        if(cntA>0||cntB>0) {--cntBA;++ans;}
    }
    ans+=min(cntA,cntB);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

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

const int Y = 365;

int main(void){
    int dp[30];
    for(int n, cnt; cin >> n, n; cnt = dp[n - 1] / 10 + (!!dp[n - 1] % 10), cout <<  cnt / Y + (!!cnt % Y) << endl)
        rep(i, n) dp[i] = (i < 3) ? 1 << i:dp[i - 3] + dp[i - 2] + dp[i - 1];

    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int ch = sc.nextInt();
    int cw = sc.nextInt();

    int total = h*w;
    int black = ch*w + (h-ch)*cw;
    System.out.println(total -black);

  }
}


Measured memory_bytes: 21844