akhauriyash/Code-Regression huggingface dataset:
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
ll x[1234],y[1234],z[1234];
int main(){
    std::ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    ll i,j;
    rep(i,n){
    	cin>>x[i]>>y[i]>>z[i];

    }
    vl vec;
    ll haha,val1,val2,val3,val;
    ll mini =0;
    rep(i,8){
    	val1=-1;
    	val2=-1;
    	val3=-1;
    	haha=i;
    	if(haha%2)
    		val1=1;
    	haha/=2;
    	if(haha%2)
    		val2=1;
    	haha/=2;
    	if(haha%2)
    		val3=1;
    	haha/=2;
    	vec.clear();
    	rep(j,n){
    		vec.pb(val1*x[j]+val2*y[j]+val3*z[j]);
    	}
    	sort(all(vec));
    	ll ans=0;
    	rep(j,m){
    		ans+=vec[j];
    	}
    	ans*=-1;
    	mini=max(mini,ans);

    }
    cout<<mini<<endl;
    return 0;  
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if(!(s[0] == '1' && s[n - 1] == '0')) {
        cout << -1 << endl;
        return 0;
    }
    for(int i = 0; i < n - 1; i++) {
        if(s[i] == '1' && s[n - i - 2] == '0') {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<P> ans;
    int pre = 0;
    for(int i = 1; i < n; i++) {
        if(s[i] == '1') {
            while(pre < i) {
                ans.emplace_back(P(pre, i));
                pre++;
            }
        }
    }
    ans.emplace_back(P(n - 2, n - 1));
    for(const auto &i : ans) {
        cout << i.first + 1 << " " << i.second + 1 << endl;
    }
}

Measured memory_bytes: 2500
class FUnionFind
  attr_reader :nodes, :parents, :ranks

  def initialize(n)
    @parents = (0...n).to_a
    @nodes = @parents.map{ |x| [x] }
    @relatives = Array.new(n, 0)
  end

  def find(i)
    @parents[i]
  end

  def union(i,j,d)
    i0,j0 = i,j
    i = @parents[i]; j = @parents[j]
    # p [i0,j0,d,i,j]
    # p @nodes, @parents, @relatives
    if i == j
      return @relatives[i0] + d == @relatives[j0]
    end
    j,i,j0,i0,d = i,j,i0,j0,-d if @nodes[i].size < @nodes[j].size

    # relatives[i0] + d == relj + relatives[j0]
    relj = @relatives[i0] + d - @relatives[j0]
    # p [@relatives[j0], d, @relatives[i0], relj]
    @relatives[i] = 0
    @nodes[j].each{ |k| 
      @parents[k] = i 
      @relatives[k] += relj
    }
    @nodes[i].concat(@nodes[j])
    @nodes[j].clear
  end
end

N,M = gets.split.map(&:to_i)
FU = FUnionFind.new(N)
M.times {
  x,y,d = gets.split.map(&:to_i)
  if !FU.union(x-1,y-1,d)
    puts "No"; exit
  end
}
puts "Yes"



Measured memory_bytes: 18008
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    vector<string> S(N);

    for (ll i = 0; i < N; i++)
    {
        cin >> S.at(i);
        sort(S.at(i).begin(), S.at(i).end());
    }
    sort(S.begin(), S.end());
    string searchword = S.at(0);
    auto beginI = S.begin();
    ll count = 0;

    while (1)
    {
        auto lower = lower_bound(beginI, S.end(), searchword);
        auto upper = upper_bound(beginI, S.end(), searchword);
        ll dist = distance(beginI, upper) - distance(beginI, lower);
        if (dist > 1)
        {
            count += dist * (dist - 1) / 2;
        }

        if (upper == S.end())
        {
            break;
        }

        beginI = upper;
        searchword = *upper;
    }

    cout << count << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}



int main(){

	ll K;
	cin >> K;
	
	vector<bool> rests(K, false);
	ll amari = 7;
	ll ans = 1;
	while(rests[amari] == false){
		if(amari % K == 0){
			cout << ans << endl;
			return 0;
		}
		rests[amari] = true;
		amari = amari*10 + 7;
		amari = amari % K;
		ans++;
	}

	cout << "-1" << endl;
	return 0;

}



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

using namespace std;
typedef long long ll;

const int N=2e5+10;
const int mod=1e9+7;
int n,k,m;
int a[N];
int b[N];
int ans[N];
string s;
int vis[N];
map<int,int> mp;

int cmp(int a, int b){
    return a>b;
}
int main()
{

    cin>>n;
    ll ans=1;
    for(int i=1;i<=n;i++){
        ans*=10;
        ans%=mod;

    }

    ll ans2=1;
    for(int i=1;i<=n;i++){
        ans2*=9;
        ans2%=mod;
    }
    ll ans3=1;
    for(int i=1;i<=n;i++){
        ans3*=8;
        ans3%=mod;
    }
    ans2=(ans2*2)%mod;
    //cout<<ans<<endl<<ans2<<endl;
    ans=(ans-ans2)%mod;
    ans=(ans+ans3)%mod;
    ans=(ans+mod)%mod;
    cout<<ans<<endl;

}



Measured memory_bytes: 3640
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
H=int(input())
W = int(input())
N = int(input())
m = max(H,W)
n=N/m
if n.is_integer():
    print(int(n))
    exit()
else:
    print(int(n)+1)

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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    string S, T; cin >> S >> T;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3616
fun main(args: Array<String>) {

    val n = readLine()!!.toLong()

    var ans = 0L

    fun dfs(s: String) {

        if (s.isNotEmpty() && s.toLong() > n) return

        if (s.contains("3") && s.contains("5") && s.contains("7")) ans++

        dfs(s + "3")
        dfs(s + "5")
        dfs(s + "7")

    }

    dfs("0")
    println(ans)
}

Measured memory_bytes: 38972
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  double x[n];
  char u[n][5];
  for (int i = 0; i < n; i++) {
    scanf("%lf", &x[i]);
    for (int j = 0; j < 5; j++) {
      scanf("%c", &u[i][j]);
    }
  }

  double answer = 0;
  for (int i = 0; i < n; i++) {
    if (u[i][1] == 'J') {
      answer += x[i];
    } else {
      answer += x[i]*380000.0;
    }
  }

  printf("%lf\n", answer);

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int n = sc.nextInt();

        if(s<=n){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

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

	vector<ll> a(n),b(n);
	for (int i = 0; i < n; i++){
		cin>>a[i]>>b[i];
	}

	ll cnt=0;
	for (int i = n-1; i >= 0 ; i--){
		if((a[i]+cnt)%b[i]==0)continue;
		cnt += b[i]-(a[i]+cnt)%b[i];
	}

	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define f(i, a, b) for (int i = a; i < (b); ++i)
#define f2(i, a, b) for (int i = a; i <= (b); ++i)
#define rep(i, n) f(i, 0, n)
#define rep2(a, n) f(i, a, n)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
long long dp[100010];

int main(void) {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) { cin >> vec[i]; }
  for (int i = 0; i < 100010; i++) dp[i] = INF;
  dp[0] = 0;
  dp[1] = abs(vec[0] - vec[1]);
  rep2(2, n) {
    dp[i] = min(dp[i - 1] + abs(vec[i] - vec[i - 1]),
                dp[i - 2] + abs(vec[i] - vec[i - 2]));
  }
  cout << dp[n-1] << '\n';
  return 0;
}

Measured memory_bytes: 4296
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int memo[1<<21];
int A[30][30];

int DP(int idx,int s)
{
	if(memo[s]!=-1)return memo[s];
	int res=0;
	rep(i,0,N)
	{
		if(A[idx][i]==0)continue;
		if((s>>i)&1)continue;
		res+=DP(idx+1,s|(1<<i));
		res%=MOD;
	}
	memo[s]=res;
	return memo[s];
}

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

	cin>>N;
	rep(i,0,N)rep(j,0,N)cin>>A[i][j];
	fill(memo,memo+(1<<N),-1);
	memo[(1<<N)-1]=1;
	cout<<DP(0,0)<<endl;

	/*rep(k,0,1<<N)
	{
		rep(i,0,N)rep(j,0,N)
		{
			if(A[i][j]==0||((k>>j)&1))continue;
			DP[k|(1<<j)]=(DP[k|(1<<j)]+DP[k])%MOD;
		}
		cout<<"a"<<endl;
	}*/

	/*map<int,int> DP[2];
	int tar=1;
	DP[0][0]=1;
	rep(i,0,N)
	{
		DP[tar].clear();
		rep(j,0,N)
		{
			if(A[i][j]==0)continue;
			for(auto p:DP[tar^1])
			{
				int k=p.first;
				if((k>>j)&1)continue;
				DP[tar][k|(1<<j)]=(DP[tar][k|(1<<j)]+p.second)%MOD;
			}
		}
		tar^=1;
	}
	tar^=1;
	cout<<DP[tar][(1<<N)-1]<<endl;*/

	return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i];
    repr(i, n) {
        int sum = 0;
        for (int j=i+(i+1); j<n; j+=i+1) sum += b[j];
        if (sum%2 == a[i]) b[i] = 0;
        else b[i] = 1;
    }
    vi ans;
    rep(i, n) if (b[i] == 1) ans.pb(i+1);
    int m = sz(ans);
    cout << m << endl;
    rep(i, m) printf("%d%c", ans[i], (i<m-1?' ':'\n'));
    return 0;
}


