akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define per(i,a,b)  for(ll i=b-1;i>=a;i--)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
#define MOD 998244353
using namespace std;
/*bool isprime(ll x)
{
    for(ll i=2;(i*i)<=x;i++)
    {
        if(x%i==0) return 0;
    }
    return 1;
}
ll power(ll x,ll n)
{
    ll res=1;
    while(n>0){
    if(n%2) res=(res*x)%mod;
    x=(x*x)%mod;
    n=n/2;}
    return res;
}*/
void solve()
{
            ll n,m,k,l=0,r=0,z,sum1=0,h,res=0,a,b,c,d,x=0,y=0;
            cin>>n;
            ll ar[n];
            rep(i,0,n) cin>>ar[i];
            sort(ar,ar+n);
            double ans=ar[0];
            //cout<<ans;
            rep(i,1,n)
            {   //cout<<ans<<" ";
                ans=(double)(ans+ar[i])/2;
                //cout<<ans<<" ";
            }
            if(n==2) cout<<(double)(ar[0]+ar[1])/2;
            else
            cout<<ans;


            }

        int main()
        {
            speed_up
            ll t=1;
            //cin>>t;
            while(t--)
                solve();
        }


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

typedef long long ll;

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))

ll mod = 1000000007;

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	int ls[n];
	int lr[n];
	int l=0,r=0;
	for(int i=0;i<n;i++){
		ls[i] = l;
		if(s[i]=='#'){l++;}
	}
	for(int i=n-1;i>-1;i--){
		lr[i] = r;
		if(s[i]=='.'){r++;}
	}
	int m = l,u;
	for(int i=0;i<n;i++){
		u = s[i]=='.' ? 1:0;
		m = min(m,(ls[i]+lr[i]+u));
	}
	cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  queue<int>que;
  cin >> N >> S >> K;
  Vec(BIT,BinaryIndexedTree<int>,26,BinaryIndexedTree<int>(N));
  rep(i,0,N)BIT[S[i]-'a'].add(i,1);
  rep(i,0,K){
    cin >> A;
    if(A==1){
      cin >> B >> T;
      B--;
      BIT[S[B]-'a'].add(B,-1);
      BIT[T[0]-'a'].add(B,1);
      S[B]=T[0];
    } 
    else{
      cin >> B >> C;
      sum=0;
      B--;
      C--;
      rep(j,0,26){
        if(!B){
          if(BIT[j].sum(C))sum++;
        }
        else if(BIT[j].sum(C)-BIT[j].sum(B-1))sum++;
      }
      que.push(sum);
    }
  }
  while(!que.empty()){
    Out(que.front());
    que.pop();
  }
}



Measured memory_bytes: 53660
N = int(input())
W = [input() for _ in range(N)]

Ws = set([W[0]])
for i in range(1, N):
    if not W[i - 1][-1] == W[i][0] or W[i] in Ws:
        print("No")
        exit()
    else:
        Ws.add(W[i])

print("Yes")


Measured memory_bytes: 3060
//package Atcoder;
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int a=fs.nextInt();
		int b=fs.nextInt();
		String ans1="",ans2="";
		for(int i=1;i<=b;i++)
			ans1+=a;
		for(int i=1;i<=a;i++)
		{
			ans2=ans2+b;
		}
		if(Integer.parseInt(ans1)>=Integer.parseInt(ans2))
		{
			System.out.println(ans1);
		}
		else
			System.out.println(ans2);
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

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

