akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n;
  string s;
  cin>>s;
  n=s.size();
  vector<int> num(n);
  vector<int> v2019(n,1);
  //for(int i=1;i<n;i++)
    
    
  rep(i,n)
    num.at(i)=(int)s.at(i)-(int)'0';
  
  vector<int> dp(n,0);
  reverse(all(num));
  dp.at(0)=num.at(0);
  in ans=0;
  rep(i,n){
    if(i==0)continue;
    v2019.at(i)=(v2019.at(i-1)*10)%2019;
    dp.at(i) = (dp.at(i-1)+num.at(i)*v2019.at(i))%2019;
    if(dp.at(i)==0) ans++;
  }
  
  
  vector<int> h(2019);
  rep(i,2019){
    rep(j,n){
      if(dp.at(j)==i)
        h.at(i)=h.at(i)+1;
    }
  }
  rep(i,2019){
    if(h.at(i)>1)
      ans+=(h.at(i)*(h.at(i)-1))/2;
  }
  
  printf("%lld\n",ans);
}

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

int main() {
    int N;
    int K;
    cin >> N >> K;
    vector<int> p(N);
    for(int i=0;i<N;i++) {
        cin >> p.at(i);
    }
    sort(p.begin(),p.end());
    cout << accumulate(p.begin(),p.end()-N+K,0) << endl;
}

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

