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

//関数プロトタイプ宣言
void moving_north(int *top, int *bottom, int *front, int *back);
void moving_south(int *top, int *bottom, int *front, int *back);
void moving_east(int *top, int *bottom, int *right_side, int *left_side);
void moving_west(int *top, int *bottom, int *right_side, int *left_side);

//ダイスの構造体
typedef struct{
	int top;
	int bottom;
	int right_side;
	int left_side;
	int front;
	int back;
}Dice;

int main(void)
{
	Dice dice1;

	//iはループ変数、input_directionは転がす方向
	int i;
	char input_direction[100];

	scanf("%d %d %d %d %d %d", 
		  &dice1.top, &dice1.front, &dice1.right_side, &dice1.left_side, &dice1.back, &dice1.bottom);

	scanf("%s", input_direction);

	//文字列の最後まで繰り返す
	for(i = 0; input_direction[i] != '\0'; i++){
		//各方向ごとに関数を呼び出す
		switch(input_direction[i]){
			case 'N':
				moving_north(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
				break;
			case 'S':
				moving_south(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
				break;
			case 'E':
				moving_east(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
				break;
			case 'W':
				moving_west(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
				break;
			default:
				break;
		}
	}

	//上の面を表示
	printf("%d\n",dice1.top);
	return 0;
}

//北側に転がす関数
void moving_north(int *top, int *bottom, int *front, int *back)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *front;
	*front = *bottom;
	*bottom = *back;
	*back = temp;
}

//南側に転がす関数
void moving_south(int *top, int *bottom, int *front, int *back)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *back;
	*back = *bottom;
	*bottom = *front;
	*front = temp;
}

//東側に転がす関数
void moving_east(int *top, int *bottom, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *left_side;
	*left_side = *bottom;
	*bottom = *right_side;
	*right_side = temp;
}

//西側に転がす関数
void moving_west(int *top, int *bottom, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *right_side;
	*right_side = *bottom;
	*bottom = *left_side;
	*left_side = temp;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    vector<vector<int>> c(3,vector<int> (3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    string ans = "Yes";
    if(!(c[0][0]-c[1][0]==c[0][1]-c[1][1]&&c[0][0]-c[1][0]==c[0][2]-c[1][2])) ans = "No";
    if(!(c[0][0]-c[2][0]==c[0][1]-c[2][1]&&c[0][0]-c[2][0]==c[0][2]-c[2][2])) ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
import Control.Monad
 
main = do
    [h, w] <- map read . words <$> getLine :: IO [Int]
    l <- replicateM h getLine
    let o = [replicate (w+2) '#'] ++ (map (\s -> "#" ++ s ++ "#") l) ++ [replicate (w+2) '#']
    mapM_ putStrLn o

Measured memory_bytes: 1404
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
using namespace std;
typedef pair<int,int> P;
const int INF = (int)((unsigned int)-1>>1) / 2;
const int MAX_N = 800;

struct edge{int to,cost;};

int n;
vector<vector<edge> > g;
vector<bool> is_node;

P dfs(int v, int par, int cost){
    P p = P(cost,v);
    for(int i=0;i<g[v].size();i++){
        edge e = g[v][i];
        if (e.to == par || !is_node[e.to])continue;
        p = max(p, dfs(e.to, v, cost+e.cost));
    }
    return p;
}

int main(){
    while(1){
        cin >> n;
        if (n==0) break;

        g.clear();
        g.resize(n);
        is_node.clear();
        is_node.resize(n);

        vector<int> p(n);
        vector<int> d(n);
        int cost_sum = 0;
        for(int i=0;i<n-1;i++){
            scanf("%d", &p[i]);
        }
        for(int i=0;i<n-1;i++){
            scanf("%d", &d[i]);
            cost_sum += d[i];
        }
        for(int i=0;i<n-1;i++){
            g[p[i]-1].push_back((edge){i+1,d[i]});
            g[i+1].push_back((edge){p[i]-1,d[i]});
        }

        int inner_sum = cost_sum;
        for(int i=0;i<n;i++){
            if(g[i].size()==1){
                inner_sum -= g[i][0].cost;
                is_node[i] = false;
            }else{
                is_node[i] = true;
            }
        }

        int longest_path = 0;
        for(int i=0;i<n;i++){
            if(is_node[i]){
                longest_path = dfs(dfs(i,-1,0).second,-1,0).first;
                break;
            }
        }

        cout << cost_sum+2*inner_sum-longest_path << endl;
    }
    return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a'||c == 'o'||c == 'e'||c == 'u'||c == 'i') {
    cout << "vowel" <<endl;
  }
  else {
    cout << "consonant" <<endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> x(n),y(n);
    rep(i,n){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(all(y));
    rep(i,n){
        if(x[i]<y[n/2]) cout<<y[n/2]<<" ";
        else cout<<y[n/2-1]<<" ";
    }
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	string S, T; cin >> S >> T;
	T.pop_back();
	if(S == T){
		cout << "Yes" << ln;
	} else {
		cout << "No" << ln;
	}
}


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

/* 入力 */
int D; //D:'D'とかくことができる最大個数
int x; //x:空欄1マスな数
char a[30]; //a[i]:i番目の正答
int p[30]; //p[i]:i番目の配点
int y; //y:空欄2マスな数
char b[30], c[30]; //b[i],c[i]:i番目の正答
int q[30]; //q[i]i番目の配点
/* おわり */

int dp[14][20][2];

int rec( int mul, int idx, bool one){ //残りＤ個数, 今のところ, 空欄1マスか
  if(~dp[mul][idx][one]) return dp[mul][idx][one];
  int ret = 0;
  if(one){
    if(idx == x) ret = rec( mul, 0, !one); //空欄2マスのやつ
    else{
      ret = rec( mul, idx + 1, one);
      if(mul > 0 && a[idx] == 'D') ret = max( ret, rec( mul - 1, idx + 1, one) + p[idx]);
    }
  }else{
    if(idx == y) return 0;
    else{
      ret = rec( mul, idx + 1, one);
      if(mul > 1 && b[idx] == 'D' && c[idx] == 'D') ret = max( ret, rec( mul - 2, idx + 1, one) + q[idx]);
    }
  }
  return dp[mul][idx][one] = ret;
}
int main(){
  fill_n( **dp, 14 * 20 * 2, -1);
  cin >> D >> x;
  for(int i = 0; i < x; i++){
    cin >> a[i] >> p[i];  
  }
  cin >> y;
  for(int i = 0; i < y; i++){
    cin >> b[i] >> c[i] >> q[i];
  }
  cout << rec( D, 0, true) << endl;
  return(0);
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(){
	while(1){
		int h, w; cin >> h >> w;
		if (h + w == 0) break;
		int taikaku = h * h + w * w;
		int larger_min = 10000000;
		int ansh = h,answ = w;
		int f = 0;
		//cout << "taikaku = " << taikaku << endl;
		for (int i = 1; i <= 150; i++){	
			for (int j = i + 1; j <= 150; j++){
				int T = i * i + j * j;
				//if (i > h and j > w)break; //?????§?¶????
				//cout << "i = " << i << " j = " << j << endl;
				if (T > taikaku){
					//cout << "i = " << i << " j = " << j << endl;
					//cout << "T = " << T  << endl;
					//cout << "hoge" << endl;
					if (larger_min > T){
						larger_min = T;
						ansh = i;
						answ = j;
					}else if (larger_min == T and ansh > i){
						larger_min = T;
						ansh = i;
						answ = j;
					}
				}else if (T == taikaku and i != h and j != w and  h < i and f == 0){
					//cout << "i = " << i << " j = " << j << endl;
					//cout << "T = " << T  << endl;
						//cout << "hoge" << endl;
						larger_min = T;
						ansh = i;
						answ = j;
						f = 1;
				}
			}	
		}
		cout << ansh << " " << answ << endl; 
	}
return 0;
}

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

using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x) { cout << setprecision(16) << x << endl; }
template<class T, class... A> void print(const T& first, const A& ... rest) { cout << first << " "; print(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;


int main() {
	string S;
	string T;
	
	cin >> S;
	cin >> T;

	vector<ull> posS[26];

	REP(i, S.length()) {
		posS[S[i] - 'a'].push_back(i);
	}

	//2周させておく
	REP(i, 26) {
		auto& p = posS[i];
		auto tmp = p;
		for (auto p2 : tmp) {
			p.push_back(p2 + S.length());
		}
	}

	ull pos = 0;
	REP(i, T.length()) {
		auto& v = posS[T[i] - 'a'];
		if (0 == v.size()) {
			print(-1);
			return 0;
		}

		auto ppos = pos % S.length();
		auto it = lower_bound(v.begin(), v.end(), ppos);
		pos += *it - ppos + 1;
	}

	print(pos);
	return 0;
}


Measured memory_bytes: 3524
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	string s,t;
	cin >> s >> t;
	sort(ALL(s));
	sort(ALL(t),greater<char>());
	for(int i=0;i<s.size()&&i<t.size();i++)
	{
		if(s[i]>t[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(s[i]<t[i])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(s.size()<t.size())
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    final int N=sc.nextInt();
    final int K=sc.nextInt();
    final String S=sc.next();
    char[] s=S.toCharArray();
    switch(s[K-1]){
      case 'A':
        s[K-1]='a';
        break;
      case 'B':
        s[K-1]='b';
        break;
      case 'C':
        s[K-1]='c';
        break;
    }
    System.out.println(String.valueOf(s));
  }
}

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

int main()
{
  int N;
  cin >> N;
  bool ok = false;
  for (int i = 1; i < 10; i++)
  {
    for (int j = 1; j < 10; j++)
    {
      if (i * j == N)
      {
        ok = true;
        break;
      }
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int l,r,d;
    cin >> l >> r >> d;

    int ans = 0;

    for(int i = l; i <= r; i++){
        if(i % d == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3564
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {

	int n,m,count=0;
	cin>> n >>m;
	vector<int>v;
	for(int i=0;i<m;i++){
		int h;
		cin>>h;
		v.push_back(h);
		count += v[i];
	}
	if(count > n)
	cout<<"-1"<<endl;

	else
	cout<<n-count<<endl;
	return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll x, y;
    cin >> x >> y;
    loop(i, x + 1)
    {
        ll a = i, b = x - i;
        if (a * 2 + b * 4 == y)
        {
            putout("Yes");
            return 0;
        }
    }
    putout("No");
    return 0;
}


Measured memory_bytes: 3636
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
#define iter(i, j) for(auto i = j.begin(); i != j.end(); ++i)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end()  
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IMAX std::numeric_limits<int>::max()
#define IMIN std::numeric_limits<int>::min()
using namespace std;

int main()
{
	int n; cin >> n;
	ll s = 0;
	vll a(n); rep(i, n) { cin >> a[i]; s ^= a[i]; }
	rep(i, n) cout << (a[i] ^ s) << " ";
	return 0;
}


Measured memory_bytes: 4328
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	key, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	A := make(map[int]int)
	B := make(map[int]int)
	for i := 0; i < N; i++ {
		if i%2 == 0 {
			A[sc.nextInt()]++
		} else {
			B[sc.nextInt()]++
		}
	}
	valA := []Val{}
	for key, count := range A {
		valA = append(valA, Val{key, count})
	}
	sort.Sort(ByNum(valA))
	valB := []Val{}
	for key, count := range B {
		valB = append(valB, Val{key, count})
	}
	sort.Sort(ByNum(valB))
	aMax := valA[len(valA)-1]
	bMax := valB[len(valB)-1]
	if aMax.key != bMax.key {
		fmt.Fprintln(wtr, N-aMax.num-bMax.num)
	} else {
		var aMax2, bMax2 int
		if len(valA) != 1 {
			aMax2 = valA[len(valA)-2].num
		} else {
			aMax2 = 0
		}
		if len(valB) != 1 {
			bMax2 = valB[len(valB)-2].num
		} else {
			bMax2 = 0
		}
		mi := min(N-aMax.num-bMax2, N-bMax.num-aMax2)
		fmt.Fprintln(wtr, mi)
	}

	wtr.Flush()
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, x, cnt = 0;
    cin >> n >> x;
    int arr[n];
    for(int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr+n);
    for(int i = 0; i < n; i++) {
        if(x - arr[i] >= 0) {
            cnt++;
            x -= arr[i];
        } else break;
    }
    if(x > 0 && cnt == n) cnt--;
    cnt = max(cnt, 0);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3652
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    H, W = read_ints()
    last_S = ''
    INF = 10**9+1
    dist = [
        [INF for _ in range(H*W)] for _ in range(H*W)
    ]
    for i in range(H*W):
        dist[i][i] = 0
    for i in range(H):
        S = input().strip()
        for j in range(W):
            if S[j] == '#':
                continue
            top = (i-1)*W+j
            left = i*W+j-1
            current = i*W+j
            if j > 0 and S[j-1] == '.':
                dist[left][current] = dist[current][left] = 1
            if i > 0 and last_S[j] == '.':
                dist[top][current] = dist[current][top] = 1
        last_S = S
    for k in range(H*W):
        for i in range(H*W):
            for j in range(H*W):
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
    return max(cell for row in dist for cell in row if cell != INF)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 77880
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll x;
    cin >> n >> x;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector <int> dp(n, 1e9);
    ll ans = 1e18;
    for (int st = 0; st < n; st++)
    {
        ll sum = 0;
        for (int i = 0; i < n; i++)
        {
            dp[i] = min(dp[i], a[(i - st + n) % n]);
            sum += dp[i];
        }
        ans = min(ans, x * st + sum);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
int main(){
	ll K;
	ll ans=0;
	scan(K);
	rep1(a,K){
		rep1(b,K){
			rep1(c,K){
				ans+=gcd(a,gcd(b,c));
			}
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = max(a+b, max(a-b, a*b));

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
finput=lambda:sys.stdin.readline().strip()

def main():
    p=10**9+7
    n=int(finput())
    a=list(map(int,finput().split()))
    k=sum(a)-(n*(n+1))//2
    pk=[i for i in range(n+1) if a[i]==k]
    fact=[1]*(n+2)
    ifact=[1]*(n+2)
    for i in range(1,n+2):
        fact[i]=fact[i-1]*i % p
    a=fact[-1]
    inv=1
    m=p-2
    while m>0:
        if m&1:
            inv=a*inv % p
        m>>=1
        a=a*a % p
    ifact[-1]=inv
    for i in range(n+1,0,-1):
        ifact[i-1]=ifact[i]*i % p
    ans0=[0]*(n+2)
    ans1=[0]*(n+2)
    ans2=[0]*(n+2)
    for i in range(n):
        ans0[i]=fact[n-1]*ifact[n-i-1]*ifact[i]%p
        ans1[i+1]=ans0[i]*2
        ans2[i+2]=ans0[i]
    sn=pk[0]+n-pk[1]
    for i in range(sn+1):
        ans1[i+1]-=fact[sn]*ifact[sn-i]*ifact[i] % p
    for i in range(1,n+2):
        print((ans0[i]+ans1[i]+ans2[i]) % p)

if __name__=='__main__':
    main()


Measured memory_bytes: 26028
var a:array[1..100010]of integer;
    n,i,j,m,mabs:integer;
    ans:int64;
    zero:boolean;
begin
  readln(n);
  m:=0;
  zero:=false;
  mabs:=100000010;
  for i:=1 to n do begin
    read(a[i]);
    if mabs>abs(a[i]) then 
      mabs:=abs(a[i]);
    if a[i]<0 then inc(m);
    if a[i]=0 then zero:=true
  end;
  ans:=0;
  for i:=1 to n do 
    if a[i]>0 then inc(ans,a[i])
    else inc(ans,-a[i]);
  if (m mod 2<>0) and not zero then
    ans:=ans-2*mabs;
  write(ans)
end.

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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)

//repetition
//------------------------------------------
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T> ostream & operator<<(ostream& os, vector<T> const& v){
        for(auto it=v.begin(); it!=v.end(); ++it){
            os << *it << (it+1==v.end() ? "" : ",");
        }
        return os;
    }
}

//clear memory
#define clr(a) memset((a), 0 ,sizeof(a))

int lcm(int a,int b){
   return a*b/__gcd(a,b);
}
 
vb pn((int)1e4+10); 
void prime_number(int n){
   fill(all(pn),true);
   pn[0]=false;pn[1]=false;
   loop(i,2,n/2+1){
      if(!pn[i]) continue;
      for(int j=2;i*j<=n;j++){
         pn[i*j]=false;
      }
   }
}

int main(){
   int n,ans,x,y,h,w;
   
   while(cin>>n){
      if(n==0) break; ans=0;
      
      rep(i,n){
         cin >> x >> y >> h >> w;
         if(x+y+h<61&&w<3) ans+=600;
         else if(x+y+h<81&&w<6) ans+=800;
         else if(x+y+h<101&&w<11) ans+=1000;
         else if(x+y+h<121&&w<16) ans+=1200;
         else if(x+y+h<141&&w<21) ans+=1400;
         else if(x+y+h<161&&w<26) ans+=1600;
         else continue;
      }
      
      cout<<ans<<endl;
   }
   
   return 0;
}

Measured memory_bytes: 1200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n, k; cin >> n >> k;
  int ans = 0;
  rep(i, n) {
    int xi; cin >> xi;
    ans += min(abs(xi - k), abs(xi)) * 2;
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 632
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int fac[(1 << 16) + 5],invfac[(1 << 16) + 5],inv[(1 << 16) + 5],N,M;
int A[25],f[(1 << 16) + 5],dp[17][(1 << 16) + 5],cnt[(1 << 16) + 5];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int lowbit(int x) {
    return x & (-x);
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= M ; ++i) read(A[i]);
    inv[1] = 1;
    for(int i = 2 ; i <= (1 << N) ; ++i) inv[i] = mul(inv[MOD % i],MOD - MOD / i);
    fac[0] = invfac[0] = 1;
    for(int i = 1 ; i <= (1 << N) ; ++i) {
	fac[i] = mul(fac[i - 1],i);
	invfac[i] = mul(invfac[i - 1],inv[i]);
    }
    sort(A + 1,A + M + 1);
    dp[0][0] = 1;
    for(int i = 1 ; i <= M ; ++i) {
	int t = M - i + 1;
	for(int S = 0 ; S < (1 << N) ; ++S) {
	    for(int j = 0 ; j < N ; ++j) {
		if(!(S >> j & 1)) {
		    update(dp[i][S ^ (1 << j)],mul(dp[i - 1][S],mul(C((1 << N) - A[t] - S,(1 << j) - 1),fac[1 << j])));
		}
	    }
	    update(dp[i][S],dp[i - 1][S]);
	}
    }
    int ans = 0;
    for(int S = 0 ; S < (1 << N) ; ++S) {
	if(S) cnt[S] = cnt[S - lowbit(S)] + 1;
	int t = mul(dp[M][S],fac[(1 << N) - 1 - S]);
	if(cnt[S] & 1) update(ans,MOD - t);
	else update(ans,t);
    }
    ans = mul(ans,1 << N);
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const string S4[4] = {"abcc", "abdd", "ccab", "ddab"};
const string S5[5] = {"abbcc", "ad..a", "bd..a", "b.eez", "oorrz"};
const string S6[6] = {"oorrzz", ".a.b.c", ".a.b.c", "d.e.f.", "d.e.f.", "oorrzz"};
const string S7[7] = {".oorrzz", "oabb...", "oa.c...", "rddc...", "r...abb", "z...a.c", "z...ddc"};

char s[1010][1010];

inline void solve(int&n, int x) {
	if(x == 4)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S4[i][j];
	if(x == 5)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S5[i][j];
	if(x == 6)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S6[i][j];
	if(x == 7)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S7[i][j];
	n += x;
}

int main() {
	int n = ri;
	if(n <= 2) return puts("-1"), 0;
	if(n == 3) {
		puts("a..");
		puts("a..");
		puts(".bb");
		return 0;
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			s[i][j] = '.';
	int x = n % 4, N = 1;
	if(x == 0) solve(N, 4);
	if(x == 1) solve(N, 5);
	if(x == 2) solve(N, 6);
	if(x == 3) solve(N, 7);
	while(N <= n) solve(N, 4);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			putchar(s[i][j]);
		puts("");
	}
	return 0;
}


Measured memory_bytes: 2176
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque,defaultdict

n,m = map(int,readline().split())
c = [set() for i in range(n)]
d = defaultdict(int)
for i in range(m+n-1):
  a,b = map(int,readline().split())
  a -= 1
  b -= 1
  c[a].add(b)
  d[b] += 1
  
ans = [0]*n
root = deque()
for i in range(n):
  if d[i] == 0:
    root.append(i)
    break
cnt = 1

while True:
  now = root.popleft()
  for nex in c[now]:
    d[nex] -= 1
    if d[nex] == 0:
      cnt += 1
      ans[nex] = now+1
      root.append(nex)
  if cnt == n:
    break
print(*ans,sep='\n')

Measured memory_bytes: 117648
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();

		ArrayList<Pair> pairs = new ArrayList<Pair>();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i = 0;i < n;i++){
			Pair pair = new Pair();
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			pair.from = a[i];
			pair.end = b[i];
			pair.num = 0;
			pairs.add(pair);
		}
		int[] c = new int[n];
		int[] d = new int[n];
		for(int i = 0;i < n;i++){
			Pair pair = new Pair();
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
			pair.from = c[i];
			pair.end = d[i];
			pair.num = 1;
			pairs.add(pair);
		}
		Collections.sort(pairs);

		//		for(int i = 0;i < pairs.size();i++){
		//			System.out.print(pairs.get(i).from + " " + pairs.get(i).end + " ");
		//			if(pairs.get(i).num == 0){
		//				System.out.println("Red");
		//			}else{
		//				System.out.println("Blue");
		//
		//			}
		//		}

		int ans = 0;
		for(int i = pairs.size()-1;i >= 0;i--){
			//System.out.println(i);

			if(pairs.get(i).num == 0){
				int x = pairs.get(i).from;
				int y  =pairs.get(i).end;

				int suby = 100000;
				int subx = 100000;
				for(int j = i+1;j < pairs.size() ;j++){					//ペアの更新
					if(pairs.get(j).num == 1){
						if(pairs.get(j).from > x && pairs.get(j).end > y && pairs.get(j).end < suby){
							suby = pairs.get(j).end ;
							subx = pairs.get(j).from;
						}
					}
				}
				if(suby != 100000){
					ans++;
					for(int j = i+1;j < pairs.size();j++){					//ペアの発見、削除
						if(pairs.get(j).num == 1){
							if(pairs.get(j).from == subx &&suby == pairs.get(j).end){
						//		System.out.println(pairs.get(j).from + " "+pairs.get(j).end);		
								pairs.remove(j);
								break;
							}
						}
					}
				}
				//System.out.println("suby "+suby);
				

			}
			
			//pairs.remove(pairs.size()-1);
		}
		System.out.println(ans);




	}



}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll INF = 1e9+7;
    ll MOD = 998244353;
    typedef pair<ll,ll> ii;
    #define f(i,a,b) for(long long i = a;i < b;i++)
    #define rf(i,a,b) for(long long i=a;i>=b;i--)
    #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define w(t) while(t--)
    #define c(n); cin>>n;
    #define p(n) cout<<n;
    #define pl(n) cout<<n<<endl;
    #define ps(n); cout<<n<<" ";
    #define F first
    #define S second
    #define pb(a) push_back(a)
    ///I hope I will get uprating and don't make mistakes
    ///I will never stop programming
    ///sqrt(-1) Love C++
    /// @TheofanisOrfanou Theo830
    ///AtCoder Beginner Contest 148
    int main(void){
        fastio;
        ll a,b;
        c(a);
        c(b);
        pl(6- (a+b));
    }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;
 
#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
 
typedef long long ll;
typedef long long int lli;
 
int main() {
    int A, B, K;
    vector<int> nums;
    cin >> A >> B >> K;
    int bigger = max(A, B);
    for (int i = 1; i <= bigger; i++) {
        if (A % i == 0 && B % i == 0) {
            nums.push_back(i);
        }
    }
    sort(nums.begin(), nums.end(), greater<int>());
    cout << nums.at(K - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;
  
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\n", prod));
  return 0;
}

Measured memory_bytes: 2464
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int n, l, r;
	cin >> n;
	int res = 0;
	REP(i, n) {
		cin >> l >> r;
		res += r - l + 1;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64

int main(){
    int x,a,b;
    cin >> x >> a >>b;
    if(b <= a) cout <<"delicious" << endl;
    else if( b <= a+x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
s = int(input())
a = [s]
for i in range(1000000):
    if a[i] % 2 == 0:
        x = a[i] // 2
    else:
        x = 3 * a[i] + 1
    if x in a:
        print(i + 2)
        exit()
    else:
        a.append(x)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
 
using namespace std;
 
typedef pair<int, int> pii;
typedef pair<int, pii> edge;
 
const int MAXN = 100005;
 
int n, m;
 
vector<int> v[MAXN];
priority_queue<pii, vector<pii>, greater<pii> > pq;
int dist[MAXN];
int prv[MAXN];
 
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b, d;
		scanf("%d%d", &a, &b);
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}	
 
	for (int i = 0; i < MAXN; i++) {
		dist[i] = 1 << 30;
		prv[i] = -1;
	}
	dist[0] = 0;
	pq.push(pii(0, 0));
	while (pq.size()) {
		int cur = pq.top().second;
		int dst = pq.top().first;
		pq.pop();
		if (dst != dist[cur]) continue;
		for (int i = 0; i < v[cur].size(); i++) {
			int nxt = v[cur][i];
			if (dist[nxt] > 1 + dist[cur]) {
				dist[nxt] = 1 + dist[cur];
				prv[nxt] = cur;
				pq.push(pii(dist[nxt], nxt));
			}
		}
	}
 
	for (int i = 1; i < n; i++) {
		if (dist[i] == 1 << 30) {
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");
	for (int i = 1; i < n; i++) {
		printf("%d\n", prv[i] + 1);
	}
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    long long x,y;
    cin>>x>>y;
    long long ans=0;
    while(y>=x){
        ans++;
        x*=2;
        
    }
    cout<<ans<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
counter = Counter(a)
ckey = list(counter.keys())
cval = list(counter.values())
ans = 0

for i in range(len(ckey)):
  if ckey[i]>cval[i]:
    ans+=cval[i]
  elif ckey[i]<cval[i]:
    ans+=cval[i]-ckey[i]
print(ans)

Measured memory_bytes: 18676
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;

int main()
{
    long long int N, x;
    cin >> N >> x;
    long long int a[N+1];//a[N]は予備
    cin >> a[0];
    a[N]=0;
    long int tmp=0;
    long long int ans=0;
    for(int i=1; i<N; i++){
        cin >> a[i];
        long int combi=a[i]+a[i-1];
        combi-=tmp;
        if(combi>x){
            if(combi-a[i]>x){
                tmp=a[i];
                ans+=tmp;
                ans=ans+(combi-a[i]-x);
            }else{
                tmp=combi-x;
                ans+=tmp;
            }
        }else{
            tmp=0;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

ans = 0
for i in make_divisors(N):
    if i > 1 and N // (i - 1)  == N % (i - 1):
        ans += i - 1

print(ans)

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

using namespace std;

int main() {
    int r, c;
    cin >> r >> c;
    vector<vector<int> > tbl(r, vector<int>(c));
    vector<int> row(r);
    vector<int> column(c);
    int sum = 0;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> tbl[i][j];
            row[i] += tbl[i][j];
            cout << tbl[i][j] << " ";
        }
        cout << row[i] << endl;
    }
    for (int j = 0; j < c; j++) {
        for (int i = 0; i < r; i++) {
            column[j] += tbl[i][j];
        }
        sum += column[j];
        cout << column[j] << " ";
    }
    cout << sum << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
vector<int> G[100000];
ll memo[100000][2];
ll solve(int v, int color, int p) {
	if (memo[v][color] != -1) return memo[v][color];
	ll ret = 1;
	for (int to : G[v]) {
		if (to == p) continue;
		ll t = solve(to, 1, v);
		if (color) (t += solve(to, 0, v)) %= MOD;
		(ret *= t) %= MOD;
	}
	return memo[v][color] = ret;
}
 int main() {
	 int N;
	 cin >> N;
	 for (int i = 0; i < N - 1; i++) {
		 int x, y;
		 cin >> x >> y;
		 x--; y--;
		 G[x].push_back(y);
		 G[y].push_back(x);
	 }
	 memset(memo, -1, sizeof(memo));
	 ll ans = solve(0, 0, -1);
	 (ans += solve(0, 1, -1)) %= MOD;
	 cout << ans << endl;
}

Measured memory_bytes: 15616
#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;

int n;
const int maxn = 10000000;
bool is[maxn];
int sum;
void f()
{
    memset(is , true , sizeof(is));
    is[0] = is[1] = false;
    int m = sqrt(maxn);
    for(int i = 2 ; i <= m ; i ++)
    {
        if(is[i])
        {
            for(int j = i * i ; j <= maxn ; j += i)
                is[j] = false;
        }
    }
}


int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    f();
    while(cin >> n)
    {
        sum = 0;
        for(int i = 0 ; i <= n ; i ++)
        {
            if(is[i])
                sum ++;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 10960
s=input()
t=input()

S=len(s)+1
T=len(t)+1

dp=[[0]*T for i in range(S)]

for i in range(1,S):
  for j in range(1,T):
    if s[i-1]==t[j-1]:
      dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1)
    dp[i][j] = max(dp[i][j],dp[i-1][j]) 
    dp[i][j] = max(dp[i][j],dp[i][j-1])
    
res=""
i=len(s)
j=len(t)
while i>0 and j>0:
  #(i-1,j)->(i,j)に更新した場合
  if dp[i][j] == dp[i-1][j]:
    i -= 1
  #(i,j-1)->(i,j)に更新した場合
  elif dp[i][j] == dp[i][j-1]:
    j -= 1
  #s[i]=t[j]であり、(i-1,j-1)->(i,j)に更新した場合
  else:
    res = s[i-1] + res
    i -= 1
    j -= 1
print(res)

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

using ll = long long;
using ull = unsigned long long;
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
    ll n;
    cin >> n;
    vector<vector<ll>> dp(n+1,vector<ll>(4));
    dp[0][0] = 1;
    rep(i,n){
        rep(j,4){
            if(j == 0){
                dp[i+1][j] = dp[i][j] * 8;
            }else if(j == 1){
                dp[i+1][j] = dp[i][j] * 9 + dp[i][0];
            }else if(j == 2){
                dp[i+1][j] = dp[i][j] * 9 + dp[i][0];
            }else{
                dp[i+1][j] = dp[i][j] * 10 + dp[i][1] + dp[i][2];
            }
            dp[i+1][j] %= mod;
        }
    }
    cout << dp[n][3] << endl;
}

Measured memory_bytes: 73240
k,a,b=map(int,input().split())
import sys

if k<a-1 or b-a <2:
  print(k+1)
  sys.exit()
if (k+1-a) %2 ==0:
  print(a+(b-a)*(k+1-a)//2)
else:
  print(a+(b-a)*((k-a)//2)+1)    


Measured memory_bytes: 9112