akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

struct camel {
    int k;
    ll l, r;
};

int main() {
    int T; cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<camel> train[n];
        int pos = 0;
        for (int i=0; i<n; i++) {
            camel c;
            cin >> c.k >> c.l >> c.r;
            c.k--;
            train[c.k].push_back(c);
            if (c.l > c.r) pos++;
        }
        ll ans = 0;

        auto pos_cmp = [](camel a, camel b) { return a.l - a.r < b.l - b.r; };
        priority_queue<camel, vector<camel>, decltype(pos_cmp)> pos_pq(pos_cmp);
        for (int i=n-1; i>=pos; i--) {
            for (auto &c:train[i])
                if (c.l > c.r)
                    pos_pq.push(c);
        }
        for (int i=pos-1; i>=0; i--) {
            for (auto &c:train[i])
                if (c.l > c.r)
                    pos_pq.push(c);
            if (!pos_pq.empty()) {
                ans += pos_pq.top().l;
                pos_pq.pop();
            }
        }
        while (!pos_pq.empty()) {
            ans += pos_pq.top().r;
            pos_pq.pop();
        }

        auto neg_cmp = [](camel a, camel b) { return a.r - a.l < b.r - b.l; };
        priority_queue<camel, vector<camel>, decltype(neg_cmp)> neg_pq(neg_cmp);
        for (int i=0; i<pos; i++) {
            for (auto &c:train[i])
                if (c.l <= c.r)
                    neg_pq.push(c);
        }
        for (int i=pos; i<n; i++) {
            if (!neg_pq.empty()) {
                ans += neg_pq.top().r;
                neg_pq.pop();
            }
            for (auto &c:train[i])
                if (c.l <= c.r)
                    neg_pq.push(c);
        }
        while (!neg_pq.empty()) {
            ans += neg_pq.top().l;
            neg_pq.pop();
        }
        
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 18048
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll N, A, B;
    cin >> N >> A >> B;
    
    cout << max(0LL, (((N - 1) * B + A) - (B + (N - 1) * A) + 1)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	HashMap<String, Integer> map = new HashMap<String, Integer>();
	String[] stations = {
			"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",
			"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"
	};
	
	public void run(){
		for(int i = 0; i < 52; i++){
			map.put(stations[i], i);
		}
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			calc(n);
		}
	}
	public void calc(int n){
		int[] k = new int[100];
		for(int i = 0; i < n; i++){
			k[i] = sc.nextInt();
		}
		
		String s = sc.next();
		int len = s.length();
		int knum = 0;
		
		for(int i = 0; i < len; i++){
			String sta = s.substring(i, i+1);
			int stanum = map.get(sta);
			stanum -= k[knum];
			if(stanum < 0) stanum += 52;
			
			System.out.print(stations[stanum]);
			
			knum++;
			if(knum == n) knum = 0;
		}
		
		System.out.println();
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 35228
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		int len=s.size();
		set<string> se;
		se.insert(s);
		for(int j=1;j<len;j++){
			string s1,s2;
			s1=s.substr(0,j);
			s2=s.substr(j,len-j);
			int l1=s1.size(),l2=s2.size();
			string s1r=s1,s2r=s2;
			for(int k=0;k<l1;k++){
				s1r[k]=s1[l1-k-1];
			}
			for(int k=0;k<l2;k++){
				s2r[k]=s2[l2-k-1];
			}
			se.insert(s1+s2r);
			se.insert(s1r+s2);
			se.insert(s1r+s2r);
			se.insert(s2+s1);
			se.insert(s2r+s1);
			se.insert(s2+s1r);
			se.insert(s2r+s1r);
		}
		cout<<se.size()<<endl;
	}

    return 0;
}

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