Measured memory_bytes: 5436
//2???n???200,000
//1???Rt???10

#include <iostream>
#include <vector>
#include <limits>

int main(){
  int N;
  std::vector<int> R;

  std::cin >> N;
  R.resize(N);
  
  for(int i =0; i<N; ++i){
    std::cin >> R[i];
  }
  
  std::vector<int> R_min(N);
  std::vector<int> R_max(N);
  
  R_min[0] = R[0];
  R_max[N-1] = R[N-1];
  
  for(int i=1; i<N; ++i){
    R_min[i] = std::min(R[i], R_min[i-1]);
  }
  for(int i=N-2; i>=0; --i){
    R_max[i] = std::max(R[i], R_max[i+1]);
  }

  // for(int i=0; i<N; ++i){
  //   std::cout << R[i] << ' ';
  // }
  // std::cout << std::endl;
  // for(int i=0; i<N; ++i){
  //   std::cout << R_min[i] << ' ';
  // }
  // std::cout << std::endl;
  // for(int i=0; i<N; ++i){
  //   std::cout << R_max[i] << ' ';
  // }
  // std::cout << std::endl;
  
  int max_diff = std::numeric_limits<int>::min();
  // for(int i=0; i<N; ++i){
  //   max_diff = std::max(max_diff, R_max[i] - R_min[i]);
  // }
  for(int i=0; i<N-1; ++i){
    max_diff = std::max(max_diff, R_max[i+1] - R_min[i]);
  }

  std::cout << max_diff << std::endl;
}

