akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    static Scanner sc = new Scanner(System.in);
    static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        
        int t = Integer.parseInt(sc.next());
        for(int i=0; i<t; i++){
            solve();
        }
    }
    
    public static void solve(){
        int n = Integer.parseInt(sc.next());
        long sum = 0;
        PriorityQueue<Long> left = new PriorityQueue<>();
        PriorityQueue<Long> right = new PriorityQueue<>();
        for(int i=0; i<n; i++){
            long k = Integer.parseInt(sc.next());
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            sum += Math.min(l, r);
            if(l < r){
                right.add(((n-k)<<32) + r-l);
            }else{
                left.add((k<<32) + l-r);
            }
        }
        
        sum += ureshisa(left) + ureshisa(right);
        System.out.println(sum);
        
    }
    
    public static long ureshisa(PriorityQueue<Long> q){
        int size = q.size();
        PriorityQueue<Integer> ok = new PriorityQueue<>();
        for(int i=0; i<size; i++){
            long x = q.poll();
            int k = (int)(x>>32);
            int dif = (int)x;
            ok.add(dif);
            while(ok.size() > k){
                ok.poll();
            }
        }
        long res = 0;
        for(int tmp : ok){
            res += tmp;
        }
        return res;
    }
}


Measured memory_bytes: 68948
#include<stdio.h>
int main() {
    int i, j, n, t, sw = 0, mini, a[100], flag = 1;
    scanf("%d", &n);
    flag = 1;
    for (i = 0; i < n; i++)scanf("%d", &a[i]);
    for (i = 0; flag; i++) {
        flag = 0;
        for (j = n - 1; j >= i + 1; j--) {
            if (a[j] < a[j - 1]) {
                t = a[j];
                a[j] = a[j - 1];
                a[j - 1] = t;
                sw++;
                flag = 1;
            }
        }
    }
    for (i = 0; i < n; i++) {
        printf("%d", a[i]);
        if (i != n - 1)printf(" ");
    }
    printf("\n%d\n", sw);
    return 0;
}

Measured memory_bytes: 604
N=int(input())
reds=[]
for i in range(N):
    reds.append(list(map(int,input().split())))
blues=[]
for i in range(N):
    blues.append(list(map(int,input().split())))
    
reds=sorted(reds,key=lambda x:x[0])
blues=sorted(blues,key=lambda x:x[0])

ans=0
tmp=[]
for b in blues:
    while len(reds)>0:
        r=reds[0]
        if b[0] > r[0]:
            tmp.append(reds.pop(0))
        else:
            break
    tmp=sorted(tmp,key=lambda x:x[1],reverse=True)
    for i,t in enumerate(tmp):
        if t[1]<b[1]:
            ans+=1
            tmp.pop(i)
            break
print(ans)

Measured memory_bytes: 3064
using System;

public class P
{
    public int n { get; set; }
    public int m { get; set; }
    public int[] got { get; set; }
    public int p { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var c = Array.ConvertAll(line, int.Parse);
        var w = new P { n = n, m = m, got = new int[6], p = 0 };
        var ans = goDfs(c, w);
        if (ans) print(w);
        else Console.WriteLine("NA");
    }
    static void print (P w)
    {
        for (int i = 1; i <= w.p; i++)
            Console.Write(w.got[i]);
        Console.WriteLine();
    }
    static bool goDfs ( int [] c, P w)
    {
        if (w.n == 0) return true;
        var ok = false;
        for (int i = 0; i <= 9; i++)
        {
            if (c[i] <=w.m && w.n > 0)
            {
                w.n--;
                w.m -= c[i];
                w.p++;
                w.got[w.p] = i;
                var a =  goDfs(c, w);
                if (a) ok = true; 
                else
                {
                    w.n++;
                    w.m += c[i];
                    w.p--;
                }
            }
        }
        return ok;
    }
}



Measured memory_bytes: 17948
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<iomanip>
using namespace std;

int main(){
  
  std::cout<<std::fixed<<std::setprecision(10);
  
  double w,h,x,y; cin >> w >> h >> x >> y;
  
  cout << w*h/2 << " ";
  
  if (x==w/2 && y==h/2){
    cout << "1";
  } else {
    cout << "0";
  } 
  
  return 0;
}


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