int main(){
    int n;
    double a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    double f = abs(a-b);
    double t = (c+d)/2.0;
    double s = (d-c)/2.0;
    rep(i,n-1) {
        f = min(abs(f+t),abs(f-t));
    }
    if(f <= (n-1)*s) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define LL long long

#define FOR(INDEX, START, END) for (int INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (int INDEX = 0; INDEX < (COUNT); ++INDEX)

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

	vector<LL> As(N);
	vector<LL> Bs(N);
	REP(i, N) {
		cin >> As[i];
	}
	REP(i, N) {
		cin >> Bs[i];
	}

	LL sum = 0;
	LL minusSum = 0;
	LL plusSum = 0;
	vector<LL> diffs;
	diffs.reserve(N);

	LL count = 0;
	REP(i, N) {
		LL diff = As[i] - Bs[i];
		if (diff < 0) {
			minusSum += diff;
			++count;
		}
		else if (diff > 0){
			plusSum += diff;
			diffs.push_back(diff);
		}
	}

	if (-minusSum > plusSum) {
		cout << -1 << endl;
		return 0;
	}

	sort(diffs.begin(), diffs.end(), greater<LL>());

	for (LL diff : diffs) {
		if (minusSum >= 0) {
			break;
		}

		minusSum += diff;
		count++;
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 2176
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main(void){
  int N;
  cin >> N;
  long long T[N], A[N];

  REP(i, N) cin >> T[i] >> A[i];
  long long dp[N][2];
  long long t, a;
  long long k, dt, da;

  dp[0][0] = T[0]; dp[0][1] = A[0];

  FOR(i, 1, N){
    t = dp[i-1][0];
    a = dp[i-1][1];
    k = max(a/A[i], t/T[i]);
    do{
      dt = k*T[i]-t;
      da = k*A[i]-a;
      k++;
    }while(!(dt >= 0 && da >= 0));
    dp[i][0] = t+dt;
    dp[i][1] = a+da;
  }

  cout << dp[N-1][0]+dp[N-1][1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<29;
const ll  longinf = 1LL<<60;
const int mod=1000000007;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  ll n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  n--;
  b-=a;
  rep(i,n+1){
    ll ma=d*i-(n-i)*c;
    ll mi=c*i-(n-i)*d;
    if(mi<=b&&b<=ma){
      cout<<"YES"<<endl;
      return 0;
      }
    }
  cout<<"NO"<<endl;
  return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

bool check(vector<int> &a, int x, int k){
    int req = 0;
    for(int i = 0 ; i < a.size() ; i++){
        if(a[i] > x)
            req += a[i]/x;
    }
    if(req > k)
        return false;
    return true;
}

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int &i : a){
    	cin >> i;
    }
    int ans = 0,low = 1, high = 1e18, mid;
    while(low <= high){
        mid = (low+high)/2;
        if(check(a, mid, k)){
            ans = mid;
            high = mid-1;   
        }
        else{
            low = mid+1;
        }
    }
    cout << ans << '\n';
}

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


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

struct edge{
	int to;
	int num;
};

vector<vector<edge>> G;
vector<int> color;

void dfs(int v, int col, int p){
	int k = 1;
	for (auto nextv: G[v]){
		//親だったらスルー
		if (nextv.to == p){
			continue;
		}
		//親と同じ色だったらkをインクリメント
		if(col == k){
			k++;
		}
		color[nextv.num] = k;
		k++;
		dfs(nextv.to, color[nextv.num], v);
	}
}
int main(){
	int N;
	cin >> N;
	G.resize(N);
	color.resize(N-1);
	rep(i,N-1){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(edge({b,i}));
		G[b].push_back(edge({a,i}));
	}
	
	dfs(0, -1, -1);
	int ans = 0;
	rep(i,N){
		ans = max(ans, int(G[i].size()));
	}
	
	cout << ans << endl;
	
	rep(i,N-1){
		cout << color[i] << endl;
	}
    return 0;
}

Measured memory_bytes: 8320
#include <stdio.h>
int main(void){
    long int a,b,t1,t2,gcd[100],lcm[100],i=0,j;
    while(scanf("%d %d",&a,&b)!=EOF){
    	t1=a;
    	t2=b;
        while(a!=0&&b!=0){
            if(a>b){
                a-=b;
            } else {
                b-=a;
            }
        }
        if(a==0) {
            gcd[i]=b;
        } else{
            gcd[i]=a;
        }
        lcm[i]=t1*t2/gcd[i];
        i++;
    }
    for(j=0;j<i;j++) printf("%d %d\n",gcd[j],lcm[j]);
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int n1 = n - 1;
		int sum = 0;
		int bb = Integer.MAX_VALUE;
		for (int i = 0; i < n1; i++) {
			// iの値を決める
			int b = sc.nextInt();
			if (bb >= b) {
				sum += b;
			} else {
				sum += bb;
			}
			bb = b;
		}
		sum += bb;
		System.out.println(sum);
	}
}


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


using namespace std;


int main() {
	long long int N, A, B;
	cin >> N >> A >> B;
	vector<long long int>X( N );
	long long int ans = 0;
	for( size_t i = 0; i < N; i++ ) {
		cin >> X[i];
		if( i ) {
			ans += min( B, (X[i] - X[i - 1] )*A );
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())
#n = ip()                                     #入力整数1つ
n,m= (int(i) for i in input().split())       #入力整数横2つ以上
#b = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
b = []
a = []
for i in range(n):
    c,d = (int(i) for i in input().split())
    a.append([c,d])
a.sort(key=lambda x:(x[0]))
s = 0
sp = 0
for i in range(n):
  #  print(s,sp)
    add = a[i][1]
    addprice = a[i][0]
    if s+add>=m:
        amo  = m-s
        s+=amo
        sp+=(addprice*amo)
 #       print(s,sp)
    else:
        s+=add
        sp+=(add*addprice)
    if m<=s: break
print(sp)


"""
while m>s:
    minpos = a.index(min(set(a)))
    if s+b[minpos]>=m:
        amo = m-s
  #      print(amo)
        s+=amo
        sp+=(a[minpos]*amo)
 #       print(s,sp)
 #       print(a,b)
    else:
        s+=b[minpos]
        sp+=(a[minpos]*b[minpos])
        a.pop(minpos)
        b.pop(minpos)
#        print(s,sp)
 #       print(a,b)
print(sp)
"""

Measured memory_bytes: 31216
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func maxs(x ...int) int {
	mv := x[0]
	for _, v := range x[1:] {
		if v > mv {
			mv = v
		}
	}
	return mv
}

func main() {
	n := scanInt()
	a, b, c := make([]int, n), make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a[i], b[i], c[i] = scanInt(), scanInt(), scanInt()
	}

	aa, ab, ac := make([]int, n+1), make([]int, n+1), make([]int, n+1)
	for i := 1; i <= n; i++ {
		aa[i] = a[i-1] + maxs(ab[i-1], ac[i-1])
		ab[i] = b[i-1] + maxs(aa[i-1], ac[i-1])
		ac[i] = c[i-1] + maxs(aa[i-1], ab[i-1])
	}
	fmt.Println(maxs(aa[n], ab[n], ac[n]))
}


Measured memory_bytes: 7168
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll h,w;
  cin >> h >> w;
  string s[h];
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  for(int i=0;i<w+2;i++){
    cout << '#';
  }
  cout << endl;
  for(int i=0;i<h;i++){
    cout << '#';
    for(int j=0;j<w;j++){
      cout << s[i][j];
    }
    cout << "#\n";
  }
  for(int i=0;i<w+2;i++){
    cout << '#';
  }
  cout << endl;
}


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

int main(){
  long long N, K, Q;
  cin >> N >> K >> Q;
  vector<long long > A(Q); // <- N Q mistake
  vector<long long > score(N, K-Q);
  map<long long, long long> test;
  // cout << score.at(2) << endl;
  rep(i,Q){
    cin >> A.at(i);
    //score.at(A.at(i)-1)++;
    test[A.at(i)-1]++;
    //cout << A.at(i) << " " << score.at(A.at(i)-1) << endl;
  }

  rep(i,N){
    //if(score.at(i) > 0) cout << "Yes" << endl;
    if(test[i] + K - Q > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }


  return 0;
}


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

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct edge{
    ll dm,cd,ct;
    bool operator<(const edge& right) const{
        return ct<right.ct;
    }
};

template <class T> bool BF(int n,int m,vector<edge>& es,vector<T>& d,int s,int t){
    T x=numeric_limits<T>::max()/2;
    d.resize(n,x);
    d[s]=0;
    T mx;
    fr(i,2*n){
        fr(j,m){
            edge e=es[j];
            if(d[e.cd]>d[e.dm]+e.ct){
                //cout<<e.dm<<" "<<e.cd<<" "<<d[e.cd]<<" "<<d[e.dm]+e.ct<<endl;
                d[e.cd]=d[e.dm]+e.ct;
                if(i>=n-1&&d[e.cd]<x/2) d[e.cd]=-x;
            }
        }
    }
    return d[t]==-x;
}

class ECoinsRespawn {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        ll n,m,p,a,b,c;
        in>>n>>m>>p;
        vector<edge> es(m);
        fr(i,m) in>>a>>b>>c,es[i]=(edge){a-1,b-1,p-c};
        vector<ll> d;
        if(BF(n,m,es,d,0,n-1)) out<<-1<<endl;
        else out<<max(0ll,-d[n-1])<<endl;
    }
};

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


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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=600+5;
int n,m;
char s[N][N];
bool b[N][N];
int left_s[N][N],up_s[N][N],left_s1[N][N];

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	cin>>n>>m;
	rep(i,1,n)scanf("%s",s[i]+1);
	rep(i,1,n)
	rep(j,1,m)b[i+m-j][i+j]=s[i][j]=='#';
	rep(i,1,N-1)
	rep(j,1,N-1)
	{
		left_s[i][j]=left_s[i][j-1]+b[i][j];
		up_s[i][j]=up_s[i-1][j]+b[i][j];
	}
	s64 ans=0;
	rep(k,1,n-1+m-1)
	{
		rep(i,1,N-1)
		rep(j,1,N-1)left_s1[i][j]=left_s1[i][j-1]+(j>=k&&b[i][j]&&b[i][j-k]);
		rep(i,1,n)
		rep(j,1,m)
		if(s[i][j]=='#')
		{
			int x=i+m-j,y=i+j;
			if(x<=k)continue;
			if(y>k&&b[x][y-k])ans+=left_s[x-k][y]-left_s[x-k][y-k-1];
			if(b[x-k][y])
			{
				if(y>k)ans+=up_s[x-1][y-k]-up_s[x-k][y-k];
				if(y+k<N)ans+=up_s[x-1][y+k]-up_s[x-k][y+k];
			}
			ans+=left_s1[x-k][min(N-1,y+k)]-left_s1[x-k][y-1];
		//	if(y+k<N&&b[x][y+k])ans+=left_s[x-k][y+k]-left_s[x-k][y-1];
		}
	}
	cout<<ans;
}


