akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int N;
        public long[] A;
        public long[] S;

        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadIntArray().Select(e => (long)e).ToArray();
            S = new long[N+1];

            S[0] = 0;
            for (int i = 0; i < N; i++)
            {
                S[i + 1] = S[i] + A[i];
            }

            Array.Sort(S);

            long ret = 0;
            long? prev = null;
            long count = 0;

            for (int i = 0; i <= N; i++)
            {
                if (prev == S[i])
                {
                    count++;
                }
                else
                {
                    ret += count * (count - 1) / 2;
                    prev = S[i];
                    count = 1;
                }

                if (i == N)
                {
                    ret += count * (count - 1) / 2;
                }   
            }

            Console.WriteLine(ret);

        }

       
    }
    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 38240
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int data_a[100001];
int data_b[100000];
int data_c[100000];

int happy_a[100000];
int happy_b[100000];
int happy_c[100000];
int max( int a, int b)
{
	return (a >= b) ? a : b;
}
int main()
{
	int N;
	cin >> N ;
	for(int i=0; i<N; i++){
		cin >> data_a[i] >> data_b[i] >> data_c[i] ;
	}

	happy_a[0]= data_a[0];	
	happy_b[0]= data_b[0];	
	happy_c[0]= data_c[0];	

	for(int i=1; i<N;i++){
		happy_a[i]= max(happy_b[i-1],happy_c[i-1])+data_a[i];
		happy_b[i]= max(happy_c[i-1],happy_a[i-1])+data_b[i];
		happy_c[i]= max(happy_a[i-1],happy_b[i-1])+data_c[i];
	}

	int ans = max(max(happy_a[N-1],happy_b[N-1]),happy_c[N-1]); 
	cout << ans << endl;
	return 0 ;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<cmath>

int main(){

    size_t n, a, b, c, d, e;
    std::cin >> n >> a >> b >> c >> d >> e;

    std::cout << static_cast<size_t>(std::ceil(static_cast<double>(n) / std::min({a, b, c, d, e})) + 4) << std::endl;
    
    return 0;
}


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

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

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

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

typedef long long ll;

const char nl = '\n' ;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   string a, b, c;
   int n, k; cin >> n >> k;
   long long ans = k;
   for(long long i = 1; i < n; i++)
   {
      ans *= (k-1);
   }
   cout << ans << nl;







	return 0;
}


Measured memory_bytes: 3624
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=[0]*(N-1)
a=A[0]
z=A[-1]

for i in range(1,N-1):
    if A[i]>=0:
        ans[i-1]=(a,A[i])
        a-=A[i]
    else:
        ans[i-1]=(z,A[i])
        z-=A[i]
ans[N-2]=(z,a)
print(z-a)
for s in ans:
    print(*s)

Measured memory_bytes: 19428
import java.util.Scanner;

public class Main {
	static StringBuilder sb;
	static void print(int a, int b){
		System.out.println(sb.substring(a, b + 1));
	}
	static void reverse(int a, int b){
		String str = new StringBuilder(sb.substring(a, b + 1)).reverse().toString();
		sb.replace(a, b + 1, str);
	}
	static void replace(int a, int b, String str){
		sb.replace(a, b + 1, str);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sb = new StringBuilder(sc.next());
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			String s = sc.next();
			switch(s){
				case "print":
					print(sc.nextInt(), sc.nextInt());
					break;
				case "reverse":
					reverse(sc.nextInt(), sc.nextInt());
					break;
				case "replace":
					replace(sc.nextInt(), sc.nextInt(), sc.next());
			}
		}
	}
}




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

string solve(int n, string s) {
  if (n & 1) return "No\n";
  int j = (n/2);
  for (int i = 0; j < n; i++, j++) {
    if (s[i] != s[j]) return "No\n";
  }
  return "Yes\n";
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  cout << solve(n, s);
}

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

