akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.StreamTokenizer
import java.util.*

var minOtherCol = IntArray( 0 )
val INF = Int.MAX_VALUE / 2
var n: Int = 0
var en: IntArray = IntArray( 0 )
var e: Array<IntArray> = Array( 0, { IntArray( 0 ) } )
var X: IntArray = IntArray( 0 )

fun main(args: Array<String>) {
//    val random = Random()
//    while ( true ) {
        try {
            val st = StreamTokenizer( BufferedReader( InputStreamReader( System.`in` ) ) )
            n = st.nextInt()
//            n = random.nextInt( 1000 ) + 1
            en = IntArray( n )
            e = Array( n, { IntArray( n ) } )
            for ( i in 1 .. n - 1 ) {
                val p = st.nextInt() - 1
//                val p = random.nextInt( i )
                e[p][en[p] ++] = i
            }
            X = IntArray( n, { st.nextInt() } )
//            X = IntArray( n, { random.nextInt( 5001 ) } )
            minOtherCol = IntArray( n, { INF } )

            for ( v in n - 1 downTo 0 ) {
                if ( en[v] == 0 ) {
                    minOtherCol[v] = 0
                    continue
                }
                val can = BooleanArray( X[v] + 1 )
                can[0] = true
                var sum = 0L
                for ( i in 0 until en[v] ) {
                    val child = e[v][i]
                    sum += X[child] + minOtherCol[child]
                    for ( j in can.lastIndex downTo 0 ) {
                        if ( ! can[j] ) continue
                        can[j] = false
                        if ( j + X[child] < can.size ) can[j + X[child]] = true
//                        println( "$j $child ${minOtherCol[child]}")
                        if ( j + minOtherCol[child] < can.size ) can[j + minOtherCol[child]] = true
                    }
                }
                if ( can.none { it } ) {
                    minOtherCol[v] = INF
                    continue
                }
                minOtherCol[v] = Math.min( INF.toLong(),sum - can.lastIndexOf( true ) ).toInt()
            }
        //    dfs( 0 )
            println( if ( minOtherCol[0] < INF ) "POSSIBLE" else "IMPOSSIBLE" )
        } catch ( ex: IndexOutOfBoundsException ) {
            ex.printStackTrace()
            return
        }
//    }
}

//fun dfs( v: Int ) {
//    for ( i in 0 until en[v] ) dfs( e[v][i] )
//    if ( en[v] == 0 ) {
//        minOtherCol[v] = 0
//        return
//    }
//    val can = BooleanArray( X[v] + 1 )
//    can[0] = true
//    var sum = 0
//    for ( i in 0 until en[v] ) {
//        val child = e[v][i]
//        sum += X[child] + minOtherCol[child]
//        for ( j in can.lastIndex downTo 0 ) {
//            if ( ! can[j] ) continue
//            can[j] = false
//            if ( j + X[child] < can.size ) can[j + X[child]] = true
//            if ( j + minOtherCol[child] < can.size ) can[j + minOtherCol[child]] = true
//        }
//    }
//    if ( can.none { it } ) {
//        minOtherCol[v] = INF
//        return
//    }
//    minOtherCol[v] = sum - can.lastIndexOf( true )
//}

private fun StreamTokenizer.nextInt(): Int {
    nextToken()
    return nval.toInt()
}


Measured memory_bytes: 60184
import heapq


def solve(n):
  a = list(map(int,input().split()))
  # 左半分を計算して右端[n+idx]でメモ
  # 左半分は最大化したいので最小値が初めに出てくるようにする
  leftHsum = [0 for i in range(n+1)]
  leftH = a[0:n]
  heapq.heapify(leftH)
  leftHsum[0] = sum(leftH) # 
  for i in range(n):
    if leftH[0] < a[n+i]:
      leftHsum[i+1] = leftHsum[i] - leftH[0] + a[n+i]
      heapq.heappop(leftH)
      heapq.heappush(leftH, a[n+i])
    else:
      leftHsum[i+1] = leftHsum[i]
  # 右半分は負の値で保持する
  # もっとも大きい値から追い出していく
  rightHsum = [0 for i in range(n+1)]
  rightH = list(map(lambda x: -x,a[2*n:3*n]))
  heapq.heapify(rightH)
  rightHsum[0] = - sum(rightH)
  for i in range(n):
    if rightH[0] < -a[2*n-i-1]:
      rightHsum[i+1] = rightHsum[i] + rightH[0] + a[2*n-i-1]
      heapq.heappop(rightH)
      heapq.heappush(rightH, -a[2*n-i-1])
    else:
      rightHsum[i+1] = rightHsum[i]
  result = -1000000000000000000
  #print(leftHsum)
  #print(rightHsum)
  for i in range(n+1):
    result = max(result, leftHsum[0+i]-rightHsum[n-i])
  return result