Measured memory_bytes: 5120
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<random>
using namespace std;
int inf = 1e9;

int main() {

  double al;
  double ar;
  double au;
  double ad;
  double bl;
  double br;
  double bu;
  double bd;
  while( cin >> al >> ad >> ar >> au >> bl >> bd >> br >> bu ){
    bool f = false;

    if( al <= br && ar >= bl && ad <= bu && au >= bd ) f = true;

    cout << ( f ? "YES" : "NO" ) << endl;
  }

  return 0;
}




// EOF

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int n, k;
    cin >> n >> k;
    if(n / 2 + n % 2 >= k){
        print("YES");
    } else{
        print("NO");
    }
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,b[101],a[101],s=0;

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<n;++i)
    {
        scanf("%d",&b[i]);
        a[i]=INT_MAX;
    }
    a[n]=INT_MAX;
}

void process()
{
    for (int i=1;i<n;++i)
    {
        a[i]=min(a[i],b[i]);
        a[i+1]=min(a[i+1],b[i]);
    }
    for (int i=1;i<=n;++i)
    {
        s+=a[i];
    }
    cout<<s;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 256
from collections import deque


def bfs(n, adj, source):
	dist = [-1] * n
	dist[source] = 0
	q = deque([source])
	mx = 0
	idx = 0
	while q:
		cur = q.popleft()
		for nxt, d in adj[cur]:
			if dist[nxt] < 0:
				dist[nxt] = dist[cur] + d
				if dist[nxt] > mx:
					mx = dist[nxt]
					idx = nxt
				q.append(nxt)
	return idx, mx, dist


def main():
	n, *L = map(int, open(0).read().split())
	adj = [[] for _ in range(n)]
	for a, b, c in zip(*[iter(L)] * 3):
		adj[a].append((b, c))
		adj[b].append((a, c))
	idx1, _, _ = bfs(n, adj, 0)
	idx2, _, dist1 = bfs(n, adj, idx1)
	idx3, _, dist2 = bfs(n, adj, idx2)
	ans = [max(x, y) for x, y in zip(dist1, dist2)]
	print("\n".join(map(str, ans)))


if __name__ == '__main__':
	main()



Measured memory_bytes: 11040
#include <iostream>
#include <algorithm>

// 0 for Weight index, 1 for Value index
long long arr[101][2];

// The first for Weight, the second for Value
// Notice that all the table is initialized to zero,
// because it's defined in global scope.
// Let's benefit from that.
long long table[100002][101];

int main()
{
	int n, w;
	std::cin >> n >> w;
	for (int i = 0; i < n; ++i)
		std::cin >> arr[i][0] >> arr[i][1];
	// It sets the initial row.
	for (int i = 0; i <= w; ++i)
	{
		if (arr[0][0] <= i)
			table[i][0] = arr[0][1];
	}
	// The outer loop for the elements.
	for (int j = 1; j < n; ++j)
	{
		// the inner loop for the weight.
		for (int i = 0; i <= w; ++i)
		{
			if (arr[j][0] > i)
				table[i][j] = table[i][j - 1];
			else
				table[i][j] = std::max(table[i][j - 1], static_cast<long long>(arr[j][1]) + table[i - arr[j][0]][j - 1]);
		}
	}
	std::cout << table[w][n - 1] << '\n';
	return 0;
}

Measured memory_bytes: 79104
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try {
			//Input
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str;
			int width, height, repeat;
			int area;

			while ((str = br.readLine()) != null) {
				//Input Initialize
				width = Integer.parseInt(str);
				repeat = 600 / width;
				height = 0; area = 0;
				//Integral
				for (int i = 0; i < repeat; i++) {
					height = (i * width) * (i * width) * width;
					area += height;
				}
				System.out.println(area);
			}
		} catch (Exception e) {
			System.out.println("error");
		}

	}

}