int main(){
  long long a,b;
  cin>>a>>b;
  if(a<=0 && b>=0){ cout<<"Zero"; return 0;}
  else if(a>0 && b>0){ cout<<"Positive"; return 0;}
  else{ if((b-a)%2==0) cout<<"Negative";
                              else cout<<"Positive";
                              return 0;
                             }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <unordered_set>
using namespace std;
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define long long long
long  pw(long  x, long  y){long  ans = 1;for(long  i = 0; i < y; i++){ans = ans * x;}return ans;}
long  factorial(long  x){long  ans = 1; for(int i = 1 ;i < x+1; i++){ans = ans *i;}return ans;}
long  combination(long  x,long  y){return factorial(x)/factorial(y)/factorial(x-y);}
long  permutation(long  x, long  y){return factorial(x)/factorial(x-y);}
#define TimeCount1    auto chrono_start = std::chrono::system_clock::now();
#define TimeCount2   auto chrono_end = std::chrono::system_clock::now();std::cout << "Elapsed time(C++):" << std::chrono::duration_cast<std::chrono::milliseconds>(chrono_end - chrono_start).count() << "[ms]" << std::endl;

//#include "./printer.hpp"

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

	long n = s.length();
	vector<long> v(26,-3);


	for(long i = 0; i < n; i++){

		if(i - v[s[i]-'a'] == 1){
			cout << i << ' ' << i + 1 << endl;
			return 0;
		}else if( i - v[s[i] - 'a'] == 2){
			cout  << i -1 << ' ' << i + 1 << endl;
			return 0;
		}else{
			v[s[i] - 'a'] = i;
		}

	}
	cout << -1 <<' ' << -1 << endl;
	return 0;
}



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

using namespace std;


int main()
{
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;

	vector<int> list;
	list.push_back(a);
	list.push_back(b);
	list.push_back(c);
	list.push_back(d);
	list.push_back(e);

    bool flg = false;
	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 5; ++j)
		{
			auto diff = std::abs(list[i] - list[j]);

			if (diff > k)
			{
              
				flg = true;
			}
		}
	}

	if (flg)
	{
		cout << ":(" << endl;
	}
	else
	{
		cout << "Yay!" << endl;
	}

	return 0;
}



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

// #define multitest 1
#ifdef WIN32
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<queue<int>> Q(n + 1);
	int x;
	set<int> Exist;
	for (int i = 1; i <= n; ++i)
	{
		Exist.insert(i);
		for (int j = 1; j < n; ++j)
		{
			cin >> x;
			Q[i].push(x);
		}
	}
	set<pair<int, int>> Matches;
	for (int i = 1; i <= n; ++i)
	{
		int wish = Q[i].front();
		if (Q[wish].front() == i)
			Matches.insert({i, wish});
	}
	int cnt = 0, over = 0;
	for (int i = 0;; ++i)
	{
		for (auto match : Matches)
		{
			Q[match.f].pop();
			if (Q[match.first].size() == 0)
				over++;
		}
		set<pair<int, int>> MatchesNew;
		for (auto match : Matches)
		{
			if (Q[match.first].size())
			{
				int wish = Q[match.first].front();
				if (Q[wish].size())
				{
					if (Q[wish].front() == match.f)
					{
						MatchesNew.insert({match.f, wish});
						MatchesNew.insert({wish, match.f});
					}
				}
				else
				{
					cout << -1;
					return;
				}
			}
		}
		pc(Matches);
		cnt++;
		if (MatchesNew.size() == 0)
			break;
		// pc(MatchesNew);
		Matches = MatchesNew;
	}
	if (over == n)
		std::cout << cnt;
	else
		cout << -1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef WIN32
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 4736
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        A: i32,
        B: i32,
        C: i32,
    }

    println!("{}", std::cmp::max(0, C - (A - B)));
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N;
  cin >> N;
  long double ans = 0;
  for(int i = 0; i < N; i++){
    long double x;
    string u;
    cin >> x >> u;
    if(u == "JPY"){
      ans += x; 
    } else{
      ans += x * 380000;
    }
  }
  cout << ans <<endl;
}


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