int maxtime(int x){
  return (x+9)/10 * 10;
}
int remtime (int x){
  return maxtime(x) - x;
}

int main() {
  int a,b,c,d,e;
  cin >> a>>b>>c>>d>>e;
  int sum=maxtime(a)+maxtime(b)+maxtime(c)+maxtime(d)+maxtime(e);
  sum -= max({remtime(a),remtime(b),remtime(c),remtime(d),remtime(e)});
  cout << sum<< endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N;

int main(){
    cin>>N;
    out(24*2-N);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int taro = 0;//太郎の得点
        int hanako = 0;//花子の得点
        int scint = sc.nextInt();//最初に持っている枚数
        for (int i = 0; i < scint; i++) {
            int c = sc.next().compareTo(sc.next());//文字列１と文字列２を比較する
            if (c > 0) {//文字列１が大きいならば太郎に３点
                taro += 3;
            } else if (c == 0) {//引き分けならお互いに一点ずつ
                taro++;
                hanako++;
            } else {//それ以外なら花子に３点
                hanako += 3;
            }
        }
        System.out.println(taro + " " + hanako);
    }
}


Measured memory_bytes: 29716
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;

class DIntegerCards {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;
        unordered_map<int, int> cnt;
        REP(i, N) {
            int a;
            cin >> a;
            cnt[a]++;
        }

        vector<P> v;
        for (auto kv :cnt) {
            v.push_back({kv.first, kv.second});
        }
        REP(i, M) {
            int b, c;
            cin >> b >> c;
            v.push_back({c, b});
        }
        sort(v.begin(), v.end(), greater<P>());

        int n = N;
        int cur = 0;
        int res = 0;
        while (n >= 0 && cur < v.size()) {
            auto kv = v[cur];
            int b = kv.first;
            int num = kv.second;

            if (num >= n) {
                res += b * n;
                break;
            }

            res += b * num;
            n -= num;
            cur++;
        }
        cout << res << endl;


    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DIntegerCards solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 12184
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range (H):
        for j in range (W):
            if i==0 or i==(H-1) or j==0 or j==(W-1):
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()
    


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;
    vector<vector<int>>V(n,vector<int>(3));
    vector<vector<int>>judge(201,vector<int>(3,0));
    vector<int>Ans(n,0);
    rep(i,n)cin>>V[i][0]>>V[i][1]>>V[i][2];
    rep(x,3){
        rep(i,n)judge[V[i][x]][x]++;
        rep(i,n){
            if(judge[V[i][x]][x]==1)Ans[i]+=V[i][x];
        }
    }
    rep(i,n)cout<<Ans[i]<<endl;
}


Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <cstring>
#include <cstdlib>

//typedef struct
//{
//    int left_val;
//    int right_val;
//};

class GcdAndLcm
{
public:
    GcdAndLcm() : m_gcd(0), m_lcm(0) {}
    void Run();

private:
    void readData();
    void GetData(std::string s, int& v1, int& v2);
    int calcGcd(int m, int n);
    int calcLcm(int m, int n);
    void Show();

private:
    std::vector<std::string> m_data;
    unsigned int m_gcd;
    unsigned int m_lcm;
};

void GcdAndLcm::Run()
{
    int val1 = 0, val2 = 0;

    readData();
    
    for (unsigned int i = 0; i < m_data.size(); ++i) {
        GetData(m_data[i], val1, val2);
        m_gcd = calcGcd(val1, val2);
        m_lcm = calcLcm(val1, val2);
        Show();
    }
}
void GcdAndLcm::readData()
{
    std::string line;

    while (std::getline(std::cin, line)) {
        m_data.push_back(line);
    }
}

void GcdAndLcm::GetData(std::string s, int& v1, int& v2)
{
    size_t pos = s.find(" ");
    char tmp[100] = { 0 };
    std::strncpy(tmp, s.c_str(), pos);
    v1 = std::atoi(tmp);
    std::memset(tmp, 0x00, sizeof(tmp));
    pos++;
    std::strncpy(tmp, s.c_str() + pos, s.size() - pos);
    v2 = std::atoi(tmp);
}
int GcdAndLcm::calcGcd(int m, int n)
{
    if ((0 == m) || (0 == n))
        return 0;

    while (m != n)
    {
        if (m > n) m = m - n;
        else         n = n - m;
    }
    return m;
}//gcd