const ll INF = ll(1e18) + 1;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll l = -INF, r = INF;
  while (l + 1 < r) {
    ll x = (l + r) / 2;
    bool ok = [&] {
      ll tot = 0;
      rep(i, n) {
        if (a[i] < 0) {
          int l = -1, r = n;
          while (l + 1 < r) {
            int c = (l + r) / 2;
            if (a[c] * a[i] < x)
              r = c;
            else
              l = c;
          }
          tot += n - r;
        } else {
          int l = -1, r = n;
          while (l + 1 < r) {
            int c = (l + r) / 2;
            if (a[c] * a[i] < x)
              l = c;
            else
              r = c;
          }
          tot += r;
        }
        if (a[i] * a[i] < x) tot--;
      }
      tot /= 2;
      return tot < k;
    }();
    if (ok)
      l = x;
    else
      r = x;
  }
  cout << l << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  bool flag = true;
  int p = h[0] - 1;
  for (int i = 1; i < n; i++) {
    if (h[i] >= p + 1) {
      p = h[i] - 1;
    }
    else if (h[i] >= p) {
      p = h[i];
    }
    else {
      flag = false;
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, k; std::cin >> n >> k;
    std::vector<int> v(n);
    for (int i = 0; i < n; i++) std::cin >> v[i];
    std::vector<int> buf;
    int ans = 0;
    for (int t = 1; t <= k; t++) {
        for (int i = 0; i <= t; i++) {
            int j = n - t + i - 1;
            if (j < i) continue;
            buf.clear();
            for (int b = 0; b < i; b++) buf.push_back(v[b]);
            for (int b = n - 1; b > j; b--) buf.push_back(v[b]);
            int s = std::accumulate(buf.begin(), buf.end(), 0);
            std::sort(buf.begin(), buf.end());
            for (int b = 0; b < std::min(t, k - t); b++) {
                if (buf[b] >= 0) break;
                s -= buf[b];
            }
            ans = std::max(ans, s);
        }
    }
    if (k >= n) {
        int s = std::accumulate(v.begin(), v.end(), 0);
        for (int b = 0; b < std::min(n, k - n); b++) {
            if (v[b] >= 0) break;
            s -= v[b];
        }
        ans = std::max(ans, s);
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
from math import gcd

def solve():
  K = int(input())
  ans = 0
  for i in range(1, K+1):
      for j in range(1, K+1):
          a = gcd(i, j)
          for k in range(1, K+1):
            ans += gcd(a, k)
  return ans
                
print(solve())

Measured memory_bytes: 9180
import java.io.*;
import java.util.*;

class Main{
  public static Scanner cin;
  public static HashSet<String> m;

  public static String reverse(String s){
    return new StringBuilder(s).reverse().toString();
  }

  public static void main(String []args){
    cin=new Scanner(System.in);
    int j=0,n=cin.nextInt();
    cin.nextLine();
    for(;j<n;j++){
    String s=cin.nextLine();
    m=new HashSet<String>();
    int i=1;
    for(;i<s.length();i++){
      String s1=s.substring(0,i),s2=s.substring(i),r1=reverse(s1),r2=reverse(s2);
      m.add(s1+s2);
      m.add(r1+s2);
      m.add(s1+r2);
      m.add(r1+r2);
      m.add(s2+s1);
      m.add(r2+s1);
      m.add(s2+r1);
      m.add(r2+r1);
    }
    System.out.println(m.size());
    }
  }
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = (new BufferedReader(new InputStreamReader(System.in)));
		StringBuilder sb = new StringBuilder();
		String line;
		br.readLine();
		while ((line = br.readLine()) != null) {
			String[] xyz = line.split(" ");
			int a = Integer.parseInt(xyz[0]);
			int b = Integer.parseInt(xyz[1]);
			int c = Integer.parseInt(xyz[2]);

			if (a > b && a > c) {
				sb.append(printIsRightTriangle(a, b, c));
			} else if (b > a && b > c) {
				sb.append(printIsRightTriangle(b, a, c));
			} else if (c > a && c > b) {
				sb.append(printIsRightTriangle(c, b, a));
			} else {
				sb.append(printIsRightTriangle(a, b, c));
			}
		}
		System.out.print(sb.toString());
	}

	public static String printIsRightTriangle(int long_value, int short_value1, int short_value2) {
		if ((long_value * long_value) == (short_value1 * short_value1 + short_value2 * short_value2)) {
			return "YES\n";
		} else {
			return "NO\n";
		}

	}
}

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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

const ll INF = 1LL << 60;
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; }

/*
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
*/

int dp[3010][3010] = { 0 };
char ans[3010];
void Main()
{
	string s, t;
	cin >> s >> t;

	rep2(i, 1, SZ(s) + 1) {
		rep2 (j, 1, SZ(t) + 1) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}

	int len = dp[SZ(s)][SZ(t)] - 1;
	if (len < 0) {
		cout << "";
		return;
	}
	int i = SZ(s);
	int j = SZ(t);
	while (len >= 0) {
		if (s[i - 1] == t[j - 1]) {
			ans[len] = s[i - 1];
			i--;
			j--;
			len--;
		}
		else if (i > 1 && dp[i][j] == dp[i - 1][j]) {
			i--;
		}
		else {
			j--;
		}
	}
	len = dp[SZ(s)][SZ(t)];
	string answer(ans, ans + len);
	cout << answer;
	return;
}

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

Measured memory_bytes: 38904
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  cout << (ll)pow(n, 3) << newl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
    int a[3];
    int i,j,v, cost;
    int aa[3][3];
    for (i=0;i<3;i++) {
        scanf("%d", &a[i]);
    }

    for (i=1;i<3;i++) {
        v = a[i];
        j = i-1;
        while (j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
    }

    if (abs(a[1]-a[0])>=abs(a[2]-a[1]) && abs(a[1]-a[0])>=abs(a[0]-a[2])){
        cost = abs(a[1]-a[0])+abs(a[2]-a[1]);
    }

    if (abs(a[2]-a[1])>=abs(a[1]-a[0]) && abs(a[2]-a[1])>=abs(a[0]-a[2])) {
        cost = abs(a[1]-a[2])+abs(a[0]-a[1]);      
    }

    if (abs(a[0]-a[2])>=abs(a[2]-a[1]) && abs(a[0]-a[2])>=abs(a[1]-a[0])) {
        if (abs(a[0]-a[1])<abs(a[2]-a[1])) {
             cost = abs(a[1]-a[2])+abs(a[0]-a[1]);       
        } else {
             cost = abs(a[1]-a[0])+abs(a[2]-a[1]);
        }

    }
    


    printf("%d\n", cost);
    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int dp[100010][3][3][2]; // k: 0->left, 1->right

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

    string s;
    while (cin >> s, s[0] != '#') {

        if (s.size() <= 2) {
            cout << 0 << endl;
            continue;
        }

        int N = s.size();
        V a(N);
        rep(i, N) a[i] = (s[i] - '1') % 3;



        const int INF = 1e9;
        rep(i, N) rep(l, 3) rep(r, 3) rep(k, 2) dp[i][l][r][k] = INF;

        if (a[0] <= a[1]) dp[1][a[0]][a[1]][1] = 0;
        if (a[1] <= a[0]) dp[1][a[1]][a[0]][0] = 0;

        rep2(i, 2, N) {
            rep(l, 3) {
                rep(r, 3) {
                    rep(k, 2) {
                        // left
                        if (a[i] <= r) {
                            dp[i][a[i]][r][0] = min(dp[i][a[i]][r][0], dp[i - 1][l][r][k] + (k == 0));
                        }
                        // right
                        if (a[i] >= l) {
                            dp[i][l][a[i]][1] = min(dp[i][l][a[i]][1], dp[i - 1][l][r][k] + (k == 1));
                        }
                    }
                }
            }
        }


        int ans = INF;
        rep(l, 3) rep(r, 3) rep(k, 2) ans = min(ans, dp[N - 1][l][r][k]);
        cout << ans << endl;
    }
}

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

int main(){
  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  vector<pair<double,pair<int,int>>> vec;
  for(int a=0;a*A*100<=F;a++){
    for(int b=0;a*A*100+b*B*100<=F;b++){
      for(int c=0;(c*C<=(A*a+B*b)*E)&(a*A*100+b*B*100+c*C<=F);c++){
        for(int d=0;(d*D<=(A*a+B*b)*E-c*C)&(a*A*100+b*B*100+c*C+d*D<=F);d++){
        	vec.push_back(make_pair((double)100*(c*C+d*D)/(a*A*100+b*B*100+c*C+d*D),make_pair(a*A*100+b*B*100+c*C+d*D,c*C+d*D)));
        }
      }
    }
  }
  
  sort(vec.begin(),vec.end());
  auto it=vec.end();
  it--;
  cout << it->second.first << " " << it->second.second << endl;
}

Measured memory_bytes: 17256
N = int(input())
S = input()
ans = S

leftStack = []
for i in range(len(S)):
    s = S[i]
    if s == "(":
        leftStack.append(s)
    elif s == ")":
        if len(leftStack) > 0:
            leftStack.pop()
        else:
            ans = "(" + ans

for i in range(len(leftStack)):
    ans = ans + ")"
print(ans)

Measured memory_bytes: 3064
#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 <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int a, b, k;
    cin >> a >> b >> k;

    vector<int> factors;
    for(int i=1; i<=min(a, b); i++)
    {
        if(a % i == 0 && b % i == 0)
            factors.push_back(i);
    }

    cout << factors[factors.size() - k] << endl;

    return 0;
}



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