int main(){
    int r, c, A[101][101];
    cin >> r >> c;

    for(int i=0; i<r; i++)
        for(int j=0; j<c; j++) cin >> A[i][j];
    
    for(int i=0; i<=r; i++) A[i][c] = 0;
    for(int j=0; j<=c; j++) A[r][j] = 0;

    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            A[i][c] += A[i][j];
            A[r][j] += A[i][j];
            A[r][c] += A[i][j];
        }
    }

    for(int i=0; i<=r; i++){
        for(int j=0; j<=c; j++){
            if( j ) cout << " ";
            cout << A[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3136
import numpy as np
 
N = int(input())
A = [input().split() for _ in range(N)]
# sum(A, []) 次元をフラット化
XY = np.array(sum(A, []),np.int64)

X = XY[::2] # x部分
Y = XY[1::2] # y部分
# Noneで次元を追加 X[:, None] shap(N,1)
dx = X[:,None] - X[None,:] 
dy = Y[:,None] - Y[None,:]

dist_mat = (dx*dx + dy*dy)**.5
ans = dist_mat.sum() / N
print(ans)

Measured memory_bytes: 12448
#include <stdio.h>
#include <algorithm>

int main(void)	{
	while (true)	{
		int umpire, temp, summ, mini, maxi;
		mini = 1000;
		maxi = 0;
		summ = 0;
	
		scanf("%d", &umpire);
		if (umpire == 0)	{
			break;
		}
		for (int i = 0; i <= umpire - 1; i++)	{
			scanf("%d", &temp);
			mini = std::min(mini, temp);
			maxi = std::max(maxi, temp);
			summ = summ + temp;
		}
		printf("%d\n", (summ - mini - maxi) / (umpire - 2));
	}
	return 0;	
}



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

using namespace std;

int main(){
        string str;
        cin>>str;
        if(str[0]=='Y'&&str[1]=='A'&&str[2]=='K'&&str[3]=='I'){
                cout<<"Yes"<<endl;
        }
        else{
                cout<<"No"<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define pb(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;



int main() {
	stack<int> s;
	string c;
	int a, b;
	while (cin >> c){
		switch (c[0]) {
		case '+':
			 a = s.top();
			s.pop();
			 b = s.top();
			s.pop();
			s.push(a + b);
			break;
		case'-':
			 a = s.top();
			s.pop();
			 b = s.top();
			s.pop();
			s.push(b - a);
			break;
		case'*':
			 a = s.top();
			s.pop();
			 b = s.top();
			s.pop();
			s.push(a*b);
			break;
		default:
			s.push(atoi(c.c_str()));
		}
	}
	cout << s.top() << endl;

	return 0;
}

Measured memory_bytes: 3212
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    
    vector<int> vec;
    bool sosu[50050]={false};
    
    vec.push_back(2);
    for(int i=3;i<50050;i+=2){
        if(sosu[i]) continue;
        vec.push_back(i);
        for(int j=i+i;j<50050;j+=i){
            sosu[j] = true;
        }
    }
   
    int n;
    while(cin >> n){
        cout << *(lower_bound(vec.begin(),vec.end(),n)-1) << " " << *upper_bound(vec.begin(),vec.end(),n) << endl;
    }
   
    return(0);
}


Measured memory_bytes: 3124
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
count=0
for i in range(N):
    total=C
    A=list(map(int,input().split()))
    for j in range(M):
        total+=A[j]*B[j]
    if total>0:
        count+=1
print(count)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		Map<Long , Integer> map = new HashMap<>();
		int i , j , n;
		n = scan.nextInt();
		for (i = 0;i < n;i ++) {
			long value = scan.nextLong();
			if (!map.containsKey(value)) {
				map.put(value , 1);
			} else {
				map.put(value , map.get(value) + 1);
			}
		}
		long ans = 0;
		List<Long> list = new ArrayList<>();
		for (Map.Entry<Long , Integer> entry : map.entrySet()) {
			if (entry.getValue() >= 4) {
				long temp = entry.getKey();
				if (temp * temp > ans) {
					ans = temp * temp;
				}
			}
			if (entry.getValue() >= 2) {
				list.add(entry.getKey());
			}
		}
		Collections.sort(list);
		if (list.size() > 1) {
			long temp = list.get(list.size() - 1) * list.get(list.size() - 2);
			if (temp > ans) {
				ans = temp;
			}
		}
		System.out.println(ans);
		
	}
	
	
}



















Measured memory_bytes: 63800
#include<iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <stack>

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

using namespace std;

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

    stack<int> S1;
    stack<pair<int, int> > S2;

    int sum = 0;
    REP(i, (int)s.length())
    {
        char c = s[i];

        if (c == '\\')
        {
            S1.push(i);
        }
        else if (c == '/' && S1.size() > 0)
        {
            int j = S1.top();
            S1.pop();
            int a = i - j;
            sum += a;
            while (S2.size() && S2.top().first > j)
            {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while(S2.size() > 0)
    {
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    REP(i, (int)ans.size())
    {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
}


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

using namespace std;

int main(){
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;

    for(int i = 0; i < N; ++i) cin >> t[i + 1] >> x[i + 1] >> y[i + 1];

    bool can = true;
    for(int i = 0; i < N; ++i){
        int dt = t[i + 1] - t[i];
        int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);

        if(dt < dist) can = false;
        if(dist % 2 != dt % 2) can = false;
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
<?php

list($hp, $n) = explode(" ", trim(fgets(STDIN)));
$line = explode(" ", trim(fgets(STDIN)));

for($i=0; $i<count($line); $i++){
    $hp -= $line[$i];
}
// var_dump($hp);
if($hp <= 0){
    echo 'Yes';
}else{
    echo 'No';
}

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

int main(){
    int m,d;
    cin>>m>>d;
    int cnt = 0;

    for(int i = 1; i<=m ;i++){
        for(int j=1; j<=d; j++){
            int x = j%10;
            int y = (j/10)%10;

            if(x >= 2 && y>=2 && (x*y == i)){
                cnt++;
            }
        }
    }

    cout<<cnt<<endl;
}


Measured memory_bytes: 256
var
        x,i,n,s:longint;
        a:array [0..10] of longint;
begin
readln(n);
for i:=1 to n do
        begin
        read(x);
        if x<400 then a[1]:=1 else
        if x<800 then a[2]:=1 else
        if x<1200 then a[3]:=1 else
        if x<1600 then a[4]:=1 else
        if x<2000 then a[5]:=1 else
        if x<2400 then a[6]:=1 else
        if x<2800 then a[7]:=1 else
        if x<3200 then a[8]:=1 else
        inc(a[9]);
        end;
for i:=1 to 8 do s:=s+a[i];
if s=0 then writeln(1,' ',a[9]) else
if a[9]<>0 then writeln(s,' ',s+a[9])
else writeln(s,' ',s);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FIO                 ios::sync_with_stdio(false); cin.tie(nullptr)
#define TC(t)               int t; cin >> t; for(int i = 1; i <= t; i++)
#define deb(x)              cerr << #x << " = " << x << endl
#define deb2(x, y)          cerr << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)         for(i = a; i < n; i++)
#define f1(i, a, n)         for(i = a; i <= n; i++)
#define ini(x, y)           memset(x, y, sizeof(x))
#define all(x)              x.begin(), x.end()
#define sz(x)               x.size()
#define ll                  long long int
#define vi                  vector<int>
#define pb                  emplace_back
#define ppb                 pop_back
#define mp                  make_pair
#define M                   1000000007
#define endl                '\n'
#define bits(x)             __builtin_popcountll(x)
#define zrbits(x)           __builtin_ctzll(x)
#define ordered_set         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

const int N = 1e5 + 1;
const int MX = 1e9;
const ll INF = 1e18;

using namespace std;
using namespace __gnu_pbds;

inline ll ceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
inline ll mod(ll x) {return ( (x % M + M) % M );}

void solve() {int m;
        string s;
        cin >> s;
        int n = sz(s);
        if(s[n-1] == 's') {
                s += "es";
        } else s += "s";
        cout << s << endl;
}

int main () {
        FIO;
        // TC(t)
        solve();
        return 0;
}

Measured memory_bytes: 3644
num_v,num_e,source=input().split()

edges=[]
verticies=[]

for i in range(int(num_e)):
    v,u,w=input().split()
    e=(int(v),int(u),int(w))
    edges.append(e)


for v in range(int(num_v)):
    v=str(v)
    verticies.append(v)

itn=int(num_v)-1
g=edges

dist=[float('inf')]*(itn+1)
dist[int(source)]=0


def BF(g):
    for i in range(itn):
        for edge in edges:
            v,u,w =edge
            if dist[v]!=float('inf'):
                if dist[v] + w < dist[u]:
                    dist[u]=dist[v] + w
                    
    #check negative cycle
    ngc=0
    for edge in edges:
        v,u,w=edge
        if dist[v]!=float('inf'):
            if dist[v] + w < dist[u]:
                ngc=1
                 
                
    if ngc==0:
        for i in range(itn+1):
            if dist[i]==float('inf'):
                print("INF")
            else: print(dist[i])
    else:
        print("NEGATIVE CYCLE")

BF(g)


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

int main(){
  int H, N; cin >> H >> N;
  vector<int> A(N), B(N); rep(i, N) cin >> A[i] >> B[i];

  const long long INF = 1e18 + 10;
  vector<long long> dp(200010, INF);
  dp[0] = 0;

  rep(i, H) {
    rep(k, N) {
      dp[i + A[k]] = min(dp[i + A[k]], dp[i] + B[k]);
    }
  }
  long long ans = INF;
  for (int i = H; i < H + 1e4; i++) {
    ans = min(ans, dp[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		double ans = 0;
		for (int i = 1; i <= N; i++) {
			int cnt;
			int d;
			if (i < K) {
				cnt = (int) Math.ceil(Math.log((double) K / i) / Math.log(2));
				d = N * (int) Math.pow(2, cnt);
			} else {
				d = N;
			}
			ans += 1.0 / d;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

typedef pair<int, int> pi;

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

    priority_queue<pi, vector<pi>, greater<pi> > pq;

    int x, y;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        pq.push({y, x});
    }

    pi tmp;
    int t = 0;
    while(!pq.empty())
    {
        tmp = pq.top();
        if(t + tmp.second <= tmp.first){
            t += tmp.second;
            pq.pop();
        }else
            break;
    }

    if(pq.empty())
        cout<<"Yes";
    else
        cout<<"No";


	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;

int main(){
	cin>>n;
	vp a;
	for(int i=0;i<n/3;i++) for(int j=0;j<n;j++) if(i%2==j%2){
		a.push_back(P(j,i*3+1));
	}
	for(int i=0;i<n;i++) if(i%2==1) a.push_back(P(0,i));
	for(int i=0;i<n;i++) if((i+n-1)%2==1) a.push_back(P(i,n-1));
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	int S=a.size();
	cout<<S<<endl;
	for(int i=0;i<S;i++) cout<<a[i].first<<' '<<a[i].second<<endl;
}

Measured memory_bytes: 2928
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadArrayInt();
            var front = new long[N];
            var back = new long[N];
            front[0] = A[0];
            back[N - 1] = A[N - 1];
            for (int i = 1; i < N; i++) front[i] = Gcd(A[i], front[i - 1]);
            for (int i = N - 2; i >= 0; i--) back[i] = Gcd(A[i], back[i + 1]);
            var ans = Math.Max(front[N - 2], back[1]);
            for (int i = 1; i < N - 1; i++)
            {
                var chk = Gcd(front[i - 1], back[i + 1]);
                if (chk > ans) ans = chk;
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static long Gcd(long a, long b) { if (b == 0) return a; return Gcd(b, a % b); }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

using namespace std;
typedef long long ll;

ll a,b;
int k;

int main(){
scanf("%lld%lld%d",&a,&b,&k);
for(register int i=1;i<=k;++i){
if(i&1){
b+=(a/2);
a/=2;
}
else{
a+=(b/2);
b/=2;
}
}
printf("%lld %lld",a,b);
return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define rep(i,n) for(i=0;i<(n);i++)
#define For(i,a,b) for(i=(a);i<(b);i++)



int main(){
  int i,j,k;
  int a,b,c;
  cin >> a >> b >> c;
  if(a>b) swap(a,b);
  if(b>c) swap(b,c);
  if(a>b) swap(a,b);
  cout << a << " " << b << " " << c << endl;
  
  return 0;
}

Measured memory_bytes: 3120
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	REP(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(all(b));
	int cnt = 0;
	REP(i, n) {
		if (a[i] != b[i])cnt++;
	}
	if (cnt == 0 || cnt == 2) {
		put("YES");
	}
	else {
		put("NO");
	}
	return 0;
}


Measured memory_bytes: 256
//prepared by dumb
#include<bits/stdc++.h>
using namespace std;
#define   ll long long int
#define   dl double  
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
// Creates a min heap 
//priority_queue <int, vector<int>, greater<int> > pq; 
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ll a, b, c=0, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
    string str, str1, str2;
    char ch;
  
     scll(n);
     for(i=1;i<=n;i++)
     {
        scll(a);
        if(i%2==1&&a%2==1)
            c++;
     }
     cout<<c;
return 0;
}

Measured memory_bytes: 3684
#-*-coding:utf-8-*-
from functools import reduce

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

def gcd_list(numbers):
    return reduce(gcd, numbers)

def main():
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))
    x_list.append(x)
    x_list.sort()
    diff = []
    for i in range(n):
        diff.append(x_list[i + 1] - x_list[i])
    print(gcd_list(diff))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14596
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int h, w;
    char a[100][100];
    std::vector<int> idx;
    
    std::cin >> h >> w;
    
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            std::cin >> a[i][j];
        }
    }
    
    int delCount = 0;
    for(int i = 0; i < h; i++){
        int dotCount = 0;
        for(int j = 0; j < w; j++){
            if(a[i][j] == '.') dotCount++;
        }
        if(dotCount == w){
            a[i][0] = '*';
        }
        //std::cout << dotCount << std::endl;
    }
    
    for(int i = 0; i < w; i++){
        int dotCount = 0;
        for(int j = 0; j < h; j++){
            //std::cout << a[j][i];
            if(a[j][i] == '.' || a[j][i] == '*') dotCount++;
        }
        if(dotCount == h){
            a[0][i] = '*';
            idx.push_back(i);
        }
        //std::cout << std::endl;
        //std::cout << dotCount << std::endl;
    }
    
    //std::cout << std::endl;
    
    for(int i = 0; i < h; i++){
            int flag = 1;
        for(int j = 0; j < w; j++){
            int f = 0;
            for(int k = 0; k < idx.size(); k++){
                if(idx[k] == j){
                    f = 1;
                }
            }
            if(f){
                continue;
            }
            
            if(a[i][0] == '*') {
                flag = 0;
                continue;
            }
            std::cout << a[i][j];
        }
        if(flag){
            std::cout << std::endl;
        }
    }
    
    /*
    for(int i = 0; i < idx.size(); i++){
        std::cout << idx[i] << std::endl;
    }
    */
    
    return 0;
}


Measured memory_bytes: 384
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$a = $sc->nextInt();
$b = $sc->nextInt();
$c = $sc->nextInt();
$d = $sc->nextInt();

$answer = max($a*$c, $a*$d, $b*$c, $b*$d);

echo $answer.PHP_EOL;

Measured memory_bytes: 16280
fun main(args: Array<String>) {
    val nd = nextIntList()
    val n = nd[0]
    val d = nd[1]

    var cnt = 0
    for(i in 0 until n){

        val xy = nextIntList()
        val x = xy[0].toDouble()
        val y = xy[1].toDouble()
        val res = Math.sqrt(x*x + y*y)
      
      
      
        if(res <= d) cnt++
    }
    println(cnt)
}
fun next() = readLine()!!
fun nextIntList() = next().split(" ").map{ it.toInt() }

Measured memory_bytes: 58872
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(3 * n);
    rep(i, 3 * n) cin >> a[i];
    
    vector<ll> ans(n + 1);
    rep(t, 2) {
        multiset<int> st;
        ll sum = 0;
        rep(i, 2 * n) {
            st.insert(a[i]);
            sum += a[i];
            if (i >= n-1) {
                if (sz(st) > n) {
                    if (t == 0) {
                        auto it = st.begin();
                        sum -= *it;
                        st.erase(it);
                    } else {
                        auto it = st.rbegin();
                        sum -= *it;
                        st.erase(st.find(*it));
                    }
                }
                if (t == 0) ans[i - n + 1] += sum;
                else ans[2 * n - i - 1] -= sum;
            }
        }
        reverse(all(a));
    }
    cout << *max_element(all(ans)) << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;

const int MAXN = 1e3 + 500;
const int MAXV = 1e4 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;
const int OFF = 1 << 17;

struct triple {
    int weight;
    int solidness;
    int value;
};

vector <triple> blocks;
ll dp[MAXN][MAXV];

int main() {
    int N, w, s, v, ind;
    int weight, solidness, value;

    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        scanf("%d%d%d", &w, &s, &v);
        blocks.push_back(triple{w, s, v});
    }

    sort(blocks.begin(), blocks.end(), [](const triple& a, const triple& b) {
        return (a.solidness + a.weight > b.solidness + b.weight);
    });

    dp[0][blocks[0].solidness] = blocks[0].value;
    for(int i = 1; i < N; i++) {
        weight = blocks[i].weight;
        solidness = blocks[i].solidness;
        value = blocks[i].value;

        dp[i][solidness] = value;
        for(int j = 0; j < MAXV - 10; j++) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);     // preskocis objekt
            if(!dp[i - 1][j] || j < weight)
                continue;

            ind = min(j - weight, solidness);           // stavis objekt
            dp[i][ind] = max(dp[i][ind], dp[i - 1][j] + value);
        }
    }

    ll ans = 0;
    for(int i = 0; i < MAXV; i++)
        ans = max(ans, dp[N - 1][i]);
    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 84224
n,k=map(int,input().split());x,t,e,c=10**9+7,[set()for _ in range(n)],enumerate,k;import sys;sys.setrecursionlimit(x)
for i in range(n-1):a,b=map(int,input().split());t[a-1].add(b);t[b-1].add(a)
def b(o):
  global c
  for i,j in e(t[o-1]):c=(c*(k-2-i))%x;t[j-1].discard(o);b(j)
for i,j in e(t[0]):c=(c*(k-1-i))%x;t[j-1].discard(1);b(j)
print(c)

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

class Main{
  static int n;
  static int[] A = new int[2000000];
  static int[] B = new int[1000000];

  public static void main(String[] args){
    int key;
    Scanner scan = new Scanner(System.in);
    String s;
    int j = 0;

    while(true){
      s = scan.next();
      if(s.equals("end")){break;}

      if(s.equals("insert")){
        key = scan.nextInt();
        insert(key);
      }
      else{
        B[j] = func();
        j++;
      }
    }
    for(int i=0 ; i<j ; i++){
      System.out.println(B[i]);
    }
  }

  public static void maxHeapify(int i){
    int l = 2 * i;
    int r = 2 * i + 1;
    int L;
    int tmp;

    if(l <= n && A[l] > A[i]){L = l;}
    else{L = i;}

    if(r <= n && A[r] > A[L]){L = r;}

    if(L != i){
      tmp = A[i];
      A[i] = A[L];
      A[L] = tmp;
      maxHeapify(L);
    }
  }

    public static int func(){
      int max;

      if(n<1){return -10000000;}

      max = A[1];
      A[1] = A[n--];
      maxHeapify(1);
      return max;
    }

    public static void insert(int key){
      n++;
      A[n] = -1000000;
      increase(n, key);
    }

    public static void increase(int i, int key){
      int tmp;
      if(key < A[i]){return;}

      A[i] = key;
      while(i > 1 && A[i/2] < A[i]){
        tmp = A[i];
        A[i] = A[i/2];
        A[i/2] = tmp;
        i /= 2;
      }
    }

}



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

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

Measured memory_bytes: 256
//#pragma GCC optimize(3)
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int dp[20010];
int a[1010],b[1010];
int main(){
	int h,n;
	cin>>h>>n;
	int mxa=-1;
	rep(i,n){
		cin>>a[i]>>b[i];
		mxa=max(mxa,a[i]);
	}
	rep(i,h+mxa){
		if(i==0)continue;
		dp[i]=INF;
		rep(j,n){
			if(i-a[j]<0)continue;
			dp[i]=min(dp[i-a[j]]+b[j],dp[i]);
		}
		//cout<<dp[i];
	}
	int ans=INF;
	for(int i=h;i<h+mxa;i++){
		ans=min(ans,dp[i]);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

int main() {
    cin.sync_with_stdio(false);

    int a, b;
    cin >> a >> b;

    if (a > 0) {
        cout << "Positive";
    } else if (a <= 0 && b >= 0) {
        cout << "Zero";
    } else {
        int dif = b - a;
        if (dif & 1) {
            cout << "Positive";
        } else {
            cout << "Negative";
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
#define PI 3.14159265358979
using P = pair<ll , ll>;
//using map = map<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    ll n, k;
    cin >> n >> k;
    vl p(n);
    rep(i,n) cin >> p.at(i);

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

    ll ans = 0;
    rep(i,k){
        ans += p.at(i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
main :: IO ()
main = do
    _ <- getLine
    list <- map read . words <$> getLine
    putStrLn $ show $ divide 0 list

divide :: Int -> [Int] -> Int
divide _ [] = 0
divide num nums
    | any odd nums = num
    | otherwise = divide (num + 1) (map (`div` 2) nums)

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
vector<int> G[100010];
int d1[100010],d2[100010];
void dfs1(int i,int d){
    d1[i]=d;
    for(auto e:G[i]){
        if(d1[e]==INF){
            dfs1(e,d+1);
        }
    }
}
void dfs2(int i,int d){
    d2[i]=d;
    for(auto e:G[i]){
        if(d2[e]==INF){
            dfs2(e,d+1);
        }
    }
}
int main(){
    int n;cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i=0;i<n;i++)d1[i]=INF,d2[i]=INF;
    dfs1(0,0);
    dfs2(n-1,0);
    int fc=0,sc=0;
    for(int i=0;i<n;i++){
        if(d1[i]<=d2[i]){
            fc++;
        }else{
            sc++;
        }
    }
    if(fc>sc){
        cout<<"Fennec"<<endl;
    }else{
        cout<<"Snuke"<<endl;
    }
}



Measured memory_bytes: 9600
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    h,w = f()
    ss = [input() for i in range(h)]
    for i in range(h):
        for j in range(w):
            if ss[i][j] == '.':
                continue
            if i-1>=0 and ss[i-1][j]=='#':
                continue
            if i+1<h and ss[i+1][j] == '#':
                continue
            if j-1>=0 and ss[i][j-1]=='#':
                continue
            if j+1<w and ss[i][j+1]=='#':
                continue
            print('No')
            return
    
    print('Yes')

solve()


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int a,b,ans;
	scanf ("%d %d", &a, &b);
	
	if (b%a==0)
	{
		ans= a+b;
	}
	else
	{
		ans= b-a;
	}
	printf("%d", ans);
	
	

return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end(), greater<int>());
  
  int sum = 0;
  for(int i = 0; i < n; i++) {
    if(i % 2 == 0)
      sum += a.at(i);
    else
      sum -= a.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ar = new int[n];
    for(int i=0;i<n;i++){
      ar[i] = sc.nextInt();
    }
    for(int j=1;j<n-1;j++){
      if((ar[j-1] < ar[j] && ar[j] < ar[j+1]) || (ar[j-1] > ar[j] && ar[j] > ar[j+1])){
        count++;
      }
    }
    System.out.println(count);
  }
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	string s,t;
	cin >> s;
	cin >> t;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i])ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	vector<int> Bs;

	cin >> N;

	int b;
	Bs.push_back(1e9);
	for (int ni = 1; ni < N; ni++){
		cin >> b;
		Bs.push_back(b);
	}
	Bs.push_back(1e9);

	vector<int>As;
	int ans = 0;
	int a;
	for (int ni = 0; ni < N; ni++) {
		a = min(Bs[ni], Bs[ni + 1]);
		As.push_back(a);
		ans += a;
	}


	printf("%d",ans);

	return 0;
}



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong x;
  cin >> x;

  cout << (x >= 30 ? "Yes": "No") << endl;

  return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, N, sr, sc;
	cin >> H >> W >> N >> sr >> sc;
	string S, T;
	cin >> S >> T;
	int l = sc, r = sc, u = sr, d = sr;
	bool ans = true;
	for (int i = 0; i < N; ++i) {
		switch (S[i])
		{
		case 'L':
			--l;
			if (l < 1) ans = false;
			break;
		case 'R':
			++r;
			if (r > W) ans = false;
			break;
		case 'U':
			--d;
			if (d < 1) ans = false;
			break;
		case 'D':
			++u;
			if (u > H) ans = false;
			break;
		}
		if (!ans) break;

		switch (T[i]) {
		case 'L':
			if (r > 1)	--r;
			break;
		case 'R':
			if (l < W)++l;
			break;
		case 'U':
			if (u > 1)--u;
			break;
		case 'D':
			if (d < H)++d;
			break;
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 920
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let p: usize = scan(tokens);
    let a: Vec<usize> = vec(p, |_| scan(tokens));
    let mut prod: Vec<usize> = vec![1];
    for i in 0..p {
        prod = mul(prod, vec![i, 1], p);
    }
    let mut factorial = 1;
    for i in 1..p {
        factorial = factorial * i % p;
    }
    let factorial_inverse = inverse(factorial, p);
    let mut b = vec![0; p];
    for i in 0..p {
        if a[i] == 1 {
            let f = div(prod.clone(), i, p);
            for j in 0..p {
                b[j] = (b[j] + factorial_inverse * f[j]) % p;
            }
        }
    }
    for i in 0..p {
        if i != 0 {
            print!(" ");
        }
        print!("{}", b[i]);
    }
    println!("");
}

fn mul(f: Vec<usize>, g: Vec<usize>, p: usize) -> Vec<usize> {
    let mut h = vec![0; f.len() + g.len() - 1];
    for i in 0..f.len() {
        for j in 0..g.len() {
            h[i + j] = (h[i + j] + f[i] * g[j]) % p;
        }
    }
    h
}

fn div(mut f: Vec<usize>, a: usize, p: usize) -> Vec<usize> {
    let mut h = vec![0; f.len() - 1];
    for i in (1..f.len()).rev() {
        h[i - 1] = f[i];
        f[i - 1] = (f[i - 1] + a * f[i]) % p;
    }
    // assert_eq!(f[0], 0);
    h
}

fn power(mut b: usize, mut e: usize, p: usize) -> usize {
    let mut a = 1;
    while e != 0 {
        if e & 1 != 0 {
            a = a * b % p;
        }
        b = b * b % p;
        e >>= 1;
    }
    a
}

fn inverse(x: usize, p: usize) -> usize {
    power(x, p - 2, p)
}


Measured memory_bytes: 4476
while True:
    n = int(input())
    if n == 0:
        break
    id = []
    pq = [-1] * 4001
    for i in range(n):
        e,p,q = list(map(int,input().split()))
        if pq[e] < 0:
            id.append(e)
            pq[e] = p*q
        else: pq[e] += p*q
    
    f = False
    for e in id:
        if pq[e] >=1000000:
            print(e)
            f = True
    if not f:
        print("NA")


Measured memory_bytes: 5828
#include "bits/stdc++.h"
using namespace std;

int main() {
  string S;
  cin >> S;
  int price = 700;
  if(S.at(0) == 'o') price += 100;
  if(S.at(1) == 'o') price += 100;
  if(S.at(2) == 'o') price += 100;
  cout << price << endl;
  return 0;
}

Measured memory_bytes: 256
A,B,Q=map(int,input().split())
S=[int(input()) for i in range(A)]
T=[int(input()) for j in range(B)]
S.sort()
T.sort()
def make_lr(L,idx,x):
    if idx==0:
        return float('inf'),L[idx]-x
    if idx==len(L):
        return x-L[idx-1],float('inf')
    return x-L[idx-1],L[idx]-x
import bisect
for i in range(Q):
    x=int(input())
    Sidx=bisect.bisect_left(S,x)
    Tidx=bisect.bisect_left(T,x)
    sl,sr=make_lr(S,Sidx,x)
    tl,tr=make_lr(T,Tidx,x)
    
    print(min(sl+tr+min(sl,tr),sr+tl+min(sr,tl),min(max(sl,tl),max(sr,tr))))

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

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

    int ans=0,now=1;
    while(true){
        ans++;
        now=a[now-1];
        if(now==2) break;
        if(ans>=1e5){
            ans=-1;
            break;
        }
    }
    cout<<ans<<endl;
}

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


#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define fr(i,a,b) for(int i = a ; i < b ; ++i)
#define backfr(i,a,b) for(int i = a ; i > b ;--i)
#define all(v) v.begin() , v.end()
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define show(x) cout << #x <<" = " << x << endl
#define fastio ios_base::sync_with_stdio(0)

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

int main()
{
	fastio;cin.tie(0);cout.tie(0);
	long long int n ,k,sum=0;
	cin>>n>>k;
	long long int h[n];
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	sort(h,h+n);
	for(int j=0;j<n-k;j++)
	{
		sum+=h[j];
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int a,b;
 cin >> a >> b;
 bool c=false;
 if(a%3==0)c=true;
 if(b%3==0)c=true;
 if((a+b)%3==0)c=true;
 if(c)cout << "Possible" << endl;
 else cout << "Impossible" << endl;
  
}



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

int main() {
    string s;
    cin >> s;
    long long ans = 0, cur = 0;
    for (char ch : s) {
        if (ch == 'W') ans += cur;
        else cur++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int W;
  int A;
  int B;
  cin >>W>>A>>B;
  int x=abs(B-A-W);
  int y=abs(A-B-W);
  if((B-A-W>=0)|| (A-B-W>=0)) {
  cout<< min(x,y)<< endl;
}
  if ((B-A-W<0)&& (A-B-W<0)) {
  cout<< 0<< endl;
}
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree< ll, null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll mod = 1e9 + 7;

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

  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector < ll > va(a), vb(b), vc(c);
  for(int i = 0; i < a; i++) cin >> va[i];
  for(int i = 0; i < b; i++) cin >> vb[i];
  for(int i = 0; i < c; i++) cin >> vc[i];
  sort(va.begin(), va.end(), greater < ll >());
  sort(vb.begin(), vb.end(), greater < ll >());
  sort(vc.begin(), vc.end(), greater < ll >());
  va.resize(x);
  vb.resize(y);
  vector < ll > v;
  for(int i = 0; i < x; i++) v.push_back(va[i]);
  for(int i = 0; i < y; i++) v.push_back(vb[i]);
  for(auto i : vc) v.push_back(i);
  sort(v.begin(), v.end(), greater < ll > ());

  ll ans = 0;
  for(int i = 0; i < x + y; i++){
    ans += v[i];
  }

  cout << ans << '\n';
}


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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  vector<int> v(N);
  bool plus_flg = true;
  int abs_max_index; 
  ll abs_max = 0;
  for(int i = 0; i < N; i++){
    ll tmp;
    cin >> tmp;
    v[i] = tmp;
    if(abs(tmp) >= abs_max){
      abs_max = abs(tmp);
      abs_max_index = i;
      plus_flg = (tmp >= 0);
    }
  }

  cout << N -1 + N - 1 << endl;
  // abs_maxを全てに足すと、符号が揃う
  for(int i = 0; i < N; i++){
    if(i == abs_max_index) continue;

    v[i] += v[abs_max_index];
    cout << abs_max_index+1 << " " << i + 1 << endl;
  }

  // 
  if(plus_flg){
    // 全部非負になるので、累積和を先頭から取ればOK
    for(int i = 0; i < N -1; i++){
      v[i+1] += v[i];
      cout << i+1 << " " << i+2 << endl;
    }
  } else {
    // 全部負になるので、累積和を後ろから取ればOK
    for(int i = N - 1; i >= 1; i--){
      v[i] += v[i-1];
      cout << i+1 << " " << i << endl;
    }
  }
}



Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
t-=a
t*=1000
t/=6
h=list(map(int,input().split()))
minn,min=0,abs(h[0]-t)
for i in range(1,len(h)):
  if min>abs(h[i]-t):min=abs(h[i]-t);minn=i
print(minn+1)

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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 360 );
const int oo   = INT_MAX;

ll n;
ll q,h,s,d;

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif
  while( cin >> q >> h >> s >> d >> n ) {
    ll ans = 0LL;
    n *= 100;
    if( 8*q > d && 4*h > d && 2*s > d && n >= 200 ) {
      ans += (n/200)*d;
      n %= 200;
    }
    if( 4*q > s && 2*h > s && n >= 100 ) {
      ans += (n/100)*s;
      n %= 100;
    }
    if( 2*q > h && n >= 50 ) {
      ans += (n/50)*h;
      n %= 50;
    }
    if( n >= 25 ) {
      ans += (n/25)*q;
      n %= 25;
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
int n,m,c[200005];
vector <int> v[200005];

int dfs(int x) {
    if(c[x]) return 0;
    c[x] = 1;
    int ret = 1;
    for(int i : v[x]) {
        ret += dfs(i);
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= m;i++) {
        int x,y; cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans = 0;
    for(int i = 1;i <= n;i++) {
        if(c[i]) continue;
        ans = max(ans,dfs(i));
    }
    cout << ans;
}

Measured memory_bytes: 21552
#include <iostream>

using namespace std;
long long I,O,T,J,L,S,Z,ans,i;
int main()
{
    cin>>I>>O>>T>>J>>L>>S>>Z;
    for(i=0;i<=10;i++)
        if(i<=I&&i<=J&&i<=L)
          ans=max(ans,6LL*i+4LL*((I-i)/2)+4LL*((J-i)/2)+4LL*((L-i)/2));
    cout<<ans/2+1LL*O;
    return 0;
}


Measured memory_bytes: 256