n = int(input())
print(solve(n))


Measured memory_bytes: 37212
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int):
    print(N*(N-1)//2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
int main()
{
  int A,B,C;
  std::cin >> A >> B >> C;
  if((C-A)*(B-C)>0){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> c(n, 0), s(n, 0), f(n, 0);
	for (int i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];
	for (int i = 0; i < n; i++)
	{
		int t = s[i] + c[i];
		for (int j = i+1; j < n-1; j++)
			t = ((max(t, s[j])-1)/f[j]+1) * f[j] + c[j];
		cout << t << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;
using ll = long long;

ll deviders(ll a, ll b)
{
	return floor(a / (double long)b) + 1;
}

int main()
{
	ll a, b, x;
	cin >> a >> b >> x;
	ll cnt = 0;

	ll head = deviders(b, x);
	ll tail = (a == 0) ? 0 : deviders(a - 1, x);
	cnt = head - tail;
	cout << cnt << endl;
}

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

int main(){
  map<string,int> s;
  int n;
  cin >>n;
  int c=1;
  rep(i,n){
    string t;
     cin >> t;
    if(s.find(t)==s.end()){
      s.insert(make_pair(t,1));
    }
    else {
      ++s.at(t);
      c= max(c,s.at(t));
    }
  }
  for(auto itr = s.begin(); itr != s.end(); ++itr){
    if(itr->second==c) cout << itr->first << endl;
  }
  return 0;
}


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

template <class T>
class Prime {
 private:
  using S = typename std::vector<T>::size_type;
  std::vector<T> mind, primes;

 public:
  Prime(T n) : mind(n + 1) {
    mind[0] = mind[1] = 1;
    for (T i = 2; i < n; i++) {
      if (mind[i] == 0) primes.push_back(mind[i] = i);
      for (auto p : primes) {
        if (!(p <= mind[i] && i * p < n)) break;
        mind[i * p] = p;
      }
    }
  }
  bool operator()(T a) const { return a >= 2 && mind[a] == a; }
  T operator[](S i) const { return primes[i]; }
  S count() const { return primes.size(); }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& e : a) cin >> e;

  Prime<int> prime(1e3);

  vector<int> v(1e6 + 1);
  int d = a.front();
  for (auto e : a) {
    d = gcd(d, e);
    for (int i = 0; i < prime.count() && prime[i] <= e; i++) {
      if (e % prime[i] != 0) continue;
      while (e % prime[i] == 0) e /= prime[i];
      v[i]++;
    }
    if (e > 1) v[e]++;
  }

  if (*max_element(v.begin(), v.end()) <= 1) {
    cout << "pairwise coprime" << endl;
  } else if (d == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}


Measured memory_bytes: 11168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;

const double PI = acos(-1.0);

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;
    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }
    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }
    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }
    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }
    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }
    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll x,y;
    cin>>x>>y;
    ll z = min(x,y);
    ll ans = 0;
    if((x + y)%3 == 0){
        ll n = (x + y)/3;
        ll l = z-n;
        if(l >=0){
            cerr<<n<<"C"<<l<<endl;
            modint a = C(n,l);
            ans = a;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 28244
from bisect import bisect_left

n = int(input())
l_ls = sorted(map(int, input().split()))

ans = 0

for i in range(n):
    for j in range(i+1, n):
        a, b = l_ls[i], l_ls[j]
        right = bisect_left(l_ls, a+b)
        ans += right-(j+1)

print(ans)

Measured memory_bytes: 3188
n,m = map(int,input().split())
s = list(list(map(int,input().split())) for i in range(m))
x = [-1]*n
b = True
ans = -1
for i in range(m):
    if x[s[i][0]-1] == -1 or x[s[i][0]-1] == s[i][1]:
        x[s[i][0]-1] = s[i][1]
    else:
        b = False
for j in range(n):
    if x[j] == -1:
        if len(x) != 1 and j == 0:
            x[j] = 1
        else:
            x[j] = 0
if len(x) != 1 and x[0] == 0:
    b = False
ans = ''.join([str(c) for c in x]) if b else -1
print(ans)

Measured memory_bytes: 3064
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;


signed main() {
	ll N, ans = 0, Wp = -1, Rp = -1, frag = 0;
	cin >> N;
	vector<char> c(N);
	REP(i, N) {
		cin >> c[i];
		if (c[i] == 'W'&& Wp == -1) Wp = i;
	}
	for (int i = N - 1; i >= 0; i--) {
		if (c[i] == 'R'&& Rp == -1) Rp = i;
	}
	while (frag == 0) {
		if (Rp == -1 || Wp == -1) {
			answer(ans);
			return 0;
		}
		if (Rp == 0 || Wp == N - 1 || Rp<Wp) {
			answer(ans);
			return 0;
		}
		c[Wp] = 'R';
		c[Rp] = 'W';
		ans++;

		for (int i = Wp + 1; i<N; i++) {
			if (c[i] == 'W') {
				Wp = i;
				break;
			}
			if (i == N - 1) {

				frag = 1;
			}
		}
		for (int i = Rp - 1; i >= 0; i--) {
			if (c[i] == 'R') {
				Rp = i;
				break;
			}
			if (i == 0) {
				frag = 1;
			}
		}
		if (Rp<Wp) {
			frag = 1;
		}

	}

	answer(ans);
	system("pause");
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
ll a[100005];
ll inf = 1000000000;
int main() {
	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll count = 0;
	for (int i = 0; i < n-1; i++) {
		if (a[a[i] - 1] == i + 1) {
			a[a[i] - 1] = 0;
			count++;
		}
		
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include <stdio.h>
#define int long long
using namespace std;
signed main() {
	double n = 0, m = 0, a, b, p, q, r, gg = 0; cin >> a >> b >> p >> q >> r;
	n = p * b; m = q * (b - a);
	gg = (n - m) / (r + q) + b;
	printf("%.14f\n", gg);
}


Measured memory_bytes: 3280
#![allow(unused_imports)]






fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut v: Vec<_> = s
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    v.swap(0, 1);
    v.swap(0, 2);

    println!("{} {} {}", v[0], v[1], v[2]);
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
)

func main() {

	var in_n int
	fmt.Scanln(&in_n)

	for i := 1; i <= in_n; i++ {
		//CHECK_NUM
		x := i

		if x%3 == 0 {

			fmt.Printf(" %d", i)

		} else {
			//INCLUDE3
			for {
				if x%10 == 3 {
					fmt.Printf(" %d", i)
					break
				}
				x /= 10
				if x == 0 {
					break
				}

			}
		}
		//END_CHECK_NUM
		if (1 + i) > in_n {
			break
		}
	}

	fmt.Print("\n")
}



Measured memory_bytes: 1164
#include <bits/stdc++.h>
#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() {
    string S, T;
    cin >> S >> T;

    if (S == T) {
        cout << "Yes" << endl;
        return 0;
    }
    int N = S.size();
    rep(i,N) {
        S = S.at(N-1) + S;
        S.erase(N);
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
} 


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if(A+B<C+D){
    cout << "Right" << endl;
  }
  
  if(A+B>C+D){
    cout << "Left" << endl;
  }
  
  if(A+B==C+D){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define rem(i,n,x) for(int i=(n);i>=(x);--i)
#define SORT(x) sort(x.begin(),x.end())
#define pb push_back
using ll = long long;

int main() {
	int n; cin >> n;
	vector<int> l(n); rep(i, 0, n) cin >> l[i];

	int ans = 0;
	SORT(l);
	rep(i, 0, n-2) {
		int a = l[i];
		rep(j, i+1, n-1) {
			int b = l[j];
			rep(k, j+1, n) {
				int c = l[k];
				if (c >= a + b) break;
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

// input
string S, T;

int sn, tn;
vector<string> w;


void input() {
    cin >> S >> T;
}


void solve(int i) {
    string s = "";
    rep(j, i) {
        if (S[j] == '?') s += 'a';
        else s += S[j];
    }
    for (int j = i; j < i + tn; j++) {
        if (S[j] == '?') {
            s += T[j - i];
        } else if (S[j] == T[j - i]) {
            s += S[j];
        } else {
            return;
        }
    }
    for (int j = i + tn; j < sn; j++) {
        if (S[j] == '?') s += 'a';
        else s += S[j];
    }
    w.push_back(s);
}


int main() {
    input();
    sn = S.size();
    tn = T.size();
    if (sn < tn) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    rep(i, sn - tn + 1) solve(i);
    if (w.empty()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(w.begin(), w.end());
    string ans = w[0];
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    string S;cin>>S;
    bool ok=false;
    bool ok1=false;
    bool ok2=false;
    REP(i,3){
        if(S[i]=='a')ok=true;
        if(S[i]=='b')ok1=true;
        if(S[i]=='c')ok2=true;
    }
    if(ok&&ok1&&ok2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using namespace std;

const int MAXN=1e5+5;
int n;
int a[MAXN],b[MAXN],c[MAXN];
//
//class BIT{
//	private:
//		long long c[MAXN*3];
//		int lowbit(int x){return x&-x;}
//		long long qry(int r){
//			long long ret=0;
//			for(;r;r-=lowbit(r))
//				ret+=c[r];
//			return ret;
//		}
//	public:
//		void add(int l,int x){
//			for(;l<=3*n;l+=lowbit(l))
//				c[l]+=x;
//		}
//		long long qry(int l,int r){return qry(r)-qry(l-1);}
//}ta1,ta2;
//
//inline void decrete(){
//	static int tmp[MAXN*3];
//	for(int i=1;i<=n;++i){
//		tmp[++tmp[0]]=a[i];
//		tmp[++tmp[0]]=b[i];
//		tmp[++tmp[0]]=c[i];
//	}
//	sort(tmp+1,tmp+tmp[0]+1);
//	tmp[0]=unique(tmp+1,tmp+tmp[0]+1)-tmp-1;
//	for(int i=1;i<=n;++i){
//		a[i]=lower_bound(tmp+1,tmp+tmp[0]+1,a[i])-tmp;
//		b[i]=lower_bound(tmp+1,tmp+tmp[0]+1,b[i])-tmp;
//		c[i]=lower_bound(tmp+1,tmp+tmp[0]+1,c[i])-tmp;
//	}
//}

inline long long solve(){
	sort(a+1,a+n+1);
//	a[0]=unique(a+1,a+n+1)-a-1;
//	for(int i=1;i<=a[0];++i)
//		ta1.add(a[i]+1,1);
	sort(c+1,c+n+1);
	//c[0]=unique(c+1,c+n+1)-c-1;
//	for(int i=1;i<=c[0];++i)
//		ta2.add(c[i],1);
	sort(b+1,b+n+1);
	//b[0]=unique(b+1,b+n+1)-b-1;
	//ta1.cal(),ta2.cal();
	long long ret=0;
	for(int i=1;i<=n;++i){
		int x=lower_bound(a+1,a+n+1,b[i])-a-1;
		int y=upper_bound(c+1,c+n+1,b[i])-c;
		ret+=(long long)x*(n-y+1);
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
		scanf("%d",&b[i]);
	for(int i=1;i<=n;++i)
		scanf("%d",&c[i]);
	//decrete();
	printf("%lld",solve());
	return 0;
}

Measured memory_bytes: 1408
// inputに入力データ全体が入る
function Main(input) {
	var min=Number.MAX_VALUE,max = Number.MIN_VALUE;
	var arr = input.split(" ").map(v=>parseInt(v)).forEach(v=>{min=Math.min(min,v); max=Math.max(max,v);});
	console.log(max-min);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
A, B, C = gets.split.map(&:to_i)

def f(n)
  sum = n - A + n - B + n - C

  sum >= 0 && sum % 2 == 0
end

target = ([A, B, C].max..100).find { |x| f(x) }

puts (target - A + target - B + target - C) / 2


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<pair<int, int>> v(n);
  rep(i, n) {
    cin >> v[i].first;
    v[i].second = i;
  }
  sort(all(v));
  rep(i, n) {
    if (i) cout << " ";
    cout << v[i].second + 1;
  }
  cout << endl;
}


Measured memory_bytes: 1664
# 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>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 long long INF = 1LL << 60;

int main()
{
    long long n;
    cin >> n;
    vector<long long> h(n);
    rep(i,n) cin >> h[i];

    reverse(h.begin(),h.end());

    long long val = 0;

    long long ans = 0;

    for(int i = 1; i < n; i++){
        if(h[i-1] <= h[i]) val++;
        else val = 0;
        ans = max(ans,val);
    }

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i <= b;++i) cout << ary[i] << (b == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int N = 2010;
vector<int> bit(2010,0);
void add(int a, int w) {
	for (int x = a;x <= N;x += x&-x) bit[x] += w;
}
int sum(int a) {
	int ret = 0;
	for (int x = a;x > 0;x -= x&-x) ret += bit[x];
	return ret;
}

int main() {
    int n,a[4010];
    char c[4010];
    cin >> n;
    for (int i = 0;i < 2*n;++i) cin >> c[i] >> a[i];
    vector<vector<int>> b(2010,vector<int>(2010,0)),w(2010,vector<int>(2010,0));

    for (int i = 0;i <= n;++i) {
        bit = vector<int>(2010,0);
        int cw = 0;
        for (int j = 2*n-1;j >= 0;--j) {
            if (c[j] == 'B') {
                b[a[j]][i] = cw+sum(a[j]);
                add(a[j],1);
            } else if (a[j] <= i) cw++;
        }
    }
    for (int i = 0;i <= n;++i) {
        bit = vector<int>(2010,0);
        int cb = 0;
        for (int j = 2*n-1;j >= 0;--j) {
            if (c[j] == 'W') {
                w[i][a[j]] = cb+sum(a[j]);
                add(a[j],1);
            } else if (a[j] <= i) cb++;
        }
    }
    
    vector<vector<int>> dp(2010,vector<int>(2010,0));
    for (int i = 0;i <= n;++i) {
        for (int j = 0;j <= n;++j) {
            if (i == 0 && j == 0) continue;
            if (i == 0) dp[i][j] = dp[i][j-1]+w[i][j];
            else if (j == 0) dp[i][j] = dp[i-1][j]+b[i][j];
            else dp[i][j] = min(dp[i-1][j]+b[i][j],dp[i][j-1]+w[i][j]);
        }
        //p_ary(dp[i],0,n,j);
    }
    cout << dp[n][n] << endl;
    return 0;
}

Measured memory_bytes: 47872
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		final long Smax = Integer.MAX_VALUE;
		
		int count = 0;
		for(int i = 0; i < n; i++){
			final long S = sc.nextInt();
			
			boolean found = false;
			for(long x = 1; ; x++){
				if(S >= 2*(x*x + x)){
					if((S - x) % (2*x + 1) == 0){
						//System.out.println(x  + " " + S);
						found = true;
						break;
					}
				}else{
					break;
				}
			}
			
			if(!found){
				count++;
			}
		}
		
		System.out.println(count);
	}

}

Measured memory_bytes: 60692
def main():
    n, m = map(int, input().split())
    p = [False] * n
    q = p[:]
    for i in range(m):
        j, k = map(int, input().split())
        if j == 1:
            p[k] = True
        if j == n:
            q[k] = True
        elif k == n:
            q[j] = True
    for i in range(n):
        if p[i] and q[i]:
            print("POSSIBLE")
            return
    print("IMPOSSIBLE")


main()


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll ans=0;
    if(s == "SUN"){
        ans = 7;
    }else if(s == "MON"){
        ans = 6;
    }else if(s == "TUE"){
        ans = 5;
    }else if(s == "WED"){
        ans = 4;
    }else if(s == "THU"){
        ans = 3;
    }else if(s == "FRI"){
        ans = 2;
    }else if(s == "SAT"){
        ans = 1;
    }
    cout<<ans<<endl;
    return  0;
}


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

int main()
{
    int N, D;

    double ans;

    cin >> N>>D;

    ans = (double)N / ((D * 2) + 1);
    if (ceil(ans) == floor(ans)) cout << ans;
    else cout << (int)ans+1;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 4) {
        if(s[i] == '+') {
            ans++;
        }
        else {
            ans--;
        }
    }

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

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

using namespace std;

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

 std:vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  int q;
  cin >> q;

  int b, e;
  for(int i=0; i<q; ++i){
    cin >> b >> e;
    e--;
    while(b<e){
      std::swap(a[b], a[e]);
      b++; e--;
    }
  }
  cout << a[0];
  for(int i=1; i<n; ++i){
    if(i != n) cout << " ";
    cout << a[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3120
X = int(input())
X_MOD = X % 100
X_DIV = X // 100

import sys
sys.setrecursionlimit(2000)
def dfs(sum_x, cnt_x, num):
    if cnt_x > X_DIV:
        return False
    if sum_x == X_MOD:
        return True

    if num == 1:
        return dfs(sum_x+1, cnt_x+1, 1) or dfs(sum_x+1, cnt_x+2, 2) or dfs(sum_x+3, cnt_x+1, 3) or dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 2:
        return dfs(sum_x+1, cnt_x+2, 2) or dfs(sum_x+3, cnt_x+1, 3) or dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 3:
        return dfs(sum_x+3, cnt_x+1, 3) or dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 4:
        return dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 5:
        return dfs(sum_x+5, cnt_x+1, 5)
    

ans = int(dfs(0,0,1))
print(ans)

Measured memory_bytes: 42860
import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Frag=0;
    int[] A;
    A = new int[N];
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
    }
    for(int i=N;i>0;i--){
      for(int j=0;j<i-1;j++){
        if(A[j]>A[j+1]){
          int ch =A[j];
          A[j]=A[j+1];
          A[j+1]=ch;
          Frag++;
        }
      }
    }
    System.out.printf("%d",A[0]);
    for(int i=1;i<N;i++){
      System.out.printf(" %d",A[i]);
    }
    System.out.println("\n"+ Frag);
    sc.close();
  }
}


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

int main() {
  string S;
  int x=0;
  vector<int> T(26);
  cin >> S;
  sort(S.begin(), S.end());
  rep(i, S.size()){
    T.at(S.at(i)-'a')++;
  }
  rep(i,26){
    if(T.at(i)==0){
      cout << char(i+'a') << endl;
      x=1;
      break;
    }
  }
  if(x==0) cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    string s; cin>>s;
    vector<int> cnt(3, 0);
    for(int i=0; i<s.size(); i++){
        if(s[i]=='a') cnt[0]++;
        else if(s[i]=='b') cnt[1]++;
        else cnt[2]++;
    }

    sort(cnt.begin(), cnt.end());

    if(cnt[0]==cnt[2] || cnt[0]+1==cnt[2]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	cout<<n*800-(n/15)*200<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <assert.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// AGC043-A, 1012, 18:00(UNSOLVED), 
	int h, w; cin >> h >> w;
	vector<string> mp(h);
	rep(i, h) cin >> mp[i];
	vector<vector<int>> dp(h, vector<int>(w, iINF));
	dp[0][0] = mp[0][0] == '#' ? 1 : 0;
	rep(i, h) {
		rep(j, w) {
			if (j != 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + (mp[i][j - 1] != mp[i][j]));
			if (i != 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (mp[i - 1][j] != mp[i][j]));
		}
	}
	if (mp[h - 1][w - 1] == '#') dp[h - 1][w - 1]++;
	cout << dp[h - 1][w - 1] / 2 << endl;
	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
using ll = long long;
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int sl = s.length(), tl = t.length();
    int c = -1;
    for (int i = sl-tl; i >= 0; --i) {
        bool f = true;
        for (int j = 0; j < tl; ++j) {
            if(s[i+j] != t[j] && s[i+j] != '?') f = false;
        }
        if(f) {c = i; break;}
    }
    if(c >= 0){
        s.replace(c, tl, t);
        replace(s.begin(), s.end(), '?', 'a');
        cout << s << "\n";
    }else{
        cout << "UNRESTORABLE\n";
    }
    return 0;
}


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

int n, m, a, b;
vector<int> v[100010];
vector<int> put;
int bio[100010];

void dfs(int x) {
	bio[x] = 1;
	put.push_back(x);
	
	for (int i = 0; i < v[x].size(); i ++) {
		int sus = v[x][i];
		if (bio[sus] == 0) {
			dfs(sus);
			break;
		}
	}
}

int main() {

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

	dfs(a);
	reverse(put.begin(), put.end());
	for (int i = 0; i < v[a].size(); i ++) {
		if (bio[v[a][i]] == 0) {
			dfs(v[a][i]);
			break;
		}
	}
	
	cout << put.size() << endl;
	for (int i = 0; i < put.size(); i ++) {
		cout << put[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 9720
#include<stdio.h>
#define N 501

static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,y,data[N][N],C[N],d[N],f[N];

void dfs_1(int r)
{
  int a;

  C[r]=GRAY;
  y++;
  d[r]=y;

  for(a=0;a<n;a++){
    if(data[r][a]==0){
      continue;
    }
    if(C[a]==WHITE){
      dfs_1(a);
    }
  }
  C[r]=BLACK;
  f[r]=++y;
}
void dfs_2()
{
  int i,g;
  for(i=0;i<n;i++){
    C[i]=WHITE;
  }
 y=0;
  for(g=0; g<n; g++){
    if(C[g] == WHITE){
      dfs_1(g);
    }
  }
  for(i=0; i<n; i++){
    printf("%d %d %d",i+1,d[i],f[i]);
    printf("\n");
  }
}

int main()
{
  int i,j,r,k,v;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      data[i][j]=0;
    }
  }
  for(i=0; i<n; i++){
    scanf("%d%d",&r,&k);
    r--;
    for(j=0; j<k; j++){
      scanf("%d",&v);
      v--;
      data[r][v] = 1;
    }
  }

  dfs_2();

  return 0;
}


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

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

    int A, B, C;
    cin >> A >> B >> C;

    int M = max(A, max(B, C));
    if (M % 2 != (A + B + C) % 2) M++;

    cout << (3 * M - (A + B + C)) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int ans[] = {4,4,9,4,7,10,18,5,21,8,16,11,11,19,19,6,14,22,22,9,9,17,17,12,25,12,113,20,20,20,108,7,28,15,15,23,23,23,36,10,111,10,31,18,18,18,106,13,26,26,26,13,13,114,114,21,34,21,34,21,21,109,109,8,29,29,29,16,16,16,104,24,117,24,16,24,24,37,37,11,24,112,112,11,11,32,32,19,32,19,94,19,19,107,107,14,120,27,27,27};
int main(){
	int s;scanf("%d",&s);;printf("%d\n",ans[s-1]);
	return 0;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back

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

#define ll long long
#define oo 1e17
#define int long long

const int N = 2e5 + 5;
int n , C;
int a[N] , dp[N];

struct line
{
    int a , b;
    void operator -= (line const &o)
    {
        a -= o.a;
        b -= o.b;
    }
};

deque < line > dq;

int CCW(line l1 , line l2 , line l3)
{
    l3 -= l2;
    l2 -= l1;
    return l2.a * l3.b - l2.b * l3.a;
}

int val(line l , int x)
{
    return l.a * x + l.b;
}

void addline(line l)
{
    while(dq.size() >= 2 && CCW(dq[dq.size() - 2] , dq[dq.size() - 1] , l) >= 0)
        dq.pop_back();
    dq.pb(l);
}

ll query(int x)
{
    int l = 0 , r = dq.size() - 1;
    int res = 1e15;
    while(l <= r)
    {
        int mid = (l + r) / 2;
        res = min(res , val(dq[mid] , x));
        if(mid != 0 && val(dq[mid - 1] , x) < val(dq[mid] , x)) r = mid - 1;
        else if(mid != dq.size() - 1 && val(dq[mid + 1] , x) < val(dq[mid] , x)) l = mid + 1;
        else break;
    }
    return res;
}

main()
{
    //freopen("Z.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> C;
    FOR(i , 1 , n)
        cin >> a[i];
    line x;
    x.a = -2 * a[1];
    x.b = a[1] * a[1] + dp[1] + C;
    addline(x);
    FOR(i , 2 , n)
    {
        dp[i] = query(a[i]) + a[i] * a[i];
        x.a = -2 * a[i];
        x.b = a[i] * a[i] + dp[i] + C;
        addline(x);
    }
    cout << dp[n];
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A;
int B;
int main(){
  int res;
  rd(N);
  rd(A);
  rd(B);
  res =min_L(A*N, B);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190708-1

// --- original code ---
// int N, A, B;
// {
//   int res;
//   rd(N,A,B);
//   res = min(A*N,B);
//   wt(res);
// }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
	int n;
	string A;
	while(cin>>n>>A) {
		for(int i=0;i<n;i++) {
			stringstream B;
			char chr=A[0];
			int count=0;
			for(int i=0;i<A.size();i++) {
				if(chr!=A[i]) {
					B<<count<<chr;
					chr=A[i],count=1;
				}else count++;
			}
			B<<count<<chr;
			A=B.str();
		}
		cout<<A<<endl;
	}
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;
	ll h; cin >> h;
	vector<ll> a(n), b(n);
	REP(i, n) cin >> a[i] >> b[i];
	sort(ALL(a));
	sort(ALL(b));

	auto itr = lower_bound(ALL(b), a[n - 1]);
	int index;
	if (itr == b.end()) index = 0;
	else index = distance(b.begin(), itr);

	ll cnt = 0;
	for (int i = n - 1; i >= index; i--) {
		h -= b[i];
		cnt++;
		if (h <= 0) break;
	}

	if (h > 0) {
		ll div = h / a[n - 1];
		ll rem = h % a[n - 1];
		if (rem) cnt += div + 1;
		else cnt += div;
	}

	cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;

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

        int m;
        int f;
        int r;

        while(true){

        	m = scan.nextInt();
        	f = scan.nextInt();
        	r = scan.nextInt();
        	int sum = m+f;

        	if( m == -1 && f == -1 && r == -1){
        		break;
        	}
        	else if(m == -1 || f == -1){
        		System.out.println("F");
        	}else if(sum < 30 ){
        		System.out.println("F");
        	}
        	else if(sum >= 80){
        		System.out.println("A");
        	}
        	else if(sum >= 65 && sum < 80 ){
        		System.out.println("B");
        	}
        	else if(sum >= 50 && sum < 65 && r == -1){
        		System.out.println("C");
        	}
        	else if(sum >= 50 && sum < 65 && r >= 50){
        		System.out.println("C");
        	}
        	else if(sum >= 30 && sum < 50 && r >= 50){
        		System.out.println("C");
        	}
        	else if(sum >= 30 && sum < 50 && r < 50){
        		System.out.println("D");
        	}
        	else if(sum >= 30 && sum < 50 && m == 0 && r < 50){
        		System.out.println("D");
        	}
        	else if(sum >= 30 && sum < 50 && f == 0 && r < 50){
        		System.out.println("D");
        	}
        }

     }
}

Measured memory_bytes: 26220
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			boolean[][] list = new boolean[n][n+1];
			for(int i = 0; i < n; i++) {
				int m = stdIn.nextInt();
				for(int j = 0; j < m; j++) {
					int p = stdIn.nextInt();
					list[i][p] = true;
				}
			}
			int k = stdIn.nextInt();
			int[] list2 = new int[k];
			for(int i = 0; i < k; i++) {
				list2[i] = stdIn.nextInt();
			}
			int id = -1;
			boolean already = false;
			for(int i = 0; i < n; i++) {
				boolean check = true;
				for(int j = 0; j < k; j++) {
					if(!list[i][list2[j]]) {
						check = false;
						break;
					}
				}
				if(check && !already) {
					id = i+1;
					already = true;
				}
				else if(check && already) {
					id = -1;
					break;
				}
			}
			
			System.out.println(id);
			
			
		}
	}
}

Measured memory_bytes: 64692
h, w = map(int, input().split())

matrix = []

for i in range(h):
  row = list(input())
  if '#' not in row:
    continue
  else:
    matrix.append(row)

removed_index = []

for i in range(len(matrix[0])):
  col = [row[i] for row in matrix]
  if '#' not in col:
    removed_index.append(i)

removed_index.reverse()

for n in removed_index:
  for row in matrix:
  	del row[n]

for row in matrix:
  print(''.join(row))


Measured memory_bytes: 3060
#include<stdio.h>
#include<limits.h>

int main(void)
{
        int num,i,tmp;
        int min = INT_MAX;
        int max = INT_MIN;
        long sum = 0;

        scanf("%d", &num);

        for ( i = 0 ; i < num ; i++ ) {
                scanf("%d", &tmp);
                if ( tmp > max ) max = tmp;
                if ( tmp < min ) min = tmp;
                sum += tmp;
        }

        printf("%d %d %ld\n", min, max, sum);

        return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    int ans=0;
    if(a<0){
        ans+=c*abs(a);
        ans+=d;
        ans+=e*b;
    }
    else if(a==0){
        ans+=d;
        ans+=e*b;
    }
    else if(a>0){ans+=e*(b-a);}
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3188
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
L=[]
a=[]
for j in range(m):
  L.append([l[j][0],l[j][1],j])
L.sort()
p=L[0][0]
c=0
for k in range(m):
  if p==L[k][0]:
    a.append([L[k][2],L[k][0],c+1])
    c+=1
  else:
    c=0
    p=L[k][0]
    a.append([L[k][2],L[k][0],c+1])
    c+=1
a.sort()
for x in range(m):
  y=str(a[x][1])
  z=str(a[x][2])
  Y=y.zfill(6)
  Z=z.zfill(6)
  print(Y+Z)

Measured memory_bytes: 49872
($N,$L)=glob<>;
@A=glob<>;
for(0..$N-2){
    if($A[$_]+$A[$_+1]>=$L){
        $f=1;
        $i=$_;
        last;
    }
}
if($f){
    print "Possible\n";
}else{
    print "Impossible";
    exit;
}
print"$_\n" for(1..$i);
print"$_\n" for(reverse($i+1..$N-1));

Measured memory_bytes: 27008
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, x, a, ans;
	map<int, int> mp;
	cin >> x >> num;
	rep(i, num) {
		cin >> a;
		mp[a];
	}
	rep(i, 51) {
		if (!mp.count(x - i)) {
			ans = x - i;
			break;
		}
		if (!mp.count(x + i)) {
			ans = x + i;
			break;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define y1 ___y1
const int N=2005;
int n,m,Q,x1,y1,x2,y2;
char s[N][N];
struct BIT{
	int num[N][N];
	void insert(int x,int y){
		for (int i=x;i<=n;i+=i&-i)
			for (int j=y;j<=m;j+=j&-j)num[i][j]++;
	}
	int find(int x,int y){
		int ans=0;
		for (int i=x;i;i-=i&-i)
			for (int j=y;j;j-=j&-j)
				ans+=num[i][j];
		return ans;
	}
}T[3];
int main(){
	scanf("%d%d%d",&n,&m,&Q);
	for (int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (s[i][j]=='1')T[0].insert(i,j);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			if (s[i][j]=='1'&&s[i][j-1]=='1')T[1].insert(i,j);
			if (s[i][j]=='1'&&s[i-1][j]=='1')T[2].insert(i,j);
		}
	while (Q--){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		printf("%d\n",T[0].find(x2,y2)-T[0].find(x1-1,y2)-T[0].find(x2,y1-1)+T[0].find(x1-1,y1-1)-T[1].find(x2,y2)+T[1].find(x1-1,y2)+T[1].find(x2,y1)-T[1].find(x1-1,y1)-T[2].find(x2,y2)+T[2].find(x1,y2)+T[2].find(x2,y1-1)-T[2].find(x1,y1-1));
	}
}


Measured memory_bytes: 52608
#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,MOD2=998244353;



int main() {
    int H1,M1,H2,M2,K;
    cin>>H1>>M1>>H2>>M2>>K;
    int x,y;
    x=H1*60+M1;
    y=H2*60+M2;
    cout<<y-x-K<<endl;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){
	int num,h=0,m=0,s=0;

	scanf("%d",&num);

	while(num >= 3600){
	num = num - 3600;
	h++;
}

	while(num >= 60){
		num = num - 60;
		m++;
	}

	s = num;

	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 592
def sumNum(lst):
    ret = sum(lst)
    return ret

def minNum(lst):
    ret = min(lst)
    return ret

def maxNum(lst):
    ret = max(lst)
    return ret

def convertLst(lst):
    l = lst.split()
    lst_int = [int(n) for n in l]
    return lst_int

def main():
    num = input()
    lst = input()
    lst_int = convertLst(lst)
    print(minNum(lst_int), maxNum(lst_int), sumNum(lst_int))

if __name__ == '__main__':
    main()


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

ll MOD = 1000000007;

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        ll tmp;
        cin >> tmp;
        tmp %= MOD;
        a[i] = tmp;
    }
    ll ans = 0;
    ll s = 0;
    rep(i,n) {
        s += a[i];
        s %= MOD;
    }
    rep(i,n-1){
        s = mod(s%MOD-a[i], MOD);
        ans += a[i]*s;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4812