akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int A, B;
    cin >> A >> B;

    cout << max(A+B, max(A+B-1, max(2*A-1, 2*B-1))) << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int x,y;
    string op;
    cin >> x >> op >> y;
    if (op == "+"){
        cout << x + y << endl;
    }
    else {
        cout << x - y << endl;
    }
    
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner=new Scanner(System.in);

		int n=scanner.nextInt();
		int l=scanner.nextInt();


		String[] data=new String[n];

		for(int i=0;i<n;i++) {
			data[i]=scanner.next();
		}

		Arrays.sort(data);

		StringBuilder sb=new StringBuilder();
		
		for(int i=0;i<n;i++) {
			sb.append(data[i]);
		}
		
		String result=sb.toString();

		System.out.println(result);



		scanner.close();

	}

	public static int getsumofkakuketa(int n) {

		int result=0;

		while(true) {

			result+=n%10;

			if(n/10!=0) {
				n/=10;
			}else {
				return result;
			}
		}



	}

	public static boolean isMacthed(int a,int b,int sum) {

		if(sum>=a && sum<=b) {
			return true;
		}else {
			return false;
		}

	}



}







Measured memory_bytes: 22100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_Grand_Contest_035
{
    class Program_A
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            var input = Console.ReadLine().Split(' ')
                .Select(__ => Int32.Parse(__));

            var ans = 0;
            foreach (int num in input)
            {
                ans ^= num;
            }

            Console.WriteLine(ans == 0 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 19808
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        q: usize,
        e: [(usize1, usize1); n - 1],
        p: [(usize1, u32); q],
    }
    let mut g = vec![vec![]; n];
    for (a, b) in e {
        g[a].push(b);
        g[b].push(a);
    }
    let mut dp = vec![0; n];
    for (p, x) in p {
        dp[p] += x;
    }
    let mut used = vec![false; n];
    let mut s = vec![];
    s.push(0);
    while let Some(v) = s.pop() {
        used[v] = true;
        for &u in g[v].iter() {
            if used[u] {
                continue;
            }
            dp[u] += dp[v];
            s.push(u);
        }
    }
    for (i, ans) in dp.iter().enumerate() {
        if i > 0 {
            write!(out, " ").unwrap();
        }
        write!(out, "{}", *ans).unwrap();
    }
    writeln!(out, "").unwrap();
}

fn main() {
    run();
}


Measured memory_bytes: 30968
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

template<typename T> struct SegmentTree {
private:
  using F = function<T(T,T)>;
  const F f;
  const T DD; // e
  int n;
  vector<T> dat;
public:
  SegmentTree(int n_, const F func, T dd):f(func),DD(dd){ init(n_);}
  void init(int n_) {
    n = 1; while(n < n_) n *= 2;
    dat.clear();
    dat.resize(2*n-1, DD);
  }
  void build(int n_, vector<T> v) {
    assert(n_ <= n);
    for(int i=0;i<n_;++i) dat[i+n-1] = v[i];
    for(int i=n-2;i>=0;--i) dat[i] = f(dat[2*i+1], dat[2*i+2]);
  }
  void set_val(int i, T x){
    assert(i < n);
    i += n-1;
    dat[i] = x;
    while (i > 0) {    
      i = (i-1)/2;  //child->parent
      dat[i] = f(dat[i*2+1], dat[i*2+2]);
    }   
  } 
  T query(int a, int b, int k, int l, int r) { 
    if (r<=a||b<=l) return DD;
    else if (a<=l&&r<=b) return dat[k];
    else {
      T vl = query(a,b,k*2+1,l,(l+r)/2);
      T vr = query(a,b,k*2+2,(l+r)/2,r);
      return f(vl, vr);
    }
  }
  T query(int a, int b) { //[a,b)
    assert(a < n);
    assert(b <= n);
    return query(a,b,0,0,n);
  }
  T operator[](const int &k) {
    assert(k < n);
    return query(k, k+1);
  }
};

const int INF = 1001001001;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,m;
  cin >> n >> m;
  string s;
  cin >> s;
  if (m >= n) {
    cout << n << endl;
    return 0;
  }
  auto f = [](int a, int b){ return min(a,b);};
  SegmentTree<int> seg(n+5, f, INF);
  seg.set_val(n,0);
  for (int i = n-1; i >= 0; --i) {
    if (s[i] == '0') {
      int v = seg.query(i+1, min(i+m,n)+1) + 1;
      seg.set_val(i,v);
    }
  }
  if (seg[0] == INF) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> ans;
  int now = seg[0], pre = 0;
  for (int i = 1; i <= n; ++i) {
    if (seg[i] == INF) continue;
    if (seg[i] == now - 1) {
      ans.emplace_back(i - pre);
      pre = i;
      now--;
    }
  }
  for (auto& x:ans) cout << x << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 2120
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
using namespace std;
 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007
 