void chmin (int& a, int b, double m) {
  if (abs(double(a) - m) > abs(double(b) - m)) a = b;
}

int main () {
  int n;
  cin >> n;
  
  vector<int> a(n);
  
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  sort(a.begin(), a.end());

  int MAX = a[n-1];
  
  double med = (double)MAX / 2;
  
  int r = a[0];
  
  for (int i = 0; i < n; i++) {
    chmin(r, a[i], med);
  }
  cout << MAX << " " << r << endl;
  
  
  
}



Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
      b--;
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if(a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t; swap(a, b);
    u -= v * t; swap(u, v);
  }
  assert(b == 1);
  if(u < 0) u += md;
  return u;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> dp(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = (a[i] < a[j]);
    }
  }
  
  int inv2 = inv(2);
  int coef = power(2, q);
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    for (int i = 0; i < n; i++) {
      if (i != x && i != y){
        {
          int tmp = dp[i][x];
          add(tmp, dp[i][y]);
          tmp = mul(tmp, inv2);
          dp[i][x] = dp[i][y] = tmp;
        }
        {
          int tmp = dp[x][i];
          add(tmp, dp[y][i]);
          tmp = mul(tmp, inv2);
          dp[x][i] = dp[y][i] = tmp;
        }
      }
    }
    {
      int tmp = dp[x][y];
      add(tmp, dp[y][x]);
      tmp = mul(tmp, inv2);
      dp[x][y] = dp[y][x] = tmp;
    }
  }

  int ans = 0;
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < j; i++) {
      add(ans, dp[j][i]);
    }
  }
  ans = mul(ans, coef);
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 37504
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn solve(
    l: usize,
    r: usize,
    n: usize,
    a: &Vec<usize>,
    sum: &Vec<usize>,
    dp: &mut Vec<Vec<Option<usize>>>,
) -> usize {
    if r - l == 2 {
        return a[l] + a[l + 1];
    } else if r - l == 1 {
        return 0;
    }
    if dp[l][r].is_some() {
        return dp[l][r].unwrap();
    }
    let mut res = 1 << 61;
    let mut i = l + 1;
    while i < r {
        let cost = { sum[r - 1] - if l > 0 { sum[l - 1] } else { 0 } };
        res = std::cmp::min(
            res,
            cost + solve(l, i, n, a, sum, dp) + solve(i, r, n, a, sum, dp),
        );
        i += 1;
    }
    dp[l][r] = Some(res);
    // println!("{}, {}, {}", l, r, res);
    res
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut dp: Vec<Vec<Option<usize>>> = vec![vec![None; n + 1]; n + 1];
    let mut sum = vec![0; n];
    for i in 0..n {
        if i > 0 {
            sum[i] += sum[i - 1];
        }
        sum[i] += a[i];
    }
    println!("{}", solve(0, n, n, &a, &sum, &mut dp));
}


