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

using ll = long long;
using namespace std;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);

#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}


void init();
void solve();

signed main()
{
	init();
	solve();
}


void init()
{
	string s;
	cin >> s;
	vector<int> x(3, 0);
	rep(i, s.length()) {
		x[s[i]-'a']++;
	}
	sort(all(x));
	YES(x[2] - x[0] <= 1);
}

void solve()
{
}




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

inline bool cek_bit(int id, int mask)
{
   return (1<<id) & mask;
}

int n,tar;
int p[15];
int c[15];

int main()
{
   scanf("%d%d",&n,&tar);
   for(int i=0;i<n;i++)
   {
      scanf("%d%d",&p[i],&c[i]);
   }
   int ans = 2000;
   for(int i=0;i<(1<<n);i++)
   {
      int tot = 0;
      int cnt = 0;
      for(int j=0;j<n;j++)
      {
         if(cek_bit(j,i))
         {
            tot+=p[j] * 100 * (j+1);
            tot+=c[j];
            cnt+=p[j];
         }
      }
      for(int j=n-1;j>=0;j--)
      {
         if(tot>=tar) break;
         if(!cek_bit(j,i))
         {
            int dif = tar - tot;
            dif = min(p[j],(dif+((100)*(j+1) -1)) /(100 * (j+1)));
            tot+=dif * 100 * (j+1);
            cnt+=dif;
         }
      }
      ans = min(ans,cnt);
   }
   printf("%d\n",ans);
 	return 0;
}


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