void solver()
{
	ll n,k;
	cin>>n>>k;
	ll temp=0;
	while(n!=0)
	{
		n /=k;
		temp++;
	}
	cout<<temp;
}

signed main() 
{
	speed;
	
	ll q=1;
	//cin>>q;
	
	while(q--)
		solver();
		
 	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <stdio.h>

constexpr char* S_OUT[31] = {
    "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n",
    "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "20\n",
    "21\n", "22\n", "23\n", "24\n", "25\n", "26\n", "27\n", "28\n", "29\n", "30\n"
};

constexpr unsigned int InputSize = 1e6;
constexpr unsigned int OutputSize = 3e5;
char Input[InputSize];
char* pointer = Input;
char Output[OutputSize];
char* m_buffer = Output;

inline unsigned int getInt(void){
    unsigned int res = 0;
    do{ res = 10 * res + (*(pointer++) - '0'); } while(*pointer >= '0');
    return res;
}

inline void out(int v){
    char* str = S_OUT[v];
    while(*str) *(m_buffer++) = *(str++);
}

unsigned int n;
unsigned int N;
constexpr unsigned int SIZE = (1U << 19) + 1;
unsigned int data[2 * SIZE];

inline void set(void){
    n = getInt(); N = 1U << (31 - __builtin_clz(n)); while(N < n) N <<= 1;
    ++pointer; // \n
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j) data[j] = 1U << (*(pointer++) - 'a');
    for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1U];
}

inline void query(void){
    pointer += 3;
    if(*(pointer - 2) == '1'){
        unsigned int index = getInt() - 1;
        unsigned char idx = *((++pointer)++) - 'a';
        data[index += N] = 1U << idx;
        while(index >>= 1) data[index] = data[index << 1] | data[(index << 1) | 1U];
    }
    else{
        unsigned int l = getInt() + N - 1; pointer++;
        unsigned int r = getInt() + N;
        unsigned int res = 0;
        while(l < r){
            if(l & 1) res |= data[l++]; l >>= 1;
            if(r & 1) res |= data[--r]; r >>= 1;
        }
        out(__builtin_popcount(res));
    }
}

int main(void){
    fread(Input, sizeof(char), InputSize, stdin);
    set(); ++pointer;
    unsigned int q = getInt();
    while(q--) query();
    setvbuf(stdout, 0, _IONBF, 0);
    fputs(Output, stdout);
    return 0;
}

Measured memory_bytes: 5120
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string T, P;
	cin >> T >> P;
	int tsz = T.size();
	int psz = P.size();

	vector<int> ans;
	for (int i = 0; i <= tsz - psz; i++) if (T.substr(i, psz) == P) cout << i << "\n";;

	return 0;
}


Measured memory_bytes: 4528
#include <iostream>
#include <map>
#include <queue>
using namespace std;
typedef pair<int,int> P;

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

void debug(int a[100][100]){
	for(int y=0 ; y <= h*2 ; y++ ){
		for(int x=0 ; x <= w*2 ; x++ ){
			cout << a[y][x];
		}
		cout << endl;
	}
}

int solve(int a[100][100]){
	int d[100][100] = {0};
	d[1][1] = 1;

	P sp(1,1);
	queue<P> q;
	q.push( sp );

	while( !q.empty() ){
		P p = q.front();
		q.pop();
		int x = p.first;
		int y = p.second;
		int cnt = d[y][x];

		if( x == w*2-1 && y == h*2-1 ) break;

		for(int i=0 ; i < 4 ; i++ ){
			int mx = x + dx[i];
			int my = y + dy[i];
			int nx = mx + dx[i];
			int ny = my + dy[i];
			if( nx < 0 || ny < 0 || nx > w*2 || ny > h*2 ) continue;
			
			if( a[my][mx] == 0 && d[ny][nx] == 0 ){
				P np( nx , ny );
				q.push( np );
				d[ny][nx] = cnt+1;
			}
		}
	}
	return d[h*2-1][w*2-1];
}

