akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> t(n);
    vector<int> l(n);
    rep (i, n) cin >> t[i] >> l[i];
    string s;
    cin >> s;
    bool chk = false;
    int ans = 0;
    rep (i, n) {
        if (chk) ans += l[i];
        if (t[i] == s) chk = true;
    }
    cout << ans << "\n";
    return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()
{

    ll a, b;
    scanf("%lld%lld", &a, &b);
    ll n = b-a;
    n = (n*(n+1))/2;
    printf("%lld\n", n-b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
double x[55], y[55];

double g(double X, double Y) {
    double maxi = 0;
    for(int i = 0; i < N; i++) {
        double dx = x[i] - X;
        double dy = y[i] - Y;
        chmax(maxi, pow(dx*dx+dy*dy, 0.5));
    }
    return maxi;
}

double f(double X) {
    double ok = 1000;
    double ng = -1000;
    for(int _ = 0; _ <= 100; _++) {
        double r = (ok * 2 + ng) / 3;
        double l = (ok + ng * 2) / 3;
        if(g(X, r) < g(X, l)) ng = l;
        else ok = r;
    }
    //cerr << X << " " << ok << " " << g(X, ok) << endl;
    return g(X, ok);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> x[i] >> y[i];
    double ok = 1000;
    double ng = -1000;
    for(int _ = 0; _ <= 100; _++) {
        double r = (2 * ok + ng) / 3;
        double l = (ok + 2 * ng) / 3;
        //cerr << ng << " " << l << " " << r << " " << ok << endl;
        if(f(r) > f(l)) ok = r;
        else ng = l;
    }
    cout << fixed << setprecision(15) << f(ok) << endl;
    return 0;
}


Measured memory_bytes: 1148
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <utility>

#define YNUM(X) ( X < 0 ? X + 3 : X )

typedef std::pair<int, int> WH;
typedef std::vector<WH> whvec;

int h, w;
bool map[502][502];
std::string in;
std::vector<std::vector<whvec> > data(3, std::vector<whvec>(502));
int data_max = 0;
int height_sum[502][502], width_sum[502][502];
WH wh;

int main(){
	while( std::cin >> h >> w, w + h != 0 ){
		data_max = 0;
		memset( map, 0, sizeof(map) );
		memset( height_sum, 0, sizeof(height_sum) );
		memset( width_sum, 0, sizeof(width_sum) );

		for( int i = 1; i <= h; ++i ){
			std::cin >> in;
			for( int l = 1; l <= w; ++l ){
				map[i][l] = ( in[l - 1] == '.' );
			}
		}

		for( int i = 1; i <= h; ++i ){
			for( int l = 1; l <= w; ++l ){
				if(map[i][l]){
					width_sum[i][l] = width_sum[i][l - 1] + 1;
					height_sum[i][l] = height_sum[i - 1][l] + 1;
				}
			}
		}

		for( int i = 1, n = 1; n <= h; n++, i = n % 3 ){
			for( int l = 1; l <= w; l++ ){
				data[i][l].clear();
				if( map[n][l] ){
					if( map[n - 1][l] && map[n][l - 1] ){
						int x_cnt = width_sum[n][l], y_cnt = height_sum[n][l];

						for( int m = 0; m < data[YNUM(i - 1)][l].size(); ++m ){
							wh = WH( std::min(data[YNUM(i - 1)][l][m].first, x_cnt), data[YNUM(i - 1)][l][m].second + 1 );
							if( std::find( data[i][l].begin(), data[i][l].end(), wh ) == data[i][l].end() ){
								data[i][l].push_back( wh );
								data_max = std::max( data_max, wh.first * wh.second );
							}
						}
						for( int m = 0; m < data[i][l - 1].size(); ++m ){
							wh = WH( data[i][l - 1][m].first + 1, std::min(data[i][l - 1][m].second, y_cnt) );
							if( std::find( data[i][l].begin(), data[i][l].end(), wh ) == data[i][l].end() ){
								data[i][l].push_back( wh );
								data_max = std::max( data_max, wh.first * wh.second );
							}
						}
						
					}else if( map[n - 1][l] ){
						for( int m = 0; m < data[YNUM(i - 1)][l].size(); ++m ){
							data[i][l].push_back( wh = WH( 1, data[YNUM(i - 1)][l][m].second + 1 ) );
							data_max = std::max( data_max, wh.first * wh.second );
						}

					}else if( map[n][l - 1] ){
						for( int m = 0; m < data[i][l - 1].size(); ++m ){
							data[i][l].push_back( wh = WH( data[i][l - 1][m].first + 1, 1 ) );
							data_max = std::max( data_max, wh.first * wh.second );
						}

					}else data[i][l].push_back( wh = WH( 1, 1 ) ), data_max = std::max( data_max, wh.first * wh.second );
				}	
			}
		}

		std::cout << data_max << std::endl;
 	}
	return 0;
}

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if((10*b+c)%4 == 0){
		cout << "YES" << endl;
		return 0;
	}else{
		cout << "NO" << endl;
		return 0;
	}
}

Measured memory_bytes: 768
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef complex<double> C;

typedef string::const_iterator State;
int expression(State& begin);
int term(State& begin);
int number(State& begin);
int factor(State& begin);

int expression(State& begin) {
    int ret = term(begin);
    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else break;
    }
    return ret;
}