int GcdAndLcm::calcLcm(int m, int n)
{
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / calcGcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

void GcdAndLcm::Show()
{
    std::cout << m_gcd << " " << m_lcm << std::endl;
}

int main()
{
    GcdAndLcm gcdAndLcm;

    gcdAndLcm.Run();
}

Measured memory_bytes: 3016
Q = int(input())
R = 10**5 + 100

def getPrimes():
    isPrime = [True] * R
    isPrime[0] = False
    isPrime[1] = False
    for i in range(R):
        if not isPrime[i]:
            continue
        for p in range(i * 2, R, i):
            isPrime[p] = False
    return isPrime

isPrime = getPrimes()
A = [1 if i % 2 == 1 and isPrime[i] and isPrime[(i + 1) // 2] else 0 for i in range(R)]
accA = [0] * R
for i in range(1, R):
    accA[i] = accA[i - 1] + A[i - 1]
accA = accA[1:]

for _ in range(Q):
    l, r = map(int, input().split())
    print(accA[r] - accA[l - 1])



Measured memory_bytes: 8496
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;
	cin>>x>>y;
	ll ans=0;
	while(x<=y){
		x*=2;
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
s = input()

if s[0] != "A":
  print("WA")
  exit()
if s[2:-1].count("C") != 1:
  print("WA")
  exit()
t = s.index("C")
if s[1:t].islower() == False or s[t+1:].islower() == False:
  print("WA")
  exit()
print("AC")

Measured memory_bytes: 8920
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

class union_find {
  mutable std::vector<intmax_t> c;

public:
  union_find(size_t n): c(n, -1) {}

  size_t find(size_t v) const {
    if (c[v] < 0) return v;
    return (c[v] = find(c[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (-c[u] > -c[v]) std::swap(u, v);
    c[v] += c[u];
    c[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) const {
    return (find(u) == find(v));
  }

  size_t size() const { return c.size(); }
  size_t size(size_t v) const { return -c[find(v)]; }
};

int main() {
  size_t n, m, k;
  scanf("%zu %zu %zu", &n, &m, &k);

  union_find uf(n);
  std::vector<size_t> group(n);
  for (size_t i = 0; i < k; ++i) {
    int t;
    scanf("%d", &t);

    if (t == 1) {
      // 1 a b
      size_t a, b;
      scanf("%zu %zu", &a, &b);
      --a;
      --b;

      size_t ga = group[uf.find(a)];
      size_t gb = group[uf.find(b)];
      if (ga != 0 && gb != 0) {
        if (ga != gb) return !printf("%zu\n", i+1);
      }
      uf.unite(a, b);
      if (ga == 0) ga = gb;
      group[uf.find(a)] = ga;
    } else if (t == 2) {
      // 2 c x
      size_t c, x;
      scanf("%zu %zu", &c, &x);
      --c;

      size_t gc = group[uf.find(c)];
      if (gc != 0 && gc != x) return !printf("%zu\n", i+1);
      group[uf.find(c)] = x;
    }
  }

  puts("0");
}



Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
int main(void){
    
    int N;
    int T, A;
    cin >> N;
    cin >> T >> A;
    
    int ans = 0;
    int index = INT_MAX;
    
    for(int i = 1; i <= N; i++){
        int H;
        cin >> H;
        double ave_Temp = T * 1000 - H * 6;
        if(index > abs(A*1000 - ave_Temp)){
            index = abs(A*1000 - ave_Temp);
            ans = i;
        }
    }
    
    cout << ans << endl;

}


Measured memory_bytes: 3152
n = int(input())
A = []
xy = []
max = 0
for i in range(n):
  a = int(input())
  A.append(a)
  xy.append([list(map(int,input().split())) for i in range(a)])
for i in range(2**n):
    ls = [0]*n
    check = 0
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = 1
    for p in range(len(xy)):
      for t in xy[p]:
        if t[1] == 1 and ls[p] == 1:
          if ls[t[0]-1] != 1:
            check = 1
            break
        elif t[1] == 0 and ls[p] == 1:
          if ls[t[0]-1] != 0:
            check = 1
            break
      else:
        continue
      break
    if check == 0:
      if ls.count(1) > max:
        max = ls.count(1)
print(max)


Measured memory_bytes: 3064
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k < 0:
            break
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 40684
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

ll gcd(ll a, ll b) {
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}

	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

//---------------------------------------------------------------
// 最小公倍数
//---------------------------------------------------------------
ll lcm(ll a, ll b) {
	ll temp = gcd(a, b);
	return temp * (a / temp)*(b / temp);
}

int kaizyou(int n) {
	if (n == 1) {
		return 0;
	}
	int ret = 1;
	for (int i = 1; i <= n; i++) {
		ret *= i;
	}
	return ret;
}

int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	int N;
	cin >> N;

	string S;
	cin >> S;


	int ans = 0;
	for (int i = 0; i+2 < N; i++) {
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
			ans++;
		}

	}


	cout << ans;

}




Measured memory_bytes: 256
list1=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(list1[k-1])

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())

def bin_search(ok, ng, cond):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = bin_search(n, 0, lambda x: (x * 1.08) >= n)
if int(ans * 1.08) == n:
    print(ans)
else:
    print(':(')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n, d, x;
    cin >> n >> d >> x;
    int ans = 0;
    while(n--){
        int a;
        cin >> a;
        for(int i = 1; i <= d; i+=a){
            ans++;
        }
    }
    ans += x;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
using ll = long long;

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  ll N, M;
  cin >> N >> M;
  ll L = lcm(N, M);
  string S, T;
  cin >> S >> T;

  map<long long, char> X;
  rep(i, N)
  {
    long long n = i * L / N;
    X[n] = S[i];
  }

  bool is_ok = true;
  rep(i, M)
  {
    long long m = i * L / M;
    if (X[m] != 0 && X[m] != T[i])
      is_ok = false;
  }

  if (is_ok)
    cout << L << endl;
  else
    cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    V<> ans(n, 0);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        ans[a]++;
        ans[b]++;
    }
    for(auto p : ans) cout << p << endl;
}

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

const int maxn = 500005;
int a[maxn], last[maxn], ans[maxn];

bool cmp(vector<int> &a, vector<int> &b) {
	return a[1] < b[1];
}

int f[maxn];
void upd(int id, int val) {
	while(id < maxn) f[id] += val, id += id&-id; 
}
int sum(int id) {
	int res = 0;
	while(id > 0) res += f[id], id -= id&-id;
	return res;
}


signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n, q;
	cin >> n >> q;
	
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	
	for(int i = 0; i < maxn; i++) {
		last[i] = -1;
	}
	
	vector<vector<int>> query(q, vector<int>(3));
	
	for(int i = 0; i < q; i++) {
		cin >> query[i][0] >> query[i][1];
		query[i][2] = i;
	}
	
	sort(query.begin(), query.end(), cmp);
	
	int idx = 0;
	for(int i = 1; i <= n; i++) {
		
		if(last[a[i]] != -1)
			upd(last[a[i]], -1);
		
		last[a[i]] = i;
		upd(i, 1);
		
		while(idx < q && query[idx][1] == i) {
			ans[query[idx][2]] = sum(query[idx][1]) - sum(query[idx][0] - 1);
			idx++;
		} 
	}
	
	for(int i = 0; i < q; i++) {
		cout << ans[i] << "\n";
	}
	
}


Measured memory_bytes: 38912
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2007

#include <iostream>
using namespace std;

const int A[4] = { 10, 50, 100, 500 };

int main() {
  int M;
  int count = 0;
  while (cin >> M && M) {
    int a[4];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    int N = 0; // 財布の中の金額
    for (int i=0; i<4; i++) {
      N += a[i] * A[i];
    }
    N -= M;
    int b[4];
    for (int i=3; i>=0; i--) {
      b[i] = N/A[i];
      N = N%A[i];
    }
    if (count > 0) {
      cout << endl;
    }
    for (int i=0; i<4; i++) { // 出力
      if (a[i] > b[i]) {
	cout << A[i] << " " << a[i]-b[i] << endl;
      }
    }
    count++;
  }
}

Measured memory_bytes: 1160
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> strings (n);
    for (int i = 0; i < n; i++) {
        cin >> strings[i];
    }
    sort(strings.begin(), strings.end());
    string ans = "";
    for (int i = 0; i < n; i++) {
        ans += strings[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, B: "List[int]"):
    ret = 0
    for i in range(N - 2):
        ret += min(B[i], B[i + 1])
    ret += B[0] + B[N - 2]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
	long long a, b, d, r;
	double f;
	cin >> a >> b;
	cout << fixed << setprecision(8);
	d = a / b; r = a % b;
	double x = a, y = b;
	f = x / y;
	cout << d << " " << r << " " << f;
	return 0;
}


Measured memory_bytes: 3288
dict={}
for _ in range(int(input())):
  s=input()
  if s not in dict:
    dict[s] = 1
  else:
    dict[s] += 1
dict=sorted(dict.items(),key=lambda x:-x[1])
print(*sorted([dict[i][0] for i in range(len(dict)) if dict[0][1]==dict[i][1]]),sep='\n')

Measured memory_bytes: 47360
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

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

	int n, p;
	string s;
	cin >> n >> p >> s;

	if(p == 2 or p == 5) {
		vector<int> dp(p);
		LL ans = 0;
		REP(i, n) {
			++dp[0];
			int c = int(s[i] - '0');
			vector<int> nxt(p);
			REP(m, p)
				nxt[(10 * m + c) % p] += dp[m];
			dp = nxt;
			debug(i, dp);
			ans += dp[0];
		}
		cout << ans << '\n';
		return 0;
	}

	int curr_sum = 0, pot10 = 1;
	vector<int> pref_cnt(p);
	pref_cnt[0] = 1;
	LL ans = 0;
	for(int i = n - 1; i >= 0; --i) {
		int c = int(s[i] - '0');
		curr_sum = (curr_sum + c * pot10) % p;
		int delta = pref_cnt[curr_sum];
		debug(i, curr_sum, pot10, delta);
		ans += delta;
		++pref_cnt[curr_sum];
		pot10 = (pot10 * 10) % p;
	}
	debug(pref_cnt);
	cout << ans << '\n';
}


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

int main(){
	int n;cin >> n;
	map<string, int> m;
	int mx = 0;
	for(int i = 0;i < n;i++){
		string t;cin >> t;
		m[t]++;
		if(m[t] > mx)mx = m[t];
	}
	for(pair<string, int> p : m){
		if(p.second == mx)cout << p.first << endl;
	}
}
// make pair, tuple
// make pair, tuple
// 
// __gcd(int, int);
// lcm = a * b / __gcd(a, b);
// 
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }
// 
// #Count leading & trailing zero of an integer bits
// __builtin_clz(n);
// __builtin_clzll(n);
//
// #Count 1s bits of an integer
// __builtin_popcount(n);
// __builtin_popcountll(n);
//
// #Error checking
// assert(n == 3);
// 
// #Error Printing
// cerr << "Some thing";

