akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int n;
vector<double> p;
double solve(int index, int heads_needed, vector<vector<double> > &dp)
{
	// Base case.
	if (heads_needed == 0)
		return 1;
	if (index == 0)
		return 0;

	// If already computed before.
	if (dp[index][heads_needed] != -1.0)
		return dp[index][heads_needed];

	// Recursive case.
	double head = p[index] * solve(index - 1, heads_needed - 1, dp);
	double tail = (1 - p[index]) * solve(index - 1, heads_needed, dp);
	return dp[index][heads_needed] = head + tail;
}
int32_t main()
{
	fast();
	cin >> n;
	p.resize(n + 1);
	for (int i = 1; i <= n; i++)	cin >> p[i];
	vector<vector<double> > dp(n + 1, vector<double> (n + 1, -1.0));
	cout << fixed << setprecision(11) << solve(n, n / 2 + 1, dp);
	return 0;
}


Measured memory_bytes: 74024
int main(void){
    int n, m, l, i, j, k;
    scanf("%d %d %d", &n, &m, &l);
    int a[100][100];
    int b[100][100];
    long c[100][100]={0};
    //printf("%d %d %d", n, m, l);
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
            //printf("%d", a[i][j]);
        }
        //printf("\n");
    }
    for(i = 0; i < m; i++){
        for(j = 0; j < l; j++){
            scanf("%d", &b[i][j]);
            //printf("%d", b[i][j]);
        }
        //printf("\n");
    }
    for(i = 0; i<n; i++){
        for(j = 0; j<l; j++){
            for(k = 0; k < m; k++){
               c[i][j] += a[i][k] * b[k][j];
            }
            printf("%lld", c[i][j]);
            if(j < l-1){
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <set>

using namespace std;

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

	set<long long int>dic;

	long long int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		string op, str;
		cin >> op;
		cin >> str;
		if (op == "insert"){
			long long int num = 0;
			for (int j = 0; j < str.length(); j++){
				if (str[j] == 'A'){
					num += 1  * pow(10, j + 1);
				}
				else if (str[j] == 'C'){
					num += 2 * pow(10, j + 1);
				}
				else if (str[j] == 'G'){
					num += 3 * pow(10, j + 1);
				}
				else if (str[j] == 'T'){
					num += 4 * pow(10, j + 1);
				}
			}
		//	cout << num << endl;
			dic.insert(num);
		}
		else{
			long long int num = 0;
			for (int j = 0; j < str.length(); j++){
				if (str[j] == 'A'){
					num += 1 * pow(10, j + 1);
				}
				else if (str[j] == 'C'){
					num += 2 * pow(10, j + 1);
				}
				else if (str[j] == 'G'){
					num += 3 * pow(10, j + 1);
				}
				else if (str[j] == 'T'){
					num += 4 * pow(10, j + 1);
				}
			}
		//	cout << num << endl;
			if (dic.find(num) == dic.end()){
				cout << "no" << endl;
			}
			else{
				cout << "yes" << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 14180
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007
//#define MOD 7

using namespace std;

int main(void){
    // Your code here!
    long long n, max_value = 0, min_value = LLONG_MAX;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        max_value = max(max_value, temp);
        min_value = min(min_value, temp);
    }
    
    cout << max_value - min_value << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int sum = 0, dp[50];

int fib( int n ){

    if( n == 0 || n == 1 ){

        return dp[n] = 1;

    } else if( dp[n] != -1 ){

        return dp[n] ;        

    } else{

        return dp[n] = fib( n - 1 ) + fib( n - 2 );

    }

}

int main(){

    int n;

    scanf("%d", &n);

    for( int i = 0; i < 50; i++ ) dp[i] = -1;

    int ans = fib(n);

    printf("%d\n", ans);

}


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

int main(){
	
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	
	if ( a == 0 )
		cout << '1' << endl;
	else if ( b == 0 )
		cout << '2' << endl;
	else if ( c == 0 )
		cout << '3' << endl;
	else if ( d == 0 )
		cout << '4' << endl;
	else 
		cout << '5' << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a,b,k;
  cin >>a>>b>>k;
  
  vi ans;
  srep(i,1,101){
    if(a%i ==0 && b%i ==0) ans.push_back(i);
  }
  sort(rng(ans),greater<int>());
  print(ans[k-1]);
  return 0;
}

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

int main(){
int a,amax;
cin>>a;
  amax=-1000;
vector<int>b(a);
  for(int i=0;i<a;i++){
  cin>>b[i];
  }
 
    for(int i=0;i<a;i++){
for(int j=0;j<i;j++){
 amax=max(amax,abs(b[i]-b[j]));
  

  }
}
cout<<amax<<endl;
}


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

map<int, int> m;

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

  for (int i = 1;; i++) {
    if (m[a]) {
      cout << i << endl;
      return 0;
    }
    m[a] = i;
    a = a % 2 == 0 ? a / 2 : 3 * a + 1;
  }

  cout << a << endl;
}

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

int N, Y;

int main(){
	scanf("%d%d", &N, &Y);
	Y /= 1000;
	for(int i = 0; i <= N; i++)
		for(int j = 0; j <= N; j++)
			if(i + j <= N && i + j + (N - i - j) == N &&  i * 10 + j * 5 + (N - i - j) == Y){
				printf("%d %d %d\n", i, j, N - i - j);
				return 0;
			}
	printf("-1 -1 -1\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	char s[11];
	cin >> s;
	s[3] = '8';
	cout << s;
	return(0);
}


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

int main() {
  int n,m;cin>>n>>m;
  int com = n * (n-1) / 2 + m * (m-1) / 2;
  cout << com;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;n++;
	int s=0,a=0,b=0;
	rep(i,n){
		a+=i;b+=n-i-1;
		if(m<=i+1)(s+=1+b-a+MOD)%=MOD;
	}
	cout<<s<<endl;
}











Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define MAX (ll)(1e6 + 7)
#define INF (ll)(1e17 + 7)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 22

using namespace std;
using ll = long long;

int main () {
	ll x;
	cin >> x;
	ll ans = (x / 500) * 1000;
	x -= (x / 500) * 500;
	ans += (x / 5) * 5;
	cout << ans << "\n";
}


Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll a, b, k;
    cin >> a >> b >> k;
    if (k >= a) {
        k -= a;
        a = 0;
        if (k >= b) {
            k -= b;
            b = 0;
            cout << 0 << ' ' << 0  << endl;
        }
        else {
            b -= k;
            k = 0;
            cout << 0 << ' ' << b << endl;
        }
    }
    else {
        a -= k;
        k = 0;
        cout << a << ' ' << b << endl;
    }
    return 0;
}




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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    struct Edge {
        Edge(int f, int t, int c) : from(f), to(t), cost(c) {}
        int from, to, cost;
    };
    int n, m; std::cin >> n >> m;
    vvi to(n, vi(n, inf)), cost;
    vector<Edge> edges;
    rep(i, n) to[i][i] = 0;
    rep(i, m) {
        int a, b, c; std::cin >> a >> b >> c;
        --a, --b;
        to[a][b] = to[b][a] = c;
        edges.pb(Edge(a, b, c));
    }
    cost = to;
    rep(k, n) rep(i, n) rep(j, n) chmin(cost[i][j], cost[i][k] + cost[k][j]);
    set<int> used;
    rep(i, n) srep(j, i+1, n) {
        rep(k, m) {
            int a = edges[k].from, b = edges[k].to;
            if (cost[i][a]+to[a][b]+cost[b][j] == cost[i][j])
                used.insert(k);
            if (cost[i][b]+to[a][b]+cost[a][j] == cost[i][j])
                used.insert(k);
        }
    }
    std::cout << m-(int)used.size() << "\n";
}


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

use std::io;
use std::io::prelude::*;
use std::collections::VecDeque;


fn main() {
    let sin = io::stdin();
    let mut l_iter = sin.lock().lines();
    let line = l_iter.next().unwrap().unwrap();

    let mut s: VecDeque<usize> = VecDeque::new();   // 下りの位置
    let mut ponds: VecDeque<(usize,usize)> = VecDeque::new();   // (現在の水たまりの最初の下りの位置, 面積)
    let mut sum = 0;

    for (id, c) in line.chars().enumerate() {
        match c {
            '\\' => { 
                s.push_back(id); 
            },
            '/' => { 
                if let Some(i1) = s.pop_back() {
                    // 上りと同じ高さの対応する下りを用いて、その幅が面積に一致する
                    let w = id - i1;
                    sum += w;

                    if ponds.len() == 0 {
                        ponds.push_back((i1, w));
                    } else {
                        // i1までに存在する水たまりを統合する
                        let mut s_p = 0;
                        while let Some(&(i2, s2)) = ponds.back() {
                            if i2 > i1 {
                                s_p += s2;
                                ponds.pop_back();
                            } else {
                                break;
                            }
                        }
                        ponds.push_back((i1, s_p + w));
                    }
                }
            },
            _ => { ; },
        }
    }

    println!("{}", sum);
    let l = ponds.len(); 
    match l {
        0 => {println!("0");},
        _ => {println!("{} {}", l, ponds.iter().map(|&(_, s)| s.to_string()).collect::<Vec<String>>().join(" "));},
    }
}



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

int32_t main () {
	// freopen("in", "r", stdin);
    int n, p, cnt = 0; cin >> n >> p;
    for(int i = 0; i < n; i++) {
    	int x; cin >> x;
    	if(x & 1) cnt++;
    }
    if(!cnt and p) cout << "0" << endl;
    else if(!cnt and !p) cout << (1LL << n) << endl;
    else cout << (1LL << (n - 1)) << endl;
}

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

using namespace std;



int main(){

	int n ; cin >> n ;
	vector<int> h(n);
	
	vector<int> ans(n,0);
	for(int i = 0 ; i < n ; i ++ ){
		cin >> h.at(i);
	}
			int count=0;
	for(int i = 0 ; i < n-1 ; i++){
			if(h.at(i)>=h.at(i+1)){
				count++;
			ans.at(i)=count;
		}
		else{
			count =0;
		}
	}
	sort(ans.begin(),ans.end());
		cout<<ans.at(n-1)<<endl;
	}





Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int value[] = new int[3];
		int temp = 0, i = 0, j = 0;
		for (i = 0; i < 3; i++)
			value[i] = stdin.nextInt();
			for (i = 0; i < 3; i++) {
				for (j = i; j < 3; j++) {
					if (value[i] > value[j]) {
						temp = value[i];
						value[i] = value[j];
						value[j] = temp;
					}
				}

			}
				System.out.print(value[0]);
				System.out.print(" ");
				System.out.print(value[1]);
				System.out.print(" ");
				System.out.println(value[2]);
		}

	}

Measured memory_bytes: 26028
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
/*ライブラリゾーン！！！！！！！！！！！！！！！*/

signed main(){
	string s, t,ans="{";
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		string m = s;
		for (int j = i; j < i + t.size(); j++) {
			if (m[j] == '?')m[j] = t[j - i];
			else if (m[j] != t[j - i] || j >= s.size())goto u;
		}
		for (int j = 0; j < m.size(); j++) {
			if (m[j] == '?')m[j] = 'a';
		}
		ans = min(m, ans);
	u:;
	}
	if (ans == "{")cout << "UNRESTORABLE" << endl;
	else cout << ans << endl;
end:;
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
	string s, t; cin >> s >> t;
	int m = s.length(), n = t.length();
	
	vector< vector<int> > dp(m+1, vector<int>(n+1, 0));
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (s[i-1] == t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	
// 	for (int i = 0; i <= m; i++) {
// 		for (int j = 0; j <= n; j++) cout << dp[i][j] << " ";
// 		cout << endl;
// 	}
 
	string r = "";
	int i = m, j = n;
	while (i > 0 && j > 0) {
		//cout << i << " " << j << endl;
		if (s[i-1] == t[j-1]) {
			r = s[i-1] + r;
			i--; j--;
		} else if (dp[i][j-1] > dp[i-1][j]) j--;
		else i--;
	}
 
	cout << r;
 
	return 0;
}

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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  cin >> N;
  int d[N];
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }

  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += d[i] * d[j];
    }
  }

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


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