int main(){
	while( cin >> w >> h , w||h ){
		int a[100][100] = {0};
		for(int x=0 ; x <= w*2 ; x++ ){
			a[0][x] = a[h*2][x] = 1;
		}
		for(int y=0 ; y <= h*2 ; y++ ){
			a[y][0] = a[y][w*2] = 1;
		}

		for(int y=0 ; y < (h*2-1) ; y++ ){
			if( y%2 == 0 ){
				for(int x=0 ; x < w-1 ; x++ ){
					//(x,y) => (2x+2,y+1);
					cin >> a[y+1][2*x+2];
				}
			}else{
				for(int x=0 ; x < w ; x++ ){
					//(x,y) => (2x+1,y+1);
					cin >> a[y+1][2*x+1];
				}
			}
		}
		cout << solve( a ) << endl;
	}
}

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

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

    vector<vector<int> > vec(m + 1);

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a <= m) {
            vec[a].push_back(b);
        }
    }

    priority_queue<int> pq;
    int res = 0;
    for (int i = 0; i < m + 1; i++) {
        for (int element : vec[i]) {
            pq.push(element);
        }
        if (!pq.empty()) {
            res += pq.top();
            pq.pop();
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 5632
a, b = map(int, input().split())
s = input()

flag = 0


if s[a] == "-":
    if s[:a].isdecimal() and s[a+1:].isdecimal():
        flag = 1
    else:
        flag = 0


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

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

int main(){
	string S,T;
	cin >> S >> T;
	int sno,tno,stlen;
	stlen=S.size();
	int roop;
	int res[27]={};
	int tur=1;
	for(roop=0;roop<stlen;roop++){
		sno=S[roop];
		tno=T[roop];
		if(res[sno-97]==0){
			res[sno-97]=tno;
		}else if(res[sno-97]!=tno){
			tur=0;
			break;
		}else{
			continue;
		}
	}
	int roop2;
	if(tur){
		for(roop=0;roop<25;roop++){
			if(res[roop]==0){
				continue;
			}
			for(roop2=roop+1;roop2<26;roop2++){
				if(res[roop]==res[roop2]){
					tur=0;
					break;
				}
			}
		}
	}
	if(tur){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main()
{
	int C, N, M;
	cin >> C >> N >> M;
	vector<int> dp(C + 1);
	for (int i = 0; i < N; i++) {
		int s, p;
		cin >> s >> p;
		for (int j = C - s; j >= 0; j--) {
			dp[j + s] = max(dp[j + s], dp[j] + p);
		}
	}
	for (int i = 1; i <= M; i++) {
		cout << dp[C / i] * i << endl;
	}
	return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n , k;
		cin >> n >> k;
		map<int,int>mp;
		for(int i= 0 ;i < k;i++){
			int d;
			cin >>d;
			for(int j =1;j<=d;j++){
				int x;
				cin>>x;
				mp[x]++;
			}
		}
		int ans= 0 ;
		fn1{
			if(mp[i]==0)ans++;
		}
		cout<<ans;
	
	
	}
	return 0;
}

Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {

    private static final int MOD = 1000000007;

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

        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();

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

        long sum = modPow(2, n, MOD);
        sum -= 1; // どれも選ばない0本のケースは無効なので引いておく
        sum -= combination(n, a);
        sum -= combination(n, b);

        System.out.println((sum + MOD * 2) % MOD);
    }

    private static long modPow(long a, long n, long p) {
        if (n == 1) {
            return a % p;
        }
        if (n % 2 == 1) {
            return (a * modPow(a, n - 1, p)) % p;
        }
        long t = modPow(a, n / 2, p);
        return (t * t) % p;
    }

    private static long combination(int n, int k) {
        long x = 1;
        long y = 1;
        for (int i = 0; i < k; i++) {
            x *= n - i;
            x %= MOD;
            y *= k - i;
            y %= MOD;
        }
        return x * modPow(y, MOD - 2, MOD) % MOD;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[])
{
    unordered_multiset<string> parts;
    vector<string> alphabet;
    for (int i = 97; i < 123; i++)
    {
        alphabet.push_back(string(1, (char)i));
    }

    char tmpc;
    while(cin >> tmpc)
    {
        parts.insert(string(1,tolower(tmpc)));
    }
    for (auto var : alphabet)
    {
        cout << var << " : " << parts.count(var) << endl;
    }

    return 0;
}



Measured memory_bytes: 3236
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

typedef std::multimap<string, string> mss;
typedef std::pair<string, string> pss;
vector<pss> calc(string r) {
  int n = r.length();
  int m = (1 << n);
  vector<pss> ret(m);;
  rep (i, m) {
    string s = "";
    string t = "";
    rep (j, n) {
      if (((i >> j) & 1) == 1) {
        s += r[j];
      } else {
        t += r[j];
      }
    }
    reverse(all(t));
    ret[i] = (pss){s, t};
  }
  sort(all(ret));
  return ret;
}

int main() {
  int n;
  cin >> n;
  n *= 2;
  string s;
  cin >> s;
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  int m = n / 2;
  string t = s.substr(0, m);
  string u = s.substr(m, n-m);
  auto mapt = calc(t);
  auto mapu = calc(u);
  ll cnt = 0;
  for (auto p : mapt) {
    auto lb = lower_bound(all(mapu), (pss){p.second, p.first});
    auto ub = upper_bound(all(mapu), (pss){p.second, p.first});
    cnt += (ub - lb);
  }
  printf("%lld\n", cnt);

  return 0;
}


Measured memory_bytes: 24832
#include <iostream>
#include <boost/math/special_functions/factorials.hpp>
using namespace std;

const long long MAX = 800000;
const long long MOD = 1000000007;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long com(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// http://drken1215.hatenablog.com/entry/2018/06/08/210000
long long knight(long long x, long long y)  {
  com_init();
  
  // 3の倍数でなければ0
  if(((x+y) % 3) != 0)
    return 0;
  // n回 (i+1, j+2)移動してm回(i+2, j+1)移動すると。
  // n+2m = x, 2n+m = yが成立
  // 2n + 4m = 2x
  // 2n + m = y
  // 3m = 2x -y
  auto m = (2*x -y) /3;
  auto n = (2*y-x)/3;

  if (m < 0 || n < 0)
    return 0;
  //boost::math::factorial(m+n);
  auto ans = com(n+m, n);
  return ans % MOD;
}
int main() {
  long long x;
  long long y;
  cin >> x;
  cin >> y;
  cout << knight(x, y);
}

Measured memory_bytes: 18944
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

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

using namespace std;
int a,b,c;
int main(){
  cin >> a >> b >> c;
  int d = b/a;
  cout << min(d,c) << endl;
	return 0;
}


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

int N; string S;
bool ani[100010];
bool greedy(bool f1, bool f2){
    ani[0]=f1;
    ani[1]=f2;
    for(int i=2; i<N; ++i){
        ani[i]=((S[i-1]=='o')^ani[i-1])^ani[i-2];
    }
    return (ani[1]^ani[N-1])^(S[0]=='o')==ani[0] && (ani[N-2]^ani[0])^(S[N-1]=='o')==ani[N-1];
}
int main() {
	cin >> N >> S;
	bool flag=false;
	for(int i=0; i<4; ++i){
	    if(greedy(i<2, i%2<1)){
	        flag=true;
	        break;
	    }
	}
	if(flag){
	    for(int i=0; i<N; ++i) cout << (ani[i] ? 'S' : 'W');
	    cout << endl;
	}
	else cout << -1 << endl;
	return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,m,memo[10000],B;

signed main() {
    rep11(i,10000) memo[i] = INF/10;
    cin >> n >> m;
    B = pow(2,n);
    rep(i,m) {
        int a,b,sum=0;
        cin >> a >> b;
        rep(j,b) {
            int c;
            cin >> c;
            c--;
            sum += pow(2,c);
        }
        rep(j,B) memo[(j|sum)] = min(memo[(j|sum)], memo[j] + a);
    }
    if (memo[B-1] == INF/10) cout << -1 << endl;
    else cout << memo[B-1] << endl;
}

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

int main() {
  string s; cin >> s;
  int n = s.size();
  bool flag = true;
  rep(i, n) {
    if (i % 2 == 0) {
      if (s[i] == 'L') flag = false;
    }else {
      if (s[i] == 'R') flag = false;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	m := make(map[int]int, 0)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		var a, b int
		sc.Scan()
		a, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ = strconv.Atoi(sc.Text())
		m[a] += b
	}
	// fmt.Println("n", n, "k", k, "m", m)
	ks := make([]int, 0)
	for k := range m {
		ks = append(ks, k)
	}
	sort.Ints(ks)
	//fmt.Println("n", n, "k", k, "m", m, "ks", ks)
	cnt := 0
	for i := 0; i < len(ks); i++ {
		if k > cnt+m[ks[i]] {
			cnt += m[ks[i]]
		} else {
			fmt.Println(ks[i])
			break
		}
	}
}


Measured memory_bytes: 7936
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	double f;
	cin >> a >> b;
	f=a*1.0/b;
	cout << a/b << " " << a%b << " ";
	printf("%.5f\n",f);
	return 0;
}

Measured memory_bytes: 1240
from operator import itemgetter
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
ws=LI()
s1=0
s2=sum(ws)
mn=sum(ws)
for i in range(n-1):
    s1+=ws[i]
    s2-=ws[i]
    if abs(s1-s2)<=mn:
        mn=abs(s1-s2)
print(mn)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    int h[N];
    int i;
    for(i=0;i<N;i++)cin >> h[i];
    int sum =0;
    for(i=0;i<N;i++)if(h[i]>=K)sum++;
    cout << sum << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const ll MAXN=1e5+10;
const ll MOD=1e9+7;
ll pri[MAXN],jud[MAXN],phi[MAXN]={0,1},cnt;
ll qpow(ll a,ll b){
    ll res=1,rem=a;
    while(b){
        if(b&1) res=(res*rem)%MOD;
        rem=(rem*rem)%MOD;
        b>>=1;
    }
    return res;
}
void euler(){
    for(ll i=2;i<MAXN;i++){
        if(!jud[i]){
            pri[cnt++]=i;
            phi[i]=(i-1)%MOD;
        }
        for(ll j=0;j<cnt&&i*pri[j]<MAXN;j++){
            jud[i*pri[j]]=1;
            if(i%pri[j]==0){
                phi[i*pri[j]]=phi[i]*pri[j];
                break;
            }
            phi[i*pri[j]]=phi[i]*phi[pri[j]];
        }
    }
}
int main(){
    euler();
    ll n,k;scanf("%lld %lld",&n,&k);
    ll res=0;
    for(ll i=1;i<=k;i++) res=(res+qpow(k/i,n)*phi[i])%MOD;
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 4844
#include<iostream>
using namespace std;
int main()
{
int i,h,m1,m2,m3;
m1=0;
m2=0;
m3=0;
for(i=0;i<10;i++)
{
	cin>>h;
	if(h>m1)
	{
		m3=m2;
		m2=m1; 
		m1=h;
	}
	else if(h>m2)
	{
		m3=m2;
		m2=h;
	}
	else if(h>m3)
	{
		m3=h;
	}
}
cout<<m1<<endl;
cout<<m2<<endl;
cout<<m3<<endl;
return 0;
}

Measured memory_bytes: 2992
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**10 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
            elif -k<k0:
                del H[i,j]
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[i,j])

Measured memory_bytes: 4596
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include <math.h>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

class Point{
	public:
	double x,y;
	Point(double x=0,double y=0):x(x),y(y) {}
	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
	Point operator * (double a) {return Point(x*a,y*a);}
	Point operator / (double a) {return Point(x/a,y/a);}
	double absv() {return sqrt(norm());}
	double norm() {return x*x+y*y;}
	bool operator < (const Point &p) const{
		return x != p.x ? x<p.x: y<p.y;
	}
	bool operator == (const Point &p) const{
		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
	}
};
typedef Point Vector;

struct Segment{
Point p1,p2;
};


double dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

//----------------kokomade temple------------



int main(){
int n;
double r,c1,c2,a1,a2,a3,a4;
cin>>c1>>c2>>r;
Point c,p1,p2,q,ans1,ans2;
c.x=c1,c.y=c2;
cin>>n;
for(int i=0;i<n;i++){
cin>>a1>>a2>>a3>>a4;
p1.x=a1,p1.y=a2;
p2.x=a3,p2.y=a4;
Vector b=(p2-p1)/(p2-p1).absv();
q=p1+b*dot(c-p1,b);
//cout<<q.x<<" "<<q.y<<endl;
double d=r*r-(c-q).norm();
if(d<EPS) d=0.0;
else d=sqrt(d);
ans1=q+b*d;
ans2=q-b*d;

if(ans1.x<ans2.x  ||(ans1.x==ans2.x && ans1.y<ans2.y )){
printf("%.10f %.10f %.10f %.10f\n",ans1.x,ans1.y,ans2.x,ans2.y);
}
else printf("%.10f %.10f %.10f %.10f\n",ans2.x,ans2.y,ans1.x,ans1.y);

}


return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  ll count = 0;
  REP(i,n){
    ll num = i+1;
    ll cnt = 0;
    while(num>0){
      cnt++;
      num /= 10;
    }
    count += cnt&1;
  }
  cout << count<< endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
 
s = [0] * (N+1)
p = 1
h = []
for i in range(K):
    h.append(p)
    s[p] = 1
    p = A[p]

    if s[p] != 0:
        break

if i == K-1:
    print(p)
    exit()
else: 
    period = len(h) - h.index(p)
    rem = (K - h.index(p)) % period
    print(h[h.index(p):][rem])


Measured memory_bytes: 32376
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ios
	ll n,m,i,j;
	cin>>n>>m;
	ll ans=1;
	if(n==1){
		cout<<m;return 0;
	}
	for(i=2;i*i<=m;i++){
		if(m%i==0){
			if(i>=n)ans=max(m/i,ans);
			if(m/i>=n)ans=max(ans,i);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	ll a,b,n;
	cin>>a>>b>>n;
	n = min(b-1,n);
	cout<<(a*n)/b-a*(n/b);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main(){
  string S, T;
  cin >> S >> T;
  bool flag = true;
  map<char,char> mp;
  for(int i=0; i<S.size(); i++){
    if(mp.count(S.at(i))){
      if(mp[S.at(i)] != T.at(i)){
        flag = false;
      }
    }
    else{
      mp[S.at(i)] = T.at(i);
    }
  }
  map<char,char> mp2;
  for(int i=0; i<S.size(); i++){
    if(mp2.count(T.at(i))){
      if(mp2[T.at(i)] != S.at(i)){
        flag = false;
      }
    }
    else{
      mp2[T.at(i)] = S.at(i);
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 904
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/cdescription.jsp?cid=ACPC2017Day1&pid=C
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1<<30
ll N, K;
ll ans;
vector<pll> T;
vector<int> f1;
vector<ll> f2;

void solve(ll n, ll k) {
	k++;
	if (k > K)return;
	if (T[n].second > k) {
		T[n].second = k;
		f1[n] = 1;
		solve(T[n].first, k);
	}
	return;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ans = 0;
	cin >> N >> K;
	T.resize(N , { 0,INF });
	f1.resize(N , 0);
	f2.resize(N, 0);
	for (int i = 0; i < N;i++) {
		cin >> T[i].first;
		if (T[i].first == 0) {
			f1[i] = 1;
		}
		else {
			T[i].first--;
			f2[T[i].first] = 1;
		}
	}

	for (int i = 0; i < N;i++) {
		if (f2[i] == 0) {
			f1[i] = 1;
			solve(i, 0);
		}
	}
	for (int i = 0; i < N;i++) {
		if (f1[i] == 1)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5472
#include "bits/stdc++.h"
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

  int h, w, d;
  cin >> h >> w >> d;
  vector<Pii> vp(h * w);
  rep(i, h) {
    rep(j, w) {
      int x;
      cin >> x;
      x--;
      vp[x] = Pii(i, j);
    }
  }

  vvi s(d, vi{0});
  rep(x, h * w - d) {
    int i, j;
    tie(i, j) = vp[x];
    int y = x + d;
    int ii, jj;
    tie(ii, jj) = vp[y];
    s[x % d].push_back(abs(i - ii) + abs(j - jj));
  }

  rep(k, d) {
    rep2(l, 1, s[k].size()) {
      s[k][l] += s[k][l - 1];
    }
  }

  int q;
  cin >> q;
  rep(t, q) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    int k = a % d;
    int l1 = a / d;
    int l2 = b / d;
    cout << s[k][l2] - s[k][l1] << endl;
  }

}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REP_REV(i,a,b) for (int i = a; i >= b; i--)
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;

void solve() {
	string n;
	cin >> n;
	int sum = 0;
	REP(i, 0, n.size() - 1) {
		int num = n[i] - '0';
		sum += num;
	}
	if (sum % 9 == 0) cout << "Yes";
	else cout << "No";
	/*
	int n;
	cin >> n;
	int highest = 7;
	int noHighest = 3;
	int bessie = 7, elsie = 7, mildred = 7;
	int ans = 0;
	bool bessieOn = true, elsieOn = true, mildredOn = true;
	vector<tuple<int, string, int>> records;
	REP(i, 0, n - 1) {
		int day, change;
		string name;
		cin >> day >> name >> change;
		tuple<int, string, int> record = tie(day, name, change);
		records.push_back(record);
	}
	sort(records.begin(), records.end());
	REP(i, 0, n - 1) {
		int currNoHighest = 0;
		int high = highest;
		if (get<1>(records[i]) == "Bessie") bessie += get<2>(records[i]);
		if (get<1>(records[i]) == "Mildred") mildred += get<2>(records[i]);
		if (get<1>(records[i]) == "Elsie") elsie += get<2>(records[i]);
		highest = max(bessie, max(elsie, mildred));

		bool bessieOnNext = bessie == highest;
		bool elsieOnNext = elsie == highest;
		bool mildredOnNext = mildred == highest;
		if (bessieOn != bessieOnNext || elsieOn != elsieOnNext || mildredOn != mildredOnNext) {
			ans++;
		}
		bessieOn = bessieOnNext;
		elsieOn = elsieOnNext;
		mildredOn = mildredOnNext;
	}

	cout << ans;*/
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("measurement.in", "r", stdin);
	//freopen("measurement.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//ll t;
	//cin >> t;
	//while (t--) {
	solve();
	//}
	return 0;
}

Measured memory_bytes: 3672
import sys
sys.setrecursionlimit(500000) 
input = sys.stdin.readline
from collections import deque
from heapq import heapify, heappop, heappush
H,W = map(int,input().split()); base = 1000
C = list(map(int,input().split()))
C[0] -= 1; C[1] -= 1
D = list(map(int,input().split()))
D[0] -= 1; D[1] -= 1
S = []; INF = float("inf")
for i in range(H):
  temp = str(input());temp =list(temp)
  S.append(temp)
#print(S)
reach = [[INF]*W for _ in range(H)]
reach[C[0]][C[1]] = 0
visit = [[False]*W for _ in range(H)]
dxdy = [(1,0),(-1,0),(0,1),(0,-1)]
Q = []
Q.append((0,C[0]+C[1]*base))
while Q:
  score,z = heappop(Q)
  x = z%base;y=z//base
  if visit[x][y]:
    continue
  visit[x][y] = True
 
  for i in range(4):
    nx = x + dxdy[i][0]
    ny = y + dxdy[i][1]
    #print(nx,ny)
    if 0<=nx<H and 0<=ny<W and S[nx][ny] == "." and reach[nx][ny] > score:
      reach[nx][ny] = min(score,reach[nx][ny])
      u = nx+ny*base
      heappush(Q,(score,u))
  #print(reach)
 
  for i in range(5): #0~4
    for j in range(5):
      mx = x-2 + i
      my = y-2 + j
      if i == 2 and j == 2:
        continue
      if mx < 0 or mx >= H or my < 0 or my >= W or S[mx][my] == "#":
        continue
      if reach[mx][my] <= score+1: #すでにこのスコア以下でいける。
        continue
      reach[mx][my] = min(score+1,reach[mx][my])
      p = mx+my*base
      #print(v,p,"X")
      heappush(Q,(score+1,p))
#dfs(C,0)
#print(reach)
#print(reach[D[0]][D[1]])
if reach[D[0]][D[1]] == INF:
  print(-1)
else:
  print(reach[D[0]][D[1]])

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

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

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

int main() {
	int N,K;
	cin >> N >> K;
	vector<int> p(N);
	rep(i,N) cin >> p[i];
	sort(p.begin(), p.end());
	int S = 0;
	rep(i,K) S += p[i];
	cout << S << endl;

  return 0;
}


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

const ll inf = (1 << 30) - 1;
ll dp[1010][1003];
int N, M;

int main()
{
    int ans = 0, m = 0;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C')
            m++;
        else
            ans = max(ans, m), m = 0;
    }
    ans = max(ans, m);
    cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::*;

fn run() {
    input! {
        n: usize,
        w: usize,
        mut s: [usize; n],
    }
    s.sort();
    const MOD: usize = 1_000_000_007;
    let mut dp: Vec<usize> = (0..=w).collect();
    for (i, a) in s.into_iter().enumerate() {
        if a <= w {
            let (x, y) = dp.split_at_mut(a);
            for (y, x) in y.iter_mut().zip(x.iter().cycle()) {
                *y = (*y * i + *x) % MOD;
            }
            x.iter_mut().for_each(|x| *x = *x * (i + 1) % MOD);
        } else {
            dp.iter_mut().for_each(|p| *p = (i + 1) * *p % MOD);
        }
    }
    let ans = dp[w];
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 2768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong a, b, n;

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

    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }

    if (n >= b - 1) {
        cout << (a * (b - 1) / b) << endl;
        return 0;
    }
    else {
        cout << (a * n / b) - a * (n / b) << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
t = gets.to_i - 2
data = gets.split
data = data.map(&:to_i)
ans = 0
a = 2
t.times do
    if data[a-1].between?(data[a-2],data[a]) == true || data[a-1].between?(data[a],data[a-2])
        ans += 1
    end
    a += 1
end
puts ans

Measured memory_bytes: 1788
#こっちはbit全探索を用いた解法

#Sは最大でも10桁、+が入る場所は9箇所なので計算量は2^9=512程度。
#全探索で余裕か

#plusの位置をlist化する。

s = str(input())
slen = len(s)

masterlist = []

for i in range (2 ** (slen-1)):
    pluslist = []
    for j in range(slen - 1):
        if i >> j & 1:
            pluslist.append(True)
        else:
            pluslist.append(False)
    masterlist.append(pluslist)

result = 0

#pl as pluslist

for pl in masterlist:
    plus_count = 0
    after_s = s
    for k in range(len(pl)):
        if pl[k] == True:
            after_s = "{0}{1}{2}".format(after_s[:k+plus_count+1],"+",after_s[k+plus_count+1:])
            plus_count += 1
    try:
        list_sum = eval(after_s)
    except NameError:
        list_sum = int(s) #もしプラスが1回も出ない場合はafter_sが定義されない。
    result += list_sum

print(result)





"""
#こっちは愚直に深さ優先探索した解法
def tansaku(number,plus_point,sum_temp):
    #print(number,plus_point,sum_temp)
    str_number = str(number)
    if len(str_number) -1 <= plus_point :
        return number + sum_temp
    else:
        next_number = int(str(number)[plus_point+1:])
        a1 = int(tansaku(next_number,0,sum_temp + int(str(number)[:plus_point+1])))
        #print(a1)

        a2 = tansaku(number,plus_point+1,sum_temp)
        #print(a2)


        return a1 + a2
 


if __name__ == "__main__":
    s = int(input())
    print(tansaku(s,0,0))
"""

Measured memory_bytes: 40432
fun main(args:Array<String>):Unit {
    val (n, q) = readLine()!!.split(' ').map(String::toInt)
    val vectors = Array(n){Vector()}
    repeat(q){
        val query = readLine()!!.split(' ').map(String::toInt)
        when(query.first()){
            0 -> vectors[query[1]].pushBack(query.last())
            1 -> println(vectors[query.last()].dump())
            else -> vectors[query.last()].clear()
        }
    }
}

class Vector{
    private var mArray:Array<Int> = Array(100){0}
    var size:Int = 0
        private set
    private fun resize():Unit {
        val newArray = Array(mArray.size * 2){0}
        mArray.forEachIndexed { index, i -> newArray[index] = i }
        mArray = newArray
    }
    fun pushBack(value:Int):Unit {
        if (size == mArray.size) resize()
        mArray[size++] = value
    }
    fun clear():Unit {
        size = 0
    }
    fun dump():String {
        return (0 until size).map{mArray[it]}.joinToString(" ")
    }
}


Measured memory_bytes: 187660
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    int n;
    cin>>n;
    vector<int>x(n);
    for(int i=0;i<n;i++)cin>>x[i];
    int ans = 10000000;
    for(int i=1;i<=100;i++){
        int tmp = 0;
        for(int j=0;j<n;j++){
            int num = x[j]-i;
            num=num*num;
            tmp+=num;
        }
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/////////////////////////
	int x,y;
	cin >> x >> y;
	x--;
	for (int i = y-x;i<=y+x;i++)
		cout << i << " ";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF = 100100100;
using namespace std;

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

    int A, B, C;
    cin >> A >> B >> C;

    int ans = 0;
    if (A + B >= C)
        ans += B + C;
    else {
        ans += 2 * B + A + 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// Created by new_sm
//
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int r;
cin>>r;
cout<<r*r;
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}



Measured memory_bytes: 3612
n = gets.to_i
s = Array.new
n.times do |i|
  s[i] = gets.to_i
end
s.sort!
p = s.inject {|sum, a| sum + a }
d = p
if d % 10 != 0
  puts d
else
  f = false
  for c in s do
    d = p - c
    if d % 10 != 0
      f = true
      break
    end
  end
  if f
    puts d
  else
    puts 0
  end
end


Measured memory_bytes: 1788
def judge(m,f,r):
    ret = 'F'
    score = m + f
    if -1 in (m,f): pass
    elif score >= 80: ret = 'A'
    elif score >= 65: ret = 'B'
    elif score >= 50: ret = 'C'
    elif score >= 30: 
        ret = 'D'
        if r >= 50:ret = 'C'
    return ret     
while True:
    m,f,r=map(int,input().split())
    if m==f==r==-1: break
    print(judge(m,f,r))

Measured memory_bytes: 7640