int term(State& begin) {
    int ret = factor(begin);
    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else break;
    }
    return ret;
}

int factor(State& begin) {
    if (*begin == '(') {
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    } else {
        return number(begin);
    }
}

int number(State& begin) {
    int ret = 0;
    while (isdigit(*begin)) {
        ret = ret*10 + (*begin - '0');
        begin++;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cin.ignore();
    for (int i = 0; i < n; i++) {
        string s;
        getline(cin, s);

        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
main :: IO ()
main = getLine >>= print . calc

calc :: String -> Int
calc = sum . map (sum . map read) . allSplits

allSplits :: String -> [[String]]
allSplits [c]    = [[[c]]]
allSplits (c:cs) = map noSplit prev ++ map split prev
  where
    noSplit (s:ss) = (c:s):ss
    split ss       = [c]:ss
    prev           = allSplits cs

Measured memory_bytes: 1020
# D - Gathering Children　★

s = list(input())
ret = [1] * len(s)

# 試行は偶数回行われ、'RL'間で起こる入れ替えも偶数回試行で元の位置に戻るので、連続する2回分の動きを考える
# → 10**100回試行する必要はない
for i in range(len(s)):
    if i + 2 > len(s) - 1:
        break
    if s[i] == 'R' and s[i + 1] == 'R':
        ret[i + 2] += ret[i]
        ret[i] = 0
    if s[-(i + 1)] == 'L' and s[-(i + 2)] == 'L':
        ret[-(i + 3)] += ret[-(i + 1)]
        ret[-(i + 1)] = 0
print(' '.join(map(str, ret)))

Measured memory_bytes: 11180
#include <stdio.h>

int main(void){
	double a, b;
	while(scanf("%lf%lf",&a,&b) != EOF){
	if(a < 35.5 && b < 71)
		printf("AAA\n");
	else if(a < 37.5 && b < 77)
		printf("AA\n");
	else if(a < 40 && b < 83)
		printf("A\n");
	else if(a < 43 && b < 89)
		printf("B\n");
	else if(a < 50 && b < 105)
		printf("C\n");
	else if(a < 55 && b < 116)
		printf("D\n");
	else if(a < 70 && b < 148)
		printf("E\n");
	else
		printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 1036
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

//dijkstra
//参考：http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/26/dijkstra-copy.html

const long long MXV = 100000;//変更可
vector<edge> G0[MXV],G1[MXV];
vector<long long> d0(MXV, INF);

void dijkstra0(int s){
    priority_queue<P, vector<P>, greater<P>> pq;
    d0[s] = 0;
    pq.push(P(0, s));
    while(pq.size()){
        P p = pq.top();
        pq.pop();
        int V = p.second;
        if(d0[V] < p.first){
            continue;
        }
        rep(i,G0[V].size()){
            edge e = G0[V][i];
            if(d0[e.to] > d0[V] + e.cost){
                d0[e.to] = d0[V] + e.cost;
                pq.push(P(d0[e.to], e.to));
            }
        }
    }
}

vector<long long> d1(MXV, INF);

void dijkstra1(int s){
    priority_queue<P, vector<P>, greater<P>> pq;
    d1[s] = 0;
    pq.push(P(0, s));
    while(pq.size()){
        P p = pq.top();
        pq.pop();
        int V = p.second;
        if(d1[V] < p.first){
            continue;
        }
        rep(i,G1[V].size()){
            edge e = G1[V][i];
            if(d1[e.to] > d1[V] + e.cost){
                d1[e.to] = d1[V] + e.cost;
                pq.push(P(d1[e.to], e.to));
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,S,T;
    cin >> N >> M >> S >> T;
    S--;T--;
    rep(i,M){
        int u,v;
        cin >> u >> v;
        u--;v--;
        int a,b;
        cin >> a >> b;
        G0[u].pb({v,a});
        G0[v].pb({u,a});
        G1[u].pb({v,b});
        G1[v].pb({u,b});
    }
    dijkstra0(S);
    dijkstra1(T);
    vl ans(N);
    ll res=-INF;
    rrep(i,N){
        chmax(res,1000000000000000-d0[i]-d1[i]);
        ans[i]=res;
    }
    rep(i,N){
        cout << ans[i] << '\n';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

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

using namespace std;

int main(){
	long long W, H, x, y;
	scanf("%lld%lld%lld%lld", &W, &H, &x, &y);
	
	printf("%.10f", (double)W*H/2.0);
	
	if(x*2 == W && y*2 == H){
		printf(" 1");
	}else{
		printf(" 0");
	}
}


Measured memory_bytes: 256
N = int(input())
a = [list(map(int, input().split())) for i in range(2)]
goukei = []

for i in range(N):
    goukei_part = 0
    goukei_part = sum(a[0][:i+1]) + sum(a[1][i:])
    goukei.append(goukei_part)

print(max(goukei))


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

int main() {
	int X = 0, max_v = 0, N;
	string S;
	cin >> N >> S;
	for (int i = 0; i < N; i++) {
		X = S[i] == 'I'? X + 1 : X - 1;
		max_v = X > max_v ? X : max_v;
	}
	cout << max_v;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int H,N;
    cin >> H >> N;
    for (int i = 0; i < N;i++){
        int a;
        cin>>a;
        H -= a;
    }
    if(H<=0){
        puts("Yes");
    }  else{
        puts("No");
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      int A, B, numOfPalindromic = 0;
      Scanner sc = new Scanner(System.in);
      A = sc.nextInt(); B = sc.nextInt();

      for(; A<=B; A++) if ((A/10000 == A%10) && ((A/1000)%10 == (A/10)%10)) numOfPalindromic++;
      System.out.println(numOfPalindromic);
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  
  cin>>n;
  
  map<string,int> m;
  
  for(int i=0;i<n;i++)
  {
    string a;
   
    cin>>a;
    
    m[a]++;
  }
  
  int k=0;
  
  for(auto it=m.begin();it!=m.end();++it)
  {
    k++;
  }
  
  cout<<k;
  
  return 0;
}


Measured memory_bytes: 19176
import java.util.Arrays
import java.util.ArrayList

const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val cntprime: MutableMap<Int, Int> = mutableMapOf()

    for (i in 2..n) {
        val p = prime_fact(i)
        for ((k, v) in p) {
            cntprime[k] = cntprime.getOrElse(k, {0}) + v
        }
    }

    var res = 1L
    for ((k, v) in cntprime) {
        res = (res * (v+1)) % MOD
    }
    println(res)
}

fun primes(n: Int) : IntArray {
    /** Return a list of primes not more than n **/
    val primes: ArrayList<Int> = arrayListOf()

    val isPrime = Array(n+1, {true})
    for (i in 2..n) {
        if (isPrime[i]) {
            primes.add(i)
            var buf = i * 2
            while (buf <= n) {
                isPrime[buf] = false
                buf += i
            }
        }
    }
    return primes.toIntArray()
}

fun prime_fact(n: Int) : Map<Int, Int> {
    /** Return a map of the numbers of prime factors **/
    var cntprime: MutableMap<Int, Int> = mutableMapOf()

    var m = n
    for (i in primes(Math.sqrt(n.toDouble()).toInt())) {
        while (m % i == 0) {
            cntprime[i] = cntprime.getOrElse(i, {0}) + 1
            m /= i
        }
    }
    if (m != 1) {
        cntprime[m] = 1
    }

    return cntprime
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

int solve1();void solve2();
int main(){
  cout<<solve1();
  return 0;
}

int solve1(){

  string s;
  cin>>s;
  if(s=="SAT")return 1;
  if(s=="FRI")return 2;
  if(s=="THU")return 3;
  if(s=="WED")return 4;
  if(s=="TUE")return 5;
  if(s=="MON")return 6;
  if(s=="SUN")return 7;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        lower, upper = [], []
        i = 1
        while i * i <= n:
            if n % i == 0:
                lower.append(i)
                if i != n // i:
                    upper.append(n // i)
            i += 1
        return lower + upper[::-1]

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


def solve():
    N = Scanner.int()
    S = defaultdict(int)
    for _ in range(N):
        x = Scanner.string()
        S[x] += 1
    for s in ['AC', 'WA', 'TLE', 'RE']:
        print(s, "x", S[s])


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10736
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m,n,aa[110000],a,b,cnt=0,ab[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
pair<int,int> p[220000];
string s,ss[220000];
char c;
signed main(){
    cin>>n;
    cout<<ab[n-1];
}

Measured memory_bytes: 1920
//use proconio::{input, fastout};
use proconio::input;
use num::*;

const L: u64 = 1000000000000000000;

//#[fastout]
fn main() {
    input! {
        n: usize,
        mut d: [u64; n],
    }
    let lim = bigint::BigUint::from_u64(L).unwrap();
    let mut r = bigint::BigUint::from_u64(1).unwrap();
    d.sort();
    if d[0] == 0 {
        println!("0");
        return;
    }
    for a in d {
        r *= a;
        if r > lim {
            println!("-1");
            return;
        }
    }
    println!("{}", r);
}


Measured memory_bytes: 5424
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<lint>p(A),q(B),r(C);
  REP(i,A)cin>>p[i];
  REP(i,B)cin>>q[i];
  REP(i,C)cin>>r[i];
  sort(ALL(p),greater<lint>());
  sort(ALL(q),greater<lint>());
  sort(ALL(r));
  multiset<lint> P,Q;
  P.insert(p.begin(),p.begin()+X);
  Q.insert(q.begin(),q.begin()+Y);
  for(auto e:r){
    if(*P.begin()>*Q.begin()){
      if(*Q.begin()<e);
      Q.insert(e);
      Q.erase(Q.begin());
    }else{
      if(*P.begin()<e);
      P.insert(e);
      P.erase(P.begin());      
    }
  }
  lint ans=0;
  for(auto e:P)ans+=e;
  for(auto e:Q)ans+=e;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 11008
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayDeque<String> ans = new ArrayDeque<String>();

		while(sc.hasNext()){
			String s = sc.next();
			StringBuffer t = new StringBuffer(s);
			t.reverse();
			ans.push(t.toString());
		}
		int num = ans.size();
		for(int i=0;i<num;i++){
			System.out.println(ans.pollLast());
		}
	}
}

Measured memory_bytes: 17116
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

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

signed main()
{
   int n; cin >> n;
   V<int> a(n);
   REP(i, n) {
      cin >> a[i];
   }

   SORT(a);
   int maxA = a[n-1];

   V<P<int,int>> p(n-1);
   REP(i, n-1) {
      p[i] = MP(abs(maxA - 2*a[i]), i);
   }
   SORT(p);

   cout << maxA << " " << a[p[0].second] << endl;

   return 0;
}


Measured memory_bytes: 2560
<?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));

//座圧する・本質的ではないが、計算量がかなり際どいのでDPの長さを50から36に落とせるメリットは大きい
list($_, $fuku, $atsu) =$r= atsu(array_merge($A, $B));
foreach($A as $i => $a)$A[$i] = $atsu[$a]+1;
foreach($B as $i => $b)$B[$i] = $atsu[$b]+1;
$MAX = max($atsu)+1;

$dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
$dp[0][0] = 0;//どの数字も選んでいない状態の最大の数字は0としてよい
for($bit = 0, $NN = 1<<$N; $bit < $NN; ++$bit){
    $consumed = countBits($bit);
    $ords = [];
    $iter = $consumed;
    for($i = 0; $i < $N; ++$i)
        if(!($bit & (1<<$i)))//0のビットだけ実行
            $ords[$i] = $iter++;
    for($s = 0; $s <= $MAX; ++$s){
        if($dp[$bit][$s] == PHP_INT_MAX)continue;
        foreach($ords as $origPosition => $newPosition){
            $newNumber = ($origPosition - $consumed) & 1 ? $B[$origPosition] : $A[$origPosition];
            if($newNumber >= $s){//広義単調増加であればよい
                $newBits = $bit | (1<<$origPosition);
                chmin($dp[$newBits][$newNumber], $dp[$bit][$s] + abs($newPosition - $consumed));
            }
        }
    }
}
$min = min($dp[(1<<$N)-1]);
if($min == PHP_INT_MAX){
    echo -1;
}else{
    echo $min;
}

/**
 * ちょっと早くBitを数える -- 18回ループするより速い。
 **/
function countBits($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}

/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}

function chmax(&$a, $b){
    if($a < $b){
        $a = $b;
        return true;
    }
    return false;
}
function chmin(&$a, $b){
    if($a > $b){
        $a = $b;
        return true;
    }
    return false;
}

Measured memory_bytes: 690680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    ll ans=b/x;
    if(a%x==0){
        ans=ans-a/x+1;
    }
    else ans=ans-a/x;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int main()
{
	int n, num;
	cin >> n;
	vector<int> ans(n, 0);
	rep(i, n - 1) {
		cin >> num;
		ans[num - 1]++;
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"
 
int32_t main()
{
    boost;
    int h,n;
    cin>>h>>n;
    int s=0,tmp;
    for(int i=0;i<n;i++){
        cin>>tmp;
        s+=tmp;
    }
  if(s>=h)
    cout<<"Yes"<<endl;
   else
     cout<<"No"<<endl;
}

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


int main(){
    ll n;cin>>n;
    
    ll tx[14],txx[14];
    rep(i,0,13)tx[i]=(ll)pow(26,i);
    txx[0]=0;
    rep(i,1,13)txx[i]=txx[i-1]+tx[i];
    ll keta;
    if(n>=1&&n<=26){
        int N=n;
        char c='a' + N-1;
        cout<<c<<endl;
        return 0;
    }
    else{
        rep(i,1,13){
            if(n>=txx[i-1]+1&&n<=txx[i]){
                keta=i;
                n-=txx[i-1];
                break;
            }
        }
    }
    n--;
    for(ll i=keta-1;i>=0;i--){
        ll tmp=n/(ll)pow(26,i);
        if(tmp==0)cout<<'a';
        else{
            char c;
            if(i==0)c='a'+tmp;
            else c='a'+tmp;
        cout<<c;
        }
        n-=tmp*(ll)pow(26,i);
    }
    cout<<endl;
}

    









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

using namespace std;

int main()
{
	int a[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

	bool t[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			t[i][j] = false;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if (a[j][k] == b[i]) {
					t[j][k] = true;
				}
			}
		}
	}

	bool ok = false;
	ok |= t[0][0] && t[0][1] && t[0][2];
	ok |= t[1][0] && t[1][1] && t[1][2];
	ok |= t[2][0] && t[2][1] && t[2][2];
	ok |= t[0][0] && t[1][0] && t[2][0];
	ok |= t[0][1] && t[1][1] && t[2][1];
	ok |= t[0][2] && t[1][2] && t[2][2];
	ok |= t[0][0] && t[1][1] && t[2][2];
	ok |= t[2][0] && t[1][1] && t[0][2];
	
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))
mcnt = 0
for i in range(n):
  if lst[i] < 0:
    mcnt += 1
if 0 in lst or mcnt % 2 == 0:
  print(sum(list(map(abs, lst))))
  exit()
m = min(lst, key=abs)
print(sum(list(map(abs, lst))) - 2 * abs(m))

Measured memory_bytes: 20120
// Author : heyuhhh
// Created Time : 2020/09/13 21:37:08
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
void run() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<int> cntA(n), cntB(n);
    multiset<int> S;
    vector<vector<int>> G(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        --a[i];
        ++cntA[a[i]];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        --b[i];
        ++cntB[b[i]];
    }
    for (int i = 0; i < n; i++) {
        if (cntA[i] + cntB[i] > n) {
            cout << "No" << '\n';
            return;
        }
    }
    reverse(all(b));
    int l = n, r = -1, c = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] == b[i]) {
            l = i;
            c = a[i];
            break;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] == b[i]) {
            r = i;
            break;
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] != c && b[i] != c && l <= r) {
            swap(b[i], b[l]);
            ++l;
        }
    }
    cout << "Yes" << '\n';
    for (int i = 0; i < n; i++) {
        cout << b[i] + 1 << " \n"[i == n - 1];
    }
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 11068
import sys
from collections import deque

def topologicalSort():
    input = sys.stdin.readline
    V, E = map(int, input().split())
    Parent_node = [0 for _ in range(V)]
    Son_node = [set() for _ in range(V)]
    for _ in range(E):
        a, b = map(int, input().split()) #default: 0-indexed
        Son_node[a] |= {b}
        Parent_node[b] += 1

    stack = deque() #入次数が0のノードを格納する
    for i, p in enumerate(Parent_node):
        if p == 0: stack.append(i)

    sortedArray = []
    while stack:
        nowNode = stack.popleft()
        sortedArray.append(nowNode)
        for nextNode in Son_node[nowNode]:
            Parent_node[nextNode] -= 1
            if Parent_node[nextNode] == 0: stack.append(nextNode)

    for a in sortedArray: print(a)

    return len(sortedArray) == V

if __name__ == "__main__":
    topologicalSort()


Measured memory_bytes: 11576
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define vbi vector<bool> 
#define mod 1000000007
#define INF 1000000000
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define ms(x,v) memset(x,v,sizeof x)
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
ll i,j;
bool f(pair<long int,long int> p1,pair<long int,long int>p2){
  if(p1.ft==p2.ft) return p1.sd>p2.sd;
  else return p1<p2;
}
int main(){
  
  ll n; cin>>n;
  cout<<(int)(pow(n,3)+.5)<<endl;


return 0;
}
 

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
constexpr int kMaxW = 1e5;
typedef long long LL;

LL dp[101][kMaxW] = {};

int main() {
  int N, W; cin >> N >> W;
  for (int i = 0; i < N; ++i) {
    LL w, v; cin >> w >> v;
    for (int j = 0; j < w ; ++j) dp[i + 1][j] = dp[i][j];
    for (int j = 0; j + w <= W ; ++j) dp[i + 1][j + w] = max(dp[i][j + w], dp[i][j] + v);
  }

  LL vmax = 0;
  for (int i = 0; i <= W; ++i) {
    vmax = max(vmax, dp[N][i]);
  }
  cout << vmax << endl;
}


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

#define ll long long

#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    int a,p; cin>>a>>p;
  	p += a*3;
  	int ans;
  	if(p!=0){
      printf("%d\n",p/2);
    }else{
      printf("0");
    }
    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d
import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    N = int(input())

    ans = 0
    i = 1
    while i * i <= N:
        if N % i == 0:
            opo1 = i - 1
            if opo1 > 0 and N // opo1 == N % opo1:
                ans += opo1
            opo2 = N // i - 1
            if opo2 > 0 and N // opo2 == N % opo2:
                ans += opo2

        i += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <algorithm>
#include <math.h>
#include <string>
#define pi 3.1415926535897932384626
#include <cmath>
#define test(t) while(t--)

#define ll  long long int

#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define pb push_back
#define fast()  ios_base::sync_with_stdio(false);cin.tie(0);
#define double long double

using namespace std;
ll form(ll n){
return (n*(n+1))/2;
}
ll exponent(ll base, ll power){
   ll res = 1;
  ll m = 1000000007;
   while(power){
    if(power&1)
        res = (res*base)%m;
    base= (base*base)%m;
    power=power>>1;
   }
return res;}
bool count_one(ll n){
    ll cnt = 0;
    while(n>0){
            cnt+=1;
       n= n&(n-1);

    }
    if(cnt>1)
        return true;
    return false;
}
void solve()
{
  ll n,k;
   in n>>k;
   ll a[n];
   for(ll i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n);
   ll ans=0;
   ans=accumulate(a,a+k,ans);
   out ans<<en;
}




int main(){ fast()
             //freopen("input.txt","r",stdin);
             //freopen("output.txt","w",stdout);
             ll t=1;
            //cin>>t;
            test(t){
            solve();
            }
return 0;}


Measured memory_bytes: 3592
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

int my_abs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

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

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> solve(M);
    vector<string> aw(M);
    for (int i = 0; i < M; i++) {
        cin >> solve.at(i) >> aw.at(i);
    }
    vector<int> AC(N);
    vector<int> WA(N);
    int ansA = 0;
    int ansW = 0;
    for (int j = 0; j < M; j++) {
        if (AC.at(solve.at(j)-1) == 0 && aw.at(j) == "AC") {
            AC.at(solve.at(j)-1)++;
            ansA++;
          	if(WA.at(solve.at(j)-1) >= 1){
            	ansW = ansW + WA.at(solve.at(j)-1);
            }
        }
        if (AC.at(solve.at(j)-1) == 0 && aw.at(j) == "WA") {
            WA.at(solve.at(j)-1)++;
        }
    }

    cout << ansA << " " << ansW << endl;

}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  vector<vector<mint>> dp(2,vector<mint>(n+1));
  dp[0][0] = 1;
  rep(i,n){
    dp[0][i+1] = dp[0][i];
    dp[1][i+1] = dp[1][i] * 2 + dp[1][i];
    if(s[i]=='1') {
      dp[0][i+1] *= 2;
      dp[1][i+1] += dp[0][i];
    }
  }
  cout << (dp[0][n]+dp[1][n]) << endl;
}


Measured memory_bytes: 2816
K, A, B = map(int, input().split())

if B - A <= 2 or A + 1 > K:
    print(K + 1)
    exit()

K -= A - 1
res = A

res += (B - A) * (K // 2)

if K % 2 == 1:
    res += 1

print(res)


Measured memory_bytes: 3060
#include <iostream>

// using namespace std;

int main()
{
    while (true)
    {
        int x;
        std::cin >> x;
        if (x == 0)
        {
            break;
        }
        long sum = 0;
        long max = 0;
        long min = 1000;
        for (int i = 0; i < x; i++)
        {
            long j;
            std::cin >> j;
            max = std::max(max, j);
            min = std::min(min, j);
            sum += j;
        }
        sum -= (min + max);
        std::cout << sum / (x - 2) << std::endl;
    }
}


Measured memory_bytes: 3088
def find(S):
    MOD=10**9+7
    S=S[::-1]
    dp=[[0]*13 for i in range(len(S))]
    power=1
    if S[0]=="?":
        for i in range(10):
            dp[0][i]=1
    else:
        dp[0][int(S[0])]=1
    
    for i in range(1,len(S)):
        power*=10
        power%=13
        if S[i]=="?":
            for j in range(13):
                for k in range(10):
                    dp[i][j]+=dp[i-1][(j-power*k)%13]
                    dp[i][j]%=MOD
        else:
            for j in range(13):
                k=int(S[i])
                dp[i][j]+=dp[i-1][(j-power*k)%13]
                dp[i][j]%=MOD              
    return dp[-1][5]

S=input()
print(find(S))

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

typedef long long int ll;

int N, D;
vector<string> names;
//
//ll to_int(string s){
//    const int MOD = 1000000009;
//    ll res = 0;
//    for(auto c: s){
//        res = (res*26 + (c - 'a')) % MOD;
//    }
//    return res;
//}

void solve(){
    sort(names.begin(), names.end());
    
    map<string, set<int>> mp;
    for(int ni=0; ni<N; ni++){
        string name = names[ni];
        int L = name.size();
        
        //delete
        for(int i=0; i<L; i++){
            string t = name;
            t.erase(t.begin()+i);
            mp[t].insert(ni);
        }
        //insert
        for(int i=0; i<=L; i++){
            for(char c='a'; c<='z'; c++){
                string t = name;
                t.insert(t.begin()+i, c);
                mp[t].insert(ni);
            }
        }
        //replace
        for(int i=0; i<L; i++){
            for(char c='a'; c<='z'; c++){
                string t = name;
                t[i] = c;
                mp[t].insert(ni);
            }
        }
        //swap
        for(int i=0; i<L-1; i++){
            string t = name;
            swap(t[i], t[i+1]);
            mp[t].insert(ni);
        }
    }
    if(D == 1){
        int cnt = 0;
        for(int ni=0; ni<N; ni++){
            string name = names[ni];
            if(mp[name].size() > 1){
                for(auto v: mp[name]){
                    if(v <= ni) continue;
                    cout << name << "," << names[v] << endl;
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    if(D == 2){
        set<pair<int, int>> s;
        for(auto v: mp) if(v.second.size() > 1){
            vector<int> vec;
            for(auto vv: v.second) vec.push_back(vv);
            for(int i=0; i<vec.size(); i++){
                for(int j=i+1; j<vec.size(); j++){
                    s.insert(make_pair(vec[i], vec[j]));
                }
            }
        }
        for(auto v: s){
            cout << names[v.first] << "," << names[v.second] << endl;
        }
        cout << s.size() << endl;
    }

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while(cin>>N, N){
        cin >> D;
        names.resize(N);
        for(auto &v: names) cin >> v;
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 30944
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    prob = [tuple(map(int,input().split())) for _ in range(N)]
    
    if N == 2:
        ans = sum(r - l + 1 for l,r in prob)
        print(ans)
        return 

    #min_Rとmax_Lが同じグループにいる時
    max_L = 0
    min_R = INF
    cnt_max = 0 #L最大を満たすのが何個あるか
    cnt_min = 0 #R最小を満たすのが何個あるか
    for l,r in prob:
        if l == max_L:
            cnt_max += 1
        elif l > max_L:
            cnt_max = 1
            max_L = l
        if r == min_R:
            cnt_min += 1
        elif r < min_R:
            cnt_min = 1
            min_R = r
    
    if cnt_min > 1 and cnt_max > 1:
        max_diff = max(r - l for l,r in prob) + 1
    elif cnt_min > 1:
        max_diff = max(r - l for l,r in prob if l != max_L) + 1
    elif cnt_max > 1:
        max_diff = max(r - l for l,r in prob if r != min_R) + 1
    else:
        max_diff = max(r - l for l,r in prob if (r != min_R) and (l != max_L)) + 1
    
    ans1 = max_diff + max(min_R - max_L + 1,0)
    
    #min_Rとmax_Lが違うグループにいる時
    prob.sort(key = lambda x:(x[1],x[0]))
    cummax_L = prob[0][0]
    ans2 = 0
    for l,r in prob[1:]:
        ans2 = max(ans2,max(r - max_L + 1,0) + max(min_R - cummax_L + 1,0))
        cummax_L = max(cummax_L,l)

    print(max(ans1,ans2))
if __name__ == '__main__':
    main()


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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)


int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	ffor(i,0,n) cin>>a[i]>>b[i]>>c[i];
	int dp[n][3];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];

	ffor(i,1,n)
	{
		dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
		dp[i][2]=max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;
}

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

int main(){
	char s[105];
	cin >> s + 1;
	int len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		if(s[i] == '9'){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);int i,d;for(int[]a=new int[3];;){for(i=0;i<3;a[i]*=a[i],++i)a[i]=s.nextInt();Arrays.sort(a);if((d=a[0]+=a[1])<1)return;for(int t=s.nextInt(),r;t-->0;)System.out.println((r=s.nextInt()*2)*r>d?"OK":"NA");}}}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    ll s[(1<<n)];
    vector<ll> v;
    rep(i,0,(1<<n)){
        cin>>s[i];
        v.push_back(s[i]);
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<ll,ll> mp;
    rep(i,0,v.size())mp[v[i]]=i+1;
    rep(i,0,(1<<n))s[i]=mp[s[i]];
    ll y=v.size();
    ll cnt[y+1];
    fill(cnt,cnt+y+1,0);
    rep(i,0,(1<<n))cnt[s[i]]++;
    if(cnt[y]>=2){
        cout<<"No"<<endl;
        return 0;
    }
    queue<ll> q;
    q.push(y);
    ll now[y+1];
    fill(now,now+y+1,0);
    now[y]=1;
    ll mi=y-1;
    rep(i,0,n){
        multiset<ll> st;
        while(q.size()>0){
            ll ss=q.front();q.pop();
            st.insert(ss);
            if(mi==0){
                cout<<"No"<<endl;
                return 0;
            }
            ll u=mi;
            if(u>=ss){
                u=ss-1;
                while(u>0&&now[u]>=cnt[u])u--;
                if(u==0){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
            st.insert(u);
            now[u]++;
            
            while(now[mi]==cnt[mi])mi--;
        }
        for(auto itr=st.begin();itr!=st.end();itr++){
            q.push(*itr);
        }
    }
    rep(i,1,y+1){
        if(now[i]!=cnt[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 39280
N, Y = map(int, input().split())

resx, resy, resz = (-1, -1, -1)
xn = Y//10000
for x in range(xn+1):
    for y in range(N+1-x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

Measured memory_bytes: 3060