int main() {
    int n, a[3]; cin >> n >> a[0] >> a[1] >> a[2];
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int dp[4][1 << n];
    int d[1 << n];
    for (int bit = 0; bit < (1 << n); bit++) {
        d[bit] = 0;
        for (int j = 0; j < n; j++) {
            if (bit & (1 << j)) d[bit] += v[j];
        }
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < (1 << n); j++) {
            dp[i][j] = 1e9;
        }
    }
    dp[0][(1 << n)-1] = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 1; j < (1 << n); j++) {
            for (int k = j; k >= 0; k = (k-1) & j) {
                if (k == j) continue;
                dp[i+1][k] = min(dp[i+1][k], dp[i][j] + abs(a[i]-d[j^k]));
                if (k == 0) break;
            }
        }
    }
    int ans = 1e9;
    for (int i = 0; i < (1 << n); i++) {
        bitset<8> bit = i;
        ans = min(ans, (int) (n-bit.count()-3) * 10 + dp[3][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq

X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort()

s = p[:X]+q[:Y]
ans=sum(s)
heapq.heapify(s)

while r and s:
    if s[0]<r[-1]:
        ans += r[-1]
        r.pop()
        ans -= heapq.heappop(s)
    else:
        break
print(ans)

Measured memory_bytes: 29592
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = defaultdict(int)
for a in A:
    cnt[a] += 1
n = 1
while n <= 2 * A[0]:
    n *= 2
n //= 2
ans = 0
while n > 0:
    for a in A:
        if cnt[a] == 0:
            continue
        b = n - a
        if b < 0:
            continue
        if b > a:
            break
        c = 0
        if b == a and cnt[a] > 1:
            c = cnt[a] // 2
        elif b != a and cnt[b] > 0:
            c = min(cnt[a], cnt[b])
        cnt[a] -= c
        cnt[b] -= c
        ans += c
    n //= 2
print(ans)

Measured memory_bytes: 102612
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define R freopen("555input.txt","r",stdin);
#define W freopen("output.txt","w",stdout);
#define N 105
int len[N],que[N],i,j,n=3;
char s[5][N];
int main()
{
    for(i=0;i<n;i++)
    scanf("%s",s[i]);
    for(i=0;i<n;i++)
    len[i]=strlen(s[i]);
    for(i=0;;)
    {
        if(len[i]==0)
        {
            printf("%c",'A'+i);
            return 0;
        }
        len[i]--;
        que[i]++;
        i=s[i][que[i]-1]-'a';
    }
    return 0;
}


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

ans = 10**1000
for i in range(2**N):
    prc = 0
    li = [0 for _ in range(M)]
    for j in range(N):
        if (i>>j)&1:
            prc += A[j][0]
            for k in range(M):
                li[k] += A[j][k+1]
    # print(bin(i),prc,li)
    for k in range(M):
        if li[k]<X:
            break
    else:
        ans = min(prc,ans)
if ans == 10**1000:
    print(-1)
else:
    print(ans) 





Measured memory_bytes: 9216
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
int main(){
    string str; cin>>str;
    int ans=0;
    for(int i=0;i<str.size();i++){
        if(str[i]=='1') ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = LI()
B = LI()
C = LI()

ans = sum(B)
for i in range(1, n):
    if A[i-1]+1 == A[i]:
        ans += C[A[i]-2]
print(ans)

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int ufp[123456],ufr[123456];

void ufinit(int N){
	int i;
	for(i=0; i<N; ++i){
		ufp[i] = i;
		ufr[i] = 0;
	}
}

int ufind(int x){
	if(ufp[x] == x){
		return x;
	}else{
		ufp[x] = ufind(ufp[x]);
		return ufp[x];
	}
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x == y){
		return;
	}
	if(ufr[x] > ufr[y]){
		ufp[y] = x;
	}else{
		ufp[x] = y;
		if(ufr[x] == ufr[y]){
			++ufr[y];
		}
	}
}

int main(void){
	int n,m,i,p[123456],x,y,ans=0;
	cin >> n >> m;
	ufinit(n);
	for(i=0; i<n; ++i){
		cin >> p[i];
		--p[i];
	}
	for(i=0; i<m; ++i){
		cin >> x >> y;
		--x; --y;
		unionf(x,y);
	}
	for(i=0; i<n; ++i){
		if(ufind(i) == ufind(p[i])){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
// orz dxm
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define y0 yORZDXM
#define y1 yORZDXM
#define y2 yORZDXM
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;

int n;

int main(){
	scanf("%d", &n);
	REP(i, 1, n) REP(j, i + 1, n){
		int k = i ^ j, ans;
		for(ans = 0; !(k >> ans & 1); ++ans);
		printf("%d%c", ans + 1, j == n ? '\n' : ' ');
	}
	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/ 
 
int sc1() {int x; scanf("%d", &x); return x;}
 
long long sc2() {long long x; scanf("%lld", &x); return x;}
 
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
 
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}
 

 
 
int solve() {
 	
 	int n=Int;
 	std::map<string, int> mp;
 	std::map<string, int> ::iterator it;
 	int x=0;
 	For(n){
 		string s;
 		cin>>s;
 		mp[s]++;
 		x=max(x,mp[s]);

 	}
 	for(it=mp.begin();it!=mp.end();it++){
 		if(it->second==x) cout<<it->first<<endl;
 	}

 
	return 0;
}
 
 
 
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 25216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int prime[300001];

signed main() {
	memset(prime, true, sizeof(prime));
	for (int i = 2; i <= 300000; i++) {
		if (!prime[i]) continue;
		if (!(i % 7 == 1 || i % 7 == 6)) {
			prime[i] = false;
			continue;
		}
		for (int j = 2 * i; j <= 300000; j += i) {
			prime[j] = false;
		}
	}

	vector<int> v;
	for (int i = 6; i <= 300000; i++) {
		if (prime[i]) {
			v.push_back(i);
		}
	}
	while (true) {
		int n;
		cin >> n;

		if (n == 1) break;

		vector<int> w;
		for (int e : v) {
			if (n % e == 0) {
				w.push_back(e);
			}
		}

		cout << n << ':';
		for (int e : w) {
			cout << ' ' << e;
		}
		cout << endl;
	}

    return 0;
}

Measured memory_bytes: 5536
#include<stdio.h>

int main(void){
    int n,q,S[10000],T[500];
    int i,j,count=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&T[i]);
    }
    
    for(i=0;i<q;i++){
        for(j=0;j<n;j++){
            if(T[i]==S[j]){
                count++;
                break;
            }
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2048
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    if a[i] != b[i] != c[i] != a[i]:
        ans += 2
    elif a[i] == b[i] == c[i]:
        ans += 0
    else:
        ans += 1
print(ans)
    

Measured memory_bytes: 61804
import sys
sys.setrecursionlimit(500000) #これがないと再帰の回数オーバーでエラー出る。
N,M,P = map(int,input().split())
N-=1 #頂点番号を0スタートに
INF = float("inf")
edge = []
to = [[] for _ in range(N+1)] #普通に移動できる点
rto = [[] for _ in range(N+1)] #逆に戻れる点
reachablefrom = [False for _ in range(N+1)] #始点0から終点N-1へ行けるかチェック
reachableto = [False for _ in range(N+1)] #終点N-1から始点0へ戻れるかチェック
OK = [False for _ in range(N+1)] #どちらからもいける点を検出。ここ以外の点はどうでもよい。
for i in range(M):
  a,b,c = map(int,input().split())
  a-=1;b-=1 #頂点番号を0スタートに
  c-=P #ここで先に最後に払う分を引いておく。
  c = -c #最短経路にしたいのでコストを負にする。
  edge.append((a,b,c))
  to[a].append(b)
  rto[b].append(a)

def dfs(v):
  if reachablefrom[v]:
    return
  reachablefrom[v] = True
  for u in to[v]:
    dfs(u)

def rdfs(v):
  if reachableto[v]:
    return
  reachableto[v] = True
  for u in rto[v]:
    rdfs(u)
    
dfs(0)
rdfs(N)
for i in range(len(OK)): #len(OK)でもまあ良いか。
  OK[i] = reachablefrom[i]&reachableto[i]
#ここからベルマンフォード法
d = [INF for _ in range(N+1)]
d[0] = 0 #スタートのコストは0
upd = True #サイクルで更新の有無をチェック
step = 0
while upd:
  upd = False
  for i in range(M):
    a,b,c = edge[i]
    if not OK[a] or not OK[b]:
      continue
    new = d[a]+c
    if new < d[b]: #aから来たほうが最短
      upd = True
      d[b] = new
  step += 1
  if step > N+1:
    print("-1")
    sys.exit()
ans = -d[N] #最後、コストをマイナスで戻す
ans = max(0,ans)
print(ans)

Measured memory_bytes: 64600
A, B, Q = gets.split.map(&:to_i)
S = A.times.map { gets.to_i }.sort
T = B.times.map { gets.to_i }.sort
X = Q.times.map { gets.to_i }

RS = S.reverse
RT = T.reverse

X.each do |x|
  ls = RS.bsearch { |i| -i >= -x }
  rs = S.bsearch { |i| i >= x }
  lt = RT.bsearch { |i| -i >= -x }
  rt = T.bsearch { |i| i >= x }

  ans = Float::INFINITY

  if ls && lt
    ans = [ans, [x - ls, x - lt].max].min
  end

  if rs && rt
    ans = [ans, [rs - x, rt - x].max].min
  end

  if ls && rt
    ans = [ans, 2 * (x - ls) + rt - x].min
    ans = [ans, x - ls + 2 * (rt - x)].min
  end

  if lt && rs
    ans = [ans, 2 * (x - lt) + rs - x].min
    ans = [ans, x - lt + 2 * (rs - x)].min
  end

  puts ans
end


Measured memory_bytes: 10152
d = {}
n = int(input())
for i in range(n):
    temp = [0 for i in range(26)]
    s = input()
    for c in s:
        t = ord(c)-97
        temp[t]+=1
    for i in range(26):
        temp[i] = str(temp[i])
    txt = ",".join(temp)
    if txt not in d:
        d[txt] = 1
    else:
        d[txt] += 1
ans = 0
for k in d:
    if d[k] != 1:
        ans += d[k]*(d[k]-1)/2
print(int(ans))


Measured memory_bytes: 21476
def dfs(ls,cur,a,b,c)
  if cur==N
    if [a,b,c].min>0
      return (a-A).abs+(b-B).abs+(c-C).abs-30
    else
      return 10**9
    end
  else
    ret0=dfs(ls,cur+1,a,b,c)
    reta=dfs(ls,cur+1,a+ls[cur],b,c)+10
    retb=dfs(ls,cur+1,a,b+ls[cur],c)+10
    retc=dfs(ls,cur+1,a,b,c+ls[cur])+10
    return [ret0,reta,retb,retc].min
  end
end
N,A,B,C=gets.split.map(&:to_i)
ls=N.times.map{gets.to_i}
puts dfs(ls,0,0,0,0)


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

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int b=0;
  int r=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B')b++;
    else r++;
  }
  if(b>= r)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}
  

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

using namespace std;
using ll = long long;
using ld = long double;

#define int long long
signed main(){
//int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<pair<int,int>> s(a+b+c);
    for(int i = 0; i < a; i++) {
        cin >> s[i].first;
        s[i].second=0;
    }
    for(int i = 0; i < b; i++) {
        cin >> s[i+a].first;
        s[i+a].second=1;
    }
    for(int i = 0; i < c; i++) {
        cin >> s[i+a+b].first;
        s[i+a+b].second=2;
    }
    sort(s.rbegin(),s.rend());
    int cnt[3]={0,0,0};
    int ans=0;
    int idx=0;
    while((cnt[0]+cnt[1]+cnt[2])<(x+y)) {
        if(cnt[0]==x && s[idx].second==0){
            idx++;
            continue;
        };
        if(cnt[1]==y && s[idx].second==1){
            idx++;
            continue;
        }
        //cout << s[idx].first << "\n";
        ans+=s[idx].first;
        cnt[s[idx].second]++;
        idx++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 7976
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();

		Arrays.sort(s);
		Arrays.sort(t);

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length; i++) {
			sb.append(s[i]);
		}
		String S = sb.toString();
		sb = new StringBuilder();
		
		for (int i = 0; i < t.length; i++) {
			sb.append(t[i]);
		}

		String T = sb.reverse().toString();
		
        if (S.compareToIgnoreCase(T) < 0) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }

	}
}

Measured memory_bytes: 23764
//============================================================================
// Name        : ATcoder.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {

	ll x,a,b;
	cin>>x>>a>>b;


	if((b-a)<=0){
		cout<<"delicious"<<endl;
	}
	if((b-a)>0){
	if((b-a)<=x){
		cout<<"safe"<<endl;
	}
	if((b-a)>=(x+1)){
		cout<<"dangerous"<<endl;
	}
	}






	return 0;
}


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

using namespace std;

int main() {
    
    long long int n, s, a[3001], i, dp[3001][3001]={}, x=1, j;
    cin>>n>>s;
    for(i=1;i<=n;i++)
    scanf("%lld", &a[i]);
    for(i=1;i<=n;i++){
    x*=2;
    x%=998244353;}
    
    dp[0][0]=x;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=s;j++)
        {
            if(j>=a[i])
            dp[i][j]=(dp[i-1][j-a[i]]*499122177+dp[i-1][j])%998244353;
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    
    cout<<dp[n][s];
}

Measured memory_bytes: 74144
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;
 
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll M = 400 + 10;
const ll N = 100 * 1000 + 10;

ll a[N];

int main()
{
	faster();
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		int x = i, xx = i;
		while(a[x] <= a[x + 1])
		{
			x++;
			if(x == n)
				break;
		}
		while(a[xx] >= a[xx + 1])
		{
			xx++;
			if(xx == n)
				break;
		}
		i = max(x, xx) + 1;
		ans++;
		i--;
	}
	cout << ans << endl;
}

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

int main(){
    int n,k;
    cin >>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=a.at(i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	Scanner s = new Scanner(System.in);
		void doIt(){
			// 自作クラス(Person)オブジェクトの並べ替え
			Person []personone = new Person[8];
			Person []result = new Person[8];
			Person []three = new Person[6];
			for(int i=0; i<8; i++){
				personone[i] = new Person(s.nextInt(), s.nextDouble());
			}
			Arrays.sort(personone);
			result[0] = personone[0];
			result[1] = personone[1];
			three[0] = personone[2];
			three[1] = personone[3];
			for(int i=0; i<8; i++){
				personone[i] = new Person(s.nextInt(), s.nextDouble());
			}
			Arrays.sort(personone);
			result[2] = personone[0];
			result[3] = personone[1];
			three[2] = personone[2];
			three[3] = personone[3];
			for(int i=0; i<8; i++){
				personone[i] = new Person(s.nextInt(), s.nextDouble());
			}
			Arrays.sort(personone);
			result[4] = personone[0];
			result[5] = personone[1];
			three[4] = personone[2];
			three[5] = personone[3];
			Arrays.sort(three);
			result[6] = three[0];
			result[7] = three[1];
			for(int i=0; i<8; i++){
				System.out.println(result[i].name+" "+result[i].age);
			}
		}
		public static void main(String[] args) {
			new Main().doIt();
		}
		class Person implements Comparable<Person>{ 
			int name;
			Double age;
			Person(int name, double age) {
				this.name = name;
				this.age = age;
				}
			@Override
			public int compareTo(Person o){
				return age.compareTo(o.age);
			}
		}
}

Measured memory_bytes: 20032
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 200000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ans = INF;
    rep(k, 2) {
        int tmp = 0;
        rep(i, S.length()) {
            char c = ((k + i) % 2) + '0';
            if (S[i] != c) tmp++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int a[10]={},b[10]={};

  for(int i =0;i < 7;i++)
    {
      cin >> a[i] >> b[i];
    }
  for(int j = 0;j < 7;j++)
    {
      cout << a[j]-b[j] << endl;
    }
}



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

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

fun func() {
    val n = nextInt()
    var aa = mutableListOf<Int>()
    val flags = Array(n){false}

    repeat(n) {
        aa.add(nextInt())
    }

    var nextIndex = 0
    var cnt = 0
    for (i in 0 until n) {
        cnt++
        if (aa[nextIndex] == 2) {
            println(cnt)
            return
        }
        if (flags[nextIndex]) {
            println(-1)
            return
        }
        flags[nextIndex] = true
        nextIndex = aa[nextIndex] - 1
    }

    println(-1)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

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

Measured memory_bytes: 40860
import java.io.*;
public class Main
{
  public static void main(String args[]) throws IOException
  {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      
      int i,A,B,C,D;
      
      //System.out.println();
      
      String s[]=br.readLine().trim().split(" ");
      
      A=Integer.parseInt(s[0]);
      B=Integer.parseInt(s[1]);
      C=Integer.parseInt(s[2]);
      D=Integer.parseInt(s[3]);
      
      A=A+B;
      B=C+D;
      
      if(A>B)
      System.out.println("Left");
      else if(A<B)
      System.out.println("Right");
      else
      System.out.println("Balanced");
  }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define ll long long int
/*#define vector<ll> vli
#define vector<int> vii
#define vector<char> vch
#define vector<string> vst*/
#define F(i,j,k,in) for(ll i=j;i<k;i+=in)
#define DF(i,j,k,in) for(ll i=j;i>=k;i-=in)
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define Dforeach(it,l) for(auto it = l.end()-1;l.begin()-1;it--)
#define PB push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;
int main()
{
    ll r;
    cin>>r;
    cout<<2*PI*r;
}


Measured memory_bytes: 3784
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
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 main() {

	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, ll>>> g(n);
	FOR(i, m) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b,c });
	}

	vector<ll> ans(n, -LLINF);
	ans[0] = 0;
	FOR(cnt, n) {
		FOR(i, n) {
			if (ans[i] <= -LLINF / 2)continue;
			for (auto e : g[i]) {
				if (chmax(ans[e.first], ans[i] + e.second)) {
					if (cnt == n - 1 && e.first == n - 1) {
						cout << "inf" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << ans[n - 1] << endl;
}

Measured memory_bytes: 384
x,k,d=input().split()
x=int(x)
k=int(k)
d=int(d)
r=0
if x<0:
  y=-x
else:
  y=x
w=y/d
w=int(w)
w=k-w
if w>0:
  a=y%d
  b=d-a
  if w%2==0:
    r=a
  else:
    r=b
else:
  r=k*d
  r=y-r
print(r)

Measured memory_bytes: 9076
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    string str;
    cin >> str;
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        ans += str[i] == str[i + 1];
    }
    int diffp = n - 1 - ans;
    for(int i = 0; i < k; i++){
        if(diffp <= 0) continue;
        ans += min(2, diffp);
        diffp -= 2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n;
	cin >> n;
	vector<int> p(n), q(n), perm(n);
	rep(i, 0, n) cin >> p[i];
	rep(i, 0, n) cin >> q[i];
	rep(i, 0, n) perm[i] = i + 1;
	int a, b;a = b = 0;
	int cnt = 1;
	do {
		rep(i, 0, n) {
			if (perm[i] != p[i])break;
			if (i == n - 1) a = cnt;
		}
		rep(i, 0, n) {
			if (perm[i] != q[i])break;
			if (i == n - 1)b = cnt;
		}
		if (a != 0 && b != 0)break;
		cnt = cnt + 1;
	} while (next_permutation(perm.begin(), perm.end()));
	cout << abs(a - b) << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
class aoj{
	static void Main(){
		string []a=Console.ReadLine().Split(' ');
		int []b=new int[2];
		for(int i=0;i<2;i++){
			b[i]=int.Parse(a[i]);
		}
		int c=int.Parse(a[2]),d=0;
		for(int i=b[0];i<=b[1];i++){
			if(c%i==0)
				d++;
		}
		Console.WriteLine(d);
	}
}

Measured memory_bytes: 9164
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void AGC024C();

#if 1
int main()
{
	AGC024C();
	fflush(stdout);
	return 0;
}
#endif

static void AGC024C()
{
	int N;
	getint(N);

	LLONG ans = 0;
	std::vector<LLONG> ai(N, 0);
	for (int i = 0; i < N; i++) {
		getint(ai[i]);
		if (ai[i] > 0) {
			ans++;
		}
		if (i) {
			if ((ai[i] <= ai[i - 1]) && (ai[i] > 1LL)) {
				ans += (ai[i] - 1LL);
			}
		}
	}
	if (ai[0] > 0) {
		printf("-1\n");
		return;
	}
	for (int i = 1; i < N; i++) {
		if (ai[i] - ai[i - 1] > 1) {
			printf("-1\n");
			return;
		}
	}

	printf("%lld\n", ans);
}


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

int main() {
   // ifstream cin("data.in");
    int n, k, q;
    cin >> n >> k >> q;
    vector<int>val(n);
    for(int i = 0; i < n; ++i)
        cin >> val[i];
    int answer = 1e9;
    for(int pos_min = 0; pos_min < n; ++pos_min) {
        int minn = val[pos_min];
        vector<int>avaible;
        for(int i = 0; i < n; ) {
            int j = i;
            vector<int>cur;
            while(j < n && val[j] >= minn) {
                cur.push_back(val[j]);
                j++;
            }
            sort(cur.begin(), cur.end());
            for(int t = 0; t + k - 1 < (int)cur.size(); ++t)
                avaible.push_back(cur[t]);

            i = j + 1;
        }
        sort(avaible.begin(), avaible.end());
        if((int)avaible.size() >= q) {
            answer = min(answer, avaible[q - 1] - minn);
        }
    }
    cout << answer;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string X, Y;
  cin >> X >> Y;

  if (X.size() < Y.size()) puts("<");
  else if (X.size() > Y.size()) puts(">");
  else if (X < Y) puts("<");
  else if (X > Y) puts(">");
  else puts("=");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;

    for (int i = 0; i < n; i++) {
        if (i + 1 == k) {
            putchar(tolower(s[i]));
        } else {
            cout << s[i];
        }
    }
}

Measured memory_bytes: 256