Measured memory_bytes: 3384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n;
	cin >> n;
	VI a(n);
	rep(i, n)cin >> a[i];

	int c = 1;
	rep(i, n)if (a[i] % 2 == 0)c *= 2;
	cout << pow(3, n) - c << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
 
using namespace std;
 
typedef long long tint;
typedef long double ld;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend() 
#define NACHO ios::sync_with_stdio(0); cin.tie(NULL);
#define dbg cout << "hu" << endl;

const int INF = 50000001;
const int MOD = 1000000007;

int main(){
	tint n; cin >> n;
	tint x = n/500;
	cout << tint(1000*x)+tint(5*((n-500*x)/5)) << endl;
}



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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    LL L = s.size();

    cout << s[0] << L - 2 << s[L - 1] << '\n';

    return 0;
}



Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

lim = 10 ** 6 + 1
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, lim + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    # 累計
    factinv.append((factinv[-1] * inv[-1]) % mod)

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % mod

N, K = getNM()

ans = 0
for i in range(min(K + 1, N)):
    # 0の場所を選ぶ通り * 重複組み合わせ
    cnt = cmb(N, i) * cmb(N - i + i - 1, i)
    ans += cnt
    ans %= mod
print(ans % mod)

Measured memory_bytes: 170640
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			Path[] paths = new Path[m];
			IntStream.range(0, m).forEach(
					// 最長距離を計算するため、距離をマイナスにする
					i -> paths[i] = new Path(scanner.nextInt() - 1, scanner.nextInt() - 1, -scanner.nextLong()));
			long[] distances = new long[n];
			if (bellmanFord(paths, 0, n, distances)) {
				System.out.println("inf");
			} else {
				System.out.println(-distances[n - 1]);
			}
		}
	}

	/**
	 * https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/ を参考に作成
	 * 
	 * @param paths     ノード間の連結パス一覧の配列
	 * @param src       開始ノード
	 * @param n         ノードの数
	 * @param distances 開始ノードから各ノードへの最短距離の配列
	 * @return グラフにはループが含まれているかどうか
	 */
	private static boolean bellmanFord(final Path[] paths, final int src, final int n, final long[] distances) {
		Arrays.fill(distances, Long.MAX_VALUE);
		distances[src] = 0;

		IntStream.range(1, n).forEach(i -> IntStream.range(0, paths.length).forEach(j -> {
			int from = paths[j].from, to = paths[j].to;
			long cost = paths[j].cost;
			if (distances[from] != Long.MAX_VALUE && distances[from] + cost < distances[to]) {
				distances[to] = distances[from] + cost;
			}
		}));

		// マイナスのループが含まれているかどうかを判定
		// 解説に参考して作成
		boolean[] negative = new boolean[n];
		Arrays.fill(negative, false);
		IntStream.range(0, n).forEach(i -> IntStream.range(0, paths.length).forEach(j -> {
			int from = paths[j].from, to = paths[j].to;
			if (distances[from] != Long.MAX_VALUE && distances[from] + paths[j].cost < distances[to]) {
				distances[to] = distances[from] + paths[j].cost;
				negative[to] = true;
			}
			if (negative[from]) {
				negative[to] = true;
			}
		}));
		return negative[n - 1];
	}

	/**
	 * ノード間の一つのパスを表すクラス
	 */
	private static class Path implements Comparable<Path> {
		/** 開始ノード */
		int from;
		/** 終了ノード */
		int to;
		/** 移動コスト */
		long cost;

		Path(int from, int to, long cost) {
			super();
			this.from = from;
			this.to = to;
			this.cost = cost;
		}

		@Override
		public int compareTo(Path path) {
			long costDiff = this.cost - path.cost;
			return (costDiff > 0) ? 1 : (costDiff < 0) ? -1 : 0;
		}
	}
}