void solve(long long N, long long K, std::vector<long long> p){
    vector<double> ruiseki;
    ruiseki.push_back(0);
    for(int i = 0;i < N;i++){
        ruiseki.push_back(ruiseki.back() +  1.0*p[i]*(p[i]+1)/2 / p[i]);
    }
    double ans = 0;
    for(int i = 0;i < N-K+1;i++){
        ans = max(ans, ruiseki[i+K] - ruiseki[i]);
    }
    cout<<setprecision(20)<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 3956
N=int(input())
A=input()
B=input()
C=input()
a=0
for i in range(N):
    if A[i]==B[i] and A[i]==C[i]:
        a+=0
    elif A[i]==B[i] or A[i]==C[i]:
        a+=1
    elif B[i]==C[i]:
        a+=1
    else:
        a+=2
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    string s, t;
    cin >> s >> t;
    ll ns = s.size();
    ll nt = t.size();
    ll ans = INFL;
    for(ll dif = 0; dif < ns; dif++) {
        if(dif + nt - 1 >= ns) break;
        ll cnt = 0;
        for(ll i = 0; i < nt; i++) {
            if(s[dif + i] != t[i]) ++cnt;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3644
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" s << "\033[0m"
#else
#define cerr(s)
#endif
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const int mod = 1e9 + 7;
// 12
void _main(int tc) {
  int h, w;
  cin >> h >> w;
  vector<string> mat(h);
  rep(i, h) cin >> mat[i];
  vector<vector<int>> mem(h, vector<int>(w));
  mem[h - 1][w - 1] = 1;
  rrep(i, h) {
    rrep(j, w) {
      for (auto& mv : vector<pairii>{{0, 1}, {1, 0}}) {
        int new_i = i + mv.fi, new_j = j + mv.se;
        if (new_i >= 0 && new_i < h && new_j >= 0 && new_j < w &&
            mat[i][j] == '.') {
          mem[i][j] = (mem[i][j] + mem[new_i][new_j]) % mod;
        }
      }
    }
  }
  cout << mem[0][0] << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 5248
import sys
input = sys.stdin.readline
s = list(input())
t = list(input())

snum = [(0,0)] #snum[j]-snum[i-1]:i-j文字目に含まれる(A,B)の数
for i in range(len(s)):
    if s[i] == 'A':
        snum.append((snum[-1][0]+1,snum[-1][1]))
    else:
        snum.append((snum[-1][0],snum[-1][1]+1))

tnum = [(0,0)]
for i in range(len(t)):
    if t[i] == 'A':
        tnum.append((tnum[-1][0]+1,tnum[-1][1]))
    else:
        tnum.append((tnum[-1][0],tnum[-1][1]+1))

q = int(input())
for i in range(q):
    a,b,c,d = map(int,input().split())
    sa = snum[b][0]-snum[a-1][0]
    sb = snum[b][1]-snum[a-1][1]
    ta = tnum[d][0]-tnum[c-1][0]
    tb = tnum[d][1]-tnum[c-1][1]
    
    #全てbにする
    b1 = sb+sa*2
    b2 = tb+ta*2
    if abs(b2-b1)%3==0:
        print('YES')
        continue
    
    
    print('NO')


Measured memory_bytes: 71060
import java.util.*;

public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int c = sc.nextInt();
			int k = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < data.length; i++){
				data[i] = sc.nextInt();
			}
			Arrays.sort(data);
			int ans = 0;
			int start = Integer.MIN_VALUE;
			int count = 0;
			for(int i = 0; i < n; i++){
				if(start + k < data[i] || count == c){
					start = data[i];
					count = 1;
					ans++;
				}
				else{
					count++;
				}
			}
			System.out.println(ans);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 50300
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a-1;i>=b;i--)
#define rep0(i,n) for(int i=0;i<n;i++)
#define per0(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 

void solve() {
    int n; cin >> n;
    vector<int> dp(100010);
    vector<int> coins;
    rep0(i, n+10){
        dp[i] = i;
    }
    int temp = 6;
    while (temp <= n)
    {
        coins.push_back(temp);
        temp *= 6;
    }
    temp = 9;
    while (temp <= n)
    {
        coins.push_back(temp);
        temp *= 9;
    }
    for(auto& coin: coins){
        rep(j, coin, n+1){
            chmin(dp[j], dp[j-coin]+1);
        }
    }
    int ans = dp[n];
    cout << ans;
    
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

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

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

int main(void){
    int x,y,a,b;
    cin >> x >> y;
    if(x==y || gcd(x,y)==y)cout << -1 << endl;
    else{
        int i=1;
        while(y%(x*i)==0)i++;
        cout<<x*i<<endl;
    }
    
}


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

using namespace std;

int main(){
  int n; cin >> n;
  int r[n];
  for(int i=0;i<n;i++) cin >> r[i];
  int maxv=r[1]-r[0];
  int minv=r[0];
  for(int i=1;i<n;i++){
      maxv=max(maxv,r[i]-minv);
      minv=min(minv,r[i]);
  }
  cout << maxv << endl;
}

Measured memory_bytes: 3856
from heapq import heappush, heappop
T = int(input())
A = []
for i in range(T):
    N, D = map(int, input().split())
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        t = 127 ^ k
        heappush(h,t)
        ans += (127 + t - k)
    A.append(ans)
for i in range(len(A)):
    print(A[i])


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main(void)
{
    int height, width;
    int black_req;

    cin >> height >> width >> black_req;

    bool is_black[6][6];

    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            char c;
            cin >> c;
            if(c == '#'){
                is_black[i][j] = true;
            }else{
                is_black[i][j] = false;
            }
        }
    }

    bool cp_is_black[6][6];
    
    int fulfill_cnt = 0;
    for(int vert = 0; vert < (1 << height); vert++){
        for(int horiz = 0; horiz < (1 << width); horiz++){
            for(int i = 0; i < height; i++){
                for(int j = 0; j < width; j++){
                    cp_is_black[i][j] = is_black[i][j];
                }
            }

            for(int h = 0; h < height; h++){
                if(vert & (1 << h)){
                    for(int w = 0; w < width; w++){
                        cp_is_black[h][w] = false;
                    }
                }
            }

            for(int w = 0; w < width; w++){
                if(horiz & (1 << w)){
                    for(int h = 0; h < height; h++){
                        cp_is_black[h][w] = false;
                    }
                }
            }
            int black_cnt = 0;
            for(int i = 0; i < height; i++){
                for(int j = 0; j < width; j++){
                    if(cp_is_black[i][j]){
                        black_cnt += 1;
                    }
                }
            }

            if(black_cnt == black_req){
                fulfill_cnt += 1;
            }
        }
    }

    cout << fulfill_cnt << endl;

    return 0;
}

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

int main() {
	int n;
	cin >> n;
	string str;
	vector<string> IDlist;
	for (int i = 0; i < n; ++i) {
		cin >> str;
		IDlist.emplace_back(str);
	}
	cin >> n;
	bool key = false;
	for (int i = 0; i < n; ++i) {
		cin >> str;
		for (int j = 0; j < IDlist.size(); ++j) {
			if (IDlist[j] == str) {
				if (key == false) {
					cout << "Opened by " << str << endl;
					key = true;
				}
				else {
					cout << "Closed by " << str << endl;
					key = false;
				}
				break;
			}
			if (j == IDlist.size() - 1) {
				cout << "Unknown " << str << endl;
			}
		}
	}
	return 0;
}

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

int judge(char myhand, char comhand) {
    if (myhand == 'p') {
        if (comhand == 'g') return 1;
        else return 0;
    } else {
        if (comhand == 'g') return 0;
        else return -1;
    }
}

int main() {
    string s; cin >> s;
    int score = 0;
    for (int i = 0; i < s.length(); i++) {
        char myhand = "gp"[i % 2], comhand = s[i];
        score += judge(myhand, comhand);
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 512
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;

struct Edge{
	int y,z,nxt;
} E[N*2];
int las[N],vis[N],used[3];
int n,cnt,wei,c,m,x,y;
ll ans;

void Add_Edge(int x,int y){
	E[cnt]=(Edge){y,1,las[x]};las[x]=cnt++;
	E[cnt]=(Edge){x,2,las[y]};las[y]=cnt++;
}
void dfs(int x,int v){
	vis[x]=v;
	used[v]++;
	for (int i=las[x],y;~i;i=E[i].nxt){
		c++;
		y=E[i].y;
		if (vis[y]==-1){
			dfs(y,(vis[x]+E[i].z)%3);
		} else{
			if (vis[y]!=(vis[x]+E[i].z)%3) wei=1;
		}
	}
}

int main(){
	memset(las,-1,sizeof(las));
	memset(vis,-1,sizeof(vis));
	n=IN();m=IN();
	For(i,0,m){
		x=IN(),y=IN();
		Add_Edge(x,y);
	}
	For(i,1,n+1) if (vis[i]==-1){
		For(j,0,3) used[j]=0;
		wei=0;c=0;
		dfs(i,0);
		if (wei){
			int tmp=used[0]+used[1]+used[2];
			ans+=1ll*tmp*tmp;
		} else{
			if (used[0]&&used[1]&&used[2]){
				ans+=1ll*used[0]*used[1]+1ll*used[1]*used[2]+1ll*used[2]*used[0];
			} else{
				ans+=c/2;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

int N; pii cords[10]; vector<int> rot;
double avg; int factorial = 1;
int main(){
    scanf("%d", &N);
    for(int i = 1; i<= N; i++){
        scanf("%d %d", &cords[i].first, &cords[i].second);
        rot.emplace_back(i); factorial *=i;
    }
    do{
        double len = 0;
        for (int i = 1; i < rot.size(); i++) {
            len += sqrt((cords[rot[i]].first-cords[rot[i-1]].first+0.0)*(cords[rot[i]].first-cords[rot[i-1]].first+0.0)
                    +(cords[rot[i]].second-cords[rot[i-1]].second+0.0)*(cords[rot[i]].second-cords[rot[i-1]].second+0.0));
        }
        avg += len;
    }while(next_permutation(rot.begin(), rot.end()));
    avg/=factorial;
    printf("%.6f", avg);
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n;
    cin >> n;

    vll L(n);
    REP(i, n) cin >> L[i];

    ll cnt = 0;
    REP(i, L.size()) FOR(j, i + 1, L.size()) FOR(k, j + 1, L.size()) {
        vector<ll> v = {L[i], L[j], L[k]};
        sort(ALL(v));
        if (v[0] + v[1] > v[2] && v[0] != v[1] && v[1] != v[2] && v[2] != v[0]) {
            cnt++;
        }
    }

    print(cnt);
    
}


Measured memory_bytes: 3664
n = gets.strip.to_i
data = n.times.map { gets.strip.split.map(&:to_i) } 

def is_reach(c, n)
	ct, cx, cy = c
	nt, nx, ny = n

	dist = (nx - cx).abs + (ny - cy).abs

	# そもそも間に合わない	
	return false if dist > (nt - ct)

	# 行ったり来たりでOK
	(dist - (nt - ct)).even?
end

current = [0, 0, 0]
data.each do |d|
	if is_reach(current, d)
		current = d
	else
		puts 'No'
		exit 0
	end
end
puts 'Yes'


Measured memory_bytes: 9468
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();
    List<String> arr = new ArrayList<String>();
    List<String> arr2 = new ArrayList<String>();
    int countx = 0;  
    int county = 0;  
    for(int i = 0; i < str.length(); i++) {
      String tmp = String.valueOf(str.charAt(i));
      arr2.add(tmp);
      if(arr.contains(tmp) == false){
        arr.add(tmp);
      }
    }
    if(arr.size() > 2){
      System.out.println("No");
      return;
    }
    String x = arr2.get(0);
    String y = arr2.get(1);
   
    for(int i = 0; i < str.length(); i++) {
      if(x.equals(String.valueOf(str.charAt(i)))){
      	countx++;
      }else{
        county++;
      }
    }
    if(countx != 2 || county != 2){     
		System.out.println("No");
      	return;
    }
	System.out.println("Yes");
  }
}


Measured memory_bytes: 23124
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;


using namespace std;

int main() {

	SINT32 N = 0;

	cin >> N;

	vector<SINT32> DATA(N+2);
	vector<SINT32> PLUS(N+2);
	vector<SINT32> SA(N+1);
	
	
	rep(i,0,N) {
		cin >> DATA[i+1];
	}
	DATA[N+1] = 0;

	PLUS[0] = 0;
	rep(i,1,N+2) {
		PLUS[i] = ABS(DATA[i-1] - DATA[i]) + PLUS[i-1];
	}
	rep(i,1,N+1) {
		SA[i] = ABS(DATA[i+1] - DATA[i]) + ABS(DATA[i] - DATA[i-1]) - ABS(DATA[i+1] - DATA[i-1]);
		cout << PLUS[N+1] - SA[i] << endl;
	}
	/*
	rep(i,0,N+2) {
		cout << DATA[i] << " ";
	}
	cout << endl;
	cout << PLUS[N+1];
	*/

	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
using namespace std;

const unsigned long long BASE = (unsigned long long)(1e9 + 7);

int main()
{
    string str;
    cin >> str;
    char last = 'R';
    int x = 0, m = 0;
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == 'R' && (x == 0 || last == 'R'))
        {
            x++;
            m = x > m ? x : m;
        }
        else
        {
            x = 0;
        }
        last = str[i];
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
    int key;
    Node *next,*prev;
};

Node *A;

Node* Search(int key){
    Node *q=A->next;
    while(q!=A&&q->key!=key)
        q=q->next;
    return q;
}

void in(){
    A=(Node *)malloc(sizeof(Node));
    A->next=A;
    A->prev=A;
}

void p(){
    Node *q=A->next;
    int a=0;
    while(1){
        if(q==A)
            break;
        if(a++>0)
            printf(" ");
        printf("%d",q->key);
        q=q->next;
    }
    printf("\n");
}

void Del(Node* t){
    if(t==A)
       return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}

void df(){
    Del(A->next);
}


void k(){
    Del(A->next);
}

void Last(){
    Del(A->prev);
}

void K(int key){
    Del(Search(key));
}

void insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=A->next;
    A->next->prev=x;
    A->next=x;
    x->prev=A;
}

int main(){
    int key,n,i,C=0,D=0,size=0;
    char B[20];
    
    scanf("%d",&n);
    in();
    for(i=0;i<n;i++){
      scanf("%s%d",B,&key);
      if(B[0]=='i'){
          insert(key);
          C++;
          size++;
      }
      else if(B[0]=='d'){
          if(strlen(B)>6){
              if(B[6]=='F')  
                df();
          else if(B[6]=='L')
                Last();
          }
          else{
               K(key);
               D++;
          }
          size--;
      }
      
    }
    p();
    
    return 0;
    
}





Measured memory_bytes: 33856
#include <stdio.h>
int main(){
 int a,b;
  scanf("%d%d", &a, &b);
  int ans;
  if(a == b){
    ans = 2 * a;
  }else if(a > b){
    ans = 2 * a - 1;
  }else{
    ans = 2 * b - 1;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();

    String k = "";
    String l = "";

    for (int i = 0; i < Integer.parseInt(b); i++) {
      k += a;
    }

    for (int i = 0; i < Integer.parseInt(a); i++) {
      l += b;
    }


    if (k.compareTo(l) < 0) {
      System.out.println(k);
    } else {
      System.out.println(l);
    }

  }

}


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

int main(){
	long long int a , b , d , r;
	double f;
	cin >> a >> b;
	d=a/b;
	r=a%b;
	f=(double)a/b;
	cout << d << " " << r << " " << fixed << setprecision(5)<<f << endl;
	return 0;
}

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

int main() {
    int32_t n, s;
    cin >> n >> s;
    int32_t t[n];

    if (n > 1) {
        int32_t answer = s;
        cin >> t[0];
        for (int32_t i = 1; i < n; i++) {
            cin >> t[i];
            answer += t[i - 1] + s > t[i] ? t[i] - t[i - 1] : s;
        }
        cout << answer << endl;
    } else {
        cout << s << endl;
    }

    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

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

    int N; cin >> N;
    vector<int> A(N), B(N);
    vector<pair<int, int>> D(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
        D[i] = make_pair(A[i] + B[i], i);
    }
    sort(rall(D));
    // rep(i, N) cout << D[i].first << ' ' << D[i].second << endl;
    ll t = 0, a = 0;
    rep(i, N) {
        if (i % 2 == 0) {
            t += A[D[i].second];
        } else {
            a += B[D[i].second];
        }
    }
    cout << t - a << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    int SW = 0;
    int S = 0;
    double Srate = 0;
    rep(i,F/100/A + A) rep(j,F/100/B + B){
        double water = A*i + B*j;
        int sugarlim = water*E;
        if(water*100 + sugarlim > F)sugarlim = F - water*100;
        rep(k,sugarlim/C + C) rep(l,sugarlim/D + D){
            double sugar = C*k + D*l;

            double tmp2 = (water*100+sugar != 0 ? sugar*100/(water*100+sugar) : 0 );
            if(water*100 + sugar <= F && sugarlim >= sugar) if(tmp2 > Srate){
                SW = water*100 + sugar;
                S = sugar;
                Srate = sugar*100/(water*100+sugar);
            }
        }
    }
    if(S == 0)SW = min(A,B)*100;
    cout << SW << " " << S << endl;
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

const int N = 1e5 + 5;
const int MOD = M;
vector<int> tree[N];
int dp[N][2], vis[N];

void f(int vertex)
{
    vis[vertex] = 1;
    int a = 1, b = 1;
    for(int i:tree[vertex])
    {
        if(vis[i] == 0)
        {
            f(i);
            a *= (dp[i][0] + dp[i][1]);
            b *= dp[i][0];
            a %= MOD;
            b %= MOD;
        }
    }
    if(a == 1 and b == 1)
    {
        dp[vertex][0] = 1;
        dp[vertex][1] = 1;
    }
    else
    {
        dp[vertex][0] = a;
        dp[vertex][1] = b;
    }
}

int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n;
    cin >> n;
    for(int i=1;i<n;i++)
    {
        int a, b;
        cin >> a >> b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    memset(dp, -1, sizeof(dp));
    f(1);
    cout << (dp[1][0] + dp[1][1])%MOD << "\n";
   // for(int i=1;i<=n;i++)
    //    cout << dp[i][0] << " " << dp[i][1] << "\n";


    return 0;
}



Measured memory_bytes: 14976
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-2-24 20:50:09
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll N;

int main()
{
  cin >> N;
  string X = to_string(N);
  bool all_nine = true;
  for (auto x : X)
  {
    if (x != '9')
    {
      all_nine = false;
      break;
    }
  }
  int ans = 0;
  for (auto x : X)
  {
    ans += x - '0';
  }
  int tans = 0;
  if (all_nine)
  {
    for (auto x : X)
    {
      tans += 9;
    }
  } else {
    int s = X.size();
    for (auto i = 0; i < s; i++)
    {
      if (i == 0)
      {
        tans += X[i] - '0' - 1;
      } else {
        tans += 9;
      }
    }
  }
  cout << max(ans, tans) << endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;

vector<bool > prime;

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}

map<ll, ll> primeFactor(ll num){

    map<ll, ll> PF;

    ll i = 2;

    while(num >= i * i){
        if(num % i == 0){
            PF[i]++;
            num /= i;
        }else{
            i++;
        }
    }

    if(num != 1){
        PF[num]++;
    }
    

    return PF;

}



int main(){

    ll A, B;
    cin >> A >> B;

    if(A < B){
        swap(A, B);
    }

    ll GCD = gcd(A, B);

    map<ll, ll> PF = primeFactor(GCD);

    ll ans = 0;

    auto begin = PF.begin(), end = PF.end();
    for (auto iter = begin; iter != end; iter++) {
        ans++;
    }

    ans++;

    cout << ans << endl;
    


}

Measured memory_bytes: 256
N = int(input())
vec = [[] for _ in range(N)]
for _ in range(N - 1) :
  a, b = map(int, input().split())
  vec[a-1].append(b-1)
  vec[b-1].append(a-1)

que = [(0, -1, 0)]
Mi, Mv = 0, 0
while que :
  cur, pre, dist = que.pop()
  if dist > Mv :
    Mi, Mv = cur, dist
  for nex in vec[cur] :
    if nex == pre :
      continue
    que.append((nex, cur, dist + 1))

que = [(Mi, -1, 1)]
Mi, Mv = 0, 0
while que :
  cur, pre, dist = que.pop()
  if dist > Mv :
    Mi, Mv = cur, dist
  for nex in vec[cur] :
    if nex == pre :
      continue
    que.append((nex, cur, dist + 1))

if Mv % 3 != 2 :
  print('First')
else :
  print('Second')

Measured memory_bytes: 125772
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  string S;
  cin >> S;
  
  string result;

  if (S == "hi") {
    result = "Yes";
  }
  else if (S == "hihi") {
    result = "Yes";
  }
  else if (S == "hihihi") {
    result = "Yes";
  }
  else if (S == "hihihihi") {
    result = "Yes";
  }
  else if (S == "hihihihihi") {
    result = "Yes";
  }
  else {
    result = "No";
  }

  cout << result << endl;

}

Measured memory_bytes: 256
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

int dp[410][410][41] = {};

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

  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;

  int a[41] = {};
  int b[41] = {};
  int c[41] = {};
  REP(i, N) {
    cin >> a[i] >> b[i] >> c[i];
  }

  REP(i, 410) {
    REP(j, 410) {
      REP(k, 41) {
        dp[i][j][k] = INF;
      }
    }
  }

  REP(i, N) {
    REP(j, 410) {
      REP(k, 410) {
        if (j + a[i] < 410 && k + b[i] < 410) {
          dp[j + a[i]][k + b[i]][i + 1] = min(dp[j + a[i]][k + b[i]][i + 1],
                                              dp[j][k][i] + c[i]);
        }
        dp[j][k][i + 1] = min(dp[j][k][i + 1], dp[j][k][i]);
      }
    }
    dp[a[i]][b[i]][i + 1] = min(dp[a[i]][b[i]][i + 1], c[i]);
  }

  int mi = INF;
  for (int i = 1; i <= N; i++) {
    mi = min(dp[i * Ma][i * Mb][N], mi);
  }
  if (mi == INF) {
    cout << "-1" << endl;
  } else {
    cout << mi << endl;
  }
  return 0;
}


Measured memory_bytes: 27136
n = int(input())
A = list(map(int, input().split()))
A.sort()

cnt = [0] * (10**6+1)
for a in A:
    if cnt[a] != 0:
        cnt[a] += 1
        continue
    for i in range(10**6+1)[a::a]:
        cnt[i] += 1
ans = 0
for a in A:
    if cnt[a] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 32172
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define INF 30000000000001
#define ll_max 9000000000000000001
#define mod 1000000007
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 10001;
const ll M = 1;

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m, x = 0, y, ans = 0, k;
        cin >> n >> m;
        ll a[n + 1], dp[n + 1] = {};
        a[0] = INF;
        dp[1] = 0;
        for(int i = 1; i <= n; i++) cin >> a[i];
        for(int i = 2; i <= n; i++)
        {
            dp[i] = INF;
            for(int j = 1; j <= m; j++)
            {
                if(i - j > 0)
                dp[i] = min(dp[i - j] + abs(a[i - j] - a[i]), dp[i]);
            }
        }
        cout << dp[n] << "\n";
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
  long W, H, x, y;
  cin>>W>>H>>x>>y;
  cout<<W*H/2.0<<" ";
  if(W/2.0==x && H/2.0==y){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 256