// #binary exponentiation
// long long binpow(long long a, long long b) {
//     long long res = 1;
//     while (b > 0) {
//         if (b & 1)
//             res = res * a;
//         a = a * a;
//         b >>= 1;
//     }
//     return res;
// }


Measured memory_bytes: 25216
#include <stdio.h>

int main(void){
	int n, count, a[10001];
	double ave;

	while(1){
		scanf("%d", &n);
		if(!n) break;

		ave = 0.0;
		for(int i=0; i<n; i++){
			scanf("%d", &a[i]);
			ave += a[i];
		}

		ave /= n;
		count = 0;
		for(int i=0; i<n; i++){
			if(ave >= a[i]) count++;
		}
		printf("%d\n", count);
	}//endwhile

	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int64_t n,c,k;
  cin>>n>>c>>k;
  vector<int64_t> t(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>t[i];
  }
  sort(t.begin(), t.end());
  std::vector<int64_t> lim(n);
  
  for (int i = 0; i < n; ++i)
  {
    lim[i]=t[i]+k;
  }
  int64_t th=0,cnt=0;
  for (int i = 0; i < n; ++i)
  {
    int64_t tmp=lim[th];
    auto l=upper_bound(t.begin(), t.end(),tmp)-t.begin();
    if(l-th<=c){
      th+=l-th;
      cnt++;
    }
    else{
      th+=c;
      cnt++;
    }
    if(th>n-1) break;
  }
  cout<<cnt;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  int hint[n];
  vector<int> arc[m+10];

  for(int i=0;i<n;i++)hint[i]=-1;

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

  queue<int> room;
  room.push(0);
  while(!room.empty()){
    int r = room.front();room.pop();
    for(int i=0;i<arc[r].size();i++){
      int to = arc[r][i];
      if(hint[to]==-1){
        hint[to]=r;
        room.push(to);
      }
    }
  }

  cout << "Yes" << endl;
  for(int i=1;i<n;i++){
    cout << hint[i]+1 << endl;
  }
}