Measured memory_bytes: 24316
tmp = list(map(int,(input().split())))
n   = tmp[0]
k   = tmp[1]
s   = input()

bound = 0
cnt = 0
score = 0
for i in range(1,n):
  if s[i] != s[i-1]:
    bound += 1
    score += cnt
    cnt = 0
  else:
    cnt += 1
    if i == n-1:
      score += cnt

if bound <= k*2:
  score = n - 1
else:
  score += k * 2

print (score)

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

int main(void){
    double a,b,c,s,l,h,r,cl;
    scanf("%lf%lf%lf",&a,&b,&c);

    r=(90.0-c)/180.0*M_PI;
    h=b*cos(r);
    s=(a*h)/2.0;
    cl=a-b*sin(r);
    l=a+b+sqrt(cl*cl+h*h);

    printf("%.8lf\n%.8lf\n%.8lf\n",s,l,h);

    return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,a[100],n,minj,count=0;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++)if(a[j]<a[minj])minj=j;
    if(i!=minj){
      swap(a[i],a[minj]);
      count++;
    }
  }
  
  for(i=0;i<n;i++){
    if(i==n-1)cout<<a[i];
    else cout<<a[i]<<" ";
  }
  cout<<endl;
  cout<<count<<endl;
  return 0;
}

    



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  vector<vector<int>>t(N,vector<int>(3));
  for(int i=0;i<N;i++){
    cin>>t[i][0]>>t[i][1]>>t[i][2];
  }
  vector<vector<int>>dp(N+1,vector<int>(3));

  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j!=k){chmax(dp[i+1][k],dp[i][j]+t[i][k]);}
      }
    }
  }
  cout<<max({dp[N][0],dp[N][1],dp[N][2]})<<endl;
  return 0;  
}

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

