akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long N, A[200001], B[200001], i, count, ans;

    cin >> N;

    B[0] = 0;

    for(i=1; i<=N; i++){
        cin >> A[i];
        B[i] = B[i-1] + A[i];
    }

    sort(B, B+N+1);

    count = 1;

    for(i=1; i<=N; i++){
        if(B[i]==B[i-1]){
            count++;
        }
        else{
            ans += count*(count-1)/2;
            count = 1;
        }
    }

    ans += count*(count-1)/2;

    cout << ans << endl;

    return 0;
}

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

using Float = double;
using Point = complex<Float>;
struct Line{ Point a,b; };
struct Circle{ Point center; Float r; };

const Float EPS = 1e-8;

inline bool eq(Float a,Float b) { return abs(a - b) < EPS; }
inline Float dot(const Point &p1,const Point &p2){ return real(conj(p1) * p2); }
inline Float cross(const Point &p1,const Point &p2){ return imag(conj(p1) * p2); }

Point projection(const Line &l,const Point &p){
	Float t = dot(l.b - l.a,p - l.a) / norm(l.b - l.a);
	return l.a + (l.b - l.a) * t;
}

signed main(){
	Float x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	Line l = {Point(x1,y1),Point(x2,y2)};
	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		Float x,y;
		cin >> x >> y;
		Point p = projection(l,Point(x,y));
		printf("%.15lf %.15lf\n",real(p),imag(p));
	}
}


Measured memory_bytes: 3312
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

typedef pair<int, int> P;

P p[200000];

const long MOD = 1000000007;

int main(){
    int N;
    queue<long> quea, queb;
    cin >> N;
    for(int i = 0; i < N ; i++){
        int a;
        cin >> a;
        p[i] = P(a, -1);
    }
    for(int i = 0; i < N ; i++){
        int b;
        cin >> b;
        p[i+N] = P(b, 1);
    }
    sort(p, p+2*N);
    long ans = 1;
    long sum = 1;
    int cur = p[0].second;
    for(int i = 1; i < 2*N; i++){
        if(cur == p[i].second){
            sum++;
        }else{
            if(sum == 0){
                sum++;
                cur = p[i].second;
            }else{
                ans *= sum;
                ans %= MOD;
                sum--;
            }
        }
    }
    
    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 q = sc.nextInt();
		ArrayList<Integer>[] graph = new ArrayList[n + 1];
		for (int i = 1; i <= n; i++) {
		    graph[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    graph[a].add(b);
		    graph[b].add(a);
		}
		long[] points = new long[n + 1];
		for (int i = 0; i < q; i++) {
		    points[sc.nextInt()] += sc.nextInt();
		}
		search(1, 0, points, graph);
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
		    if (i != 1) {
		        sb.append(" ");
		    }
		    sb.append(points[i]);
		}
		System.out.println(sb);
   }
   
   static void search(int to, int from, long[] points, ArrayList<Integer>[] graph) {
       points[to] += points[from];
       for (int x : graph[to]) {
           if (x == from) {
               continue;
           }
           search(x, to, points, graph);
       }
   }
}


Measured memory_bytes: 225460
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int N;