Measured memory_bytes: 12624
a, b = list(map(int, input().split()))

if a == b:
	print(a+b)
elif a > b:
	c = a
	a = a - 1
	d = max(a,b)
	c += d 
	print(c)
elif a < b:
	c = b
	b = b - 1
	d = max(a,b)
	c += d 
	print(c)


Measured memory_bytes: 8984
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    stack<char> k;
    k.push(s[0]);

    for(int i=1;i<n;i++){
        if(!k.empty()){
            char c=k.top();
            if(c=='(' && s[i]==')'){
                k.pop();
            }
            else{
                k.push(s[i]);
            }
        }
        else{
            k.push(s[i]);
        }
    }
    int l=0,r=0;    // l=( r=)
    while(!k.empty()){
        char c=k.top();
        if(c==')')
            r+=1;
        else
            l+=1;
        k.pop();
    }
    for(int i=0;i<r;i++){
        cout<<'(';
    }
    cout<<s;
    for(int i=0;i<l;i++){
        cout<<')';
    }
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  int ans=0;
  bool check=true;
  while(check){
    for(int i=0;i<n;i++){
      if(a[i]%2!=0){
        cout<<ans<<endl;
        check=false;
        break;
      }
      else{
        a[i]/=2;
        if(i==n-1) ans++;
      }
    }
  }  
}