int main(){
    int N;
    cin >> N;
    int a[100];
    for(int i=0;i<N;i++)
        cin >> a[i];
    //灰茶緑水青黄橙赤任意
    int C[9] = {};
    for(int i=0;i<N;i++){
        if(a[i]<400) C[0]++;
        else if(a[i]<800) C[1]++;
        else if(a[i]<1200) C[2]++;
        else if(a[i]<1600) C[3]++;
        else if(a[i]<2000) C[4]++;
        else if(a[i]<2400) C[5]++;
        else if(a[i]<2800) C[6]++;
        else if(a[i]<3200) C[7]++;
        else C[8]++;
    }
    //何種類の色が存在するか
    int type = 0;
    for(int i=0;i<8;i++){
        if(C[i] != 0)
            type++;
    }
    //最小値 = type
    //最大値 = type + 任意（C[8]）
    //任意色のみの場合に注意
    if(type==0 && C[8]>0)
        cout << 1 << ' ' << type + C[8] << endl;
    else
        cout << type << ' ' << type + C[8] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int H, N, a;
    int sum = 0;
    cin >> H >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> a;
        sum += a;
    }
    if (H <= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
 
string rotate(string s){
  return s.substr(1)+s[0];
}
 
int main() {
  string s, t;
  cin >> s >> t;
  int sz = s.size();
  for (int i=0; i<sz; i++){
    if (s==t){
      cout << "Yes" << endl;
      return 0;
    }
    
    s = rotate(s);
  }
  
  cout << "No" << endl;
  return 0;
  
}

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

using namespace std;

//#define FILE_IO

typedef long long LL;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif
    /**
    k * (k + 1) / 2 >= n
    k^2 + k >= 2n
    k^2 + k - 2n >= 0
    k12 = (-1 +- sqrt(1 + 8n)) / 2
    **/

    LL N;
    scanf("%lld", &N);
    LL K = ceil( (-1 + sqrt(1 + 8 * N)) / 2);
    printf("%lld\n", K);

    return 0;
}


