akhauriyash/Code-Regression huggingface dataset:
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let mut v = get!([usize]);
    v.sort();

    if v == &[1, 4, 7, 9] {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 8572
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();

    StringBuilder sb = new StringBuilder();
    int[] r = new int[N];
    for (int i = 0; i < N; i++) {
      r[0] += (i % 2 == 0 ? 1 : -1) * a[i];
    }
    sb.append(r[0]).append(' ');
    for (int i = 1; i < N; i++) {
      r[i] = 2 * a[i - 1] - r[i - 1];
      sb.append(r[i]).append(' ');
    }
    sb.setLength(sb.length() - 1);
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 54480
#include <iostream>
#include <string>

using namespace std;

int main(){
    long N; cin >> N;
    long long ans = 0;

    for (long i = 1; i <= N; i++)
    {
      if((i%3==0.0)||(i%5==0.0)) continue;
      ans += i;
    }
    
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin>>p.at(i);

  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<n-1;i++) ans+=p.at(i);
  ans=ans+p.at(n-1)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main{
  def main(args: Array[String]){
    val line = StdIn.readLine().split(" ").map(_.toInt)
    val a = initArray(line(0), line(1))
    val b = initArray(line(1), line(2))
    val c = Array.ofDim[Long](line(0), line(2))

    for(i <- 1 to line(0)){
      for(j <- 1 to line(2)){
        for(k <- 1 to line(1)){
          c(i-1)(j-1) += a(i-1)(k-1) * b(k-1)(j-1)
        }
      }
    }

    for(i <- 0 until line(0)){
      for(j <- 0 until line(2)){
        print(c(i)(j))
        if(j != line(2) - 1){
          print(" ")
        }
      }
      println
    }
  }

  def initArray(i: Int, j: Int):Array[Array[Long]] ={
    val a = Array.ofDim[Long](i, j)

    for(index <- 0 until i){
      val line = StdIn.readLine().split(" ").map(_.toInt)
      for(index2 <- 0 until j){
        a(index)(index2) = line(index2)
      }
    }
    a
  }
}

Measured memory_bytes: 53428
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  char H[100][100];
  int isYes = 1;
  for(int i = 0; i < a; i++){
    for(int j = 0; j < b; j++){
      cin >> H[i][j];
    }
  }

  for(int i = 0; i < a; i++){
    for(int j = 0; j < b; j++){

      if(H[i][j] == '#'){
        if(i == 0 && j == 0){
          if(H[i+1][j] == '.' && H[i][j+1] == '.'){
            isYes = 0;
          }
        }
        else if(i == a-1 && j == b-1){
          if(H[i-1][j] == '.' && H[i][j-1] == '.'){
            isYes = 0;
          }
        }
        else if(i == 0){
          if(H[i+1][j] == '.' && H[i][j+1] == '.' && H[i][j-1] == '.'){
            isYes = 0;
          }
        }
        else if(j == 0){
          if(H[i+1][j] == '.' && H[i][j+1] == '.' && H[i-1][j] == '.'){
            isYes = 0;
          }
        }
        else if(i == a-1){
          if(H[i][j+1] == '.' && H[i-1][j] == '.' && H[i][j-1] == '.'){
            isYes = 0;
          }
        }
        else if(j == b-1){
          if(H[i+1][j] == '.' && H[i-1][j] == '.' && H[i][j-1] == '.'){
            isYes = 0;
          }
        }
        else if(H[i+1][j] == '.' && H[i][j+1] == '.' && H[i-1][j] == '.' && H[i][j-1] == '.'){
          isYes = 0;
        }
      }
    }
  }

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
using namespace std;


ll max =0;





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

sort(ALL(v));
reverse(ALL(v));


double tmp =1;
for(ll i=0;i<n-1;i++){
tmp*=2.0;
v[i]=v[i]/tmp;
}
v[n-1]=v[n-1]/tmp;
double ans=0;
for(ll i=0;i<n;i++){
ans+=v[i];
}

cout<<ans<<endl;


}


/*

void ser(vector<double> a){

  if(a.size()==1){
    if(max<a[0])
    max = a[0];

    return;
  }



  for(ll i=0;i<a.size();i++){
    for(ll j=i;j<a.size();j++){
      if(i!=j){

      }
    }
  }

  return;
}


*/


Measured memory_bytes: 256
n=int(input())
lis=list(map(int,input().split()))
       
f_ans=100000000000000
for i in range(min(lis),max(lis)+1):
  ans=0
  for l in lis:
    ans+=(i-l)**2
  f_ans=min(ans,f_ans)
    