Measured memory_bytes: 256
M=99;main(n,i,j,k,a,b,c){
	float p=atan(1)*4,X[100],Y[100],x,y;
	for(;scanf("%d",&n),n;printf("%d\n",a)){
		for(i=0;i<n;i++)scanf("%f,%f",X+i,Y+i);
		for(a=i=0;i<n;a=a>b?a:b,i++){
			for(b=k=0;k<M;b=b>c?b:c,k++){
				x=X[i]+cos(p*k/M),y=Y[i]+sin(p*k/M);
				for(c=0,j=i;j<n;j++)if((X[j]-x)*(X[j]-x)+(Y[j]-y)*(Y[j]-y)<1+1e-3)c++;
			}
		}
	}
exit(0);}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y float64
	fmt.Scan(&w)
	fmt.Scan(&h)
	fmt.Scan(&x)
	fmt.Scan(&y)

	fmt.Print(w * h / 2)
	fmt.Print(" ")
	if x*2 == w && y*2 == h {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 512
(n,q),*t=[map(int,t.split())for t in open(0)]
s=[0]
d=s*n
f=s+[1]*n
e=[[]for _ in d]
for t in t:
 a,b=t
 if~-n:n-=1;e[a-1]+=b-1,;e[b-1]+=a-1,
 else:d[a-1]+=b
while s:
 v=s.pop()
 for w in e[v]:
  if f[w]:d[w]+=d[v];s+=w,;f[w]=0
print(*d)

Measured memory_bytes: 207620
/*AMETHYSTS*/
#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>
#include <unordered_map>
#include <random>

#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define mp make_pair
#define ui unsigned ll
#define pll pair <ll, ll>

using namespace std;

int cnt[26];

int main() {
	string s;

	cin >> s;

	ll ans = 1;

	for (int i = 0; i < (int)s.size(); i++) {
		ans += i - cnt[s[i] - 'a'];
		cnt[s[i] - 'a']++;
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> mochi(n);
  for (int i = 0; i < n; i++)
    cin >> mochi[i];
  
  sort(mochi.begin(), mochi.end());
  
  int count = 0, mochi_size;
  for (int i = n-1; i >= 0; i--) {
    if (count == 0) {
      mochi_size = mochi[i];
      count++;
    }
    else {
      if (mochi_size == mochi[i])
        continue;
      else {
        mochi_size = mochi[i];
        count++;
      }
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    bool res[4];
    for(int i = 0; i < 4; i++)  res[i] = false;
    for(int i = 0; i < 4; i++){
        int x;
        cin >> x;
        if(x == 1){
            res[0] = true;
        }
        else if(x == 9){
            res[1] = true;
        }
        else if(x == 7){
            res[2] = true;
        }
        else if(x == 4){
            res[3] = true;
        }
    }

    if(res[0] && res[1] && res[2] && res[3]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;

}



Measured memory_bytes: 256
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException{
		
		        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		        String str = br.readLine();
		        String[] div = str.split(" ");
		        int s =  Integer.parseInt(div[0]);
		        int l =  Integer.parseInt(div[1]);
		        System.out.println(s*l + " "+ 2*(s+l));
		    }   
		}

Measured memory_bytes: 24196
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;
double a[3005];
double dp[3005][3005];
int n;
double find(int h,int t)
{
	if(h+t==n)
	{
		if(h>t)return 1;
		else return 0;
	}
	if(dp[h][t]!=-1)return dp[h][t];
	return dp[h][t]=find(h+1,t)*a[h+t]+find(h,t+1)*(1.0-a[h+t]);
}
void solve()	
  {

	
	cin>>n;
	rep(i,3001)
	rep(j,3001)dp[i][j]=-1;
	rep(i,n)cin>>a[i];
	cout<<fixed<<setprecision(9)<<find(0,0);
	// cout<<dp[0][0];

  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


Measured memory_bytes: 74476
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
pre_idx = -1
pre_val = -1
for idx, val in enumerate(a):
    if pre_idx == -1:
        pre_idx = idx
        pre_val = val
    else:              # pre_idx != -1:
        if pre_val == val  - 1:
            ans = ans + c[pre_val - 1]
            pre_idx = idx
            pre_val = val
        else:
            pre_idx = idx
            pre_val = val   
        
print(ans)

Measured memory_bytes: 3064
import collections
import sys

def solve(n, A, B):
  Ac = {}
  ABc = {}
  Bc = {}
  for a in A:
    Ac[a] = 1 + Ac.get(a, 0)
    ABc[a] = 1 + ABc.get(a, 0)
    Bc[a] = Bc.get(a, 0)
  for b in B:
    Ac[b] = Ac.get(b, 0)
    Bc[b]  = 1 + Bc.get(b, 0)
    ABc[b] = 1 + ABc.get(b, 0)
  cAB = sorted([(c, ab) for ab, c in ABc.items()])
  #print(cAB)
  pool = collections.deque()  #[bbbb]   # [(b, count)], FIFO to match at the end

  matched = {}  # {a: bbbb}    # {a: {b, count}
  current = n   # how many are not matched yet
  for c, ab in cAB[::-1]:
    if c > current + len(pool):
      print('No')
      return
    matched[ab] = []
    while c > current:
      # take c - current from pool, add to matched
      c -= 1
      matched[ab].append(pool.popleft())
    # add (ab, Bc[ab]) to pool
    current -= Bc[ab]
    for _ in range(Bc[ab]):
      pool.append(ab)
  #print(pool, matched)
  skipped = []
  for c, ab in cAB:
    # take c - matched[ab] from pool, add to matched
    nn = Ac[ab]-len(matched[ab])
    while skipped and  Ac[ab]-len(matched[ab]) > 0:
      matched[ab].append(skipped.pop())
    while Ac[ab]-len(matched[ab]) > 0:
      p = pool.popleft()
      if p == ab:
        skipped.append(p)
      else:
        matched[ab].append(p)
      #print(ab, pool, matched, skipped)

  ans = []
  for a, bb in sorted(matched.items()):
    ans += [str(b) for b in bb]
  print('Yes')
  print(' '.join(ans))


def main():
  input = sys.stdin.readline
  n = int(input())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  solve(n, A, B)

main()


Measured memory_bytes: 205144
import java.util.*;
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<>();
    for (int i=0; i<N; i++) {
        int num = sc.nextInt();
    	list.add(num);
    }
    Collections.sort(list, Collections.reverseOrder());
    long ans = (long)list.get(0);
    long count = 1;
    int j = 1;
    for (int i=1; i<N-1; i++) {
        ans += list.get(j);
        if (count%2 == 0) {
        	j++;
        }
      	count++;
    }
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 65512
// Aizu 1347: Shopping
// 2017.11.3 bal4u@uu

#include <stdio.h>

int f[1002];

int main()
{
	int n, m, c, d, i, min, max, ans;
	
	scanf("%d%d", &n, &m);
	min = n, max = 0;
	while (m--) {
		scanf("%d%d", &c, &d);
		if (c < min) min = c;
		if (d > max) max = d;
		for (i = c; i < d; i++) f[i] = 1;
	}
	for (ans = 0, i = min; i <= max; i++) ans += f[i];
	printf("%d\n", n + (ans << 1) + 1);
	return 0;
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

void ib(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

vector < int > a;

int main(){
	a.pb(1);
	a.pb(1);
	a.pb(1);
	a.pb(2);
	a.pb(1);
	a.pb(2);
	a.pb(1);
	a.pb(5);
	a.pb(2);
	a.pb(2);
	a.pb(1);
	a.pb(5);
	a.pb(1);
	a.pb(2);
	a.pb(1);
	a.pb(14);
	a.pb(1);
	a.pb(5);
	a.pb(1);
	a.pb(5);
	a.pb(2);
	a.pb(2);
	a.pb(1);
	a.pb(15);
	a.pb(2);
	a.pb(2);
	a.pb(5);
	a.pb(4);
	a.pb(1);
	a.pb(4);
	a.pb(1);
	a.pb(51);
//	cout << a.size() << endl;
	int n;
	cin >> n;
	cout << a[n-1] << endl;
	return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

xkd = input().split()
N = int(xkd[0])
X = int(xkd[1])
T = int(xkd[2])

times = int(N/X)
if N%X != 0:
    times+=1

ans = T*times
print(ans)




Measured memory_bytes: 9288
#include<stdio.h>

int max(int,int);
int main()
{
  int x,y,temp,a;

  scanf("%d%d",&x,&y);
 
  printf("%d\n",max(x,y));
  return 0;
}
  
int max(int x,int y)	
{
  int a,temp;
  if(x<y)
    {
      temp=x;
      x=y;
      y=temp;
    }
   while(y>0)
    {
      a = x % y;
      x = y;
      y = a;
    }
   return x;
}



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

int main()
{
  int n,d;
  cin >> n >> d;
  
  int x[n],y[n];
  for(int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    double dist = hypot(x[i],y[i]);
    if(dist <= d){
      ans++;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 5208
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
     
template<typename T>
T gcd(T a, T b){
	return b != 0 ? gcd(b, a % b) : a;
}    


int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,ans=0,sum=0,Max=-1,Min=1e9+1;
  bool ok = true;
  string s,t,r;
  cin >> n >> s;

  rep(i,n){
    if(s[i]=='R') x++;
    if(s[i]=='G') y++;
    if(s[i]=='B') z++;
  }
  sum = x*y*z;
  for(int j=1;j<=n;j++){
    for(int i=0;i<n;i++){
      if(i-j<0 || i+j>=n) continue;

      if(s[i-j]!=s[i+j] && s[i]!=s[i+j] && s[i-j]!=s[i]) sum--;
    }
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3640
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(M)]

P = [[] for _ in range(N+1)]

class City():
    def __init__(self, i, p, y):
        self.i = i
        self.p = p
        self.y = y
        self.x = None
        self.id = None
        
for i, (p, y) in enumerate(A):
    city = City(i, p, y)
    P[p].append(city)
    
for p, cities in enumerate(P):
    cities.sort(key=lambda x: x.y)
    for x, city in enumerate(cities):
        city.id = ('000000'+str(p))[-6:] + ('000000'+str(x+1))[-6:]
        city.x = x+1

P = [city for cities in P for city in cities]
P.sort(key=lambda x: x.i)

for city in P:
    print(city.id)


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

int main() {
  int n,x,t=0;
  cin>>n>>x>>t;
  if(n%x==0){
    cout<<t*(n/x);
  }else{
    cout<<t*(n/x+1);
  }
}

Measured memory_bytes: 3632