Measured memory_bytes: 43840
#include <bits/stdc++.h>
using namespace std;
inline int read() 
{
    register int x = 0 , ch = getchar(); 
    while( !isdigit( ch ) ) ch = getchar(); 
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x; 
}
inline long long ll_read() 
{
    register long long x = 0 , ch = getchar(); 
    while( !isdigit( ch ) ) ch = getchar(); 
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x; 
}
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b)
{
    return a*b/gcd(a,b);
}
long long turtle_muti(long long ain,long long bin,long long modn)
{
    long long res=0;
    for(;bin;bin>>=1) 
    {
        if(bin&1)
            res=(res+ain)%modn;
        ain=(ain<<1)%modn;
    }
    return res;
}
long long quick_power(long long a,long long b,long long p)
{
    long long ans=1;
    while(b)
    {
        if(b%2)
        {
            ans=ans*a%p;        
        }
        a=a*a%p;
        b=(b>>1);
    } 
}
const int maxn=20;
const long long inf=5e18;
int n;
long long a[maxn],dp[maxn][maxn][maxn][maxn];
long long solve(int l,int r,int dl,int dr)
{
    if(l+1>=r)
        return 0;
    long long res=inf;
    for(int i=l+1;i<=r-1;i++)
        res=min(res,solve(l,i,dl,dr+dl)+solve(i,r,dl+dr,dr)+a[i]*(dl+dr));
    return res;
}