int main() {
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
     
    int res = 0;
    for (int i = 0; i < N; i++) {
        while (A[i] % 2 == 0) {
            A[i] /= 2;
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
function dfs(G,D,u,p,x)
	D[u]=x
	for v=G[u]
		if v!=p
			dfs(G,D,v,u,x+1)
		end
	end
end
function main()
	N=parse(Int,readline())
	G=[Int[] for _=1:N]
	for s=readlines()
		x,y=map(x->parse(Int,x),split(s))
		push!(G[x],y)
		push!(G[y],x)
	end
	D1=zeros(Int,N)
	dfs(G,D1,1,-1,0)
	DN=zeros(Int,N)
	dfs(G,DN,N,-1,0)
	cnt=0
	for i=1:N
		if D1[i]<=DN[i]
			cnt+=1
		else
			cnt-=1
		end
	end
	println(cnt>0 ? "Fennec" : "Snuke")
end
main()


Measured memory_bytes: 167320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, c;
  cin >> n >> c;
  vl x(n + 1, 0), v(n), y(n + 1, 0), a(n + 1, 0), b(n + 1, 0);
  rep(i, n) cin >> x[i + 1] >> v[i];
  rep(i, n) {
    a[i + 1] = a[i] + v[i];
    b[i + 1] = b[i] + v[n - 1 - i];
    y[i + 1] = c - x[n - i];
  }
  ll ans = 0, v1 = 0, v2 = 0;
  for(int i = n; i >= 0; i--) {
    ll now1 = a[i] - x[i] * 2;
    ll now2 = a[i] - x[i];
    int j = n - i;
    v1 = max(v1, b[j] - y[j]);
    v2 = max(v2, b[j] - y[j] * 2);
    now1 += v1;
    now2 += v2;
    ans = max(ans, max(now1, now2));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String first;
		char table[] = new char[20000];

		int M,h,left,right;


		try {

			while(!(first = br.readLine()).equals("-")){

				for(int i = 0; i < first.length(); i++){
					table[i] = first.charAt(i);
				}

				left = 0;
				right = first.length()-1;

				M = Integer.parseInt(br.readLine());

				for(int loop = 0; loop < M; loop++){
					h = Integer.parseInt(br.readLine());

					for(int i = 0; i < h; i++){
						table[right+1+i] = table[left+i];
					}
					left += h;
					right += h;
				}

				for(int i = left; i <= right; i++){
					System.out.printf("%c", table[i]);
				}
				System.out.printf("\n");
			}


		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 24772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int n, m, k;
string s[1100];

int table[1100][1100][10];

int a[4];

int main(){
	cin >> m >> n >> k;
	REP(i, m){
		cin >> s[i];
		REP(j, n){
			if (s[i][j] == 'J')table[i][j][0] = 1;
			if (s[i][j] == 'O')table[i][j][1] = 1;
			if (s[i][j] == 'I')table[i][j][2] = 1;
		}
	}
	REP(i, m){
		FOR(j, 1, n){
			table[i][j][0] += table[i][j - 1][0];
			table[i][j][1] += table[i][j - 1][1];
			table[i][j][2] += table[i][j - 1][2];
		}
	}
	FOR(i, 1, m){
		REP(j, n){
			table[i][j][0] += table[i - 1][j][0];
			table[i][j][1] += table[i - 1][j][1];
			table[i][j][2] += table[i - 1][j][2];
		}
	}
	REP(i, k){
		REP(i, 4){
			cin >> a[i];
			a[i]--;
		}
		REP(i, 3){
			int num = table[a[2]][a[3]][i];
			if (a[1] > 0)num -= table[a[2]][a[1] - 1][i];
			if (a[0] > 0)num -= table[a[0] - 1][a[3]][i];
			if (a[1] > 0 && a[0] > 0)num += table[a[0] - 1][a[1] - 1][i];
			if (i == 0)cout << num;
			else cout << " " << num;
		}
		cout << endl;
	}
}

Measured memory_bytes: 45244
inp1=input().rstrip()
inp2=input().rstrip()

rvs1="".join([inp1[x:x+1] for x in range(2,-1,-1)])
rvs2="".join([inp2[x:x+1] for x in range(2,-1,-1)])

if rvs1==inp2 and rvs2==inp1:
    print("YES",flush=True)
else:
    print("NO",flush=True)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{   int a,b,d,i,j,sum=0,ck=1;

    scanf("%d%d",&a,&b);

    int c[55];

    if(a>=1 && a<=50 && b>=1 && b<=a)
    {


        for(i=0;i<a;i++)
        {
            scanf("%d",&c[i]);
                if(c[i]<1 || c[i]>50)
                    ck=0;
        }
    if(ck)
    {


        for(i=0;i<a;i++)
            for(j=i+1;j<a;j++)
                {
                    if(c[j]>c[i])
                        {
                            d=c[i];
                            c[i]=c[j];
                            c[j]=d;

                        }

                }
        for(i=0;i<b;i++)
        {
            sum=sum+c[i];

        }
            printf("%d\n",sum);
    }

    }
    return 0;
}

Measured memory_bytes: 128
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;





vector<vector<vector<ll>>> rosen(110000);

int main(){
    #define int ll
    ll k=1000000000000000;
    ll n,m,s,t;
    cin>>n>>m>>s>>t;
    for(ll i=0;i<m;i++){
        ll u,v,a,b;
        cin>>u>>v>>a>>b;
        rosen[u].push_back({v,a,b});
        rosen[v].push_back({u,a,b});
    }
    ll a[110000];
    ll b[110000];
    for(int i=0;i<110000;i++){
        a[i]=-E;
        b[i]=-E;
    }
    a[s]=0;
    b[t]=0;
    bool done[110000]={};
    priority_queue<vector<ll>> q;
    q.push({0,s});
    while(!q.empty()){
        vector<ll> s=q.top();
        q.pop();
        if(done[s[1]]){continue;}
        for(int i=0;i<rosen[s[1]].size();i++){
            vector<ll> r=rosen[s[1]][i];
            if(a[r[0]]<s[0]-r[1]){a[r[0]]=s[0]-r[1]; q.push({a[r[0]],r[0]});}
        }
        done[s[1]]=true;
    }
    
    
    for(int i=0;i<110000;i++){
        done[i]=false;
    }
    q.push({0,t});
    while(!q.empty()){
        vector<ll> s=q.top();
        q.pop();
        if(done[s[1]]){continue;}
        for(int i=0;i<rosen[s[1]].size();i++){
            vector<ll> r=rosen[s[1]][i];
            if(b[r[0]]<s[0]-r[2]){b[r[0]]=s[0]-r[2]; q.push({b[r[0]],r[0]});}
        }
        done[s[1]]=true;
    }
    ll mx=-E;
    vector<ll> ans;
    for(int t=n;t>0;t--){
        mx=max(mx,a[t]+b[t]);
        ans.push_back(k+mx);
    }
    for(int i=n-1;i>=0;i--){
        cout<<ans[i]<<endl;
    }
    
    /*
    for(int i=0;i<n;i++){
        ll mx=-E;
        for(int t=i+1;t<=n;t++){
            mx=max(mx,a[t]+b[t]);
        }
        cout<<k+mx<<endl;
    }
     */
    
    
    
    return 0;
}


Measured memory_bytes: 21684
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        StringBuilder[] res = new StringBuilder[100005];
        for (int i = 1; i <= 9; i++) {
            res[i] = new StringBuilder().append(i);
        }
        int size = 9;
        for(int start = 1; ; ++start) {
            StringBuilder s = res[start];
            char c = s.charAt(s.length() - 1);
            if (c == '0') {
                res[++size] = new StringBuilder(s).append('0');
                res[++size] = new StringBuilder(s).append('1');
            } else if (c < '9') {
                res[++size] = new StringBuilder(s).append((char)(c - 1));
                res[++size] = new StringBuilder(s).append(c);
                res[++size] = new StringBuilder(s).append((char)(c + 1));
            } else {
                res[++size] = new StringBuilder(s).append('8');
                res[++size] = new StringBuilder(s).append('9');
            }
            if (size >= k) break;
        }
        System.out.println(res[k].toString());
    }
}


Measured memory_bytes: 29780
#include <stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b){
		printf("a < b\n");
	}
	else if (a > b){
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	ll a,b,c;
	scanf("%lld %lld %lld",&a,&b,&c);
	ll ans = 0;
	if(a >= c){
		ans = c;
		a -= c;
		c = 0;
		ans += b;

	}else{
		ans = a;
		c -= a;
		a = 0;
		if(b >= c){
			ans += (b + c);	
		}else{
			ans += 2LL*b;
			ans++;
		}
		

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<vector>
 
#define mx(ans, cnt) ans = max(ans, cnt)
#define fauto(a) for(auto i : a) cout << i << " "; cout << endl;
#define sp(n) fixed << setprecision(n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define _ << " " <<
#define swp(x, y) if (x > y) swap(x, y);
#define swpg(x, y) if (x < y) swap(x, y);
#define ff first
#define ss second
#define xx first
#define yy second
#define pb push_back
#define nn end1
 
 
using ll = long long;
using ull = unsigned long long;
using namespace std;
int main ()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll i,j,c=0,n;
        string s;
        cin>>s;
        n=s.size();
        for(i=0;i<n-1;i++)
        {
            if(s[i]==s[i+1])
            {
                if(s[i]=='1')
                {s[i+1]='0';}
                else
                {
                    s[i+1]='1';
                }
                c++;
            }

        }
       cout<<c<<endl;   
    }
    return 0;
}

Measured memory_bytes: 3760
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) 
{
	ll ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

void solve() 
{
	int a,b; cin >> a >> b;
	For(i,1,1e6)
	{
		int x = i * 0.08;
		int y = i * 0.1;
		if (x == a and y == b)
		{
			cout << i << endl;
			return;
		}
	}	
	cout << -1 << endl;
}

int main() 
{
	fast_io();
	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Data.Vector.Unboxed((!),fromList)
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
binarySearch :: (Int -> Bool) -> Int -> Int -> Int
binarySearch !pred !ok !ng
  | abs (ok-ng) <= 1 = ok
  | pred mid = binarySearch pred mid ng
  | otherwise = binarySearch pred ok mid
    where mid = (ok+ng) `div` 2

main = do
    n <- readLn :: IO Int
    l <- fromList . sort <$> getIntList
    let list = [max 0 (right-left+1) |
           i <- [0 .. n - 3],
           let a = l ! i,
           j <- [i + 1 .. n - 2],
           let b = l ! j,
           -- condition :: l!k < a+b,abs (a-b) < l!k , j < k
           let !left = binarySearch (\k -> abs (a-b) < l ! k) (n-1) j,
           let !right = binarySearch (\k -> l ! k < a+b) 0 n
           ]
    print $ sum list


Measured memory_bytes: 5408
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define MOD 1000000007
using namespace std;
typedef long long ll;
int pos[MAXN];
int n,m;
struct node{
	ll x[3][3];	
	void operator *=(const node &a) {
		ll c[3][3]={0};
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					(c[i][j]+=x[i][k]*a.x[k][j])%=MOD;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				x[i][j]=c[i][j];
	}
}e,a,e1,e2;
void fsp(node &x,node y,int t){
	node y1=y;
	while(t){
		if(t&1)
			x*=y1;
		y1*=y1;
		t>>=1;	
	}
}
ll A[3],B[3];
int main(){
	SF("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		SF("%d",&pos[i]);
	e.x[0][0]=e.x[1][1]=e.x[2][2]=e.x[1][2]=e.x[0][2]=1;
	e.x[0][1]=2;
	e2.x[0][0]=e2.x[1][1]=e2.x[2][2]=e2.x[2][0]=1;
	e1=e;
	e1*=e2;
	m++;
	pos[m]=n;
	B[0]=1;
	for(int l=1;l<=m;l++){
		int s=pos[l]-pos[l-1]-1;
		memset(a.x,0,sizeof a.x);
		for(int i=0;i<3;i++)
			a.x[i][i]=1;
		fsp(a,e1,s);
		a*=e;
		for(int i=0;i<3;i++){
			A[i]=0;
			for(int j=0;j<3;j++)
				A[i]=(A[i]+B[j]*a.x[j][i])%MOD;
		}
		for(int i=0;i<3;i++)
			B[i]=A[i];
	}
	PF("%lld",B[2]);
}

Measured memory_bytes: 512
# https://atcoder.jp/contests/abc123/tasks/abc123_b
# https://upura.hatenablog.com/entry/2019/04/07/011914

# 1の位が1番小さいものを最後に頼む（0を除く）

A_E = [input() for _ in range(5)]

# 1の位だけ抜き出して整数に
unit_place_lst = [int(x[-1]) for x in A_E]
min_except0 = 10
min_index = 0
for i, n in enumerate(unit_place_lst):
    if 0 < n < min_except0:
        min_except0 = n
        min_index = i

ans = 0
for i, x in enumerate(A_E):
    if i == min_index:
        ans += int(x)
    # elif (int(x) % 10) == 0:
    #    ans += int(x)
    # else:
    #    ans += int(x) - (int(x) % 10) + 10
    else:
        ans += (int(x) + 9)//10 * 10

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, std::numeric_limits<T>::max());
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    while(!pq.empty()) {
        int d = pq.top().first, now = pq.top().second;
        pq.pop();
        if(d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to, cost = g[now][i].cost;
            if(dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int n;
vector<int> a;
vector<int> dist;
int solve(int i, vector<bool> &nowsel) {
  if(nowsel[i]) {
    dist[i] = n;
  } else if(a[i] == 0) {
    dist[i] = i;
  } else if(dist[i] == -1){
    nowsel[i] = true;
    dist[i] = solve(i + a[i], nowsel);
    nowsel[i] = false;
  }
  return dist[i];
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  a.clear();
  a.resize(n);
  dist.clear();
  dist.resize(n, -1);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  dist[0] = 0;
  dist[n-1] = n-1;
  vector<bool> nowsel(n);
  for(int i=0;i<n;++i) {
    dist[i] = solve(i, nowsel);
  }
  Graph<int> g(n+1);
  for(int i=0;i<=n-2;++i) {
    for(int j=1;j<=6;++j) {
      if(i + j > n-1) continue;
      g[i].push_back(Edge<int>(i, dist[i+j], 1));
    }
  }
  vector<int> d = dijkstra(g, 0);
  cout << d[n-1] << endl;
}



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

using V = std::vector<uint64_t>;

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

  int N;
  std::cin >> N;

  V a(N, 0), b(N, 0), c(N, 0);
  for (int i = 0; i < N; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    std::cin >> b[i];
  }
  for (int i = 0; i < N; i++) {
    std::cin >> c[i];
  }
  std::sort(a.begin(), a.end());
  std::sort(b.begin(), b.end());
  std::sort(c.begin(), c.end());

  V bs(N);
  for (int i = 0; i < N; i++) {
    bs[i] = c.end() - std::upper_bound(c.begin(), c.end(), b[i]);
  }

  V sum(N);
  sum[N - 1] = bs[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    sum[i] = sum[i + 1] + bs[i];
  }

  uint64_t ans = 0;
  for (int i = 0; i < N; i++) {
    ans += sum[std::upper_bound(b.begin(), b.end(), a[i]) - b.begin()];
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define PI  3.14159265358979323846
using namespace std;

int main()
{
	int a,b,h,m;
	double p1,p2;
	cin>>a>>b>>h>>m;
	p1=h*60+m;
	p1=p1*1.0/(12*60);
	p1=p1*360;
	p2=m*1.0/60*360;
	double p=abs(p1-p2);
	if(p>=180) p=360-p;
	//cout<<p<<endl;
	double c;
	p=p/180*PI;
	//cout<<cos(p)<<endl;
	c=a*a*1.0+b*b*1.0-2.0*a*b*cos(p);
	c=sqrt(c);
	printf("%.20lf",c);
	return 0; 
}

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

int main() {
  int s;
  cin >> s;
  
  int N = 1000000;
  vector<int> vec(N);
  
  vec.at(0) = s;
  
  int i = 0;
  int answer;
  bool finished = false;
  
  while (i < N){
    if (vec.at(i) % 2 == 0){
      vec.at(i+1) = vec.at(i) / 2;
    }
    else{
      vec.at(i+1) = vec.at(i) * 3 + 1;
    }
    
    for (int j = 0; j < i+1; j++){
      if (vec.at(j) == vec.at(i+1)){
        answer = (i+1) + 1;
        finished = true;
        break;
      }
    }
    if (finished){
      break;
    }
    i++;
  }
  cout << answer << endl;
   
}

Measured memory_bytes: 4096
N, M = map(int, input().split())
flag = [False for i in range(N)]
WA = [0 for i in range(N)]
ans = 0
WA_count = 0
for _ in range(M):
    p, s = input().split()
    p = int(p)-1
    if flag[p]:
        pass
    else:
        if s == 'WA':
            WA[p] += 1
        else:
            flag[p] = True
            WA_count += WA[p]
            ans += 1
print(ans, WA_count)


Measured memory_bytes: 4656
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int s;
    cin >> s;
    
    int h = s / 3600;
    int m = (s % 3600) / 60;
    int s2 =s - h * 3600 - m *60;
    cout << h << ":" << m << ":" << s2 << endl;
}



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

#define A 0
#define B 1

int main(){
    int info[2], math[2], science[2], english[2];

    cin >> info[A] >> math[A] >> science[A] >> english[A];
    cin >> info[B] >> math[B] >> science[B] >> english[B];

    cout << max(info[A]+math[A]+science[A]+english[A], info[B]+math[B]+science[B]+english[B]) << endl;
}

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

#define rep(var, start, end)  for(int var = start; var <= end; ++var)
#define drep(var, start, end) for(int var = start; var >= end; --var)

typedef long long ll;

using namespace std;

int main() {

    ll N, M;
    vector<ll> H(100001);
    vector<ll> ans(100001, 1);
    vector<ll> A(100001), B(100001);

    cin >> N >> M;

    rep(i, 1, N) {
        cin >> H[i];
    }

    rep (m, 1, M) {
        cin >> A[m] >> B[m];
        if (H[A[m]] > H[B[m]]) {
            ans[B[m]] = 0;
        } else if(H[A[m]] < H[B[m]]) {
            ans[A[m]] = 0;
        } else {
            ans[A[m]] = ans[B[m]] = 0; 
        }
    }

    ll cnt = 0;
    rep(i, 1, N) {
        if (ans[i]) {
            ++cnt;
        }
    }

    cout << cnt << endl;
    
    return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;

int r , c;

inline int get(pii p){
	if(p.fi == 0)return 0;
	if(p.se == c - 1)return 1;
	if(p.fi == r - 1)return 2;
	return 3;
}

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

	int n;
	cin >> r >> c >> n;
	++r;
	++c;
	
	vector<pair<pii , int>> g[4];
	
	repi(i , n){
		int x1 , y1 , x2 , y2;
		cin >> x1 >> y1 >> x2 >> y2;
		bool ck1 = x1 == 0 || y1 == 0 || x1 == (r - 1) || y1 == (c - 1);
		bool ck2 = x2 == 0 || y2 == 0 || x2 == (r - 1) || y2 == (c - 1);
		if(ck1 && ck2){
			g[get({x1 , y1})].pb({{x1 , y1} , i});
			g[get({x2 , y2})].pb({{x2 , y2} , i});
		}
	}
	
	sort(all(g[0]) , less<pair<pii , int>>());
	sort(all(g[1]) , less<pair<pii , int>>());
	sort(all(g[2]) , greater<pair<pii , int>>());
	sort(all(g[3]) , greater<pair<pii , int>>());
	
	auto gg = g[0];
	
	repi(i , 3){
		for(auto e : g[i]){
			gg.pb(e);
		}
	}
	
	vi used(n + 1);
	stack<int> s;

	rep(i , sz(gg)){
		int e = gg[i].se;
		
		if(used[e]){
			if(s.top() == e){
				s.pop();
			}else{
				dier("NO");
			}
		}else{
			s.push(e);
			used[e] = 1;
		}
	}
	
	cout << "YES\n";

	return 0;
}

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

int main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    
    vi p(a), q(b), r(c);
    rep(i,a)cin>>p[i];
    rep(i,b)cin>>q[i];
    rep(i,c)cin>>r[i];
    
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    
    rep(i,x)r.push_back(p[i]);
    rep(i,y)r.push_back(q[i]);
    
    sort(r.rbegin(), r.rend());
    
    ll ans = 0;
    
    rep(i,x+y)ans += r[i];
    
    cout << ans << endl;
    return 0;
}

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

int N, M;
typedef pair<int, int> P;
vector<P> r;
int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        P p;
        cin >> p.first >> p.second;
        r.push_back(p);
    }
    sort(r.begin(), r.end());
    int cnt = 0;
    int c = 1;
    int i = 0;
    while (true) {
        int n = 0;
        while (i < r.size() && r[i].first <= c) {
            n = max(n, r[i].second);
            i++;
        }
        c = n + 1;
        if (n == 0) {
            if (c <= N) {
                cout << "Impossible" << endl;
                return 0;
            }
        }
        cnt++;
        if (c > N) {
            break;
        }
        if (i == r.size()) {
            if (c <= N) {
                cout << "Impossible" << endl;
                return 0;
            }
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1204
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct edge{
    int to;
    int id;
};

int k = 1;
vector<int> col;

void dfs(int v, int p, int c, int i, vector<vector<edge>> &G){
    if(i != -1) col[i] = c;
    chmax(k,c);
    int cnt = 1;
    for(auto nv : G[v]){
        if(nv.to == p) continue;
        if(cnt == col[i]) cnt++;
        dfs(nv.to, v, cnt, nv.id, G);
        cnt++;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<edge>> G(n);
    col.resize(n-1);
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge e;
        e.to = b;
        e.id = i;
        G[a].push_back(e);
        e.to = a;
        G[b].push_back(e);
    }
    dfs(0, -1, 0, -1, G);
    cout << k << endl;
    rep(i,n-1) cout << col[i] << endl;
	return 0;
}

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

int read() {
	char c = getchar();
	int x;
	while(c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x;
}

int m1, m2, d1, d2;
int main() {
	cin >> m1 >> d1;
	cin >> m2 >> d2;
	if(m2 - m1 == 1) cout << "1" << endl;
	else cout << "0" << endl;
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();
		String strLine = sc.nextLine();
		String[] strArr = strLine.split(" ");

		String re = "YES";
		List l = Arrays.asList(strArr);
		Collections.sort(l);

		for (int i = 0; i < l.size() - 1; i++) {
			if (l.get(i).equals(l.get(i + 1))) {
				re = "NO";
				break;
			}
		}

		System.out.println(re);

	}

}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

string conv(string s) {
    string t = "";
    for (char c : s) if (t.empty() || c != t.back())
        t.push_back(c);
    return t;
}

int cnt(string t) {
    return sz(t);
    // if (sz(t) == 1) return 1;
    // int ans = sz(t) - 2;
    // ans += (t[0] == 'L');
    // ans += (t.back() == 'R');
    // return ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    string t = conv(s);
    int m = sz(t);

    int ans = cnt(t);
    for (int z = 0; z < 2; ++z)
    for (int o = 0; o < 2; ++o) 
    for (int p = 0; p < 2; ++p) {
        char c = (z ? 'L' : 'R');
        int nk = k;
        string nt = t;
        if (o == 1) if (nt.back() != c && nk > 0) {nt.back() = c; --nk;}
        if (p == 1) if (nt[0] != c && nk > 0) {nt[0] = c; --nk;}
        for (int i = 1; i < m - 1; ++i)
            if (nk > 0 && nt[i] != c) {--nk; nt[i] = c;}
        string ct = conv(nt);
        // cout << ct << ' ' << cnt(ct) << endl;
        ans = min(ans, cnt(ct));
    }
    std::cout << n - ans << '\n';
    return 0;
}

Measured memory_bytes: 928
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

'''
def gcd(a, b):
    if a<b:
      a,b = b,a
    while b != 0:
        a, b = b, a % b
    return a
'''

G = A[0]
for i in range(N-1):
  G = gcd(G,A[i+1])
  
print(G)

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

int main() {

    ll X, K, D;
    cin >> X >> K >> D;

    X = abs(X);

    if (X / D>= K) {
        cout << X - D*K << endl;
    }
    else {
        ll cnt = X / D;
        X -= (D*cnt);
        K -= cnt;

        if (K%2 == 0) cout << X << endl;
        else cout << abs(X-D) << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    int n,ans=0;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int l,r;
        cin >> l >> r;
        ans += r-l+1;
    }

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

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify

N, K = map(int, input().split())
V = list(map(int, input().split()))

W = V[::-1]

patterns = []

for i in range(1, N+1): # 何個取り出すパターンなのか

  for left in range(i+1): # 左側から何個抽出するのか
    right = i - left
    heap = V[:left] + W[:right]
    heapify(heap)
    patterns.append(heap)

  
ans = 0

for pattern in patterns:
  length = len(pattern)
  subable = K - length

  if subable < 0:
    continue
  
  while subable > 0 and pattern:
    useless = heappop(pattern)
    subable -= 1
    if useless > 0:
      heappush(pattern, useless)
      ans = max(ans, sum(pattern))
      break
  else:
    ans = max(ans, sum(pattern))

print(ans)

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

using namespace std;

int main()
{
  int A, B, C; cin >> A >> B >> C;
  for (int i = 0; A*i < A*B; ++i) {
    if (A*i % B == C) {
      cout << "YES";
      return 0;
    }
  }

  cout << "NO";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i==4){
      cout<<" "<<flush;
    }
    cout<<s[i]<<flush;
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define p pair<ll,ll>
#define pb push_back
#define mp make_pair
#define PI 3.14159265359

using namespace std;

int h,w;
int a[81][81],b[81][81];
bitset<25600>dp[81][81];

int main(){
    
    cin >> h >> w;

    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> b[i][j];
        }
    }

    dp[0][0][12800+abs(a[0][0] - b[0][0])] = 1;

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            int d = abs(a[i][j] - b[i][j]);
            if(i) dp[i][j] |= dp[i-1][j]<<d | dp[i-1][j]>>d;
            if(j) dp[i][j] |= dp[i][j-1]<<d | dp[i][j-1]>>d;
        }
    }

    ll ans = 0;
    while(!dp[h-1][w-1][12800+ans] && !dp[h-1][w-1][12800-ans]) ans++;
    co(ans);
    
    return 0;
}

Measured memory_bytes: 20864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i;
		int x[] = new int[256];
		int n = scan.nextInt();
		for(i = 1; i <= n; i++) {
		 x[i] = scan.nextInt();
		}
		 for( i = n; i >= 1 ; i--){
			 System.out.print(x[i]);
			 if(i==1){
				 break;
			 }
			 System.out.print(" ");
		 }
		 System.out.println("");
		}
	}

Measured memory_bytes: 26224
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) 
{ 
	if (b == 0) 
		return a; 
	return gcd(b, a % b); 
	
}

