akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <cstring>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int r,c;
char a[1001][1001];
ll dp[1001][1001];
ll f(int i,int j){
    if (i>r ||j>c)
        return 0;
    if (i==r&&j==c)
        return 1;
    else if (a[i][j]=='#')
        return 0;
    if (dp[i][j]!=-1)
        return dp[i][j];
    return dp[i][j]=(f(i+1,j)+f(i,j+1)+mod)%mod;;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>r>>c;
    for (int i=1;i<=r;i++)
    {
        for (int j=1;j<=c;j++){
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<f(1,1);

    return 0;
}


Measured memory_bytes: 9216
h,w=map(int,raw_input().split())
n=input()
g=map(int,raw_input().split())
l=[]
for i in range(n):
    l=l+[i+1]*g[i]
for i in range(h):
    l1=l[i*w:(i+1)*w]
    if i%2==1:
        l1.reverse()
    for j in l1:
        print j,
    print 


Measured memory_bytes: 3572
#include <stdio.h>

int main(void){
    int r, D, x;
    scanf("%d%d%d", &r, &D, &x);
    int tmp = x;
    for (int i = 0; i < 10; i++){
        tmp = tmp * r - D;
        printf("%d\n", tmp);
    }
    return 0; 
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  long double a;
  long double b;
  cin >> a >> b;
  long double ans = a*b;
  ans = floor(ans);
  cout << (ll)ans << endl;
  
  /*ll a;
  long double b;
  cin >> a;
  cin >> b;
  
  b *= (double)100;
  ll bb = b;

  ll ans;
  ans = a*bb;
  ll hyaku = 100;
  ll ama = ans%hyaku;
  ll An = ans - ama;
  An /= hyaku;
  cout << An << endl;*/
  
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> area(h, vector<bool>(w,false));

    rep(i,h) {
        string s;
        cin >> s;
        rep(j,w) {
            if(s[j] == '#') {
                area[i][j] = true;
            }
        }
    }

    bool flag = true;

    rep(i,h)
    rep(j,w) {
        if(area[i][j]) {
            int check = 0;
            if(i-1 >= 0 && area[i-1][j]) {
                check++;
            }
            if(i + 1 < h && area[i+1][j]) {
                check++;
            }
            if(j-1 >= 0 && area[i][j-1]) {
                check++;
            }
            if(j + 1 < w && area[i][j+1]) {
                check++;
            }
            if(check == 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <utility>
#include <vector>
#include <iostream>
using namespace std;

int cnt_swap(vector<int> A){
  int c = 0;
  for(size_t i = 0; i < A.size(); ++i){
    for(size_t j = 1; j < A.size(); ++j){
      if(A[j] < A[j-1]){
        swap(A[j],A[j-1]);
        ++c;
      }
    }
  }
  return c;
}

int main(){
  const int INF = 1e9;
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i) cin >> B[i];
  int ans = INF;
  for(int i = 0; i < (1<<N); ++i){
    if(__builtin_popcount(i)%2) continue;
    vector<vector<pair<int,int>>> C(2);
    for(int j = 0; j < N; ++j){
      if(i>>j&1){
        C[(j+1)%2].emplace_back(B[j],j);
      }else{
        C[j%2].emplace_back(A[j],j);
      }
    }
    if(C[1].size() != N/2) continue;
    sort(C[0].begin(), C[0].end());
    sort(C[1].begin(), C[1].end());
    vector<pair<int,int>> V(N);
    for(int i = 0; i < N; ++i){
      V[i] = C[i%2][i/2];
    }
    bool f = false;
    for(int i = 1; i < N; ++i){
      if(V[i-1].first > V[i].first){
        f = true;
        break;
      }
    }
    if(f) continue;
    vector<int> I(N);
    for(int i = 0; i < N; ++i){
      I[V[i].second] = i;
    }
    int cnt = cnt_swap(I);
    ans = min(ans,cnt);
  }
  if(ans >= INF) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a=0,b=0,x,h,w,n,z=0,min=100000000000,k,ans=0;
    string s1,s2,s3;
    cin >> h >> w;
    VS s(h);
    rep(i,h){
        cin >> s[i];
    }
    rep(i,h){
        cout << s[i] <<endl;
        cout << s[i] <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

long long N;
long long M;
long long Q;
std::vector<long long> a(Q);
std::vector<long long> b(Q);
std::vector<long long> c(Q);
std::vector<long long> d(Q);
ll ma=0;
void dfs(vector<ll> v){
    if(v.size()==N){
        ll sum=0;
        for (long long i = 0; i < Q; i++) {
            if(v[b[i]-1]-v[a[i]-1]==c[i]) sum+=d[i];
        }
        chmax(ma,sum);
    }else{
        for (long long i = v[v.size()-1]; i <= M; i++) {
            vector<ll> t=v;
            t.push_back(i);
            // if(N==3) vout(t);
            dfs(t);
        }
    }
}

int main(){
    scanf("%lld",&N);
    scanf("%lld",&M);
    scanf("%lld",&Q);
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }

    vector<ll> v={1};
    dfs(v);
    cout << ma << endl;

    return 0;
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,q;
    cin>>n>>q;
    vector<T> tx(n);
    rep(i,n){
        int s,t,x;
        cin>>s>>t>>x;
        tx[i]=T(x,s-x,t-x);
    }
    sort(all(tx));
    map<int,int> mp;
    set<int> st;
    rep(i,q){
        int x;
        cin>>x;
        mp[x]=i;
        st.insert(x);
    }
    vec ans(q,-1);
    rep(i,n){
        int s,t,x;
        tie(x,s,t)=tx[i];
        auto it=st.lower_bound(s);
        // for(auto x:st) cout<<x<<" ";cout<<endl;
        while(true){
            if(*it>=t||it==st.end()) break;
            ans[mp[*it]]=x;
            st.erase(it++);
        }
        // debug(st.size());
    }
    rep(i,q){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 34688
#include <stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    for(;;){
        c = c-b;
        if(c <= 0) break;
        a = a-d;
        if(a <= 0) break;
    }
    if(c<=0) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 1728
using System.Linq;
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var m = s.Max();

            var target = 0;

            for (int i = 0; i < s.Count; i++)
            {
                if (s[i] == m)
                {
                    target = i;
                    break;
                }
            }

            s.RemoveAt(target);

            WriteLine(m * 10 + s.Sum());
        }
    }
}


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

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

  int ans = 0;

  for ( int i = 1; i <= N; i += 2) {

    int tmp = 0;

    for ( int j = 1; j <= i; j++) {
        if (i % j == 0) {
          tmp++;
        }
    }

    if (tmp == 8) {
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
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)*}
    };
}

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

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

fn main() {
    input!{
        a:chars,
        b:chars
    }
    if a == b{
        println!("H");
    }else{
        println!("D");
    }
}



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

int main() {
  int N, N1, N2, N3, N4;
  cin >> N;
  N1 = N / 1000;
  N2 = (N % 1000) / 100;
  N3 = (N % 100) / 10;
  N4 = N % 10;
  
  if (N1 == N2 && N2 == N3 && N3 == N4) {
  	cout << "Yes" << endl;
  }
  else if (N1 != N2 && N2 == N3 && N3 == N4) {
  	cout << "Yes" << endl;
  }
  else if (N1 == N2 && N2 == N3 && N3 != N4) {
  	cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int x,n,ans,p[105],b[105];
int main(){
	cin >> x >> n;
	for(int i=0;i<n;i++)
		cin >> p[i],b[p[i]]=1;
	for(int i=0;i<102;i++){
		if(b[i]==0 and abs(i-x)<abs(ans-x))
			ans=i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3576
def main():
    n,m,k = map(int,input().split())
    # frend = [[10**6] * n for i in range(n)]
    # block = [[0] * n for i in range(n)]
    # f = [[0]*n for i in range(n)]
    fq = []
    # b = [[0]*n for i in range(n)]
    bq = []
    uf = UnionFind(n)
    dame = [0] * n

    for _ in range(m):
        a,bb = map(int,input().split())
        # f[a-1][bb-1] = 1
        # f[bb-1][a-1] = 1
        uf.union(a-1,bb-1)
        fq.append([a-1,bb-1])

    for _ in range(k):
        c,d = map(int,input().split())
        # b[c-1][d-1] = 1
        # b[d-1][c-1] = 1
        bq.append([c-1,d-1])
        if uf.same(c-1,d-1):
            dame[c-1] += 1
            dame[d-1] += 1


    for i, ff in enumerate(fq):
        if uf.same(ff[0],ff[1]):
            dame[ff[0]] += 1
            dame[ff[1]] += 1



    for i in range(n):
        print(str(uf.size(i)-dame[i]-1 ), end = " ")
    print("")

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


if __name__=='__main__':
    main()


Measured memory_bytes: 41840
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w,a,b,ans=0;
    cin >> w >> a >> b;
    if(max(a,b)>min(a,b)+w){
        ans+=max(a,b)-min(a,b)-w;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
ll f(ll A,ll B){
	if(A>B)std::swap(A,B);
	if(B%A==0)return A*(B/A*2-1);
	else return 2*A*(B/A)+f(A,B%A);
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	ll N=gi(),X=gi();
	printf("%lld\n",N+f(X,N-X));
	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FBracketSequencing {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<string> s(n);
      rep(i, n) {
        cin >> s[i];
      }
      vector<int> a(n), b(n);
      rep(i, n) {
        int now = 0;
        for(auto e: s[i]) {
          if (e == '(') {
            now++;
          } else {
            now--;
          }
          chmin(a[i], now);
        }
        b[i] = now;
      }

      ll sum = 0;
      rep(i, n) {
        sum += b[i];
      }
      if (sum != 0) {
        cout << "No" << endl;
        return;
      }
      priority_queue<P> que1;
      priority_queue<P, vector<P>, greater<>> que2;
      rep(i, n) {
        if (b[i] >= 0) {
          que1.emplace(a[i], b[i]);
        } else {
          // a - b, b
          que2.emplace(a[i]-b[i], b[i]);
        }
      }

      ll now = 0;
      while(!que1.empty()) {
        if (now + que1.top().first < 0) {
          cout << "No" << endl;
          return;
        }
        now += que1.top().second;
        que1.pop();
      }
      while(!que2.empty()) {
        if (now + que2.top().first + que2.top().second < 0) {
          cout << "No" << endl;
          return;
        }
        now += que2.top().second;
        que2.pop();
      }
      cout << "Yes" << endl;


    }
};

signed main() {
  FBracketSequencing solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main() {
        long long h[4];
        int a, b, c, ab, cc;
        int i, n;
        long long j, minl, amari;

        cin >> n;
        for (i = 0; i < n; i++) {
                cin >> h[i];
        }
        minl = h[0];
        for (i = 1; i < n; i++) {
                if (minl > h[i]) minl = h[i];
        }

        for (j = 1; j <= minl; j++) {
                amari = 0;
                for (i = 0; i < n; i++) {
                        amari += h[i] % j;
                }
                if (amari == 0) cout << j << endl;
        }
        return 0;
}



Measured memory_bytes: 3116
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> h(n); REP(i, n) cin >> h[i];
  int ans = 0, water = 0;
  REP(i, n) {
    water = min(water, h[i]);
    ans += h[i] - water;
    water = h[i]; // 花 i + 2 は water 回分の水やりを無償でできる
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int x[100000];
int y[100000];
int w[100000];
int A[100001];
int B[100001];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++){
		scanf("%d%d%d",x+i,y+i,w+i);
	}
	for(int i=0;i<a;i++){
		int L=max(0,x[i]-w[i]);
		int R=min(b,x[i]+w[i]);
		A[L]++;
		A[R]--;
	}
	for(int i=0;i<a;i++){
		int L=max(0,y[i]-w[i]);
		int R=min(c,y[i]+w[i]);
		B[L]++;
		B[R]--;
	}
	bool ok1=true;
	long long d=0LL;
	for(int i=0;i<b;i++){
		d+=A[i];
		if(!d)ok1=false;
	}
	d=0LL;
	bool ok2=true;
	for(int i=0;i<c;i++){
		d+=B[i];
		if(!d)ok2=false;
	}
	if(ok1||ok2)printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 4488
n = int(input())
A = list(map(int,input().split()))
ans = 10**15

for i in [-1,1]:
    ansi,sum=0,0
    for a in A:
        sum+=a
        if sum*i<=0:
          ansi+=abs(sum-i)
          sum=i
        i*=-1
    ans=min(ans,ansi)
print(ans)

Measured memory_bytes: 14332
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Text()
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func main() {
	n := nextInt()
	w := make([]int,n)
	for i:=0;i<n;i++{
		w[i]= nextInt()
	}

	min:=100

	for i:=0;i<n;i++{
		//first
		f:=0
		l:=0
		for _,v := range w[0:i]{
			f+=v
		}
		for _,v := range w[i:n]{
			l+=v
		}
		if min > abs(f-l){
			min = abs(f-l)
		}
	}

	fmt.Printf("%d\n",min)
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  

  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin >> k;
  cout << a[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#define pb push_back
#define ll long long
#define inf 0x3f3f3f3f
#define fill(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(b))
template<typename T> inline bool MIN(T &a,const T &b) {return a>b? a=b,1:0;}
template<typename T> inline bool MAX(T &a,const T &b) {return a<b? a=b,1:0;}
#define mod 1000000007
inline int plu(int a,int b) {return a+b>=mod? a+b-mod:a+b;}
inline int sub(int a,int b) {return a-b<0? a-b+mod:a-b;}
inline int mul(int a,int b) {return (ll)a*b%mod;}
inline int inc(int &a,int b) {a+=b;if (a>=mod) a-=mod;}
inline int dec(int &a,int b) {a-=b;if (a<0) a+=mod;}
#define mp make_pair
#define SZ(a) ((int)a.size())
#define BK(a) (a[SZ(a)-1])
#define fi first
#define se second
#define N 100010
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

int n,A[N];

vi q;

int main()
{

    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        scanf("%d",&A[i]);

    }
    sort(A+1,A+n+1);
    for (int i=1,j=1;i<=n;i=j) {

        for (;j<=n&&A[i]==A[j];++j);

        if (j-i>1) q.pb(A[i]);
        if (j-i>3) q.pb(A[i]);
    }
    sort(q.begin(),q.end());
    if (SZ(q)>1) cout<<(ll)q[SZ(q)-1]*q[SZ(q)-2];
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
	int i,j,x[10],y;
	for(i=0;i<10;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<10;i++){
	for(j=i+1;j<10;j++){
	if(x[i]<x[j]){
		y=x[i];
		x[i]=x[j];
		x[j]=y;
	}
	}
	}
	for(i=0;i<3;i++){
	printf("%d\n",x[i]);
	}
return 0;
}

Measured memory_bytes: 600
public class Main {

    public static void main(String[] args) {
        for(int i = 1 ; i <= 9 ; i++)
        {
            for(int j = 1 ; j<=9 ; j++)
            {
                System.out.printf("%dx%d=%d",i,j,i*j);
                System.out.println();
             
            }
        }
       
    }

}

Measured memory_bytes: 17040
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string first, last;
    cin >> first >> last;
    int c = 0;
    for(int x = 0; x < first.length(); x++)
    {
        if(first[x] == last[x])
            c++;
    }
    if(c == first.length() && c+1 == last.length())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	int a,b,c; cin >> a >> b >> c;
	if (a == b)
		cout << c;
	else if (a == c)
		cout << b;
	else if (b == c)
		cout << a;
	return (0);
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;

void main()
{
	foreach (line; stdin.byLine) {
		auto x = line.split.map!(to!int);
		auto l = iota(1, 11).array;
		foreach (xx; x) {
			l.remove(xx-1);
		}
		auto sum = x[0] + x[1];
		int cnt;
		foreach (i; l) {
			if (sum + i <= 20) cnt++;
		}
		if (cnt / 7.0 >= 0.5) writeln("YES");
		else writeln("NO");
	}
}

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

#define rep(i,beg,end)   for (auto i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
#define rall(cont)           rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k, q;
	cin >> n >> k >> q;
	const int N_MAX = 100000;
	ll t[N_MAX] = { 0 };
	rep(i, 0, q) {
		ll a;
		cin >> a;
		t[a-1]++;
	}
	rep(i, 0, n) {
		if (k + t[i] > q)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    vector<bool> baisu(10000001, true);
    unordered_map<int, int> hist;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        list[i] = tmp;
        hist[tmp]++;
    }

    for (auto x : hist)
    {
        int p = x.first, q = 2;
        while (p * q <= 1000000)
        {
            baisu[p * q] = false;
            q++;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int tmp = list[i];
        if (hist[tmp] == 1 && baisu[tmp])
            ans++;
    }
    cout << ans;
}


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

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

    int sum = 0, i = 1, j = 1;

    while(1){
        if (s - 500 * i < 0) break;
        i++;
        sum += 1000;
    }

    while(1){
    if (s - 500 * (i-1) - 5 * j < 0) break;
        j++;
        sum += 5;
    }

    cout << sum << endl;

}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
  /**
   * Main method.
   */
  public static void main(String[] args) throws IOException {
    Scanner s = new Scanner(System.in);
    
    int A = s.nextInt();
    int B = s.nextInt();
    int C = s.nextInt();
    
    System.out.println(C <= A+B ? "Yes" : "No");
 
  }
}


Measured memory_bytes: 22228
<?php
fscanf(STDIN,"%d %d",$x,$y);

for ($i = 0;$i <= $x;++$i) {
    $tmp = ($i * 4) + (($x - $i) * 2);
    if ($y == $tmp) {
        echo "Yes".PHP_EOL;
        exit;
    }
}
echo "No".PHP_EOL;

Measured memory_bytes: 16160
a=int(input())
b=int(input())
c=int(input())
x=int(input())
count=0
for i in range(0,a+1):
    j=0
    for j in range(0,b+1):
        k=0
        for k in range(0,c+1):
            if 500*i+100*j+50*k==x:
                count+=1
print(count)        


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db; 
#define fi first
#define se second 
#define pb push_back
#define vi vector<int>
#define SZ(x) (int)(x.size())
#define sci(x) scanf("%d",&(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
ll modpow(ll x,ll n,ll mod){ll res=1;for(;n;n>>=1,x=x*x%mod)if(n&1)res=res*x%mod;return res;} 
const db eps=1e-8,PI=acos(-1.0);
const int N=33,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
ll a,b,c;
bool ok(){
	ll lef=4ll*a*b;
	ll rig=c-a-b;
	if(rig<=0)return 0;
	rig*=rig;
	return lef<rig;	
}
int main(){
	scanf("%lld%lld%lld",&a,&b,&c);
	puts(ok()?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int m, f, r;

  do {
    scanf("%d %d %d", &m, &f, &r);
    if (m != -1 || f != -1 || r != -1) {
      if (m == -1 || f == -1) {
        printf("F\n");
      } else if (m + f >= 80) {
        printf("A\n");
      } else if (m + f >= 65) {
        printf("B\n");
      } else if (m + f >= 50) {
        printf("C\n");
      } else if (m + f >= 30) {
        if (r >= 50) {
          printf("C\n");
        } else {
          printf("D\n");
        }
      } else {
        printf("F\n");
      }      
    }
  } while (m != -1 || f != -1 || r != -1);
  
  return 0;
}


Measured memory_bytes: 2056
#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 yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<double,int> Pdi;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
priority_queue<Pdi,vector<Pdi>,greater<Pdi>> que;
vector<Pli> v[18];
P2 xy[MAX_N]={};
ll dp[1<<18]={};
string str[100000];
int ygd(int a,int b){
	  while(1) {
	    if(a < b) swap(a, b);
	    if(!b) break;
	    a %= b;
	  }
	  return a;
}
int main() {
	int N,X;
	int a[100001];
	cin>>N>>X;
	for(int i=0;i<N;++i){
		cin>>a[i];
		a[i]=abs(X-a[i]);
	}
	int ans=a[0];
	for(int i=1;i<N;++i){
		ans=ygd(ans,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1408
A,B,C=map(int,input().split())

k=0
if A%2==B%2==C%2==0 and A==B==C:
    k=-1
else:
    while A%2==B%2==C%2==0:
        a=A
        b=B
        c=C
        A=(b+c)/2
        B=(a+c)/2
        C=(a+b)/2
        k+=1

print(k)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define MX 100005
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    double a[MX];
    priority_queue<double> que;
    rep(i,n){
        cin>>a[i];
        que.push(a[i]);
    }
    rep(i,m){
        int max=que.top();
        que.pop();
        max/=2;
        que.push(max);
    }
    ll ans=0;
    rep(i,n){
        ans+=(int)que.top();
        que.pop();
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define FOR(i, k, n)    for(signed i=k; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define min(x,y)    (x<y)?x:y
#define max(x,y)    (x>y)?x:y
#define ll  long long
int main(void){
    int N, K;
    cin >> N >> K;
    int h[N], i;
    rep(i, N) cin >> h[i];
    int count = 0;
    rep(i, N) if(h[i] >= K) count++;
    cout << count << endl;
}

Measured memory_bytes: 640
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

def main():
    import collections
    import heapq

    class Dijkstra:
        def __init__(self):
            self.e = collections.defaultdict(list)

        def add(self, u, v, d):  # 無向グラフの場合
            self.e[u].append([v, d])
            self.e[v].append([u, d])

        def delete(self, u, v):
            self.e[u] = [_ for _ in self.e[u] if _[0] != v]
            self.e[v] = [_ for _ in self.e[v] if _[0] != u]

        def search(self, s):  # d[i]はsからiまでの最短距離
            d = collections.defaultdict(lambda: float('inf'))
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True

                for uv, ud in self.e[u]:
                    if v[uv]:
                        continue
                    vd = k + ud
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            return d

    n, m, s, t = MI()

    G1 = Dijkstra()  #円だけ
    G2 = Dijkstra()  #スヌースだけ

    for i in range(m):
        u,v,a,b = MI()
        G1.add(u,v,a)
        G2.add(u,v,b)

    D1 = G1.search(s)
    D2 = G2.search(t)

    A = []

    for i in range(1, n + 1):
        A.append((D1[i] + D2[i], i))

    A.sort()

    b = 0
    for i in range(n):
        if i == 0:
            print(10 ** 15 - A[i][0])
        elif i < A[b][1]:
            print(10 ** 15 - A[b][0])
        else:
            while i >= A[b][1]:
                b += 1
            print(10 ** 15 - A[b][0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 204672
def num_to_match(n):
    if n == 1:
        return 2
    elif n == 7:
        return 3
    elif n == 4:
        return 4
    elif n in [2, 3, 5]:
        return 5
    elif n in [6, 9]:
        return 6
    else:
        return 7


def max_length(N, match):
    match = set(match)
    INF = 10**15
    dp = [- INF for _ in range(N + 1)]
    dp[0] = 0
    for n in range(1, N + 1):
        max_l = dp[n]
        for m in match:
            if n - m >= 0 and dp[n - m] >= 0:
                max_l = max([max_l, 1 + dp[n - m]])
        dp[n] = max_l
    return dp


def main():
    N, _ = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    A.sort(reverse=True)
    match = list(map(num_to_match, A))
    max_l = max_length(N, match)
    digits = [0 for _ in range(max_l[N])]
    n_match = N
    for i in range(max_l[N]):
        for a in A:
            ma = num_to_match(a)
            if n_match - ma < 0:
                continue
            if max_l[n_match - ma] == max_l[n_match] - 1:
                digits[i] = a
                n_match -= ma
                break
    print(''.join(map(str, digits)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main(){

  int N,x,y,b,p,sum1,sum2;

  cin >>N;

  for(int i=0 ; i < N ; i++){

    cin >>x>>y>>b>>p;

    sum1=x*b+y*p;
    
    if( b >= 5 && p >= 2 ){
      cout <<(x*b+y*p)*0.8<<endl;
    }else if( b >=5 && p < 2){
      sum2=(x*b+y*2)*0.8;
      if( sum1 >= sum2 ){
	cout <<sum2<<endl;
      }else{
	cout <<sum1<<endl;
      }
    }else if( b < 5 && p >=2){
      sum2=(x*5+y*p)*0.8;
      if( sum1 >= sum2 ){
	cout <<sum2<<endl;
      }else{
	cout <<sum1<<endl;
      }
    }else{
      sum2=(x*5+y*2)*0.8;
      if( sum1 >= sum2 ){
	cout <<sum2<<endl;
      }else{
	cout <<sum1<<endl;
      }
    }
    
  } 
  return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>
int main(int argc,const char *argv[]){
int time;
int h,m,s;
    scanf("%d",&time);
    m = time / 60;
    h = m/60;
    m = m - (h*60);
    s = time - (h*60+m) * 60;
    printf("%d:%d:%d\n",h,m,s);

return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <math.h>
#include <string>

using namespace std;

void solve(){

}

int main(){
    int N,K;
    scanf("%d %d", &N, &K);
    double retProb = 0.0;
    for (int i=1; i<N+1; i++){
        if(i >= K){
            retProb += 1.0/N;
        }else{
            retProb += 1.0/N * pow(1.0/2, ceil(log2(double(K)/i)));
        }
    }
    printf("%.16f\r\n", retProb);
    return 0;
}

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


/*
    Bellman-Ford's Algorithm
    Time Complexity : (VE)
    
    verify : AOJ GRL_1_B (2020-01-13)
    URL : https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_B
*/


template<typename T>
pair<bool, vector<T>> bellmanford(const vector<vector<pair<int, T>>> &G, int s) {
    const T inf = numeric_limits<T>::max();
    int V = G.size();
    vector<T> dist(V, inf); dist[s] = 0;
    bool negative_cycle = false;
    
    for (int relax = 0; relax <= V; relax++) {
        for (int from = 0; from < V; from++) {
            for (const auto &e : G[from]) {
                int to; T cost; tie(to, cost) = e;
                if (dist[from] == inf) continue;
                if (dist[from] + cost < dist[to]) {
                    dist[to] = dist[from] + cost;
                    if (relax == V) negative_cycle = true;
                }
            }
        }
    }
    return {negative_cycle, dist};
}



int main() {
    int V, E, s;
    cin >> V >> E >> s;
    vector<vector<pair<int, long long>>> G(V);
    for (int i = 0; i < E; i++) {
        int from, to; long long cost;
        cin >> from >> to >> cost;
        G[from].emplace_back(to, cost);
    }
    
    bool negative_cycle;
    vector<long long> dist;
    tie(negative_cycle, dist) = bellmanford(G, s);
    if (negative_cycle) { cout << "NEGATIVE CYCLE" << endl; }
    else {
        for (auto ans : dist) {
            if (ans == INT64_MAX) cout << "INF" << endl;
            else cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3212
n,m = map(int, input().split())
x = [tuple(map(int, input().split())) for _ in range(n)]
from itertools import *
print(max(sum(sorted((sum(i*j for i,j in zip(a,t)) for t in x),reverse=True)[:m]) for a in product([-1,1],[-1,1],[-1,1])))


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

int main(){
	int S,h,m,s;
	cin>>S;
	h = S/3600;
	m = (S/60)%60;
	s = S % 60;
	cout<<h<<":"<<m<<":"<<s<<endl;

	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second

using namespace std;

int main(){
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n,h,w;
	cin >> n >> h >> w;
	cout << (n-h+1)*(n-w+1) << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())

A=[0]*(N+1)
for k in range(1,N+1):
    A[k]=int(input())

T=[False]*(N+1)
x=1
I=0
while not T[x] and x!=2:
    T[x]=True
    I+=1
    x=A[x]
    
if x==2:
    print(I)
else:
    print(-1)


Measured memory_bytes: 75936
#include <iostream>
#include <string>
#include <array>

using namespace std;

int main() {
    int n, i, x, y;
    cin >> n;

    array<string, 500> s;
    for(i = 0; i < n; i++) cin >> s[i];

    int ans = 0, xx, yy;
    bool b;
    for(i = 0; i < n; i++) {
        b = true;

        for(x = 0; x < n; x++) {
            for(y = 0; y < n; y++) {
                xx = y - i < 0 ? n + y - i : y - i;
                yy = x + i >= n ? x + i - n : x + i;
                if(s[x][y] != s[xx][yy]) {
                    b = false;
                    break;
                }
            }

            if(!b) break;
        }

        if(b) ans += 1;
    }

    cout << ans * n << endl;
}

Measured memory_bytes: 1016
N,M=map(int,input().strip().split())
a=[int(input()) for _ in range(M)]

danger=[0 for n in range(N+1)]
for m in range(M):
    danger[a[m]]=1

dp=[0 for n in range(N+1)]
dp[0]=1
if danger[1]!=1:
    dp[1]=1
for n in range(2,N+1):
    if danger[n]==1:
        dp[n]=0
    else:
        dp[n]=dp[n-1]+dp[n-2]

print(dp[N]%1000000007)

Measured memory_bytes: 466756
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T int
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
auto clk=clock();
 
ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

const int N = 100005;

ll dp1[N]; // a + b < L
ll dp2[N]; // a + b = L

int main(){
    IOS
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());


    string s;
    cin >> s;
    int n = s.length();
    dp1[0] = 0, dp2[0] = 1;
    FOR(i,0,n-1){
        if(s[i] == '0'){
            dp1[i+1] = (3 * dp1[i]) % MOD;
            dp2[i+1] = dp2[i];
        }
        else{
            dp1[i+1] = (3 * dp1[i] + dp2[i]) % MOD;
            dp2[i+1] = (2 * dp2[i]) % MOD;
        }
    }
    cout << (dp1[n] + dp2[n]) % MOD;

    cerr<<endl<<endl<<"Time: "<<fixed<<setprecision(12)<<(long double)(clock()-clk)/CLOCKS_PER_SEC<<" ms"<<endl<<endl;
 
    return 0;
}

Measured memory_bytes: 2000
from sys import stdin

L = stdin.readline().rstrip()
inf = 10 ** 9 + 7
ones = 3
if L[-1] == '0':
    ans = 1
else:
    ans = 3

if len(L) == 1:
    print(ans)
    exit()

for i in range(2, len(L) + 1):
    if L[-i] == '1':
        ans = (ones + 2 * ans) % inf
    ones = (3 * ones) % inf

print(ans)


Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int x, a, b;
  cin >> x >> a >> b;
  
  if(a >= b)
  	cout << "delicious" << endl;
  else if(a + x < b)
    cout << "dangerous" << endl;
  else
  	cout << "safe" << endl;
  
  return 0;
}



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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    int H[N];
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    H[0] --;
    for (int i = 0; i < N - 1; i++) {
        if (H[i + 1] > H[i]) H[i + 1] --;
        else if (H[i] == H[i + 1]) continue;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;


template <class edge_t> class graph_t {
	std::vector<std::vector<edge_t>> g;

public:
	using reference = std::vector<edge_t> &;
	using const_reference = const std::vector<edge_t> &;
	using iterator = typename std::vector<edge_t>::iterator;
	graph_t() : g(0) { ; }
	graph_t(int n) : g(n) { ; }
	int size() const { return g.size(); }
	void push_back(const std::vector<edge_t> &es) { g.push_back(es); }
	reference operator[](int x) { return g[x]; }
	const_reference operator[](int x) const { return g[x]; }
	iterator &begin() { return begin(g); }
	iterator &end() { return end(g); }
};

int n, m;
int a[50], b[50];

bool graph[50][50];
bool visited[50];

void bfs(int v) {
	visited[v] = true;
	for (int v2 = 0; v2 < n; v2++) {
		if (!graph[v][v2]) continue;
		if (visited[v2])continue;
		bfs(v2);
	}
}

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

	rep(0, n) {
		for (int j = 0; j < m; j++) {
			graph[i][j] = false;
		}
	}

	rep(0, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}

	rep(0, n) {
		visited[i] = false;
	}

	int count = 0;

	rep(0, m) {
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
		visited[a[i]] = true;
		bfs(a[i]);
		for (int j = 0; j < n; j++) {
			if (!visited[j]) {
				count++;
				break;
			}
		}

		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;

		rep(0, n) {
			visited[i] = false;
		}
	}

	cout << count << endl;
}

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

using std::cin;
using std::string;

bool threshold_over(std::string value)
{
  string threshold = "2019/04/30";
  int thresh_year = 2019;
  int thresh_month = 4;
  int thresh_day = 30;

  int year = std::stoi(value.substr(0,4));
  int month = std::stoi(value.substr(5,2));
  int day = std::stoi(value.substr(8,2));

  if(year > 2019)
  {
    return true;
  }else if (year < 2019)
  {
    return false;
  }
  else
  {
    if(month > 4)
    {
      return true;
    }
    else
    {
      return false;
    }
  }
}


int main()
{
  std::string s;
  cin >> s;
  if(threshold_over(s))
  {
    std::cout << "TBD" << "\n";
  }
  else
  {
    std::cout << "Heisei" << "\n";
  }

  return 0;
}


Measured memory_bytes: 256