Measured memory_bytes: 256
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on





auto Main() {
	int h, w, k;
	cin>>h>>w>>k;
	array<array<char, 6>, 6> G {};
	FOR(i,0,h) FOR(j,0,w) cin>>G[i][j];

	const auto Count = [&](auto const& g) {
		int ans = 0;
		FOR(i,0,h)FOR(j,0,w) ans += (g[i][j]=='#');
		return ans;
	};

	
	using Bs = bitset<6>;

	int ans = 0;
	FOR(i, 0, 1<<h) {
		Bs bi = i;
		FOR(j,0,1<<w) {
			Bs bj = j;
			auto g = G;
			FOR(ii,0,h) {
				FOR(jj,0,w) {
					if(bi[ii] or bj[jj]) g[ii][jj]='0';
				}
			}
			if(Count(g)==k) ans++;
		}
	}
	cout<<ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define REV(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq  priority_queue<int>
using ll = long long;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 2000000000;
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/*---------------------template----------------------*/
/*----------------------end--------------------------*/
/* --------------------ライブラリ--------------------*/
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
/*---------------------臨時関数----------------------*/
/*----------------------end-------------------------*/
signed main(){
  int N;cin>>N;
  cout<<N*(N+1)/2<<endl;
}


Measured memory_bytes: 3648
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto a = readLongs();
    DList!long b;
    foreach(i; iota(n)) {
        if(i % 2 == 0) {
            b.insertBack(a[i]);
        } else {
            b.insertFront(a[i]);
        }
    }
    if(n % 2 == 0) { 
        writeln(b[].map!(to!string).join(" "));
    } else {
        writeln(b[].retro().map!(to!string).join(" "));
    }
}



Measured memory_bytes: 24432
import sys
from io import StringIO
# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=list(input())
    B=list(input())
    C=list(input())

    W=[[None]*3 for i in range(N)]
    for j in range(N):
        for i,k in zip([A,B,C],[0,1,2]):
            W[j][k]=i[j]

    val=0
    for k in W:
        mc=Counter(k).most_common()[0][1]
        val+=3-mc

    print(val)





resolve()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using ll = long long;
using ull = unsigned long long;
ull mod = 1e9 + 7;
using namespace std;


int main(){

    int ans = 0;
    int N; cin >> N;
    vector<int> d(N); rep(i, N)cin >> d[i];
    rep(i, N){
        rep(j, N){
        if(i >= j)continue;
        ans += (d[i] * d[j]); 
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
   string s,t;
   cin>>s>>t;
   int l1=s.length();
   string test="";
   for(int i=0;i<l1;i++)
      test=test+t[i];
    if(test==s)
       cout<<"Yes";
    else cout<<"No";
 return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>

using namespace std;

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

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

    sort(sorted_X, sorted_X + N);
    for (int i = 0; i < N; ++i) {
        int mode_index = (N - 1) / 2;
        if (X[i] <= sorted_X[mode_index]) {
            cout << sorted_X[mode_index + 1] << endl;
        } else {
            cout << sorted_X[mode_index] << endl;
        }
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int N,Q;
ll A[101010],sum[101010],sumE[101010],sumO[101010];

int main(){
  cin>>N>>Q;
  for(int i=1;i<=N;i++){
    cin>>A[i];
    sum[i]=sum[i-1]+A[i];
    sumE[i]=sumE[i-1]+(i%2==0?A[i]:0);
    sumO[i]=sumO[i-1]+(i%2?A[i]:0);
  }
  while(Q--){
    int X; cin>>X;
    ll res=0;
    int ok=0,ng=N+1;
    while(abs(ng-ok)>1){
      int mid=(ok+ng)/2;
      int l=N-mid+1,r=N-mid/2+(mid%2==0);
      if(abs(A[l]-X)<=(abs(A[r]-X))) ok=mid;
      else ng=mid;
    }
    int r=N-ok/2+(ok%2==0),l=N-ok+1;
    if(r==l){
      if(N%2) cout<<sumO[N]<<endl;
      else cout<<sumE[N]<<endl;
      continue;
    }
    res=sum[N]-sum[r-1];
    if((l-1)%2){
      if(ok%2) res+=sumE[l-1];
      else res+=sumO[l-1];
    }else{
      if(ok%2) res+=sumO[l-1];
      else res+=sumE[l-1];
    }
    cout<<res<<endl;
  }
  return 0;
}


Measured memory_bytes: 4864
ret = []
while True:
   n, x = map(int, raw_input().split())
   num_arr = [i for i in range(1, n+1)]
   if (n, x) == (0, 0):
       break

   cnt = 0
   for i in range(len(num_arr)):
       for j in range(i + 1, len(num_arr)):
           k_flg = False
           for k in range(j + 1, len(num_arr)):
               work = num_arr[i] + num_arr[j] + num_arr[k]
               if x == work:
                   cnt += 1
                   k_flg = True
                   break
   ret += [cnt]
for i in ret:
    print i


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


signed main()
{
    int n,tot=1,a[200005];

    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
    }

    for (int i=1; i<=n; i++)
    {
        if (a[i]==0)
        {
            cout<<0;
            return 0;
        }
    }
    for (int i=1; i<=n; i++)
    {
        if (tot>inf/a[i])
        {
            cout<<-1;
            return 0;
        }
        else
        {
            tot*=a[i];
        }
    }
    cout<<tot<<endl;

    return 0;
}



Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false);

int main()
{
	string s, t;
	cin >> s;
	cin >> t;
	int l = s.length();
	int flag = 1;
	for(int i = 0; i < l; i++){
		if(s[i]!=t[i]){
			flag = 0;
			break;
		}
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}



Measured memory_bytes: 3632
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define erep(i,n) for (int i = 1; i <= (n); ++i)
#define brep(i,n) for (int i = n; i >= 0; i--)
#define PI 3.14159265359
using namespace std;
using P = pair<int,int>;
using ll = long long;
using Graph = vector<vector<int> > ;
const int INF = 100005;
const int MAX_K = 55;
const int MAX_W = 200005; 
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// ユークリッド互除法
unsigned gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}
*/

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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  int n;
  string s;
  cin >> n >> s;
  ll b,g,r;
  b = g = r = 0;
  rep(i,n){
    if(s[i] == 'B') b++;
    if(s[i] == 'R') r++;
    if(s[i] == 'G') g++;
  }
  ll ans = b*g*r;
  //cout << ans << endl;
  rep(i,n-2){
    for(int j = i+1; j<n-1;j++){
      int k = 2*j-i;
      if(k>=n) continue;
      if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]) ans--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

#define vcitr vector<int>::iterator
#define vcsitr vector<string>::iterator
#define mapcitr map<char, int>::iterator
#define mapsitr map<string, int>::iterator

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

int main () {
	double lv;
	
	while (cin >> lv) {
		double t = lv/9.8;
		double y = 4.9 * t*t;
		
		int i=1;
		while (1) {
			int f = 5*i-5;
			
			if (y <= (double)f) break;
			
			i++;
		}
		cout << i << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, n)
    {
        rep(j, m)
        {
            int count = 0;
            if (a[i][j] != '.')
                continue;
            rep(k, 8)
            {
                if (0 <= i + dx[k] && i + dx[k] < n && 0 <= j + dy[k] && j + dy[k] < m)
                {
                    if (a[i + dx[k]][j + dy[k]] == '#')
                        count++;
                }
            }
            a[i][j] = (char)(count + '0');
        }
    }
    rep(i, n)
    {
        cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int xp=1e9+7;
int d[1002][1002],n,m;
char a[1002][1002];
int main()
{
    cin>>n>>m;
    d[1][0]=1;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='.')
            d[i][j]=(d[i-1][j]+d[i][j-1])%xp;
    }
    cout<<d[n][m];
}


Measured memory_bytes: 5120
s = input().split()
intX = int(s[0])
intN = int(s[1])
inList = list(map(int,input().split()))

iCnt = 101
minDiv = 101
rCnt = -2
div = 0
while iCnt > -2 :
    if (inList.count(iCnt) == 0) : 
        div = abs(intX - iCnt)
        if (minDiv >= div) :   
            minDiv = div
            rCnt = iCnt
    iCnt -= 1
print(rCnt)

Measured memory_bytes: 9204
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

	int w,h;
int dy[]={-1,0,1,0},dx[]={0,-1,0,1};
int dfs(vvi &f,pii from,int cnt,pii goal){
	if(from==goal){
		return cnt;
	}
	if(cnt==10){
		return INT_MAX;
	}
	int ret=INT_MAX;
	REP(d,4){
		int y=from.first;
		int x=from.second;
		int ny=from.first+dy[d];
		int nx=from.second+dx[d];
		if(ny>=0&&nx>=0&&ny<h&&nx<w&&f[ny][nx]==1)continue;
		vvi nf(f);
		while(ny>=0&&nx>=0&&ny<h&&nx<w){
			if(nf[ny][nx]==1){
				nf[ny][nx]=0;
				break;
			}else if(nf[ny][nx]==3){
				y=ny;x=nx;
				break;
			}
			y=ny;x=nx;
			ny+=dy[d];
			nx+=dx[d];
		}
		if(ny>=0&&nx>=0&&ny<h&&nx<w){
			ret=min(ret,dfs(nf,make_pair(y,x),cnt+1,goal));
		}
	}
	return ret;
}

int main(){
	while(cin>>w>>h,w|h){
		vvi f(h,vi(w));
		pii start,goal;
		REP(i,h){
			REP(j,w){
				cin>>f[i][j];
				if(f[i][j]==2){
					start=make_pair(i,j);
				}
				if(f[i][j]==3){
					goal=make_pair(i,j);
				}
			}
		}
		int ans=dfs(f,start,0,goal);
		cout<<(ans==INT_MAX?-1:ans)<<endl;
	}
}

Measured memory_bytes: 1276