print(f_ans)
    
    


Measured memory_bytes: 9036
# include <bits/stdc++.h>
# 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 rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int countDigit(int n)
{
  int digit = 1;
  while((n /= 10) != 0)
    digit++;
  return digit;
}

int main()
{
  int keta = 0;
      int f = 10000;
  long n; cin >> n;
  reps(i,sqrt(n)+1){
    if(n % i != 0) continue;
    long a = i;
    long b = n /a;
    //cout << a << "," << b << endl;
    keta = countDigit(max(a,b));
    //cout << "大きい方の桁数：" << keta << endl;

    chmin(f,keta);
  }
  cout << f;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];
    
    typedef pair<ll, ll> P;
    vector<P> p(a.size());
    rep(i, a.size()) p[i] = P(b[i], a[i]);

    sort(all(p));

    ll latest = -1;
    ll res = 0;
    rep(i, m) {
        ll A = p[i].second;
        ll B = p[i].first;
        if (A <= latest) {

        }
        else {
            latest = B - 1;
            res++;
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 6428
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;


int main()
{
	int n, m, k;

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

	bool ok = false;

	for(int i = 0; i <= n; ++i) {
		for(int j = 0; j <= m; ++j) {

			int x = m;
			int xs = i * x;
			int y = (n - i) - i;
			int ys = j * y;
			int s = xs + ys;

			if(s == k)
				ok = true;
		}
	}

	printf("%s\n", ok ? "Yes" : "No");

	return 0;
}

/* waffle */


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
int main() {
    int n,k; cin >> n >> k;
    map<string,int>m;
    rep(i,k){
        int d; cin >>d;
        rep(j,d){
            string A;
            cin >> A;
            m[A]++;
        }
    }
    cout << n-m.size() <<endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);
  rep(i,n){
    int x;
    cin >> x;
    x--;
    a[i] = x;
  }
  rep(i,n){
    cin >> b[i];
  }
  rep(i,n-1){
    cin >> c[i];
  }
  int sum=0;
  rep(i,n){
    sum += b[a[i]];
  }
  rep(i,n-1){
    if(a[i+1]-a[i]==1){
      sum += c[a[i]];
    }
    //cout << sum << endl;
  }
  cout << sum << endl;
  return 0;
}

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

const int MOD = (int)1e9+7;

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

  if(S.size()!=26){
    vector<bool> alphabet(26,false);
    for(int i=0;i<S.size();i++){
      alphabet.at(S.at(i)-'a')=true;
    }
    for(int i=0;i<26;i++){
      if(!alphabet.at(i)){
        S+=i+'a';
        cout << S;
        break;
      }
    }
    return 0;
  }
  if(S=="zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }

  for(int i=0;i<26;i++){
    bool flag=true;
    for(int j=i+1;j<26;j++){
      if(S.at(j)>S.at(j-1))  flag=false;
    }
    if(flag){
      char s=S.at(i-1);
      char q;
      for(int j=i;j<26;j++){
        if(s<S.at(j)){
          q=S.at(j);
        }
      }
      for(int j=0;j<i-1;j++){
        cout << S.at(j);
      }
      cout << q << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1LL;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll mod_inv(ll x, ll mod) {
	return mod_pow(x, mod - 2, mod);
}

class Combination {
public:
	Array fact;//n！
	Array inv;//n!の逆元
	ll mod;
	Combination(ll n, ll _mod) {
		mod = _mod;
		fact.resize(n + 1);
		fact[0] = 1;
		REP(i, n) {
			fact[i + 1] = (fact[i] * (i + 1LL)) % mod;
		}
		inv.resize(n + 1);
		inv[n] = mod_inv(fact[n]);
		for (int i = n; i > 0; i--) {
			inv[i - 1] = inv[i] * i % mod;
		}
	}
	//modの逆元
	ll mod_inv(ll x) {
		ll n = mod - 2;
		ll res = 1LL;
		while (n > 0) {
			if (n & 1) res = res * x % mod;
			x = x * x % mod;
			n >>= 1;
		}
		return res;
	}
	ll nCr(ll n, ll r) {
		return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
	}
	ll nPr(ll n, ll r) {
		return (fact[n] * inv[n - r]) % mod;
	}
	ll nHr(ll n, ll r) {
		//重複組み合わせ：n種類のものからr個取り出す組み合わせ
		return nCr(r + n - 1, r);
	}
};

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

	ll n, k;
	cin >> n >> k;
	Combination com(401010, MOD);

	if (k >= n - 1) {
		cout << com.nCr(2 * n - 1, n - 1) << en;
		return 0;
	}

	ll ans = com.nCr(2 * n - 1, n - 1);

	ll pre = 0;
	rep(i,1,n - k) {

		ll now = com.nCr(n - 1, i - 1);
		(now *= com.nCr(n, i)) %= MOD;
		(ans += MOD - now) %= MOD;
	}

	cout << ans << en;

	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int prime[100010];
bool isprime[100010];
int a[100010];

int sieve(int n)
{
  int p=0;
  for (int i=0; i<=n; i++) isprime[i] = true;
  isprime[0] = isprime[1] = false;
  for (int i=2; i<n; i++) {
    if (isprime[i]) {
      prime[p++] = i;
      for (int j=2*i; j<=n; j+=i) isprime[j] = false;
    }
  }
  return p;
}

int main()
{
  int q; cin>>q;
  vector<int> ans;

  sieve(100000);
  for (int i=1; i<=100000; i+=2) {
    if (!isprime[i]) continue;
    if (isprime[(i+1)/2]) a[i] = 1;
  }
  for (int i=0; i<=100000; i++) {
    a[i+1] += a[i];
  }

  while (q--) {
    int l,r; cin>>l>>r;
    ans.push_back(a[r]-a[l-1]);
  }
  for (auto v:ans) cout << v << endl;

  return 0;
}


Measured memory_bytes: 4388
#include<stdio.h>
int main(){
    int x,ans=0;
    scanf("%d", &x);
    if(x<=599){
      printf("8");
      return 0;
    }else if(x<=799){
      printf("7");
      return 0;
    }else if(x<=999){
      printf("6");
      return 0;
    }else if(x<=1199){
      printf("5");
      return 0;
    }else if(x<=1399){
      printf("4");
      return 0;
    }else if(x<=1599){
      printf("3");
      return 0;
    }else if(x<=1799){
      printf("2");
      return 0;
    }else if(x<=1999){
      printf("1");
      return 0;
    }
}


Measured memory_bytes: 1664
using System;
class aoj
{
    static void Main()
    {
        int[,] a = new int[14, 14];
        while (true)
        {
            string z = Console.ReadLine();
            if (String.IsNullOrEmpty(z)) break;
            string[] b = z.Split(',');
            int x = int.Parse(b[0]) + 2, y = int.Parse(b[1]) + 2, s = int.Parse(b[2]);
            if (s == 1)
            {
                a[x, y] += 1;
                a[x, y + 1] += 1;
                a[x, y - 1] += 1;
                a[x + 1, y] += 1;
                a[x - 1, y] += 1;
            }
            else if (s == 2)
            {
                a[x, y] += 1;
                a[x, y + 1] += 1;
                a[x, y - 1] += 1;
                a[x + 1, y] += 1;
                a[x - 1, y] += 1;
                a[x - 1, y - 1] += 1;
                a[x + 1, y + 1] += 1;
                a[x - 1, y + 1] += 1;
                a[x + 1, y - 1] += 1;
            }
            else if (s == 3)
            {
                a[x, y] += 1;
                a[x, y + 1] += 1;
                a[x, y - 1] += 1;
                a[x + 1, y] += 1;
                a[x - 1, y] += 1;
                a[x - 1, y - 1] += 1;
                a[x + 1, y + 1] += 1;
                a[x - 1, y + 1] += 1;
                a[x + 1, y - 1] += 1;
                a[x + 2, y] += 1;
                a[x - 2, y] += 1;
                a[x, y + 2] += 1;
                a[x, y - 2] += 1;
            }
        }
        int k = 0, l = 0;
        for (int i = 2; i < 12; i++)
        {
            for (int j = 2; j < 12; j++)
            {
                if (a[i, j] == 0)
                {
                    k++;
                }
                if (a[i, j] > l)
                {
                    l = a[i, j];
                }
            }

        }
        Console.WriteLine(k + "\n" + l);
    }
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    Scd(N);
    vector<int> a(N);
    multimap<int,int> m;
    priority_queue<int> p;
    int ind = INF;

    p.push(0);
    Rep(i,N){
        Scd(a[i]);
        m.insert( {a[i],i} );
        if( p.top() < a[i] ) ind = i;
        p.push(a[i]);
    }

    vector<ll> ans(N);

    ll cnt = 0;
    ll diff = 0;
    ll tmp = p.top();
    ll top = 0;
    while( !p.empty() ){
        top = p.top();
        if( top == 0 ) break;
        while( p.top() == top ) p.pop();


        auto it = m.find(top);
        while( it != m.end() ){
            cnt++;
            ind = min( ind,it->second );
            m.erase(it);
            it = m.find(top);
        }

        diff = top - p.top();

        // printf ("!%llu: %llu*%llu \n", top, cnt, diff );

        ans[ind] += cnt*diff;
    }

    Rep(i,N){
        printf ("%llu\n", ans[i] );
    }

    return 0;
}



Measured memory_bytes: 7288
#include<stdio.h>
#include<math.h>
int main(void){
    double a,b,c,d,e,f,output1,output2;

    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
        output1=(c*e-b*f)/(a*e-b*d);
        output2=(c*d-a*f)/(b*d-a*e);
        if(fabs(output1) < 0.00000001)output1 = 0;
        if(fabs(output2) < 0.00000001)output2 = 0;
        printf("%.3f %.3f\n",output1,output2);
    }
    return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll soln(vector<vector<int>>a,int w){
    int n=a.size();
    ll dp[n+1][w+1];memset(dp,0,sizeof(dp));
    dp[1][a[0][0]]=a[0][1];
    for(int i=2;i<=n;i++){
        for(int j=0;j<=w;j++){
            dp[i][j]=INT_MIN;
            if(j-a[i-1][0]>=0)dp[i][j]=a[i-1][1]+dp[i-1][j-a[i-1][0]];
            dp[i][j]=max(dp[i-1][j],dp[i][j]);
        }
    }
    return *max_element(dp[n],dp[n]+w+1);
}
int main() {
    int t,k;cin>>t>>k;vector<vector<int>>ans;
    while(t--){
        int x,y;cin>>x>>y;
        ans.push_back({x,y});
    }
    cout<<soln(ans,k);
    return 0;
}

Measured memory_bytes: 82448
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = 100100100100;
const int MOD = 1000000007;
const ld EPS = 1e-10;

int main(){
  int N, K, R, S, P; cin >> N >> K >> R >> S >> P;
  string T; cin >> T;

  ll ans = 0;
  rep(i, K) {
    int M = (N - i + K - 1) / K;
    vector<ll> xr(M+1), xp(M+1), xs(M+1);
    rep(j, M) {
      int l = i + K*j;
      xr[j+1] = max({xp[j], xs[j]}) + ((T[l] == 's') ? R : 0);
      xs[j+1] = max({xr[j], xp[j]}) + ((T[l] == 'p') ? S : 0);
      xp[j+1] = max({xs[j], xr[j]}) + ((T[l] == 'r') ? P : 0);
    }
    ans += max({xr[M], xs[M], xp[M]});
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2816
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S = to_string(N);
    ll keta_n = S.size();
    ll ans = 0;
    rep(A,1,N+1){
        string as = to_string(A);
        ll sz = as.size();
        char lv = as[0];
        char rv = as[sz-1];
        if(rv == '0') continue;
        if(lv == rv){
            ll v = lv - '0';
            if(v <= N) ans++;
        }
        ll keta = 2;
        while(keta <= keta_n){
            if(keta != keta_n){
                ll val = 1;
                rep(i,0,keta-2){
                    val *= 10;
                }
                ans += val;
            }else{
                ll val = 1;
                rep(i,0,keta-2){
                    val *= 10;
                }
                ll start = (rv - '0');
                rep(i,0,keta-1) start *= 10;
                start += (lv - '0');
                if(S[0] > rv){
                    ans += val;
                }else if(S[0] == rv){
                    ll hidari = -1, migi = val;
                    while(migi - hidari > 1){
                        ll mid = (hidari + migi) / 2;
                        ll res = start + mid * 10;
                        if(res <= N){
                            hidari = mid;
                        }else{
                            migi = mid;
                        }
                    }
                    ans += hidari+1;
                }

            }
            keta++;

        }

    }
    print(ans);

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define SIZE 2010
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n;

int main() {
	io(); cin >> n;
	int ans = 1;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			ll tmp = n;
			while (tmp % i == 0) tmp /= i;
			if ((tmp - 1) % i == 0) ans++;
			tmp = n;
			if (i * i == n) continue;
			ll x = n / i;
			while (tmp % x == 0) tmp /= x;
			if ((tmp - 1) % x == 0) ans++;
		}
	}
	n--;
	if (n > 1) ++ans;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			ans += 2;
			if (i * i == n) --ans;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
using namespace std;
const int mod=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    rep(i,0,m-1)cin >> p[i] >> s[i];
    vector<bool> isac(n);
    rep(i,0,n-1)isac[i] = false;
    int ac = 0,wa = 0;
    vector<int> wat(n);
    int now = 0;
    rep(i,0,m-1){
        if(s[i] == "WA")wat[p[i]-1]++;
        if(s[i] == "AC" && !isac[p[i]-1]){
            ac++;
            wa += wat[p[i]-1];
            isac[p[i]-1] = true;
        }
    }


    cout << ac << " " << wa <<  endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 6528
#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; cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    auto w = v;
    sort(w.begin(), w.end());

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(v[i] != w[i])
            cnt++;
    }
    cout << (cnt <= 2 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(void){
	int n, i, a, b, x, y;
	while(1){
		scanf("%d",&n);
		if(!n){
			break;
		}
		a = b = 0;
		for(i = 0;i < n;i++){
			scanf("%d%d",&x,&y);
			if(x > y){
				a += x + y;
			}else if(x < y){
				b += x + y;
			}else{
				a += x;
				b += y;
			}
		}
		printf("%d %d\n",a,b);
	}
	return 0;
}

Measured memory_bytes: 1028
from collections import deque

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

  # 前後をチェックする再帰関数( 要素として深さも必要そう / DPのメモ化とか使えそう )
  # 
  # 生データ
  # 1桁
  # [1, 2, 3, 4, 5, 6, 7, 8, 9]
  # 2桁 
  # [10, 11, 12, 21, 22, 23,..., 98, 99]
  #
  # 1
  # 10 11 12
  #
  #          2
  # .. .. .. 21 22 23
  #
  # Point.
  #   1の木, 2の木と小さい順に自然となってる
  #   重複していない
  #
  # キューを使った方法の解説
  #
  # 初期状態
  # 1 2 3 4 5 6 7 8 9
  #
  # 遷移1
  # . 2 3 4 5 6 7 8 9 10 11 12
  #
  # 遷移2
  # . . 3 4 5 6 7 8 9 10 11 12 21 22 23
  #
  # 遷移3
  # . . . 4 5 6 7 8 9 10 11 12 21 22 23 32 33 34

  # 最初の1桁データの用意
  q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

  for _ in range(k-1):
    p = q.popleft()
    l = p % 10
    # print("l:", l)

    if l - 1 >= 0:
      new_data1 = int(str(p) + str(l - 1))
      # print("new_data1:", new_data1)
      q.append(new_data1)
      # print("q:", q)
    
    new_data2 = int(str(p) + str(l))
    # print("new_data2:", new_data2)
    q.append(new_data2)
    # print("q:", q)

    if l + 1 <= 9:
      new_data3 = int(str(p) + str(l + 1))
      # print("new_data3:", new_data3)
      q.append(new_data3)
      # print("q:", q)

  # print("===============")
  print(q[0])
  # print("===============")

if __name__ == "__main__":
  main()


Measured memory_bytes: 10916
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            string A = ReadLine();
            string B = ReadLine();
            string C = ReadLine();

            string turn = "a";

            while (A.Length > 0 || B.Length > 0 || C.Length > 0)
            {

                if (turn == "a")
                {
                    if (A.Length == 0)
                    {
                        WriteLine("A");
                        break;
                    }
                    turn = A[0].ToString();
                    A = A.Remove(0, 1);
                }
                else if (turn == "b")
                {
                    if (B.Length == 0)
                    {
                        WriteLine("B");
                        break;
                    }
                    turn = B[0].ToString();
                    B = B.Remove(0, 1);
                }
                else if (turn == "c")
                {

                    if (C.Length == 0)
                    {
                        WriteLine("C");
                        break;
                    }
                    turn = C[0].ToString();
                    C = C.Remove(0, 1);
                }
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A ,B ,C;
  cin >> A >> B >> C;
 if(A == 5 && B == 5 && C == 7)
   cout << "YES" << endl;
 else if(C == 5 && B == 5 && A == 7)
   cout << "YES" << endl;
  else if(A == 5 && C == 5 && B == 7)
   cout << "YES" << endl;
  else{
  cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int m,f,r,sum;
	while(1){
		cin>>m>>f>>r;
		sum=m+f;
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		else if(m==-1||f==-1){
			cout<<"F";
		}
			else if(sum>=80){
				cout<<"A";
			}
			else if(sum>=65){
				cout<<"B";
			}
			else if(sum>=50){
		         cout<<"C";
			}
			else if(sum>=30){
			if(r>=50){
				cout<<"C";
			}
			else {
				cout<<"D";
			}
			}
			else {
				cout<<"F";
	}
			cout<<endl;
	}
	return 0;
}

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

using namespace std;

int n, p;
string s;
long long tbl[10000] = {0};

long long complx (long long a){
    if(a <= 1) return 0;
    return (a * (a - 1)) / 2;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> p;
    cin.ignore();
    cin >> s;
    cin.ignore();

    reverse(s.begin(), s.end());
    long long ans = 0;
    if(p == 2 || p == 5){
        for(int i = 0; i < s.size(); i++){
            if((s[i] - '0') % p == 0) ans += s.size() - i;
        }
        cout << ans << endl;
        return 0;
    }

    long long m = 0;
    long long te = 1;
    tbl[0] = 1;
    for(int i = 0; i < s.size(); i++){
        m += (s[i] - '0') * te;
        m %= p;
        ++tbl[m];
        te *= 10;
        te %= p;
    }

    for(int i = 0; i < p; i++){
        ans += complx(tbl[i]);
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
	int n,m;	cin>>n>>m;

	if(n>=m) cout<<0<<endl;
	else{
		int x[m];	for(int i=0;i<m;i++)cin>>x[i];
		sort(x,x+m);
		int d[m-1];	
		for(int i=0;i<m-1;i++){
			d[i]=x[i+1]-x[i];
		}

		sort(d,d+m-1);
		reverse(d,d+m-1);

		int ans=0;
		for(int i=0;i<n-1;i++){
			d[i]=0;
		}
		for(int i=0;i<m-1;i++)ans+=d[i];

		cout<<ans<<endl;
	}

	return 0;
}


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

int main()
{
    lld n;
    cin>>n;
    if (n%2){
        cout<<"0\n";
        return 0;
    }
    lld ans = 0;
    for (lld i = 10; n / i >= 1; i *= 5){
        ans += n / i;
    }
    cout<<ans<<'\n';
    return 0;
}


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

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

int main() {
    string S;
    cin >> S;
    int ans = 999;
    for(int i = 0;i<S.size()-2;i++){
        int num = (S.at(i) - '0')*100 + (S.at(i+1) - '0')*10 + (S.at(i+2) - '0') ;
        int sa = num - 753;
        sa = my_abs(sa);
        if(ans >= sa){
            ans = sa;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         1000000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;
int gcd(int a, int b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int power(int x,  int y, int p){
    int res = 1;      // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1; // y = y/2
            x = (x*x) % p;
    }
    return res;
}

int mod_inv(int a,int m){
    a=a%m;
    return power(a,m-2,m)%MOD;
}

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

bool mod(double a,double b) {
    return a/b - floor(a/b);}

int logb(int base, int x) {
    return (log(x) / log(base));
}
char ToLower(char c)
{
    if ((c >= 'A') && (c <= 'Z')) return (char)((int)c - 'A' + 'a');
    else return c;
}

int Vowel(char c)
{
    c = ToLower(c);
    return (c == 'a') || (c == 'o') || (c == 'i') || (c == 'y') || (c == 'u') || (c == 'e');
}
bool cmp(pair<int,int> &a,pair<int,int> &b)
{
    if(a.first!=b.first)
    return a.first<b.first;
    return a.second>b.second;
}
int countSetBits(int x)
{
    if(x==0)return 0;
    else return 1+countSetBits(x&(x-1));
}
int fact(int n);

int nCr(int n, int r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

// Returns factorial of n
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
int n;
bool in_range(int x,int y)
{
    if(x>=0 && x<=n-1 && y>=0 && y<=n-1)return true;

    return false;
}
bool palindrom(string s)
{
    int len=s.length();
    bool okay=true;
    for(int i=0;i<=len/2;i++)
    {
        if(s[i]!=s[len-i-1]){okay=false; break;}
    }
    return okay;
}
signed main()
{
    fastio;
    int n;
    cin>>n;
    string s;
    cin>>s;
    map<char,int> m;
    for(int i=0;i<n;i++)
    {
        m[s[i]]++;
    }
    if(m['R'==n])
    {
        cout<<0<<endl;
    }
    else
    {
        vector<int> r,w;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='R')r.push_back(i);
            else w.push_back(i);
        }
        int k=0;
        int ans=0;
        for(int i=0;i<m['R'];i++)
        {
            if(s[i]!='R')ans++;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 5720
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ull unsigned long long
#define lli long long int
#define pb push_back
ll mob=1000000007;
using namespace std;
ll dp[1000000][3];
int main()

{ int n;
std::cin >> n;
int a[n][3];
FOR(i,n)
{
    FOR(j,3){cin>>a[i][j];}
}

FOR(i,n)
{
    FOR(j,3)
    {
    if(i==0)
    {
        dp[i][j]=a[i][j];
        
    }
    else
    {
        FOR(k,3)
        {
            if(j==k)
            continue;
            dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
            
        }
    }
        
    }
    
}
ll u=0;
if(u<dp[n-1][0])
u=dp[n-1][0];
if(u<dp[n-1][1])
u=dp[n-1][1];
if(u<dp[n-1][2])
u=dp[n-1][2];

cout<<u;
return 0;
}










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

#define INF 1e18;
#define MAX_N 100005
long long N, h[MAX_N], memo[MAX_N];

long long dp(int pos) {
  if (pos < 1) {
  	return INF;
  }
  if (pos == 1) {
  	return 0;
  }
  if (pos == 2) {
  	return abs(h[2] - h[1]);
  }
  if (memo[pos] != -1) {
  	return memo[pos];
  }
  return memo[pos] = min(abs(h[pos] - h[pos - 1]) + dp(pos - 1), (abs(h[pos] - h[pos - 2]) + dp(pos - 2)));
}

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
  	cin >> h[i];
  }
  /*
  memo[2] = abs(h[2] - h[1]);
  for (int i = 3; i <= N; i++) {
  	memo[i] += min(abs(h[i] - h[i - 1]) + memo[i - 1], abs(h[i] - h[i - 2]) + memo[i - 2]);
  }
  */
  /*
  for (int i = 1; i <= N; i++) {
  	cout << i << ' ' << memo[i] << '\n';
  }
  */
  // cout << memo[N] << '\n';
  memset(memo, -1, sizeof memo);
  cout << dp(N) << '\n';
}

Measured memory_bytes: 3328
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int, int> P;
 
int h, w, ans;
int castle[1001][1001], times[1001][1001];
int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
char beach[1001][1001];
 
int main(){
    scanf("%d%d", &h, &w);
    for(int i = 0; i < h; i++){
        scanf("%s", &beach[i]);
    }
 
    queue<P> Q;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(beach[i][j] == '.'){
                Q.push(P(i, j));
            } else{
                castle[i][j] = beach[i][j] - 48;
            }
        }
    }
 
    while(Q.size()){
        P p = Q.front();
        Q.pop();
        ans = max(ans, times[p.first][p.second]);
 
        for(int i = 0; i < 8; i++){
            int y = p.first + dy[i], x = p.second + dx[i];
            if(y < 0 || y >= h || x < 0 || x >= w){
                continue;
            }
 
            castle[y][x]--;
            if(castle[y][x] == 0){
                Q.push(P(y, x));
                times[y][x] = times[p.first][p.second] + 1;
            }
        }
    }
 
    printf("%d\n", ans);
 
    return 0;
}

Measured memory_bytes: 10040
# Reference: https://note.nkmk.me/python-union-find/
class UnionFind:
    # if x is root: self.parents[x] = -(the number of the group nodes)
    # else: self.parents[x] = the parent of x
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # return the parent of x
    def find(self, x):
        history = []
        while self.parents[x] >= 0:
            history.append(x)
            x = self.parents[x]
        for node in history:
            self.parents[node] = x
        return x

    # merge the group of x and the group of y
    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

    # return the size of the group of x
    def size(self, x):
        return -self.parents[self.find(x)]

    # return whether x and y in a same group
    def same(self, x, y):
        return self.find(x) == self.find(y)

from sys import stdin
input = stdin.buffer.readline

def main():
    n, m = map(int, input().split())
    a = [0] * m
    b = [0] * m
    for ind in range(m):
        i, j = map(int, input().split())
        a[ind] = i - 1
        b[ind] = j - 1

    ans = [0] * m
    uf = UnionFind(n)
    cnt = n * (n-1) // 2
    for ind in range(m-1, -1, -1):
        ans[ind] = cnt
        if not uf.same(a[ind], b[ind]):
            cnt -= uf.size(a[ind]) * uf.size(b[ind])
            uf.union(a[ind], b[ind])

    for i in ans:
        print(i)

main()

Measured memory_bytes: 79772
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    V< bitset<100> > bs(n);
    for (int i = 0; i < n; ++i) {
      int m; cin >> m;
      for (int j = 0; j < m; ++j) {
        int p; cin >> p, --p;
        bs[i][p] = true;
      }
    }
    bitset<100> b;
    int m; cin >> m;
    for (int j = 0; j < m; ++j) {
      int p; cin >> p, --p;
      b[p] = true;
    }
    set<int> se;
    for (int i = 0; i < n; ++i) {
      if ((b | bs[i]) == bs[i]) {
        se.insert(i);
      }
    }
    if (se.size() != 1) cout << -1 << '\n';
    else cout << *begin(se) + 1 << '\n';
  }
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,gcd;
  cin >> n >> k;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(i==0){
      gcd = a[i];
    }
    gcd = __gcd(gcd, a[i]);
  }
  sort(a,a+n);
  if(a[n-1]>=k and k%gcd==0) cout << "POSSIBLE\n";
  else cout << "IMPOSSIBLE\n";
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <functional>

using namespace std;

int main () {
    int n,k,ans = 1;

    cin >> n >> k;

    for(int i = 0;i < n;i++){
        if(ans * 2 < ans + k){
            ans *= 2;
        }
        else{
            ans += k;
        }
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#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 ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200003;
int n, a[2][N], b[2][N];

ll get(int x) {
	ll res = 0;
	for (int i = 0; i < n; i++)
		res += upper_bound(b[1], b[1] + n, x - a[1][i]) - b[1];
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[0][i];
	for (int i = 0; i < n; i++) cin >> b[0][i];
	ll ans = 0;
	for (int i = 0; i < 29; i++) {
		int m = (1 << (i + 1)) - 1;
		for (int j = 0; j < n; j++)
			a[1][j] = a[0][j] & m, b[1][j] = b[0][j] & m;
		sort(a[1], a[1] + n), sort(b[1], b[1] + n);
		int ways = get(m) - get((1 << i) - 1) + get((1 << (i + 1)) + m) - get((1 << (i + 1)) + (1 << i) - 1);
		if (ways & 1) ans |= (1 << i);
	}
	cout << ans;
}


Measured memory_bytes: 6780
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    String s = Integer.toString(n);

    char c = s.charAt(s.length() - 1);

    if (c == '3') {
      System.out.println("bon");
    } else if ((c == '0') || (c == '1') || (c == '6') || (c == '8')) {
      System.out.println("pon");
    } else {
      System.out.println("hon");
    }

  }

}

Measured memory_bytes: 35772
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int count_ans(string s1, string s2) {
    vector<int> a1(26, 0);
    vector<int> a2(26, 0);
    for(char c: s1)
        a1[c-'a'] = 1;
    for(char c: s2)
        a2[c-'a'] = 1;
    int ans = 0;
    for(int i = 0; i < 26; i++)
        if (a1[i] == 1 && a2[i] == 1)
            ans += 1;
    return ans;
}

int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for(int i = 1; i < n; i++) {
        ans = max(ans, count_ans(s.substr(0, i), s.substr(i, n-i)));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while(true) {
        int h,w;cin>>h>>w;
        if (h==0 && w==0) {
            return 0;
        }
        rep(i,h) {
            rep(j,w) {
                cout << '#';
            }
            cout << "\n";
        }
        cout << "\n";
    }
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ks(ll weight, ll *w, ll *v, int n){
	ll k[n+1][weight+1];
	for(int j=0; j<= weight; j++) k[0][j] = 0;
	for(int i=1; i<= n; i++){
		for(int j = 0; j<=weight; j++){
			if(w[i-1] > j) k[i][j] = k[i-1][j];
			else
				k[i][j]= max(k[i-1][j], k[i-1][j-w[i-1]] + v[i-1]);
		}
	}
	return k[n][weight];
}
int main(){
	int n;
	ll  weight;
	cin >> n >> weight;
	ll w[n], v[n];
	for(int i=0; i<n; i++) cin >> w[i] >> v[i];
	cout << ks(weight, w, v, n);
}

Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
int main(){
  int n; cin>>n;
  vector<int> h(n);
  for(int i=0;i<n;i++)
  cin >>h[i];

  int ans=0;

  while(1){
    int mx=0;

    for(int i=0;i<n;i++){
      if(mx<h[i]) mx=h[i];
    }
    if(mx==0) break;

    int i=0;
    while(i<n){
      if(h[i]==0)
      i++;
      else{
        ans++;
        while(h[i]!=0 && i<n){
          h[i]--;
          i++;
        }
      }
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int N;
    cin>>N;
    N%=10;
    string ans="hon";
    if(N==3){ans="bon";}
    else if(N==0 || N==1 || N==6 || N==8){ans="pon";}
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    string s;
    cin >> s;

    if ('5' <= s[6]) {
        cout << "TBD" << endl;
    } else if ('1' == s[5]) {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }

    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);
      	String[] sep = sc.nextLine().split(" ");
      	int n = Integer.parseInt(sep[0]); 
  		int m = Integer.parseInt(sep[1]);
  		System.out.println( n * (n - 1) / 2 + m * (m - 1) / 2 );
    }
  
}

Measured memory_bytes: 21716