Measured memory_bytes: 6396
N,M = map(int,input().split())
def make_divisors(n):
    divisors = []
    # 試し割りで、かつ積でnを作るときの相方も同時に追加してる
    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
div_ls = make_divisors(M)
ans = 1
for div in div_ls:
    if div*N <= M:
        ans = max(ans,div)
print(ans)

Measured memory_bytes: 9440
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]

l=sorted([(a+b,a,b) for a,b in ab],reverse=True)

ans=sum([a for s,a,b in l[::2]])-sum([b for s,a,b in l[1::2]])

print(ans)

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

#define MOD (1000000000+7)
int dp[100001][13];

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

	for (int i = 0; i <= 100000; i++) {
		for (int j = 0; j < 13; j++) {
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;

	int base_div = 1%13;
	int digit_div = 1%13;

	for (unsigned int i = 0; i < S.length(); i++) {
		char c = S[S.length()-i-1];
		if (c=='?') {
			for (int j = 0; j <= 9; j++) {
				int mod = j*digit_div;
				for (int pos = 0; pos < 13; pos++) {
					dp[i+1][(pos+mod)%13] = (dp[i+1][(pos+mod)%13] + dp[i][pos]) % MOD;
				}
			}
		} else {
			int j = (int)c-(int)'0';
			int mod = j*digit_div;
			for (unsigned int pos = 0; pos < 13; pos++) {
				dp[i+1][(pos+mod)%13] = (dp[i+1][(pos+mod)%13] + dp[i][pos]) % MOD;
			}
		}
		digit_div = digit_div * 10 % 13;
	}
	cout << dp[S.length()][5] << endl;
  return 0;
}


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

using namespace std;

int main() {
  int n, m[26], s[26];
  cin >> n;
  string S;
  fill(begin(m),end(m),50);
  while (cin >> S) {
    fill(begin(s),end(s),0);
    for (char c : S) ++s[c-'a'];
    for (int i = 0; i != 26; ++i) m[i] = min(m[i], s[i]);
  }
  for (int i = 0; i != 26; ++i) cout << string(m[i], char('a'+i));
  cout << endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>
#define MAX_S 999999

int main(void) {
	int prime_f[MAX_S], prime_sum[MAX_S], sum = 0, n;

	for (size_t i = 0; i < MAX_S; i++)
	{
		prime_f[i] = 1;
		prime_sum[i] = 0;
	}
	prime_f[0] = 0;

	for (size_t i = 1; i < sqrt(MAX_S); i++)
	{
		if (prime_f[i] == 1) {
			for (size_t j = i + 1; j*(i + 1) <= MAX_S; j++)
			{
				prime_f[(i + 1)*j - 1] = 0;
			}
		}
	}

	for (size_t i = 0; i < MAX_S; i++)
	{
		if (prime_f[i] == 1) sum++;
		prime_sum[i + 1] = sum;
	}

	while (scanf("%d", &n) != EOF)
	{
		printf("%d\n", prime_sum[n]);
	}
	return 0;
}

Measured memory_bytes: 10536
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値

int main() {
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        // 累積和を前計算
        vector<int> s(N+1, 0);
        for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        // 答えを求める
        long long res = -INF; // 最初は無限小の値に初期化しておく
        for (int i = 0; i <= N-K; ++i) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int H, W;
  cin >> H >> W;

  vector <string> vec(H);
  rep(i,H) cin >> vec.at(i);

  rep(i,W + 2) {
    cout << "#";
  }
  cout << endl;

  rep(i,H){
    cout << "#";
    cout << vec.at(i);
    cout << "#" << endl;
  }

  rep(i,W + 2) {
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define C 500000004
long long dp[5002][5002];
int main(){
        REP(i,5002){
           REP(j,5002){
               dp[i][j]=0;
           }
        }
	int N;
	string s;
	cin>>N>>s;
	if(N<s.size()){
	   cout<<0<<endl;
	   return 0;
	}
	dp[0][0]=1;
	for(int i=1;i<=N;i++){
	    for(int j=0;j<=N;j++){
                dp[i][j+1]=(dp[i][j+1]+dp[i-1][j]*2)%MOD;//0か1の挿入
	        if(j!=0){
	           dp[i][j-1]=(dp[i][j-1]+dp[i-1][j])%MOD;//Bの挿入

	        }else{
	           dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;//Bを先頭に挿入
	        }
	    }
	}
/*
        REP(i,N+1){
            REP(j,N+1){
                cout<<dp[i][j]<<" ";
            }
            cout<<endl;
        }
*/
        //重複の削除
        REP(i,s.size()){
            dp[N][s.size()]=(dp[N][s.size()]*C)%MOD;
        }
        
        cout<<dp[N][s.size()]<<endl;
	return(0);
}

Measured memory_bytes: 195712
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a<b){
            if(b<c){
                System.out.printf("%d %d %d\n",a,b,c);
            }else if(a>c){
                System.out.printf("%d %d %d\n",c,a,b);
            }else {
                System.out.printf("%d %d %d\n",a,c,b);
            }
        }else{
            if(a<c){
                System.out.printf("%d %d %d\n",b,a,c);
            }else if(c<b){
                System.out.printf("%d %d %d\n",c,b,a);
            }else{
                System.out.printf("%d %d %d\n",b,c,a);
            }
        }
        sc.close();
    }

    
}


Measured memory_bytes: 26420
require 'prime'
class D169
  def call(n)
    primes = Prime.prime_division(n)
    result = primes.map { |x| plus_division(x[1]) }.inject(:+)
    if result.nil?
      0
    else
      result
    end
  end

  def plus_division(target)
    used = []
    result = target
    (1..target).each do |x|
      tmp = result - x
      break if tmp < 0
      next unless used.index(tmp).nil?
      result -= x
      used.push(x)
    end
    used.length
  end

  def main
    n = gets.to_i
    puts call(n)
  end
end

D169.new.main

Measured memory_bytes: 14368
#include <stdio.h>

int main()
{
  int x,y,n,m;

  scanf("%d %d",&n,&m);

  if(n > 1000000000 || m > 1000000000 || n < 1 || m < 1) return 0;

  if(n > m)
    {
      x = n;
      y = m;
    }
  else
    {
      x = m;
      y = n;
    }

  while(n != 0)
    {
      n = x%y;
      x = y;
      y = n;
    }
  printf("%d\n",x);
  
  return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=s-1; i>=s; i--)

int main(){

    int n, m; cin >> n >> m;
    priority_queue<ll> pq;
    rep(i, n){
        int temp; cin >> temp;
        pq.push(temp);
    }

    pair<ll, ll> cb[m];
    rep(i, m){
        ll t1, t2; cin >> t1 >> t2;
        cb[i] = {t2, t1};
    }

    sort(cb, cb+m, greater<pair<ll, ll>>());

    ll cnt = 0;
    rep(i, m){
        cnt += cb[i].second;
        rep(j, cb[i].second){
            pq.push(cb[i].first);
        }
        if(cnt > n) break;
    }

    ll ans = 0;
    rep(i, n){
        ans += pq.top();
        pq.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7920
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
 
 
using namespace std;
 
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
 
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
#define int long long
#define left left228
#define right right228
#define prev prev228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second

const int N = 100 * 1000 + 228;

int n, k;
vector<int> g[N];
int a[N], max_deep[N];
int res = 0;

void dfs(int v, int par) {
    max_deep[v] = 0;
    for (int to : g[v]) {
        if (to == par) continue;
        dfs(to, v);
        max_deep[v] = max(max_deep[v], max_deep[to] + 1);
    }
    if (max_deep[v] == k - 1 && par != 1) {
        ++res;
        max_deep[v] = -1;
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    if (a[1] != 1) {
        ++res;
        a[1] = 1;
    }
    for (int i = 2; i <= n; ++i) {
        g[a[i]].push_back(i);
    }
    for (int sons : g[1]) {
        dfs(sons, 1);
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 10240
module Main where

import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import qualified Data.Vector.Algorithms.Tim    as VAT
import           Data.Heap                      ( Heap )
import qualified Data.Heap                     as Heap
import           Data.Ord

main :: IO ()
main = do
  n   <- readLn :: IO Int
  as  <- VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  as' <- do
    x <- VU.thaw as
    VAT.sortBy (comparing Down) x
    VU.freeze x
  let s   = Heap.singleton $ Down $ VU.head as'
  let ans = VU.foldl' go (s, 0) $ VU.tail as'
  print $ snd ans
 where
  go :: (Heap (Down Int), Int) -> Int -> (Heap (Down Int), Int)
  go (s, c) a =
    let Down v = Heap.minimum s -- maximum
        s'     = Heap.insert (Down a) $ Heap.insert (Down a) $ Heap.deleteMin s -- deleteMax
    in  (s', c + v)



Measured memory_bytes: 39660
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    lis=[[0,0] for i in range(n)]
    for i in range(n):
        x,l=LI()
        lis[i][0]=x-l
        lis[i][1]=x+l
    lis.sort(key=lambda x:x[1])
    now=-inf
    ans=0
    for i in range(n):
        if lis[i][0]>=now:
            now=lis[i][1]
            ans+=1
    print(ans)
        
        
        
        



        
        
        
        
        
    
if __name__=="__main__":
    main()



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

int main(){
	int n;
	int ice[11];
	while(cin >> n, n){
	fill(ice, ice+10, 0);
		for(int i=0; i < n; i++){
			int m;
			cin >> m;
			ice[m]++;
		}
		for(int i=0; i < 10; i++){
			if(ice[i] == 0)cout << "-" << endl;
			else {
				for(int j=0; j < ice[i]; j++){
					cout << "*";
				}
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
   int temp;cin>>temp;
   if(temp>=30)
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
    
}
int32_t main()
{
    rapido;
    int t;
    //cin>>t;
      t=1;
    while(t--)
    solve();
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int[] money = {1, 5, 10};
		int[][] charge = new int[1000000][3];
		for (int i = 0; i < charge.length; i++) {
			int j = i;
			for (int k = 2; k >= 0; k--) {
				charge[i][k] += j / money[k];
				if ((j %= money[k]) == 0) {
					break;
				}
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int a, b, c;
			a = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			b = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			if ((a | b) == 0) {
				break;
			}
			c = (b - a) / 100;
			System.out.println(charge[c][0] + " " + charge[c][1] + " " + charge[c][2]);
		}
	}
}

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

int main(){
    int k,n,ma,ma2,p ;
    cin >> n  ;
    cin >> ma ;
    p = 0 ;
    cin >> k ;
    if(k>ma){
        ma2 = ma ;
        ma = k ;
        p = 1 ;
    }else{
        ma2 = k ;
    }
    for(int i=2 ; i<n ; i++){
        cin >> k ;
        if(k>ma){
            p = i ;
            ma2 = ma ;
            ma = k ;
        }else{
            if(k>ma2){
                ma2 = k ;
            }
        }
    }

    for(int i=0 ; i<n ; i++){
        if(i == p){
            cout << ma2 << endl ;
        }else{
            cout << ma << endl ;
        }
    }

    return 0 ;
}


Measured memory_bytes: 1664
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio;
    string s,s2,s3;
    int a,b,x;
    cin>>s;
    cout<<((s[0]!=s[1] && s[1]!=s[2] && s[2]!=s[0]) ? "Yes" :"No");
    return(0);
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i;
	int a[200000], b[200000];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
		b[i]=a[i];
	}
	qsort(b, n, sizeof(int), comp);
	int m1=b[n/2-1], m2=b[n/2];
	if(m1==m2){
		for(i=0; i<n; i++){
			printf("%d\n", m1);
		}
	}else{
		for(i=0; i<n; i++){
			if(a[i]<=m1){
				printf("%d\n", m2);
			}else{
				printf("%d\n", m1);
			}
		}
	}
}


Measured memory_bytes: 3704
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z), D, ans;
    rep(i, X) { cin >> A[i]; }

    rep(i, Y) { cin >> B[i]; }

    rep(i, Z) { cin >> C[i]; }

    rep(i, X) {
        rep(j, Y) { D.push_back(A[i] + B[j]); }
    }

    sort(all(D), greater<ll>());
    sort(all(C), greater<ll>());
    for (int i = 0; i < min(X * Y, 3001); i++) {
        rep(j, Z) { ans.push_back(D[i] + C[j]); }
    }

    sort(all(ans), greater<ll>());
    rep(i, K) { cout << ans[i] << endl; }
}

Measured memory_bytes: 43240
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 5e3 + 10, mod = 1e9 + 7;

int add(int a, int b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

int sub(int a, int b) {
	a -= b;
	if (a < 0) a += mod;
	return a;
}

int mul(ll a, int b) {
	return (a * b) % mod;
}

int pwr(int x, int e) {
	int res = 1;
	while (e) {
		if (e & 1) {
			res = mul(res, x);
		}
		x = mul(x, x);
		e /= 2;
	}
	return res;
}

int par[N], sz[N];

int get_root(int u);
bool merge(int u, int v);

int main() {
	fast_cin();
	int n; cin >> n;
	vector<int> p(n);
	int e_cycles = 0;
	for (int i = 0; i < n; ++i) {
		sz[i] = 1;
		par[i] = i;
	}
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
		if (p[i] != -1) {
			--p[i];
			e_cycles += !merge(i, p[i]);
		}
	}
	vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
	dp[0][0] = 1;
	int k = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= k; ++j) {
			dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
			if (p[i] == -1) {
				dp[i + 1][j + 1] = add(dp[i + 1][j + 1], mul(sz[get_root(i)], dp[i][j]));
			}
		}
		k += (p[i] == -1);
	}
	vector<int> fact(n + 1, 1);
	for (int i = 2; i <= n; ++i) {
		fact[i] = mul(i, fact[i - 1]);
	}
	int tot = pwr(n - 1, k), cycles = mul(e_cycles, tot);
	cycles = add(cycles, mul(sub(dp[n][1], k), pwr(n - 1, k - 1)));
	for (int x = 2; x <= k; ++x) {
		cycles = add(cycles, mul(mul(fact[x - 1], dp[n][x]), pwr(n - 1, k - x)));
	}
	int ans = sub(mul(tot, n - 1), sub(cycles, tot));
	cout << ans << endl;
}

int get_root(int u) {
	if (u != par[u]) {
		par[u] = get_root(par[u]);
	}
	return par[u];
}

bool merge(int u, int v) {
	u = get_root(u);
	v = get_root(v);
	if (u == v) {
		return false;
	} else {
		sz[u] += sz[v];
		par[v] = u;
		return true;
	}
}

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

int main()
{
  int N; cin >> N;

  int a_4multi = 0, a_2num = 0;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    if (a % 4 == 0) a_4multi++;
    else if (a % 2 == 0) a_2num++;
  }

  if (a_4multi + a_2num/2 >= N/2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cstdio>
#include <cctype>
using namespace std;
int main(){
	string s,t,u;
	vector<char>v(3);
	cin>>s>>t>>u;
	v.at(0)=s.at(0);
	v.at(1)=t.at(0);
	v.at(2)=u.at(0);
	for(int i=0;i<3;i++){
		v.at(i)=toupper(v.at(i));
	cout<<v.at(i);
	}
}	


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
const long long MOD=1e9+7;
long long quickpow(long long x,int times){
	long long tmp=1;
	while(times){
		if(times&1) tmp=tmp*x%MOD;
		x=x*x%MOD;
		times>>=1;
	}
	return tmp;
}
long long dp[2005][2005],po[5000005],inpo[5000005];
long long C(int n,int m){
	return (po[n]*inpo[m]%MOD*inpo[n-m]%MOD);
}
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	if(k==1){
		cout<<1;
		return 0;
	}
	po[0]=1;
	inpo[0]=1;
	for(int i=1;i<=5000002;i++){
		po[i]=i*po[i-1]%MOD;
		inpo[i]=quickpow(po[i],MOD-2);
	}
	dp[0][0]=1;
//	cout<<C(0,0)<<endl;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			dp[i][j]=(dp[i-1][j]+((j!=0)?dp[i][j-1]*C(k*n-i-(j-1)*(k-1)-1,(k-2))%MOD*(n-j+1):0))%MOD;
		//	cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	}
	cout<<dp[n][n];
}

Measured memory_bytes: 109696
import itertools


N = int(input())
nums = [int(i) for i in input().split(" ")]
longest = len(bin(max(nums))) - 2
nums_bin = [format(i, "b").zfill(longest) for i in nums]


result = 0
for index, numbers in enumerate(zip(*nums_bin)):
    i = longest - index - 1
    zero = numbers.count("0")
    one = N - zero
    result += (2 ** i) * (zero * one)
print(result % (10 ** 9 + 7))


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

int main(){
	int n; cin >> n;
	int a[(int)1e5 + 1] = {};
	for(int i = 0; i < n; ++i){
		int b; cin >> b;
		++a[b];
	}
	int ans = 0;
	for(int i = 1; i < (int)1e5; ++i) ans = max(a[i - 1] + a[i] + a[i + 1], ans);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
n = int(input())
a = list(map(int, input().split()))
ans = []
Ma = 0
iMa = -1
for i in range(n):
	if abs(a[i]) > Ma:
		Ma = abs(a[i])
		iMa = i
if Ma == 0:
	print(0)
	sys.exit()
for i in range(n):
	if a[i] * a[iMa] < 0:
		a[i] += a[iMa]
		ans.append([iMa+1, i+1])
if a[iMa] > 0:
	for i in range(n-1):
		if a[i] > a[i+1]:
			a[i+1] += a[i]
			ans.append([i+1, i+2])
else:
	for i in range(n-1, 0, -1):
		if a[i-1] > a[i]:
			a[i-1] += a[i]
			ans.append([i+1, i])

print(len(ans))
for an in ans:
	print(*an)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 100010

vi adj[SIZE];
int mark = 0, found = 0, num[SIZE] = {0}, depth, sec = 0;

void dfs (int v, int p, int u, int d) {
   int prv = found;
   if (v == u) {
      found = 1;
      depth = (d >> 1);
   }
   num[v] = 1;
   for (int i = 0 ; i < adj[v].size() ; ++i) {
      int t = adj[v][i];
      if (t == p) continue;
      dfs (t, v, u, d + 1);
      num[v] += num[t];
   }
   if (prv != found && d > depth) sec = num[v];
}

int main() {
   int n;
   cin >> n;
   for (int i = 1 ; i < n ; ++i) {
      int u, v;
      cin >> u >> v;
      adj[u].PB(v);
      adj[v].PB(u);
   }
   dfs (1, 1, n, 0);
   int first = n - sec;
   if (first > sec) cout << "Fennec" << endl;
   else cout << "Snuke" << endl; 
   return 0;
}

Measured memory_bytes: 15488
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open System

[<EntryPoint>]
let main argv = 
    let input = stdin.ReadLine()

    let a = input.ToCharArray() |> Array.countBy(fun x -> x)

    if a.Length = 2 && 
      (a 
      |> Array.filter(fun (key, count) -> count = 2) 
      |> Array.length = a.Length) then
        printfn "Yes"
    else
        printfn "No"

    0 // return an integer exit code


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

int main() {
    string S, T;
    cin >> S >> T;
    cout << T + S << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <limits>
using namespace std;
int imax = std::numeric_limits<int>::max();
long b[100002],a[100002],c[100002],v[100002][4],i,j,n,k;
int main()
{
    
    //cout<<"P:";
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    v[1][1]=a[1];
    v[1][2]=b[1];
    v[1][3]=c[1];
    for(i=2;i<=n;i++)
    {
        v[i][1]=a[i]+max(v[i-1][2],v[i-1][3]);
        v[i][2]=b[i]+max(v[i-1][1],v[i-1][3]);
        v[i][3]=c[i]+max(v[i-1][1],v[i-1][2]);
        //cout<<a[i]<<" ";
        //a[i]=min(a[i-2]+abs(h[i]-h[i-2]),a[i-1]+abs(h[i]-h[i-1]));
       
    }
    cout<<max(max(v[n][1],v[n][2]),v[n][3]);
    return 0;
}

Measured memory_bytes: 5760