signed main()
{
    n=read();
    for(int i=1;i<=n;++i)
        a[i]=ll_read();
    cout<<a[1]+a[n]+solve(1,n,1,1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int A = Integer.parseInt(sc.nextLine());
    int y =0;
    for (int i = 0;i<N; i++) {
      for (int j = 0; j <= A; j++) {
        y = 500 * i + j;
        if (y == N) {
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21076
/*Never Give up*/
/*
Problem  :
Verdict     :
Time         :
Memory  :
*/
#include<bits/stdc++.h>
using namespace std;
#define sf(a)          scanf("%d",&a)
#define sff(a,b)         scanf("%d%d",&a,&b)
#define sfff(a,b,c)         scanf("%d%d%d",&a,&b,&c)
#define sffff(a,b,c,d)         scanf("%d%d%d%d",&a,&b,&c,&d)
#define sl(a)          scanf("%lld",&a)
#define sll(a,b)         scanf("%lld%lld",&a,&b)
#define slll(a,b,c)         scanf("%lld%lld%lld",&a,&b,&c)
#define sllll(a,b,c,d)         scanf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define sc(a) scanf("%c",&a)
#define sz(a)              a.size()
#define ff first
#define ss second
#define all(a)          a.begin(), a.end()
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pf         printf
#define pf1        pf("%d\n");
#define ll           long long
#define ull        unsigned long long
#define pb        push_back
#define vi           vector<int>
#define vl           vector<ll>
#define li            list<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define mp         map
#define nl         printf("\n")
#define en        pf("Entered\n")
#define en1      pf("Entered 2\n")
#define gcd(a,b) __gcd(a,b)

// priority_queue<int, vector<int>, greater<int> > Q;//for smaller values

#define MAX    100000

//int dx[] = {-1, 0, 1, 0};
//int dy[] = {0, 1, 0, -1};
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/

//'A'=65,'Z'=90 'a'=97 'z'=122 '0'=48

int main()
{

string str;
cin>>str;
int ck=0;
for(int i=1;i<sz(str);i++)
    if(str[i]!=str[i-1])ck++;
pf("%d\n",ck);

return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,n,a,b,ac,bc[101],s[101];
	scanf("%d",&n);
	scanf("%d %d",&a,&b);
	scanf("%d",&ac);
	s[1]=ac;
	for(i=1;i<=n;i++){
		scanf("%d",&bc[i]);
	}
	
	sort(bc+1,bc+n+1,greater<int>());
	for(i=1;i<=n;i++){
		s[i+1]=s[i]+bc[i];
	}
	s[1]=s[1]/a;
	for(i=2;i<=n+1;i++){
		s[i]=s[i]/(a+(b*(i-1)));
	}
	sort(s+1,s+n+2,greater<int>());
	printf("%d\n",s[1]);
	return 0;
}
	

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

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

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

    ll N; cin >> N;
    double v[100];
    for (int i = 0;i < N;i++){
        cin >> v[i];
    }

    sort(v,v+N);

    for (int i = 0;i < N-1;i++){
        v[i+1] = (v[i]+v[i+1])/2.0;

    }

    printf("%.10f\n",v[N-1]);

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    int ans=0;
    int N;
    cin >> N;
    int V[20],C[20];
    for(int i=0; i<N; i++){
        cin >> V[i];
    }
    for(int i=0; i<N; i++){
        cin >> C[i];
    }
    
    for(int i=0; i<N; i++){
        if(V[i]-C[i]>=0){
            ans +=V[i]-C[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;


ll n;
string s;

bool solve(bool first,bool second){
  bool place[n];
  ll current = 0;

  place[0]=first;
  place[1]=second;

  while(current < n){
    if(current == 0){
        if(s[current]=='o')
          place[n-1]=!(first ^ second);
        else
          place[n-1]=(first ^ second);
      }
      if(current == n-2){
        if(s[current]=='o'){
          if(!(place[current-1]^place[current])!=place[current+1])
            return false;
        }
        if(s[current]=='x'){
          if((place[current-1]^place[current])!=place[current+1])
          return false;
        }
      }
      if(current == n-1){
        if(s[current]=='o'){
          if(place[current] && (place[current-1]^place[0]))
            return false;
          if((!place[current]) && (!(place[current-1]^place[0])))
            return false;
        }else{
          if(place[current] && (!(place[current-1]^place[0])))
            return false;
          if((!place[current]) && (place[current-1]^place[0]))
            return false;
        }
      }
      if(current > 0 && current < n-2){
        if(s[current] =='o'){
          if(place[current] == true)
            place[current+1] = place[current-1];
          else
            place[current+1] = !place[current-1];
        }else{
          if(place[current] == true)
            place[current+1]=!place[current-1];
          else
            place[current+1]=place[current-1];

          }
      }
      current++;
    }
    for(int i=0;i<n;i++){
      if(place[i]==true){
        cout<<'S';
      }else{
        cout<<'W';
      }
    }
    cout<<endl;
    return true;
}

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

  bool place[n];
  for(int i=0;i<n;i++){
    place[i]=true;
  }

  bool flag = false;

  flag = solve(true,true);
  if(flag)
    return 0;

  flag = solve(true,false);
  if(flag)
  return 0;

  flag = solve(false,true);
  if(flag)
  return 0;

  flag = solve(false,false);
  if(flag)
  return 0;

  cout<<-1<<endl;


  return 0;
}


Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
class ilds1_3_d{
  public static void Main(){
    Stack<int> s1 = new Stack<int>();
    Stack<Data> s2 = new Stack<Data>();
    String str = Console.ReadLine();
    int sum = 0;
    for(int i=0; i<str.Length; i++){
      if(str[i] == '\\') s1.Push(i);
      else if(str[i] == '/' && s1.Count > 0){
        int j = s1.Pop();
        sum += i-j;
        int a = i-j;
        while(s2.Count > 0){
          Data d = s2.Pop();
          if(d.pos <= j){
            s2.Push(d);
            break;
          }
          a += d.area;
        }
        Data td = new Data(j,a);
        s2.Push(td);
      }
    }
    List<int> ans = new List<int>();
    while(s2.Count > 0){
      ans.Add(s2.Pop().area);
    }
    ans.Reverse();
    Console.WriteLine(sum);
    Console.Write(ans.Count);
    for(int i=0; i<ans.Count; i++){
      Console.Write(" {0}",ans[i]);
    }
    Console.WriteLine();
  }
}

class Data{
  public int pos {set; get;}
  public int area {set; get;}
  public Data(int tp, int ta){
    pos = tp;
    area = ta;
  }
}



Measured memory_bytes: 20484
n = gets.to_i
@flag = true
@t, @a, @b = 0, 0, 0

n.times do
  t,a,b = gets.split.map(&:to_i)
  diff_t = (t - @t)
  diff_a = (a - @a)
  diff_b = (b - @b)

  distance = diff_a+diff_b

  if diff_t < distance || (distance+diff_t).odd?
    @flag = false
    break
  end

  @a = a
  @b = b
  @t = t
end

if @flag
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void) {

	//??°????????\????????????????????°?????\???
	int row, col;
	scanf("%d %d\n", &row, &col);

	int i, j;
	int num[100][100];

	//?????°?????????
	for (i = 0; i < row; i++) {
		char tmp[10000];
		fgets(tmp,sizeof(tmp),stdin);

		//1????????????????????????
		num[i][0] = atoi(strtok(tmp," "));

		//?????°?????????
		for (j = 1; j < col; j++) {
			//2????????\??????????????????
			num[i][j] = atoi(strtok(NULL, " "));
			

		}
		//?????°???????????????

	}
	//?????°???????????????
	int product[100];

	//?????°?????????
	for (i = 0; i < col; i++) {

		//???????¨????
		char tmp[10000];
		fgets(tmp,sizeof(tmp),stdin);
		product[i]=atoi(tmp);
	}
	//?????°???????????????
	int sum[100]={0};

	//?????°?????????
	for (i = 0; i < row;i++) {
		
		//?????°?????????
		for (j = 0; j < col; j++) {
			//??????????¨??????????????????¨??¨?¶????
			sum[i] += num[i][j]*product[j];
		}
		//?????°???????????????

		//?¶?????????°???????????????
		printf("%d\n",sum[i]);
	}
	//?????°???????????????

	return 0;
}

Measured memory_bytes: 644
import numpy as np
import itertools

N,M = map(int,input().split())
xyz = [[int(x) for x in input().split()] for _ in range(N)]
xyz = np.array(xyz,dtype=np.int64)

answer = 0

# 正か負どちらで取るかを決める。
# ソートして大きいものからとる。
for sgn in itertools.product([1,-1],repeat = 3):
  x = (xyz * sgn).sum(axis = 1)
  x.sort()
  x = x[::-1]
  answer = max(answer, x[:M].sum())
  
print(answer)

Measured memory_bytes: 12536
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int POW[22];
	for(int i = 0; i < 22; i++)POW[i] = pow(2,i);

	ll N,M,A,B,P,Q;

	scanf("%lld %lld %lld %lld %lld %lld",&N,&M,&A,&B,&P,&Q);

	if(A == 1 && B == 1){

		ll num = M/(P+Q);

		if(num >= N){
			printf("%lld\n",M-N*(P+Q));
		}else{
			printf("%lld\n",min(M%(P+Q),(num+1)*(P+Q)-M)); //少し足りないと、少し多いの、差が小さい方
		}

		return 0;
	}

	vector<ll> FIRST;

	ll tmp = P+Q;
	ll a = 1, b = 1;
	ll count = 0,over_count = 0;

	double check;

	while(true){

		if(tmp > M)over_count++; //超過は1回だけ許す

		FIRST.push_back(tmp);
		count++;
		if(count == N || over_count == 1)break;

		check = P*a*A+Q*b*B;
		if(check > (double)M)break;

		a *= A;
		b *= B;

		tmp = P*a+Q*b;
	}

	//数字を2つのグループに振り分ける
	vector<ll> G[2];
	for(ll i = 0; i < FIRST.size(); i++){
		if(i <= (FIRST.size())/2){
			G[0].push_back(FIRST[i]);
		}else{
			G[1].push_back(FIRST[i]);
		}
	}

	int num[2];
	num[0] = (int)G[0].size();
	num[1] = (int)G[1].size();

	//各グループで数字を作る
	vector<ll> V[2];
	V[1].push_back(0);
	for(int group = 0; group < 2; group++){
		for(int state = 0; state < POW[num[group]]; state++){
			tmp = 0;
			for(int loop = 0; loop < num[group]; loop++){
				if(state & (1 << loop)){
					tmp += G[group][loop];
				}
			}
			V[group].push_back(tmp);
		}
		sort(V[group].begin(),V[group].end());
		V[group].erase(unique(V[group].begin(),V[group].end()),V[group].end());
	}

	ll ans = M,tmp_ans;

	int left,right,m,loc;

	for(int i = 0; i < V[0].size(); i++){

		if(V[0][i] >= M){
			ans = min(ans,V[0][i]-M);
			break;
		}

		//2分探索で、和がMを超えない、最大のindexを求める
		left = 0,right = (int)V[1].size()-1,m = (left+right);
		loc = 0;

		while(left <= right){
			if(V[0][i]+V[1][m] <= M){
				loc = m;
				left = m+1;
			}else{
				right = m-1;
			}
			m = (left+right)/2;
		}

		tmp_ans = (M-(V[0][i]+V[1][loc]));
		if(loc < (int)V[1].size()-1){
			tmp_ans = min(tmp_ans,V[0][i]+V[1][loc+1]-M);
		}

		ans = min(ans,tmp_ans);
	}

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

	return 0;
}



Measured memory_bytes: 31824
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int r, d, x, x_next;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        x_next = r * x - d;
        cout << x_next << endl;
        x = x_next;
    }
    return 0;
}


Measured memory_bytes: 256
/* Author rumoisen */
/* date 2018/10/08 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
using namespace std;

int yj(int n)
{
    int sum=0;
    while(n%2==0){
        sum++;
        n/=2;
    }
    return sum;
}
int main()
{
    int n;
    cin>>n;
    int sum=0,ans=0;
    for(int i=1;i<=n;i++){
        if(yj(i)>=sum) sum=yj(i),ans=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
lS=list(S)
o=0
e=0

for i in range(len(lS)):
    if i % 2 == 0:
        if lS[i]=='R':
            e=e+1
        elif lS[i]=='U':
            e=e+1
        elif lS[i]=='D':
            e=e+1
    elif i % 2 == 1:
        if lS[i]=='L':
            o=o+1
        elif lS[i]=='U':
            o=o+1
        elif lS[i]=='D':
            o=o+1

if o+e==len(lS):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 111111
#define M 222222
#define P 10001000
using namespace std;
int T,n,m,i,x,y,tot,S,fir[N],la[M],ne[M],V[N],L[N],R[N],AN[N];char s[N];bool ff,v[N];
void ins(int x,int y){la[++tot]=y;ne[tot]=fir[x];fir[x]=tot;}
void dfs1(int x,int fa){
	int lv=-1e9,rv=1e9;
	if(v[x])lv=rv=V[x];
	for(int i=fir[x];i;i=ne[i])if(la[i]!=fa){
		dfs1(la[i],x);
		lv=max(lv,L[la[i]]-1);
		rv=min(rv,R[la[i]]+1);
	}
	if(lv>rv)ff=1;
	if(!v[x])L[x]=lv,R[x]=rv;else{
		L[x]=R[x]=V[x];
		if(V[x]<lv||V[x]>rv)ff=1;
	}
}
void dfs2(int x,int fa){
	int lv=L[x],rv=R[x];
	if(fa)lv=max(lv,L[fa]-1),rv=min(rv,R[fa]+1);
	if(!v[x])L[x]=lv,R[x]=rv;else{
		if(V[x]<lv||V[x]>rv)ff=1;
	}
	for(int i=fir[x];i;i=ne[i])if(la[i]!=fa){
		dfs2(la[i],x);
	}
	if(lv>rv)ff=1;
	
}
int change(int x,int y){
	x--;
	int w=(y-x+1)/2;
	return x+w*2;
}
int gg(int x,int y){
	x++;
	int w=(x-y+1)/2;
	return x-w*2;
}
int to(int l1,int r1,int l2,int r2){
	if(l1-1<=l2)return change(l1,l2);
	if(r1+1>=r2)return gg(r1,r2);
}
void getans(int x,int fa){
	int o,i,lv,rv;
	if(v[x]){
		if(!fa||(AN[fa]-1==V[x]||AN[fa]+1==V[x]))AN[x]=V[x];else ff=1;
	}
	else{
		if(AN[fa]-1>=L[x]&&AN[fa]-1<=R[x])AN[x]=AN[fa]-1;
		else if(AN[fa]+1>=L[x]&&AN[fa]+1<=R[x])AN[x]=AN[fa]+1;
		else ff=1;
	}
	for(i=fir[x];i;i=ne[i])if(la[i]!=fa)getans(la[i],x);
}
void check(int x,int fa){
	if(fa)if(AN[fa]+1!=AN[x]&&AN[fa]-1!=AN[x])ff=1;
	for(int i=fir[x];i;i=ne[i])if(la[i]!=fa)check(la[i],x);
}
int main(){
	for(scanf("%d",&n),i=1;i<n;i++)scanf("%d%d",&x,&y),ins(x,y),ins(y,x);
	for(scanf("%d",&m),i=1;i<=m;i++)scanf("%d%d",&x,&y),v[x]=1,V[x]=y,S=x;
	if(!m)v[1]=1,V[1]=1,S=1;
	dfs1(1,0);
	dfs2(1,0);
	getans(S,0);
	if(ff)return puts("No"),0;
	check(S,0);
	if(ff)return puts("No"),0;
	puts("Yes");
	for(i=1;i<=n;i++)printf("%d\n",AN[i]);
}

Measured memory_bytes: 11008
#include<stdio.h>
int main(void){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/b;
    printf("%d %d %lf\n",d,r,f);
    return 0;
}


Measured memory_bytes: 2104
# coding: utf-8
import bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        n=L[i]+L[j]
        ans+=bisect.bisect_left(L,n)-j-1
        #print(L[i],L[j],n)
print(ans)

Measured memory_bytes: 42972
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
 
void main() {
	auto N = readln.split[0].to!ulong;
	ulong[] p;
	N.iota.each!(x => p ~= readln.split[0].to!ulong);
	auto sum = p.sum, max_price = p.minPos!("a > b")[0];
	(p.sum - max_price/2).writeln;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

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;
}

int main()
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int ans = max(0, min(b, d) - max(a, c));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int sum = 0;
        for(int i = 1; i * i <= n; i++){
            if(n % i == 0 && n != 1){
                sum += i;
                if(n/i != n)sum += n / i;
                if(i * i == n)sum -= i;
            }
        }
        if(sum < n) cout << "deficient number" << endl;
        else if(sum > n) cout << "abundant number" << endl;
        else if(sum == n) cout << "perfect number" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> x(n);
		REP(i,n) cin >> x[i], x[i]--;
		vector<P> xp(n);
		REP(i,n){
			xp[i] = {x[i],i+1};
		}
		sort(ALL(xp));
		vector<int> am(n,n-1);
		vector<int> ans(n*n,-1);
		int p = 0;
		bool ex = true;
		[&](){
			REP(i,n){
				int m = xp[i].S;
				int pp = xp[i].F;
				ans[pp] = m;
				REP(i,m-1){
					while(p < n*n and ans[p] != -1) p++;
					if(p > pp or p >= n*n){
						ex = false;
						return;
					}
					ans[p] = m;
					am[m-1]--;
				}
				dpite(ALL(ans));
			}
		}();
		dpite(ALL(am));
		dpite(ALL(ans));
		
		p = n*n-1;
		[&](){
			RREP(i,n){
				int m, pp;
				tie(pp,m) = xp[i];
				DEBUG(m);

				REP(j,am[m-1]){
					while(p >= 0 and ans[p] != -1) p--;
					if(p < pp or p == -1){
						ex = false;
						return;
					}
					ans[p] = m;
				}
			}
		}();
		if(ex){
			cout << "Yes" << endl;
			pite(ALL(ans));
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2176
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

int n, m, q;
int a[55], b[55], c[55], d[55];
ll ans = 0;
int arr[55];

void func(int depth) {
    if(depth == n+1) {
        ll tmp = 0;
        rep(i, q) {
            if(arr[b[i]] - arr[a[i]] == c[i]) {
                tmp += d[i];
            }
        }
        ans = max(ans, tmp);
    }
    else {
        for(int i = arr[depth-1]; i <= m; ++i) {
            arr[depth] = i;
            func(depth + 1);
        }
        
    }
}

int main() {
    cin >> n >> m >> q;
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    for(int i = 1; i <= m; ++i) {
        arr[0] = i;
        func(1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{a:i64, b:i64, c:i64};
    println!("{}", min(a+b,min(b+c,a+c)));

}


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

int main(){
    ll n ;cin>>n;
    ll ans = LONG_LONG_MAX;
    for(ll i=1;i*i<=n;i++){
         //   cout<<i<<endl;
        if(n%i == 0){
            ans = min(ans , i+(n/i)-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

const ll MOD=1e9+7;

int N;
int a[100005];
  
int main(){
 
cin>>N;

for(int i=0; i<N; i++){
    int x;
    scanf("%d",&x); x--;
    a[i]=x;
}

int x=0,cnt=0;
for(int i=0; i<N; i++){
    x=a[x]; cnt++; 
    if(x==1){
        cout<<cnt<<endl; return 0;
    }
}

cout<<-1<<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll x,ll y)
{
  if(x<y)return x;
  return y;
}

int main()
{
  ll n;cin>>n;
  ll move=n-1;
  for(ll i=2;i<=sqrt(n);i++){
    if(n%i==0)move=min(move,i+n/i-2);
  }
  cout<<move<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
vector<string>q;
int main()
{
	int n;
	cin >> n;
	string x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		mp[x]++;
	}
	int max = 0;
	for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)
	{
		if (it->second == max)
		{
			q.push_back(it->first);
		}
		else if (it->second > max)
		{
			max = it->second;
			q.clear();
			q.push_back(it->first);
		}

	}
	sort(q.begin(), q.end());
	for (int i = 0; i < q.size(); i++)
		cout << q[i] << endl;
}

Measured memory_bytes: 27760
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)



signed main()
{
	string s;
	string tmp = "abcdefghijklmnopqrstuvwxyz";
	cin >> s;
	vector<int> moji(26,0);
	vector<int> res(s.size(), 0);
	char c_tmp;
	/*REP(i, s.length()) {
		REP(j, tmp.length()) {
			if (tmp[j] == s[i]) moji[j]++;
		}
	}
	*/
	int n = 1;
	int min = 9999999;
	int cc = 0;
	bool clear = true;
	REP(i, 26) {
		c_tmp = tmp[i];
		REP(j, s.length()) {
			if (c_tmp == s[j]) res[j] = 1;
			else res[j] = 0;
		}
		n = 1;
		cc = 0;

		while (true) {
			clear = true;
			REP(j, s.length() - n + 1) {
				if (res[j] == 0) {
					clear = false; break;
				}
			}
			if (clear == true) break;
			REP(j, s.length()-n) {
				if (res[j + 1] == 1) res[j] = 1;
			}
			n++;
			cc++;
		}
		if (min > cc) min = cc;
	}
	cout << min << endl;
}

Measured memory_bytes: 256