int d[32][32],g[501][501];
ll co[3][32];
int main(){
    int n,c;
    cin>>n>>c;
    FOR(i,1,c+1)FOR(j,1,c+1) cin>>d[i][j];
    rep(i,n)rep(j,n) cin>>g[i][j];
    ll ans=1000100010;
    //rep(i,3)FOR(j,1,c+1)co[i][j]=1000100010;
    rep(k,3){
        FOR(i,1,c+1){
            int sum=0;
            rep(p,n)rep(q,n){
                if((p+q)%3==k){
                    sum+=d[g[p][q]][i];
                }
            }
            co[k][i]=sum;
        }
    }
    FOR(i,1,c+1)FOR(j,1,c+1)FOR(k,1,c+1){
        if(i==j||i==k||j==k) continue;
        ans=min(ans,co[0][i]+co[1][j]+co[2][k]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
int h , w;
int dp[N][N];
char a[N][N];
int main() {
    abdelrahman010
    cin >> h >> w;
    for(int i = 1;i <= h;i++)
        for(int j = 1;j <= w;j++)
            cin >> a[i][j];
    dp[0][1] = 1;
    for(int i = 1;i <= h;i++)
        for(int j = 1;j <= w;j++) {
            int &ans = dp[i][j];
            if(a[i][j] == '#') {
                ans = 0;
                continue;
            }
            ans = (ans + dp[i - 1][j]) % mod;
            ans = (ans + dp[i][j - 1]) % mod;
        }
    cout << dp[h][w];
    return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<string>
using namespace std;
  
int main() {
  string word, cmd, repwrd;
  int n, s, e;
  
  cin >> word;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    cin >> s;
    cin >> e;
    if (cmd == "replace") cin >> repwrd;
  
    if (cmd == "print") cout << word.substr(s, e - s + 1) << endl;
    else if (cmd == "reverse") {
      string str = word.substr(0, s);
      for (int j = e; s <= j; j--) {
        str += word[j];
      }
      str += word.substr(e+1, word.size()-e);
      word = str;
    }
    else if (cmd == "replace") word.replace(s, e - s + 1, repwrd);
  }
  
  return 0;
}


Measured memory_bytes: 3228
def solve():
    N = int(input())
    s = [int(input()) for _ in range(N)]
    sm = sum(s)
    dp = [False] * (sm + 1)
    dp[0] = True

    for val in s:
        for i in range(sm, -1, -1):
            if dp[i] and i+val <= sm:
                dp[i+val] = True
    
    for i in range(sm, -1, -1):
        if dp[i] and i % 10 != 0:
            print(i)
            return
    else:
        print(0)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 65736
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void YES(bool ok){
    cout << (ok ? "First" : "Second") << endl;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> dp(n_max);
    auto f = [&](ll x){
        vector<ll> vec(n+1);
        for(auto &i : a){
            if(x >= i)vec[dp[x - i]] = 1;
        }
        rep(i,n+1)if(vec[i] == 0)return i;
        assert(false);
        return n;
    };
    
    reps(i,k){
        dp[i] = f(i);
    }
    YES(dp[k] != 0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a,b;
  cin >> a >> b;
  cout << lcm(a,b) << endl;
}


Measured memory_bytes: 3612
from collections import deque
import sys
N = int(input())

if N == 1:
	print('a')
	sys.exit()
else:
	ans = []
	def solve(s,m):
		if len(s) == N:
			ans.append(s)
			return 
		for n in range(97, m+2):
			solve(s + chr(n), max(n,m))
	solve('a',97)
	for a in ans:
		print(a)
	

Measured memory_bytes: 12996
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	char c; 
	int sum=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>c;
		if(c=='I')sum++;
		if(c=='D')sum--;
		ans=max(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <unordered_map>
typedef long long ll;
#define re register

#define gc getchar
#define pc putchar
#define sp pc(' ')
#define ln pc('\n')

template <class t>
inline void read(t&num) {
    register char c = gc();
    register bool flag = 0;
    while (c != '-' && (c < '0' || c > '9')) c = gc();
    if (c == '-') flag = 1, c = gc();
    num = 0;
    while (c >= '0' && c <= '9') num = (num << 1) + (num << 3) + (c ^ 48), c = gc();
    flag && (num = ~(num - 1));
}

template <class t>
inline void print(t num) {
    if (num < 0) pc('-'), num = ~(num - 1);
    if (num >= 10) print(num / 10);
    pc(num % 10 ^ 48);
}

int n;
int a[21], b[21], c[21];

int main() {
    read(n);
    for (int i = 1; i <= n; i++) read(a[i]);
    for (int i = 1; i <= n; i++) read(b[i]);
    for (int i = 1; i < n; i++) read(c[i]);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += b[a[i]];
        if (a[i + 1] == a[i] + 1) ans += c[a[i]];
    }
    print(ans), ln;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

bool card[4][13];
char suits[4] = {'S', 'H', 'C', 'D'};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, num;
    char suit;
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>suit>>num;
        if(suit=='S') card[0][num-1]=true;
        if(suit=='H') card[1][num-1]=true;
        if(suit=='C') card[2][num-1]=true;
        if(suit=='D') card[3][num-1]=true;
    }
    for(int i=0; i<4; i++) {
        for(int j=0; j<13; j++) {
            if(card[i][j]==false) {
                cout<<suits[i]<<' '<<j+1<<'\n';
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1196
INF = 1 << 29
COINS = [500,100,50,10,5,1]
while gets
  l = $_.split.map(&:to_i)
  p = l.shift
  break if p == 0
  ret = INF
  for change in 0..499
    ps = cs = 0
    pay = p + change
    for k in 0..5
      m = [pay/(c=COINS[k]), l[5-k]].min
      ps += m
      pay -= m*c
      break if pay == 0
    end
    for coin in COINS
      m = change / coin
      cs += m
      change -= m*coin
      break if change == 0
    end
    ret = ps + cs if ret > (ps + cs)
  end
  p ret
end

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

int main (void) {
    int a, b, c, d, ttl;
    cin >> a >> b >> c >> d;

    if (a < b) {
        ttl += a;
    } else {
        ttl += b;
    }

    if (c < d) {
        ttl += c;
    } else {
        ttl += d;
    }

    int ans = ttl;
    cout << ans << endl;
}

Measured memory_bytes: 3648
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll a, b, c, d;

int main() {
    fast_io; cout_precision;
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> es(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		es[--a]++;
		es[--b]++;
	} 
	rep(i, n) cout << es[i] <<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in();
	cout << (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: usize,
        q: u32,
        s: chars,
        lr: [[usize; 2]; q]
    }
    let mut m: [u32; 100009] = [0; 100009];
    for i in 2..n+1 {
        m[i] = if s[i-2] == 'A' && s[i-1] == 'C' { m[i-1] + 1 } else { m[i-1] }; 
    }
    lr.into_iter().for_each(|lr_| {
        println!("{}", m[lr_[1]] - m[lr_[0]]);
    })
}


Measured memory_bytes: 9484
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
    var n = int.Parse(ReadLine());
    var input = ReadLine().Split(' ').Select(int.Parse).ToArray();
    var min = 2000000000;
    
	for(var i = 0;i < 101;i++){
      var result = 0;
    	for(var j = 0;j < n;j++){
        	result = result + Math.Abs((input[j] - i)*(input[j] - i));
        }
      if(result < min){
      	min = result;
      }
    }
    Write(min);
    
  }
}


Measured memory_bytes: 18944
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = next()
    println(when(n) {
        "Sunny" -> "Cloudy"
        "Cloudy" -> "Rainy"
        "Rainy" -> "Sunny"
        else -> ""
    })
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31620
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
[print(*x) for x in [[sum(j*k for j,k in zip(x,y)) for y in zip(*b)] for x in a]]


Measured memory_bytes: 7000
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a,b;
  cin>>n;
  if(n%1000==0)
  {
    cout<<"0";
  }
  else
  {
    a=(n%1000);
    b=1000-a;
    cout<<b;
  }
  
  }


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    b += a;
    if(a>k){
        cout << k;
    }else if(b>=k){
        cout << a;
    } else {
            c = k-b;
            cout << a-c;
    }
    return 0;
}

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

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 305

int n;
double memo[N][N][N];
double dfs(int a, int b, int c) {
  if(memo[a][b][c] >= -1) {
    return memo[a][b][c];
  }
  double r = 0;
  if(a) {
    r += (dfs(a-1, b, c)+1) * a;
  }
  if(b) {
    r += (dfs(a+1, b-1, c)+1) * b;
  }
  if(c) {
    r += (dfs(a, b+1, c-1)+1) * c;
  }
  int p = (a + b + c);
  return memo[a][b][c] = (r + n - p) / p;
}
int c[4];

int main() {
  cin >> n;
  rep(i, n) {
    int a; cin >> a;
    ++c[a];
  }
  rep(a, N) {
    rep(b, N) {
      rep(c, N) {
        memo[a][b][c] = -2;
      }
    }
  }
  memo[0][0][0] = 0;
  printf("%.10f\n", dfs(c[1], c[2], c[3]));
  return 0;
}

Measured memory_bytes: 221952
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
vector<int> data[100];
int finds[100];
/*
int dfs(int foo, int timer)
{
    //foo is node number
    if (finds[foo].first != -1)
        return timer;
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i, data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second = ++result;
    return result;
}
*/
int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        cin >> temp;
        rep(j, temp)
        {
            int hoge;
            cin >> hoge;
            data[i].push_back(hoge - 1);
        }
        finds[i] = -1;
    }
    queue<int> que;
    que.push(0);
    finds[0] = 0;
    while (!que.empty())
    {
        int temp = que.front();
        que.pop();
        rep(i, data[temp].size())
        {
            if (finds[data[temp][i]] == -1)
            {
                finds[data[temp][i]] = finds[temp] + 1;
                que.push(data[temp][i]);
            }
        }
    }
    rep(i, n)
    {
        cout << i + 1 << " " << finds[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>

using namespace std;

typedef long long ll;

const ll prime = 10000000000 + 7;

/*
vector<int> z_algorithm(const string& s) {
	vector<int> prefix(s.size());
	for (int i = 1, j = 0; i < s.size(); i++)
	{
		if (i + prefix[i - j] < j + prefix[j]) {
			prefix[i] = prefix[i - j];
		}
	}
}
*/

struct UnionFind {
	vector<ll> par;
	vector<ll> rank;

	UnionFind(ll n) {
		par = vector<ll>(n);
		rank = vector<ll>(n);
		for (ll i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}

	ll root(ll x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return root(par[x]);
		}
	}

	bool is_same(ll x, ll y) {
		return (root(x) == root(y));
	}

	void connect(ll x, ll y) {
		if (!is_same(x, y)) {
			ll x1, y1;
			x1 = root(x);
			y1 = root(y);
			if (rank[x1] < rank[y1]) {
				par[x1] = y1;
			}
			else if (rank[x1] > rank[y1]) {
				par[y1] = x1;
			}
			else {
				par[x1] = y1;
				rank[y1]++;
			}
		}
	}
};

int main() {

	ll n;
	cin >> n;
	
	ll m = ll(pow(double(n), 0.5));

	ll ans;
	while (true) {
		if ((n % m) == 0) {
			ans = m + (n / m);
			break;
		}
		m--;
	}
	ans -= 2;

	cout << ans << endl;

	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1000000000 //
#define LINF (ll)4000000000000000000 //
#define MOD (ll)1000000007
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    string s;
    cin >> s;
    vector<string> v;

    rep(i, 16) {
        int j = i;
        int a, b, c, d;
        d = j % 2;
        j /= 2;
        c = j % 2;
        j /= 2;
        b = j % 2;
        j /= 2;
        a = j;
        string t;
        if (a == 1) t.push_back('A');
        t += "KIH";
        if (b == 1) t.push_back('A');
        t.push_back('B');
        if (c == 1) t.push_back('A');
        t.push_back('R');
        if (d == 1) t.push_back('A');
        v.push_back(t);
    }

    bool can = false;

    rep(i, 16) {
        if (s == v[i]) can = true;
    }

    YES(can);

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
#define vll			vector<ll>
#define sll			set<ll>
const ll inf = 1000000000000000;
ll in = 1000000000000000000;
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

int main()
{
	FastIO;
	ll t, a, i, j, k, q, c, d, b, r,n;
	cin >> n;
	vll v, u;
	f(i, n-1)
	{
		cin >> a;
		v.push_back(a);
	}
	ll sum = v[0];
	for(i=0;i<n-2;i++)
	{
		sum += min(v[i], v[i + 1]);
	}
	cout << sum + v[n - 2] << endl;
	return 0;
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			int n = Integer.parseInt(br.readLine());
			
			if(n == 0){
				break;
			}
			
			String[] tmpArray = br.readLine().split(" ");
			
			int fieldW = Integer.parseInt(tmpArray[0]);
			int fieldH = Integer.parseInt(tmpArray[1]);
			
			boolean[][] persimmon = new boolean[fieldH+1][fieldW+1];
			for(int i = 0; i <= fieldH; i++){
				Arrays.fill(persimmon[i], false);
			}
			//init persimmon
			for(int i = 0; i < n; i++){
				tmpArray = br.readLine().split(" ");
				int x = Integer.parseInt(tmpArray[0]);
				int y = Integer.parseInt(tmpArray[1]);
				persimmon[y][x] = true;
			}
			tmpArray = br.readLine().split(" ");
			int estateW = Integer.parseInt(tmpArray[0]);
			int estateH = Integer.parseInt(tmpArray[1]);
			
			//??¨?????????????????????????????§?????£?????????
			int max = 0;
			for(int i = 1; i + estateH - 1<= fieldH ; i++){
				for(int j = 1; j + estateW - 1 <= fieldW ; j++){
					int sumOfPersimmon = 0;
					for(int k = i; k < i + estateH ; k++){
						for(int l = j; l < j + estateW ; l++){
							if(persimmon[k][l]){
								sumOfPersimmon++;
							}
						}
					}
					
					if(sumOfPersimmon > max){
						max = sumOfPersimmon;
					}
				}
			}
			System.out.println(max);
		}
	}

}

Measured memory_bytes: 32768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    double n,a[110];
    double sum=0;
    cin>>n;
    lol(i,n){
	cin>>a[i];
	sum+=a[i];
    }
    sum/=(n+0.0);
    double mini=mod,ans=0;
    lol(i,n){
	double dis=abs(sum-a[i]);
	if(dis<mini){
	    ans=i;
	    mini=dis;
	}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

D = int(input().strip())
C = list(map(int,input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

ans = 0
score = 0
last = [[-1] for i in range(26)]
schedule = []

for d in range(D):
  t = d%26
  last[t].append(d)
  score += S[d][t]
  schedule.append(t)

for i in range(26):
  last[i].append(D)
  for k in range(len(last[i])-1):
    g = last[i][k+1]-last[i][k]-1
    score -= C[i]*g*(g+1)//2

count = 1000000
import random
while count:
  count -= 1
  prev = score
  d = random.choice(range(D))
  c = (d + random.choice(range(1,26)))%D
  p = schedule[d]
  q = schedule[c]
  schedule[d] = q
  schedule[c] = p
  score -= S[d][p]
  score += S[d][q]
  score -= S[c][q]
  score += S[c][p]
  
  pos = last[p].index(d)
  score -= C[p]*(last[p][pos]-last[p][pos-1])*(last[p][pos+1]-last[p][pos])
  last[p].remove(d)
  
  pos = bisect.bisect(last[q],d)
  score += C[q]*(d-last[q][pos-1])*(last[q][pos]-d)
  bisect.insort(last[q],d)
  
  pos = last[q].index(c)
  score -= C[q]*(last[q][pos]-last[q][pos-1])*(last[q][pos+1]-last[q][pos])
  last[q].remove(c)
  
  pos = bisect.bisect(last[p],c)
  score += C[p]*(c-last[p][pos-1])*(last[p][pos]-c)
  bisect.insort(last[p],c)
  if score<prev:
    score = prev
    bisect.insort(last[p],d)
    last[q].remove(d)
    bisect.insort(last[q],c)
    last[p].remove(c)
    schedule[d] = p
    schedule[c] = q
    
for i in schedule:
  print(i+1)

Measured memory_bytes: 95572
#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()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int K, T;
  cin >> K >> T;
  vector<int> a(T);
  REP(i,T) cin >> a[i];

  int res = 0;
  REP(i,T) {
    res += max(0, a[i] - (K - a[i] + 1));
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
//Mix Juice

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,k;cin>>n>>k;
    vecrep(n,a,int);
    sort(range(a));
    int ans = 0;
    rep(i,0,k){
        ans+=a[i];
    }
    cout<<ans<<nnn;
    return 0;
}

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

int main (){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int z=n-k;
    if(z>0) cout << x*k+y*z << endl;
    else cout << x*n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int d;
    while(cin>>d)
    {
        if(d==22)
        {
            cout<<"Christmas Eve Eve Eve"<<endl;
        }
        else if(d==23)
        {
            cout<<"Christmas Eve Eve"<<endl;
        }
        else if(d==24)
        {
            cout<<"Christmas Eve"<<endl;
        }
        else
        {
            cout<<"Christmas"<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
#define rep(i,j,k) for(ll i=0;i<j;i+=k)
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n);
	for(ll i=0;i<n;i++) {
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	ll ans =0;
	for(ll i=0;i<k;i++)
		ans += a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>  
#include <cstring>  
#include <cmath>  
#include <sstream>  
#include <iostream>  
#include <algorithm>  
#include <string>  
#include <stack>  
#include <queue>  
#include <vector>  
#include <map>  
#include <set>  
#include <utility>  
   
using namespace std;  
#define LL long long  
#define pb push_back  
#define mk make_pair  
#define pill pair<int, int>  
#define ft first  
#define sd second  
#define mst(a, b)   memset(a, b, sizeof a)  
#define REP(i, x, n)    for(int i = x; i <= n; ++i)  
const int qq = 1e5 + 10;  
const int MOD = 1e9 + 7;  
LL num[60];  
   
int main(){  
    LL k;   scanf("%lld", &k);  
    int cnt = 0;  
    LL tmp = k / 50;  
    for(int i = 49; i >= 0; --i) {  
        num[cnt] = i;  
        num[cnt] += tmp;  
        cnt++;  
    }  
    k = k % 50;  
    for(int i = 0; i < 50 && k > 0; ++i, --k) {  
        num[i]++;  
    }  
    printf("50\n");  
    for(int i = 0; i < 49; ++i) {  
        printf("%lld ", num[i]);  
    }  
    printf("%lld\n", num[49]);  
    return 0;  
}  

Measured memory_bytes: 256
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();
		
		String res = new Integer(a * b).toString();
		res += " ";
		res += (2*a + 2*b);
		System.out.println(res);
	}
}



Measured memory_bytes: 26224
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, A, B;

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

  if(A > B || (N == 1 && A != B)) cout << 0 << endl;
  else cout << A + (N - 1) * B - ((N - 1) * A + B) + 1 << endl;


  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <cmath>
#include <iomanip>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr double pi = std::acos(-1.0);

int main() {
  double A, B, H, M;
  std::cin >> A >> B >> H >> M;
  std::cout << std::fixed << std::setprecision(20);
  double angle = std::abs((2.0 * pi * (H / 12.0 + M / 720.0)) - (2 * pi * M / 60.0));
  std::cout << std::sqrt(A * A + B * B - 2.0 * A * B * std::cos(angle)) << '\n';
  return 0;
}


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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)


int main() {
   int a,b;
   cin >> a >> b;
   if(a+b==15){
       cout << "+" << endl;
   }
   else if(a*b==15){
       cout << "*" << endl;
   }
    else{
        cout << "x" << endl;
    }
    return 0;
}


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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int[] scores = new int[N];
        int Q = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            scores[i] = K - Q;
        }

        for (int i = 0; i < Q; i++ ) {
            scores[Integer.parseInt(sc.next())-1]++;
        }
        sc.close();

        for (int i = 0; i < N; i++) {
            if (scores[i] > 0) {
                out.printf("Yes\n");
            } else {
                out.printf("No\n");
            }
        }
        out.flush();
    }
}


Measured memory_bytes: 51252
N = int(input()) #1行目のNを取得する
s = list(map(int, input().split())) #複数行の数値の入力を取得


les = []

for i in range(1,N):
    tmp1 = 0
    tmp2 = 0
    for j in range(i):
         tmp1 = tmp1 + s[j]
         
    for k in range(i,N):
        tmp2 = tmp2 + s[k]


    les.append(abs(tmp1 - tmp2))

print(min(les))




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

const int M = 402;
const int N = 100002;
int n, m, X_[N], Y_[N];
bool valid[M], killed[M][M];

signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>m>>n;
    for(int i=1;i<=n;i++)
    	cin>>X_[i]>>Y_[i];

    for(int i=1;i<=m;i++){
    	killed[i][i] = true;
    	valid[i] = true;
    	for(int j=n;j>=1;j--)
    		if(killed[i][X_[j]] && killed[i][Y_[j]]){
    			valid[i] = false;
    			break;
    		}
    		else if(killed[i][X_[j]])
    			killed[i][Y_[j]] = true;
    		else if(killed[i][Y_[j]])
    			killed[i][X_[j]] = true;
    }


    int ans = 0;
    for(int i=1;i<=m;i++)
    	for(int j=i+1;j<=m;j++)
    		if(valid[i] && valid[j]){
    			bool good = true;
    			for(int k=1;k<=m;k++)
    				if(killed[i][k] && killed[j][k])
    					good = false;
    			ans += good;
    		}

    cout<<ans;
    return 0;
}




 



Measured memory_bytes: 1920
#![allow(non_snake_case)]

use proconio::input;
use proconio::fastout;

#[fastout]
fn main() {
    input! {
        W: usize,
        H: usize,
        p: [usize; W],
        q: [usize; H],
    }
    let mut pq = Vec::new();
    for i in 0..W {
        pq.push((p[i], 0));
    }
    for i in 0..H {
        pq.push((q[i], 1));
    }
    pq.sort();
    let mut result = 0;
    let mut n_roads = 0;
    let M = H * W + H + W;
    let mut n_rows = 0;
    let mut n_cols = 0;
    for (r, k) in pq {
        if k == 0 {
            let a = H + 1 - n_rows;
            result += a * r;
            n_cols += 1;
            n_roads += a;
        } else {
            let a = W + 1 - n_cols;
            result += a * r;
            n_rows += 1;
            n_roads += a;
        }
        if n_roads >= M {
            break;
        }
    }
    assert_eq!(n_roads, M);
    println!("{}", result);
}

Measured memory_bytes: 10156
n = int(input())
rain = list(map(int, input().split()))

rain_two = list(map(lambda x: x*2, rain))
total = sum(rain)

res = 0
for i in range(1, n, 2):
    res += rain_two[i]

ans = []
previous = total - res
ans.append(previous)
print(previous, end=" ")
for elm in rain_two[:-1]:
    tmp = elm - previous
    ans.append(tmp)
    previous = tmp
    print(previous, end=" ")


Measured memory_bytes: 17112
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC149A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = RString;
            var T = RString;
            Console.WriteLine(T+S);




        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n;
    cin >> n;

    int max = 0;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int num = i;
        int count = 0;
        while(true){
            if(num % 2 == 0){
                count++;
                num /= 2;
            }else{
                break;
            }
        }
        if(cnt <= count){
            cnt = count;
            max = i;
        }
    }

    p(max);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int P[2*100000];
int main() {
    int N,cnt=1;
    cin >> N;
    for (int i=0; i<N; i++) cin >> P[i];
    int m=P[0];
    for (int i=1; i<N; i++) {
        if (P[i] <= m) {
            cnt++;
            m = P[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def gcd2(a,b,c):
	a=gcd(a,b)
	a=gcd(a,c)
	return a

K = int(input())
ans = 0
for i in range(1,K+1):
	for j in range(1,K+1):
		for k in range(1,K+1):
			ans += gcd2(i,j,k)
print(ans)

Measured memory_bytes: 74012
// 72 72 72 72 72 72 72 72 72 72 72
#include <bits/stdc++.h> 
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef double ld;
typedef string st;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e17;                                                                                                  
ll mpow(ll a,ll b){a=a%MOD;ll res=1;while(b>0){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b=b>>1;}return res%MOD;}             

int main()
{ 
ios_base::sync_with_stdio(false);
cin.tie(NULL);
///freopen("input.txt", "r", stdin);
//freopen("output.txt","w",stdout);
ll k=0;
st s;
cin>>s;
forn(i,s.length())
{
    if(s[i]=='+') k++;
    else k--;
}
cout<<k;
return 0;    
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N = 100000;

int n, a[MAX_N];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int k;
		cin >> k;
		if((upper_bound(a, a + n, k)) - a == lower_bound(a, a + n, k) - a) cout << 0 << endl;
		else cout << 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 3480
n, m = map(int, input().split())
first = [False for _ in range(n + 1)]
second = [False for _ in range(n + 1)]

for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        first[b] = True
    if b == n:
        second[a] = True

for i, j in zip(first, second):
    if i and j:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')


Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
  ll N; cin>>N;
  vi A(N); REP(i,N) cin>>A[i];
  sort(ALL(A));
  vi B(N); B[0]=A[0]; FOR(i,1,N) B[i]=B[i-1]+A[i];
  vi C(N); C[N-1]=1;
  for(ll i=N-2;i>=0;i--) if(B[i]*2>=A[i+1]&&C[i+1]==1) C[i]=1;
  ll ans=0; REP(i,N) ans+=C[i];
  cout<<ans<<endl;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    vector<int> x(n);
    x.at(0) = 1;
    int c = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (a.at(i) == a.at(i + 1))
        {
            x.at(c)++;
        }
        else
        {
            c++;
            x.at(c)++;

        }
    }
    sort(x.begin(), x.end());
    reverse(x.begin(), x.end());
    int count = 0;
    for (int i = k; i < n; i++)
    {
        count += x.at(i);
    }
    cout << count << endl;
}

Measured memory_bytes: 1792