int main() {
    long int n;
    cin>>n;
    long long int sum=0;
    for(int a=1;a<=n;a++)
    {
        for(int b=1;b<=n;b++)
        {
            for(int c=1;c<=n;c++)
            {
                sum=sum+gcd(a,gcd(b,c));
            }
        }
    }
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int main() {
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	printf("%f\n", sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)));
	return 0;
}

Measured memory_bytes: 1228
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var s = next();
	if(s == "ABC"){
		myout("ARC");
	}else{
		myout("ABC");
	}
}

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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

	int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
	int time1 = h1*60 + m1;
	int time2 = h2*60 + m2;
	cout << time2-time1-k << '\n';
}

Measured memory_bytes: 3648
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
ll n, m, MOD;
vector<vector<ll> > v(100000);
vector<ll> dp(100000);//iを塗った組み合わせ(0から下向き)
vector<ll> dp2(100000);
void dfs1(int k,int prev){
    dp[k]=1;
    for(int i=0;i<v[k].size();i++){
        if(v[k][i]==prev)continue;
        dfs1(v[k][i],k);
        dp[k]*=dp[v[k][i]]+1;//+1塗らない
        dp[k]%=MOD;
    }
}
void dfs2(int k,int prev){//次に行く点に渡す 次に行く点を除いた今の点の情報は累積積で求める
    dp2[k]=1;
    int sizev=v[k].size();
    for(int i=0;i<sizev;i++){
        dp2[k]*=dp[v[k][i]]+1;//+1塗らない
        dp2[k]%=MOD;
    }
    //累積積を求めるよ
    vector<ll> l(sizev), r(sizev);
    ll sum=1;
    for(int i=0;i<sizev;i++){
        sum*=dp[v[k][i]]+1;
        sum%=MOD;
        l[i]=sum;
    }
    sum=1;
    for(int i=sizev-1;i>=0;i--){
        sum*=dp[v[k][i]]+1;
        sum%=MOD;
        r[i]=sum;
    }
    /*
    cout<<k<<"\n";
    debug(l);
    debug(r);
    */
    //累積積を求めたよ
    for(int i=0;i<sizev;i++){
        if(v[k][i]==prev)continue;
        //それぞれの子供に対してその子供の情報を除いた組み合わせをO(1)で渡す
        dp[k]=1;
        if(i){
            dp[k]*=l[i-1];
            dp[k]%=MOD;
        }
        if(sizev>i+1){
            dp[k]*=r[i+1];
            dp[k]%=MOD;
        }
        dfs2(v[k][i],k);
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    MOD=m;
    if(n==1){
        return cout<<1<<"\n",0;
    }
    for (int i = 0; i < n-1; i++)
    {
        ll temp, temp1;
        cin >> temp>>temp1;
        temp--;
        temp1--;
        v[temp].push_back(temp1);
        v[temp1].push_back(temp);
    }
    dfs1(0,-1);
    dfs2(0,-1);
    for(int i=0;i<n;i++)
    cout << dp2[i] << "\n";
}



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

int main(){
	ll n=0,num=1,s;
    
    cin >> n;
    
    vector<ll> vec(n);
    rep(i,n){
    	cin >> vec[i];
      	if(vec[i] == 0){
        	num = 0;
            cout << num << endl;
          	return 0;
        }
    }
  	rep(i,n){
        if(vec.at(i) <= 1000000000000000000/num){
        	num *= vec[i];
    	}else{
        	num = -1;
          	break;
        }
    }
    cout << num << endl;
    
    return 0;
}

Measured memory_bytes: 3972
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val a = new Array[Int](n)
  for (i <- 0 until n) {
    a(i) = sc.nextInt()
  }

  var currentNum = 0
  for(num <- a) {
    if(currentNum + 1 == num) currentNum += 1
  }
  println(if(currentNum == 0) -1 else n - currentNum)

// ↓最初の解答
//  if (!a.contains(1)) {
//    println(-1)
//  } else {
//    var breakCount = 0
//    var currentNum = 1
//    for (i <- 0 until n) {
//      if (a(i) == currentNum) {
//        currentNum += 1
//      } else {
//        breakCount += 1
//      }
//    }
//    println(breakCount)
//  }
}


Measured memory_bytes: 70424
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string s;
    cin >> s;
    if(s.size() == 3)swap(s[0], s[2]);
    cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int a[20][20];
int val[20];
int32_t main(){
	fastio();
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<n;i++){
		cin>>val[i];
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	int ans = INF;
	for(int i=0;i<(1<<n);i++){
		int curr = 0;
		int done[m+3];
		memset(done,0,sizeof(done));
		set<int>s;
		bool ok = true;
		for(int j=0;j<n;j++){
			if(i&(1<<j)) s.insert(j);
		}
		for(auto j:s){
			curr+=val[j];
			for(int k=0;k<m;k++){
				done[k]+=a[j][k];
			}
		}
		for(int j=0;j<m;j++){
			if(done[j]<x) ok = false;
		}
		if(ok) ans = min(ans,curr);
	}
	if(ans==INF) cout<<"-1";
	else cout<<ans;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <map>
using namespace std;

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

  vector<char> S(N);

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

  if(N % 2 == 1) cout << "No" << endl;
  else{
    bool flag = true;
    for(int i = 0; i < N / 2; i++){
      if(S[i] != S[i + N / 2]){
        flag = false;
        break;
      }
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256