akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
struct BIT
{
	int bit[(1<<20)+5];
	int f(int x)
	{
		return x&-x;
	}
	void add(int i,int x)
	{
		for(int s=i;s<=(1<<20);s+=f(s)) bit[s]+=x;
	}
	int sum(int i)
	{
		int res=0;
		for(int s=i;s>0;s-=f(s)) res+=bit[s];
		return res;
	}
}bit[2];
int n,x[3][100005],p[100005],f[2];
int main(){
	cin>>n;
	rep(i,3){
		rep(j,n) cin>>x[i][j];
	}
	bool bad = 0;
	rep(j,n){
		int a = max(x[0][j],max(x[1][j],x[2][j]));
		if(x[0][j] == a && x[1][j] == a-1 && x[2][j] == a-2){
			p[j] = a/3;
			f[j%2] ++;
		}
		else if(x[2][j] == a && x[1][j] == a-1 && x[0][j] == a-2){
			p[j] = a/3;
		}
		else{
			bad = 1;
		}
		if(p[j]%2 != 1-j%2) bad=1;
		if(bad) break;
		int X = bit[j%2].sum(1<<20)-bit[j%2].sum(p[j]);
		f[1-(j%2)] += X%2;
		bit[j%2].add(p[j],1);
	}
	if(!bad && f[0]%2==0 && f[1]%2==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define MOD (LL)pow(10,9) + 7


int main(){
    string s;
    cin >> s;
    if(s.size() % 2 != 0){
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0; i < s.size() - 1; i += 2){
        if(s.substr(i,2) != "hi"){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    string s;
    cin >> s;
    ll res = 0;
    REP(i, N){
    	int j = i;
    	while(j<N && s[i]==s[j])j++;
    	i = j-1;
    	res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		String s=input.next();
		if(s.charAt(0)=='R' && s.charAt(1)=='R' &&s.charAt(2)=='S')
		{
			System.out.println(2);
		}
		
		else if(s.charAt(1)=='R' && s.charAt(2)=='R' &&s.charAt(0)=='S')
		{
			System.out.println(2);
		}
		else if(s.charAt(0)=='R' &&s.charAt(1)=='S' && s.charAt(2)=='R')
		{
			System.out.println(1);
		}
		else if(s.charAt(0)=='S' &&s.charAt(1)=='S' && s.charAt(2)=='R')
		{
			System.out.println(1);
		}
		else if(s.charAt(0)=='R' &&s.charAt(1)=='S' && s.charAt(2)=='S')
		{
			System.out.println(1);
		}
		else if(s.charAt(0)=='S' &&s.charAt(1)=='R' && s.charAt(2)=='S')
		{
			System.out.println(1);
		}
		else if(s.charAt(0)=='R' && s.charAt(1)=='R' && s.charAt(2)=='R')
		{
			System.out.println(3);	           
		}
		else if(s.charAt(0)=='S' && s.charAt(1)=='S' && s.charAt(2)=='S')
		{
			System.out.println(0);	           
		}

	}

}


Measured memory_bytes: 35532
#include <array>
#include <iostream>
#include <algorithm>
using std::for_each;
using std::array;
using std::cout;
using std::endl;
using std::cin;

int main() {
	array<int,4> a,b;
	for_each(a.begin(),a.end(),[](int &s){cin >> s;});
	for_each(b.begin(),b.end(),[](int &s){cin >> s;});
	int sum_a = 0,sum_b = 0;
	for_each(a.begin(),a.end(),[&sum_a](int s)mutable{sum_a += s;});
	for_each(b.begin(),b.end(),[&sum_b](int s)mutable{sum_b += s;});
	cout << (sum_a >= sum_b ? sum_a : sum_b) << endl;
}

Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, A;
            N = int.Parse(Console.ReadLine());
            A = int.Parse(Console.ReadLine());
            if (N % 500 - A <= 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
 
            Console.ReadKey();
        }
    }
}

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

int count_two(int x)
{
    int temp = x, result = 0;
    while(temp % 2 == 0)
    {
        result++;
        temp = temp / 2;
    }

    return result;
}

int main()
{
    int N; cin >> N;
    int arr[N]; int result = INT_MAX;

    for(int i = 0; i < N; i++)
    {
        cin >> arr[i];
        if(result > count_two(arr[i]))
        {
            result = count_two(arr[i]);
            if(result == 0)
            {
                cout << result << endl;
                return 0;
            }
        }
    }

    cout << result << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

long long n, ans;
long long a[200005];
set<long long> se;

int main()
{
    scanf("%lld", &n);
    for(long long i = 1; i <= n; i++)
    {
        long long t;
        scanf("%lld", &t);
        a[t] = i;
    }
    se.insert(0);
    se.insert(n + 1);
    for(long long i = 1; i <= n; i++)
    {
        set<long long>::iterator it = se.lower_bound(a[i]);
//        long long now = i * (*it - a[i]);
//        it--;
//        ans += now * (a[i] - *it);
        ans += i * (*it - a[i]) * (a[i] - *(--it));
        se.insert(a[i]);
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<" : "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	REP(i,s.size()){
		s[i]+=n;
		if(s[i]>'Z') s[i]-=26;
	}
	
	cout<<s<<endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <cstdio>
using namespace std;

inline int getint()
{
	int x = 0, c = getchar();
	while (c > 47 && c < 58)
	{
		x = x * 10 + c - 48;
		c = getchar();
	}
	return x;
}

constexpr int MAX = 300000;
int res[MAX * 4];

int main()
{
	int H = getint();
	int W = getint();
	int M = getint();

	int h, w, ans;
	int mxr = 0;
	int mxc = 0;
	int ctrow = 0;
	int ctcol = 0;
	for (int i = 0; i < M; ++i)
	{
		h = getint() - 1, w = getint() - 1;
		res[i + 2 * MAX] = h, res[i + 3 * MAX] = w;
		int x = ++res[h], y = ++res[w + MAX];

		if (x == mxr) ++ctrow;
		else if (x > mxr) mxr = x, ctrow = 1;

		if (y == mxc) ++ctcol;
		else if (y > mxc) mxc = y, ctcol = 1;
	}
	ans = mxr + mxc;

	long ct = ctrow;
	ct *= ctcol;
	if (ct > M)
	{
		printf("%d\n", ans);
		return 0;
	}

	for (int i = 0; i < M; ++i) if (res[res[i + 2 * MAX]] == mxr && res[res[i + 3 * MAX] + MAX] == mxc) --ct;
	if (ct <= 0) --ans;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 6264
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int k=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        boolean ans=false;
        for (int d=a;d<=b;d++){
            if(d%k==0){
                ans=true;
                break;
            }
        }
        if(ans){
            System.out.println("OK");
        }
        else{
            System.out.println("NG");
        }
   
    }
}

Measured memory_bytes: 35800
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    d = defaultdict(lambda : 0)
    for i in range(1,n+1):
        s = str(i)
        l = s[0]
        r = s[-1]
        d[(l,r)] += 1
    ans = 0
    for i in range(1,n+1):
        s = str(i)
        l = s[0]
        r = s[-1]
        ans += d[(r,l)]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 41324
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    ll q, h, s, d;
    cin >> q >> h >> s >> d;
    ll N;
    cin >> N;
    ll sum = 0;
    ll mn = min({q * 4, h * 2, s});
    ll mn_next;
    if(2 * mn > d){
        mn_next = mn;
        mn = d;
        if(N % 2 == 0){
            sum += mn * (N / 2);
        }else{
            sum += mn * (N / 2) + mn_next;
        }
    }else{
        sum += N * mn;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int b,w;
  b = w = 0;
  for(int i = 0;i < s.size();i++){
    if(i % 2 == 0){
      if(s[i] == '1')b++;
    }else{
      if(s[i] == '0')b++;
    }
  }
  for(int i = 0;i < s.size();i++){
    if(i % 2 == 0){
      if(s[i] == '0')w++;
    }else{
      if(s[i] == '1')w++;
    }
  }
  int ans = min(w,b);
  cout << ans << endl;
}

Measured memory_bytes: 512
N,K,S = map(int,input().split())
if S>N:
  ans = [S]*K + [1]*(N-K)
elif S<10**9:
  ans = [S]*K + [S+1]*(N-K)
elif S==10**9:
  ans = [S]*K + [S-1]*(N-K)
print(*ans)

Measured memory_bytes: 6500
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll K,N,X,A[200010];
ll ans=0;
ll S[3][5000];
map< int64_t, int > ret;
int main(){
    cin>>N;
    EREP(i,N){
        ll Y=N/i;
        ans+=i*Y*(Y+1)/2;
    }

    cout<<ans<<endl;

}
//ABC 121 D - XOR World


Measured memory_bytes: 3604
n=int(raw_input())
a=[[0 for i in xrange(0,n)] for j in xrange(0,n)]
 
for i in xrange(n):
    a[i]=map(int,raw_input().split())
 
omomi=0
A=[0]
B=range(1, n)
while B!=[]:
    c=2000
    for i in A:
        for j in B:
            if 0<=a[i][j]<=c:
                c=a[i][j]
                AA=j
    A.append(AA)
    B.remove(AA)
    omomi=omomi+c
 
print omomi

Measured memory_bytes: 6460
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

#define pb push_back
#define mp make_pair
#define mod 1000000007

int main() {
    string s;
    cin>>s;
    int n = s.size();

    if(s[0] == s[n-1]) {
        if(n%2 == 0) {
            cout<<"First";
        } else cout<<"Second";
    } else {
        if(n%2 != 0) {
            cout<<"First";
        } else cout<<"Second";
    }

    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
res = sum(b)
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        res+=c[a[i]-1]
print(res)

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

int main(){
	int a, b;
	for(int i=0; i>=0; i++){
		cin >> a >> b;
		if(a==0 && b==0) break;
		for(int j=0; j<a; j++){
			for(int k=0; k<b; k++){
				if((j+k)%2==0)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <math.h>

#define PI  3.141592653589793
//円周率の宣言

int main(int argc, const char * argv[]) {
    double r;
    
    scanf("%lf", &r);
    printf("%lf %lf\n", PI*r*r, 2*PI*r);
    return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n;
	cin >> n;
 
	vector<ll> a(n);
	for (auto &v : a) {
		cin >> v;
	}
 
	vector<ll> dp = a;
	for (ll i = 1; i < n; i++) {
		dp[i] += dp[i - 1];
	}
 
	map<ll, ll> mp;
	mp[0]++;
 
	ll ans = 0;
	for (auto v : dp) {
		if (mp.count(v) != 0) {
			ans += mp[v];
		}
 
		mp[v]++;
	}
 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15872
import numpy as np

M = 10 ** 9 + 7

N = int(input())
x = np.array(list(map(int, input().split())))

x = np.diff(x)

# (N-1)!を求める
fac = 1
for i in range(1, N):
    fac = fac * i % M

c = [0] * N

for i in range(1, N):
    c[i] = (fac * pow(i, M - 2, M) % M) + c[i - 1] % M

# print(c)

ans = 0
for i in range(N - 1):
    ans = (ans + x[i] * c[i + 1] % M) % M

print(ans)


Measured memory_bytes: 23112
n=int(input())

x=list(map(int,input().split()))
y=list(map(int,input().split()))
p=[0]*4

for i in range(n):
    p[0]+=abs(x[i]-y[i])
    p[1]+=abs(x[i]-y[i])**2
    p[2]+=abs(x[i]-y[i])**3
    p[3]=max(p[3],abs(x[i]-y[i]))
p[1]=p[1]**(1/2)
p[2]=p[2]**(1/3)
for i in range(4):
    print("{0:.5f}".format(p[i]))



Measured memory_bytes: 5648
#include <cmath>
#include<iostream>
using namespace std;
int main() {
    int N,T,A,ans=0;
    cin >> N >> T >> A;
    double data[N];
    for (int i=0; i<N; i++) {
        int tmp;
        cin >> tmp;
        data[i] = T - tmp * 0.006;
    }
    double diff = abs(A - data[0]);
    int num = 0;
    for (int i=0; i<N; i++) {
        //cout << i << ' ' << abs(A - data[i]) << endl;
        if (diff > abs(A - data[i])) {
            num = i;
            diff = abs(A - data[i]);
        }
    }
    cout << num+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int s = in.nextInt();
        int t = in.nextInt();
        int q = in.nextInt();
        TreeSet<Long> shrines = new TreeSet<Long>();
        TreeSet<Long> temples = new TreeSet<Long>();
        for( int i = 0; i < s; i++ ) shrines.add(in.nextLong());
        for( int i = 0; i < t; i++ ) temples.add(in.nextLong());
        shrines.add(Long.MIN_VALUE);
        shrines.add(Long.MAX_VALUE);
        temples.add(Long.MAX_VALUE);
        temples.add(Long.MIN_VALUE);
        for( int i = 0; i < q; i++ ) {
            long temp = in.nextLong();
            long[] dists = new long[4];
            dists[0] = shrines.floor(temp);
            dists[1] = shrines.ceiling(temp);
            dists[2] = temples.floor(temp);
            dists[3] = temples.ceiling(temp);
            long ans = Long.MAX_VALUE;
            for( int j = 0; j < 2; j++ ) {
                for( int k = 2; k < 4; k++ ) {
                    // shrine closest left or right
                    long a = Math.abs(dists[j]-temp)+Math.abs(dists[k]-dists[j]);
                    // temple closest left or right
                    long b = Math.abs(dists[k]-temp)+Math.abs(dists[j]-dists[k]);
                    if( a > 0 ) ans = Math.min(ans, Math.abs(dists[j]-temp)+Math.abs(dists[k]-dists[j]));
                    if( b > 0 ) ans = Math.min(ans, Math.abs(dists[k]-temp)+Math.abs(dists[j]-dists[k]));
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 112164
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
int n, arr[105], cnt=0;

int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	cnt=arr[0];
	for(int i=1;i<n;i++){
		if(arr[i]>=arr[i-1]){
			cnt+=arr[i]-arr[i-1];
		}
	}
	printf("%d\n", cnt);
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1005],b[1005];
int main()
{
	int n,h,w,ans=0;
	cin>>n>>h>>w;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		if(a[i]>=h&&b[i]>=w)
			ans++;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		h := make([]int, 5)
		h[0], _ = strconv.Atoi(scanner.Text())
		if h[0] == 0 {
			break
		}
		for i := 1; i <= 4; i++ {
			scanner.Scan()
			h[i], _ = strconv.Atoi(scanner.Text())
		}
		tbl := make([]bool, 3)
		aiko := false
		for _, v := range h {
			tbl[v-1] = true
		}
		if tbl[0] && tbl[1] && tbl[2] { // 全ての手があるあいこ
			aiko = true
		}
		if h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4] {
			aiko = true
		}
		if aiko {
			fmt.Printf("3\n3\n3\n3\n3\n")
		} else {
			win := 0
			if !tbl[0] {
				win = 2
			}
			if !tbl[1] {
				win = 3
			}
			if !tbl[2] {
				win = 1
			}
			for i := 0; i < 5; i++ {
				if h[i] == win {
					fmt.Println(1)
				} else {
					fmt.Println(2)
				}
			}
		}
	}
}


Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
#define TC cin>>t;while(t--)
const ll MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;

int main()
{
    int n,m;
    cin>>n;
    int a[n];
    int f[n]={0};
    for(int i=0;i<n-1;i++)
    {
        cin>>a[i];
        f[a[i]-1]++;
    }
    for(int i=0;i<n;i++)
        cout<<f[i]<<nl;


}

Measured memory_bytes: 5160
int_h, int_w = map(int, input().split())
l_h = list()
for i in range(int_h):
    l_h.append(input())

l_temp = list()
l_temp.append(list(map(int, "0" * (int_w + 2))))
for r in l_h:
    l_temp.append(list(map(lambda x: int(x) if x != "#" else x, "0" + r.replace(".", "0") + "0")))

l_temp.append(list(map(int, "0" * (int_w + 2))))


# print(l_temp)


for rownum, row in enumerate(l_temp):
    for colnum, col in enumerate(row):
        if col == "#":
            for c in [-1, 0, 1]:
                if l_temp[rownum - 1][colnum + c] != "#":
                    l_temp[rownum - 1][colnum + c] += 1
                if l_temp[rownum + 1][colnum + c] != "#":
                    l_temp[rownum + 1][colnum + c] += 1
            for c in [-1, 1]:
                if l_temp[rownum][colnum + c] != "#":
                    l_temp[rownum][colnum + c] += 1


for row in l_temp[1:-1]:
    print("".join(map(str,row[1:-1])))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			String S = scan.next();//奇数である文字列
			char []s = new char[S.length()];
			char []x = new char[S.length()];
			s = S.toCharArray();
			
			int ok1 = 0;
			int ok2 = 0;
			int ok3 = 0;
			
			if(kaibunn(s)) {
				ok1=1;
				//System.out.println(ok1);
			}
			int N = S.length();
			String S2 = S.substring(0, (N-1)/2);
			char[] s2 = S2.toCharArray();
			if(kaibunn(s2)){
				ok2 =1;
				//System.out.println(ok2);
			}
			String S3 = S.substring((N+3)/2-1, N);
			char[] s3  = S3.toCharArray();
			if(kaibunn(s3)) {
				ok3=1;
				//System.out.println(ok3);
			}
			
			System.out.println(ok1==1&&ok2==1&&ok3==1?"Yes":"No");
			
			
			
			
			
			
		}
		
		
	}
	
	
	private static boolean kaibunn(char[]s) {//文字列が回文かどうか
		boolean hante =true;
		char []x = new char[s.length];
		for(int i = s.length-1;i>=0;i--) {
			x[i] = s[s.length-1-i];
		}
		
		for(int i = 0;i<s.length;i++) {
			//System.out.println(s[i]);
			//System.out.println(x[i]);
			if(s[i]!=x[i]) {
				hante = false;
				break;
			}
		}	
		return hante;
		
	}
		
}


Measured memory_bytes: 23636
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#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) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mask = (1 << 5) - 1;
const int mod = 1e9 + 7;
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H, W;
	scanf("%d", &H);
	scanf("%d", &W);

	ll dp[1001];
	dp[0] = 1;
	char A[1001];
	scanf("%s", A);
	rep1(w, W - 1) dp[w] = (A[w] == '.' ? dp[w - 1] : 0);

	rep1(h, H - 1) {
		scanf("%s", A);
		dp[0] = (A[0] == '.' ? dp[0] : 0);
		rep1(w, W - 1) {
			dp[w] = (A[w] == '.' ? dp[w] + dp[w - 1] : 0);
			if (!(h + w & mask)) dp[w] %= mod;
		}
	}
	printf("%d", dp[W - 1] % mod);

	Would you please return 0;
}

Measured memory_bytes: 128
function Main(input) {
    input = input.split('\n');
    var n = parseInt(input[0], 10);
    var inputVal = input[1].split(' ');
    var sortedVal = (inputVal.map(str => parseInt(str, 10))).sort(function(a,b){
        return b - a;
    });
    var sum1 = 0;
    for(var i = 0; i < sortedVal.length; i+=2) {
        sum1 += sortedVal[i];
    }
    var sum2 = 0;
    for(var j=1 ; j < sortedVal.length; j+=2) {
        sum2 += sortedVal[j];
    }
    console.log('%s', sum1 - sum2);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
import java.util.*;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
  	    int m = sc.nextInt();
        int K[] = new int[n];
      	int A[][] = new int[n][m]; 
      	int fav[] = new int[m];
      	int ans = 0;
        
        for(int i=0; i<n; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i] ; j++){
                A[i][j] = sc.nextInt();
			    fav[A[i][j]-1] += 1;
     	    }
        }
      	
      	for(int i=0; i<m; i++){
            if(fav[i] == n){
                ans++;
            }
        }
       	
       	System.out.println(ans);
    }
}

Measured memory_bytes: 38568
#include <vector>
#include <cstdio>

using namespace std;

const int INF = 1000;

int v, e;

//edge src and dst
vector<int> s, t;

//bellman-ford
bool check( int start ){

    vector<int> dist( v, INF );

    dist[start] = 0;
    
    int n = 0;
    for ( ; n<v; ++n ) {

	bool update = false;
	
	for ( int i=0; i<e; ++i ) {

	    int from = s[i];
	    int to = t[i];

	    if ( dist[from] != INF && dist[from] - 1 < dist[to] ) {
		dist[to] = dist[from] - 1;
		update = true;
	    }
	}

	if ( !update ) break;
    }

    return n == v;
}

int main(){

    scanf("%d %d", &v, &e);

    s.resize( e );
    t.resize( e );
    
    for ( int i=0; i<e; ++i ) {
	scanf("%d %d", &s[i], &t[i]);
    }
    
    for ( int i=0; i<v; ++i ) {
	if ( check( i ) ) {
	    printf("1\n");
	    return 0;
	}
    }

    printf("0\n");
    
    return 0;
}



Measured memory_bytes: 2696
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

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

  if(N==3 || N==5 || N==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[3];
int main() {
    for(int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    sort(a, a + 3);
    int n = a[2] - a[0], m = a[2] - a[1];
    int rem = n - m;
    if(rem % 2) m += rem / 2 + 2;
    else m += rem / 2;
    cout << m << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN = 2e5+5;
int h,w,a,b,ans,inv[mxN],fac[mxN];
int binpow(int a, int b) 
{
   	a%=mod;
    int res=1;
    while(b>0) 
	{
        if(b&1)
            res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int inverse(int x)
{
	return binpow(x,mod-2);
}
int calc(int k, int n)
{
	return (((fac[n]*inv[k])%mod)*inv[n-k])%mod;
}
signed main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    fac[0]=inv[0]=1;
    for(int i=1;i<mxN;i++)
    {
    	fac[i]=(fac[i-1]*i)%mod;
    	inv[i]=inverse(fac[i]);
	}
    cin>>h>>w>>a>>b;
    for(int i=0;i<=h-a;i++)
    {
    		ans+=calc(i-1,i+b-2)*(calc(h-i,h-i+w-b-1))%mod;
//    		cout<<ans<<endl;
    		ans%=mod;
	}	
    return cout<<ans,0;
}


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

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n, a, b; scan(n, a, b);

    // 両方を購読している人の最大数
    int x = min(a, b);
    // 両方を購読している人の最小数
    int y = max(0, a + b - n);
    writeln(x, " ", y);
}


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

int main() {
	int n;
	cin >> n;
	map<int, int> m;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		m[a]++;
	}
	int r = 0;
	for (auto e : m) {
		r += e.second >= e.first ? e.second - e.first : e.second;
	}
	cout << r << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 59;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int h, w;
  cin >> h >> w;
  vector<vector<int>> c(10, vector<int>(10));
  rep(i, 10) rep(j, 10) cin >> c[i][j];
  rep(k, 10) rep(i, 10) rep(j, 10) chmin(c[i][j], c[i][k]+c[k][j]);

  ll ans = 0;
  rep(i, h) rep(j, w) {
    int a; cin >> a;
    if(a == -1) continue;
    ans += c[a][1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    if (s=="Sunny")
        cout<<"Cloudy";
    else if (s=="Rainy")
        cout<<"Sunny";
    else
        cout<<"Rainy";
    return 0;
}


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

using namespace std;

const int MOD=1e9+7;
//const int MOD=998244353;

const double PI=3.14159265359;




int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,k;
    cin>>n>>k;
    
    vector<int> v(n);
    
    
    for(int&i:v)cin>>i;
    sort(v.begin(),v.end());
    
    
    int ans=MOD;
    for(int i=0; i+k-1<n; i++){
        ans=min(ans, v[i+k-1]-v[i]);
    }
    cout<<ans;
    
    
    
    return 0;
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 10000000
#define MOD 998244353
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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

  vector<int>black(N+1,0);
  vector<int>white(N+1,0);
  for(int i=0;i<N;i++){
    if(s[i]=='#')black[i+1]++;
    else white[i+1]++;
  }
  for(int i=0;i<N;i++)black[i+1]+=black[i];
  for(int i=0;i<N;i++)white[i+1]+=white[i];

  int ans=INF;
  for(int i=0;i<=N;i++){
    ans=min(ans,black[i]-black[0]+white[N]-white[i]);
  }

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



Measured memory_bytes: 2180
#include<stdio.h>
int times[1001][1001];
int d[1000][1000];
int main(){
	int a,b,c;
	while(1){
		scanf("%d%d%d",&a,&b,&c);
		if(a==0)return 0;
		for(int i=0;i<1001;i++)
			for(int j=0;j<1001;j++)
				times[i][j]=0;
		
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++)
				scanf("%d",&d[i][j]);
		
		times[0][0]=c-1;
		
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++){
				if(times[i][j]%2==0){
					times[i+1][j]+=times[i][j]/2;
					times[i][j+1]+=times[i][j]/2;
				}else if(d[i][j]==1){
					times[i+1][j]+=times[i][j]/2;
					times[i][j+1]+=times[i][j]/2+1;
				}else{
					times[i+1][j]+=times[i][j]/2+1;
					times[i][j+1]+=times[i][j]/2;
				}
			}
			
		int x=1,y=1;
		while(x<b+1&&y<a+1){
			if((times[y-1][x-1]+d[y-1][x-1])%2==0)y++;
			else x++;
		}
		printf("%d %d\n",y,x);
	}
}

Measured memory_bytes: 8588
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ll x, k, d;

int main()
{
  ll ans;
  ll n;

  cin >> x >> k >> d;

  if (x<0) x= -x;

  n = x/d;

  if (n > k) {
    ans = x-k*d;
    cout << ans << endl;
    return 0;
  }

  if ((k+n)%2==0) {
    ans = x-n*d;
  } else {
    ans = (n+1)*d-x;
  }

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


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

void fnMaximumProfit(const vector<int> &a_cnrviValue, int &a_riMinval, int &a_riMaxProfit)
{
  for (int i = 1; i < a_cnrviValue.size(); i++)
  {
    a_riMinval = min(a_riMinval, a_cnrviValue[i - 1]);
    int iMaxProfit = a_cnrviValue[i] - a_riMinval; 
    a_riMaxProfit = max(a_riMaxProfit, iMaxProfit);
  }
}

int main()
{
  vector<int> viValue;
  int iMaxSize;
  
  cin >> iMaxSize;
  for (int i = 0; i < iMaxSize; i++)
  {
    int iValue;
    cin >> iValue;
    viValue.push_back(iValue);
  }

  int iMinval = viValue[0];
  int iMaxProfit = -1000000000;
  fnMaximumProfit(viValue, iMinval, iMaxProfit);
  cout << iMaxProfit << endl;

  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;

    vector<ll> t;
    for (ll i = 2; i * i <= A; ++i) {
        if (A % i != 0)
            continue;
        t.push_back(i);
        while (A % i == 0)
            A /= i;
    }
    if (A > 1)
        t.push_back(A);

    vector<ll> v;
    REP(i, t.size()) {
        if (B % t[i] == 0)
            v.push_back(t[i]);
    }
    cout << v.size() + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    L, R = 0, float('inf')
    for _ in range(M):
        l, r = map(int, input().split())
        L = max(L, l)
        R = min(R, r)
    print(max(R - L + 1, 0))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 1000000007
#define MM 2005
#define MN 1005
using namespace std;
inline ll in(){
    ll x=0ll;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct edge{
	int fr,to;
	ll val;
}e[MM];
int fa[MN],n,m,sum1,sum2;
ll sum,x;
inline bool cmp(edge x,edge y){
	return (x.val==y.val)?x.fr<y.fr:x.val<y.val;
}
inline int gf(int x){
	return fa[x]?fa[x]=gf(fa[x]):x;
}
inline int qpow(int x,int k){
	int res=1;
	while (k){
		if (k&1) res=(1ll*res*x)%mod;
		x=(1ll*x*x)%mod;k>>=1;
	}return res;
}
int main()
{
	n=in();m=in();x=in();sum2=1;
	for (int i=1;i<=m;++i){
		e[i].fr=in();e[i].to=in();e[i].val=in(); 
	}sort(e+1,e+m+1,cmp);
	for (int i=2;i<=m;++i){
		memset(fa,0,sizeof(fa));sum=0;
		int fx=gf(e[i].fr),fy=gf(e[i].to);
		if (fx!=fy) fa[fx]=fy,sum+=e[i].val;
		for (int j=1;j<=m;++j){
			fx=gf(e[j].fr),fy=gf(e[j].to);
			if (fx!=fy) fa[fx]=fy,sum+=e[j].val;
		}if (sum==x) ++sum1;if (sum>x) ++sum2;
	}
	printf("%d",(1ll*(qpow(2,sum1)+mod-1)%mod*qpow(2,sum2)%mod)%mod);
	return 0;
}

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

long f (long n, int p) {
  long x;
  n /= p;
  while (n > 0) {
    x += n;
    n /= p;
  }
  return x;
}

void main() {
  long n;
  readf (" %d", &n);
  if (n & 1) {
    writeln (0);
    return;
  }
  n /= 2;
  writeln (f (n, 5));
  //writeln (min (f (n, 2), f (n, 5)));
}



Measured memory_bytes: 256
m, d = map(int, input().split(' '))

cnt = 0
if d < 22:
  print(0)
else:
  for i in range(22,d + 1):
    d10 = i // 10
    d1 = i % 10
    if d10 >= 2 and d1 >= 2 and d10*d1 <= m:
      cnt += 1
      
  print(cnt)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct edge{
  ll u,v,c;
};

ll N,M,p;
vector<edge> es;
ll dp[3000];
bool broken[3000];

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

  cin>>N>>M>>p;
  rep(i,M){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    es.push_back((edge){a,b,c-p});
  }

  rep(i,N)dp[i]=-INF;
  dp[0]=0;

  rep(_,N){
    rep(i,M){
      edge e=es[i];
      if(dp[e.u]!=-INF&&dp[e.u]+e.c>dp[e.v]){
        dp[e.v]=dp[e.u]+e.c;
      }
    }
  }

  rep(_,N){
    rep(i,M){
      edge e=es[i];
      if(dp[e.u]!=-INF&&dp[e.u]+e.c>dp[e.v]){
        dp[e.v]=dp[e.u]+e.c;
        broken[e.v]=true;
      }
      broken[e.v]|=broken[e.u];
    }
  }

  if(broken[N-1]) cout<<-1<<endl;
  else cout<<max(0LL,dp[N-1])<<endl;

  return 0;
}


Measured memory_bytes: 576
# Input
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

# Init
min = 99999
ans = -1

# Loop n Times
for idx in range(n):
    if abs(a - (t - h[idx] * 0.006)) < min:
        min = abs(a - (t - h[idx] * 0.006))
        ans = idx + 1

# Output
print(int(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n;
vector<vector<ll>> g, dp;

vector<ll> ide(){
    return {1, 0, 0, 0};
}

vector<ll> f1(vector<ll> a, vector<ll> b){
    vector<ll> res(4, 0);
    zep(i, 0, 3){
        zep(j, 0, 3){
            ll k = min(i+j, 2LL);
            res[k] += (a[i]*b[j])%MOD;
            res[k] %= MOD;
        }
    }
    return res;
}

vector<ll> f2(vector<ll> a){
    return {a[0], (a[0]+2*(a[1]+a[2]))%MOD, 0, a[2]};
}

void dfs1(ll at, ll from = -1){
    dp[at] = ide();
    zep(i, 0, g[at].size()){
        ll nx = g[at][i];
        if(nx != from){
            dfs1(nx, at);
            dp[at] = f1(dp[at], f2(dp[nx]));
        }
    }
}

void dfs2(ll at, ll from = -1, vector<ll> x = ide()){
    dp[at] = f2(f1(dp[at], x));

    ll m = g[at].size();
    vector<ll> l[m], r[m];
    zep(i, 0, m){l[i] = r[i] = (g[at][i] == from)? x : f2(dp[g[at][i]]);}
    rep(i, 1, m-1){l[i] = f1(l[i], l[i-1]);}
    rrep(i, m-2, 0){r[i] = f1(r[i], r[i+1]);}

    zep(i, 0, m){
        ll nx = g[at][i];
        if(nx != from){
            vector<ll> tmp = ide();
            if(i > 0){tmp = f1(tmp, l[i-1]);}
            if(i < m-1){tmp = f1(tmp, r[i+1]);}
            dfs2(nx, at, f2(tmp));
        }
    }
}

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

    cin >> n;
    g.resize(n);
    dp.resize(n);
    zep(i, 0, n-1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs1(0);
    dfs2(0);

    ll res = 0;
    zep(i, 0, n){
        res += dp[i][3];
        res %= MOD;
    }
    zep(i, 0, n){
        res *= (MOD+1)/2;
        res %= MOD;
    }
    print(res)
    return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  vector< int64 > A(N), B(N);
  cin >> A >> B;
  priority_queue< pair< int64, int > > que;
  auto pre = [&](int idx) { return (idx + N - 1) % N; };
  auto nxt = [&](int idx) { return (idx + 1) % N; };

  for(int i = 0; i < N; i++) {
    que.emplace(B[i] - (B[pre(i)] + B[nxt(i)]), i);
  }
  int64 add = 0;
  while(que.size()) {
    auto p = que.top();
    que.pop();
    int i = p.second;
    if(B[i] - (B[pre(i)] + B[nxt(i)]) != p.first) {
      continue;
    }
    if(p.first <= 0 || B[i] <= A[i]) {
      continue;
    }
    int64 diff = (B[i] - A[i]) / (B[pre(i)] + B[nxt(i)]);
    add += diff;
    if(diff == 0) continue;
    B[i] -= diff * (B[pre(i)] + B[nxt(i)]);
    que.emplace(B[i] - (B[pre(i)] + B[nxt(i)]), i);
    que.emplace(B[pre(i)] - (B[pre(pre(i))] + B[i]), pre(i));
    que.emplace(B[nxt(i)] - (B[i] + B[nxt(nxt(i))]), nxt(i));
  }

  if(B == A) cout << add << endl;
  else cout << -1 << endl;
}




Measured memory_bytes: 70880
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

struct Edge {
  int to;
  ll coin, cost;
  Edge(int to, ll coin, ll cost) : to(to), coin(coin), cost(cost) {}
};

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  vector<vector<Edge>> g(n);
  vector<pair<ll, ll>> cd(n);
  ll a, b, c, d;
  rep(i, 0, m) {
    cin >> a >> b >> c >> d;
    --a, --b;
    g[a].emplace_back(b, c, d);
    g[b].emplace_back(a, c, d);
  }
  rep(i, 0, n) cin >> cd[i].first >> cd[i].second;

  using tup = tuple<ll, ll, int>;
  vector<vector<ll>> dp(n, vector<ll>(2525, INFL));
  s = min(s, (ll)2500);
  dp[0][s] = 0;
  priority_queue<tup, vector<tup>, greater<tup>> pq;
  pq.emplace(0, s, 0);

  vector<ll> ans(n, INFL);
  // もつお金の上限 - aの上限50, nの上限50から50 * 50 程度持っていれば十分
  ll cost, coin;
  int now;
  while (pq.size()) {
    tie(cost, coin, now) = pq.top();
    pq.pop();
    if (cost > dp[now][coin]) continue;

    for (Edge e : g[now]) {
      if (coin >= e.coin && dp[e.to][coin - e.coin] > dp[now][coin] + e.cost) {
        dp[e.to][coin - e.coin] = dp[now][coin] + e.cost;
        pq.emplace(dp[e.to][coin - e.coin], coin - e.coin, e.to);
      }
    }
    if (coin + cd[now].first < 2500 &&
        dp[now][coin + cd[now].first] > dp[now][coin] + cd[now].second) {
      dp[now][coin + cd[now].first] = dp[now][coin] + cd[now].second;
      pq.emplace(dp[now][coin + cd[now].first], coin + cd[now].first, now);
    }
  }

  rep(i, 1, n) { cout << *min_element(dp[i].begin(), dp[i].end()) << '\n'; }

  return 0;
}

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

int main(){
  int n,t,a,h,ans;
  float calc,min;
  cin >> n >> t >> a;
  min = 999999;
  for(int i =1;i<n+1;i++){
    cin >> h;
    calc = abs(t - (h * 0.006) - a);
    if(calc < min){
      ans = i;
      min = calc;
    }
  }
  cout << ans;
}

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

// ABC059B Comparison

int main() {
    string A, B;
    cin >> A >> B;
    if (A.length() > B.length()){
        cout << "GREATER" << endl;
    }else if (A.length() < B.length()){
        cout << "LESS" << endl;
    }else {
        for (int i = 0; i < A.length(); ++i){
            if (A[i] > B[i]){
                cout << "GREATER" << endl;
                return 0;
            }else if (A[i] < B[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}



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

void code()
{
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    ll A[m];
    for(ll i=0;i<m;i++)
    {
        cin>>A[i];
        sum+=A[i];
    }
    if(sum>n)
        cout<<"-1";
    else
        cout<<n-sum;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);  
    freopen("output.txt", "w", stdout);
    #endif
    ll t=1;
    // cin>>t;
    while(t--)
    {
        code();
    }
}

Measured memory_bytes: 3684