akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector <int> A(N + 1);
    rep (i, N) cin >> A[i];
    A[N] = A[N - 1];

    int ans = 0;
    bool inc = false, dec = false;
    rep (i, N) {
        if (!inc && !dec) {
            ans += (A[i] != A[i + 1]) || (i == N - 1);
            if (A[i] < A[i + 1]) inc = true;
            if (A[i] > A[i + 1]) dec = true;
        }
        else if (inc && A[i] > A[i + 1]) inc = false;
        else if (A[i] < A[i + 1]) dec = false;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 100001
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;


template<typename T>
T pow(T i, T n){
    T re;
    if(n == 0) return 1;
    re = pow(i, n / 2);
    if(n % 2 == 0){
        return re * re;
    }else{
        return i * re * re;
    }
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll N, x;
ll A[MAXN], B[MAXN] ;

int main(){
    string S;
    cin >> S;
    int length = S.length();
    bool flag = true;//true :first, false :second 
    if(length % 2 == 0) flag = false;
    if(S[0] == S[length - 1]) flag = !flag;
    if(flag) printf("First\n");
    else printf("Second\n");
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N, K; cin >> N >> K;
	vector<int> h(N);
	vector<int> dp(N);
	rep(i, N)cin >> h[i];
	REP(i, 1, N, 1) {
		dp[i] = dp[i - 1] + abs(h[i - 1] - h[i]);
		if (i > 1) for (int j = 2; j <= min(K, i); ++j)dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
	}
	cout << dp[N - 1] << endl;
	cin >> N;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
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 sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const double pi = acos(-1.0);
template <class A>ostream & operator<<(ostream & o, const vector<A> & p) { o << "{"; for (int i = 0; i < (int)p.size(); ++i)o << (i > 0 ? ", " : "") << p[i]; o << "}"; return o; }
template <class A, class B>ostream & operator<<(ostream & o, const pair<A, B> & p) { o << "{" << p.first << ", " << p.second << "}"; return o; }
template <class A, class B>ostream& operator<<(ostream & o, const map<A, B> & p) { o << "{"; for (auto it = p.begin(); it != p.end(); ++it) o << (it != p.begin() ? ", " : "") << *it; o << "}"; return o; }
template <class A>ostream & operator<<(ostream & o, const set<A> & p) { o << "{"; for (auto it = p.begin(); it != p.end(); ++it) o << (it != p.begin() ? ", " : "") << *it; o << "}"; return o; }
void print() { cerr << endl; }
template <class H> void print(H && h) { cerr << h << endl; }
template <class H, class... T> void print(H && h, T && ... t) { cerr << h << " "; print(forward<T>(t)...); }

int main() {
	double r1, r2; cin >> r1 >> r2;
	printf("%.20f\n", 1 / (1 / r1 + 1 / r2));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision;
// #define int cpp_int
using namespace std;

#define fastio 			ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int 			long long
#define ll 				long long
#define ld 				long double
#define vi 				vector<int>
#define pii 			pair<int,int>
#define vpii 			vector< pair<int,int> >
#define uset			unordered_set
#define umap 			unordered_map
#define maxpq 			priority_queue<int>
#define minpq			priority_queue<int,vi,greater<int>()>

#define all(v) 			v.begin(),v.end()
#define part(v,s,e)		v.begin()+s,v.begin()+e
#define rev(v)			reverse(v.begin(),v.end())
#define sz(x)			(int)x.size()
#define def(v)			memset(v,-1,sizeof(v));
#define def0(v)			memset(v,0,sizeof(v));
#define minv(a)			*min_element(all(a))
#define maxv(a)			*max_element(all(a))
#define sumv(a)			accumulate(all(a),0)

#define	lb				lower_bound
#define	ub				upper_bound
#define	desc			greater<int>()
#define	pb				emplace_back
#define	mp				make_pair
#define	F				first
#define	S				second

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a/(__gcd(a,b)))*b

#define setbits(x) 		__builtin_popcountll(x)
#define zerobits(x)		__builtin_ctzll(x)

#define ip(v)	 		for(auto& i:v)	cin>>i;
#define op(v) 			for(auto i:v)	cout<<i<<" ";cout<<endl;
#define deb(x) 			cout <<"Value of " #x << " : " << x << endl;


void solve()
{	

	string a,b;
	cin>>a>>b;

	int ans=0;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]==b[i])
			ans++;
	}
	cout<<ans<<endl;

}	

int32_t main()
{

	fastio
	cout<<setprecision(15)<<fixed;



	int t=1;
	// cin>>t;
	
	for(int i=1;i<=t;i++)
	{
		// cout<<"Case "<<i<<" : "<<endl;
		solve();
	}
	
	#ifndef ONLINE_JUDGE	
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	#endif

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=0
b=0
ab=0
ba=0
bet=0
for i in range(n):
  s=input()
  ab+=s.count('AB')
  if s[len(s)-1]=='A' and s[0]!='B':
    a+=1
  if s[0]=='B' and s[-1]!='A':
    b+=1
  if s[-1]=='A' and s[0]=='B':
    ba+=1
if a!=0 and b!=0:
  bet+=ba+1
  bet+=min(a-1,b-1)
elif a==0 and b==0:
  if ba>0:
    bet+=ba-1
else:
  bet+=ba
print(ab+bet)
  

Measured memory_bytes: 3064
N = int(input())
A = "abcdefghijklmnopqrstuvwxyz"
x = [A[(N-1)%26]]
N -= 26
i = 1
while N > 0:
    x.append(A[((N-1)//(26**i))%26])
    i += 1
    N -= 26**i
ans = ""
for i in range(1,len(x)+1):
    ans += x[-i]
print(ans)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)(0);
}
int a[300010];

int main() {
	int n,k,l,r,x;
	int ans;

	cin >> n >> k ;

	segtree<int, op, e> seg(300010);
	rep(i,n) cin >> a[i];
	rep(i,n) {
		x=a[i];
		l=max(x-k,0);
		r=min(x+k+1,300010);
		ans=seg.prod(l,r)+1;
		seg.set(x,ans);
	}
	ans=seg.prod(0,300010);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8540
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        long x = Long.parseLong(s);

        long base = 2 * (x / 11);

        long mod = x % 11;

        out.println(
            mod == 0 ? base :
            mod <= 6 ? base + 1 : base + 2);

        out.flush();
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int pow_10(int a) {
	int answer = 1;
	for (int i = 0; i < a; i++) {
		answer *= 10;
	}
	return answer;
}
int main()
{
	int n;
	cin >> n;
	string ketasuu = to_string(n);
	int answer = 0;

	if (ketasuu.length() % 2 > 0) {
		answer += n - pow_10(ketasuu.length()-1) + 1;
	}
	for (int i = 1; i < ketasuu.length(); i+=2) {
		answer += 9 * pow_10(i) / 10;
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

b = sorted([v[i]-c[i] for i in range(n)],reverse=True)
ans = 0
for i in range(len(b)):
    if b[i] > 0:
        ans += b[i]
    else:
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	char A[101];
	char B[101];
	char C[101];
	scanf("%s",A);
	scanf("%s",B);
	scanf("%s",C);

	int a=0;
	int b=0;
	int c=0;

	int player = 0;
	while(true){
		if(player==0){
			if(a==strlen(A)){
				printf("A\n");
				return 0;
			}
			player = A[a] - 'a';
			a++;
		}else if(player==1){
			if(b==strlen(B)){
				printf("B\n");
				return 0;
			}
			player = B[b] - 'a';
			b++;
		}else if(player==2){
			if(c==strlen(C)){
				printf("C\n");
				return 0;
			}
			player = C[c] - 'a';
			c++;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int main()
{
        string str;
        int sum_v = 0, sum_n = 0, i = 0;
        int tmp_v, tmp_n;
        double avg;
        vector< string > vec;

        while ( cin >> str )
        {
                vec = split( str, ',' );
                tmp_v = atoi( vec[0].c_str() );
                tmp_n = atoi( vec[1].c_str() );
                sum_v = sum_v + tmp_v * tmp_n;
                sum_n = sum_n + tmp_n;
                i++;
        }

        avg = 1.0 * sum_n / i;
        avg = avg - sum_n / i;
        if ( avg >= 0.5 )
                sum_n = sum_n / i + 1;
        else
                sum_n = sum_n / i;

        cout << sum_v << endl;
        cout << sum_n << endl;

        return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	long long ans = 0;
	for(long long x = 1; x<n;x++) {
		for(long long y = x+1;y<n;y++) {
			if(x * y < n) ans+=2;
			else break;
		}
	}
	long long ret = 1;
	while(ret*ret < n) {
		ans++;
		ret++;
	}
	cout<<ans;
}
	


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

void solve() {
    int K;
    cin >> K;
    queue<ull> q;
    for (int i = 1; i < 10; ++i) {
        q.push(i);
    }
    int k = 0;
    ull ans = 0;
    while (k < K) {
        ans = q.front();
        q.pop();
        ull mod = ans % 10;
        ull ten = ans * 10;
        if (mod == 0) {
            q.push(ten);
            q.push(ten + 1);
        } else if (mod < 9) {
            for (int i = 0; i < 3; ++i) {
                q.push(ten + mod - 1 + i);
            }
        } else {
            q.push(ten + 8);
            q.push(ten + 9);
        }
        ++k;
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Edge{
  int dst, index;
  bool b;
  Edge(int d) : dst(d) {}
  Edge(int d, int idx) : dst(d), index(idx), b(false) {}
};
typedef vector<Edge> Node;
typedef vector<Node> Graph;
void update(int& x, int y){ if(x < y) x = y; }

int main(){
  int N, M;
  while(cin >> N >> M){
    Graph G(N);
    Graph G_inv(N);
    REP(i, M){
      int a, b; cin >> a >> b;
      a--; b--;
      G[a].push_back(Edge(b, i + 1));
      G_inv[b].push_back(Edge(a, i + 1));
    }
    vector<int> dp(N);
    REP(u, N){
      FORIT(e, G[u]){
        update(dp[e->dst], dp[u] + 1);
      }
    }
    int max_height = 0;
    REP(i, N) update(max_height, dp[i]);
    vector<bool> use(N);
    REP(i, N) if(max_height == dp[i]) use[i] = true;
    map<int, int> m;
    for(int i = N - 1; i >= 0; i--)if(use[i]){
      FORIT(e, G_inv[i]){
        if(dp[e->dst] + 1 == dp[i]){
          e->b = true;
          m[dp[e->dst]]++;
          use[e->dst] = true;
        }
      }
    }
    vector<int> ans;
    REP(i, N)FORIT(e, G_inv[i])if(e->b && m[dp[e->dst]] == 1){
      ans.push_back(e->index);
    }
    sort(ans.begin(), ans.end());
    if(ans.empty()){
      cout << -1 << endl;
    }else{
      REP(i, ans.size()) cout << ans[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 17704
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;

int main(){

ll x;cin>>x;
ll m=100,y=0;
while(m<x){
    m = m*1.01;
    y++;
}
cout<<y<<endl;
    return 0;
}

Measured memory_bytes: 3636
import numpy
N = int(input())
a = [int(i) for i in input().split()]
b = 0
i = 0
while i < N:
    if a[i] % 2 == 0:
        b = b + 1
        a[i] = a[i] / 2
    else:
        i = i+1

print(b)

Measured memory_bytes: 19240
#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;

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	rep(i,N){
		cin >> p[i];
	}
	
	int ans = 0;
	
	REP(i,N-2){
		if (p[i] > min(p[i+1],p[i-1]) && p[i] < max(p[i+1],p[i-1]) ){
			ans++;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <set>


using namespace std;


int main() {
	int N; cin >> N;
	vector<pair<int, int>> blue(N), red(N);
	vector<bool> used(N);
	for (int i = 0; i < N; i++) cin >> red[i].first >> red[i].second;
	for (int i = 0; i < N; i++) cin >> blue[i].first >> blue[i].second;
	sort(red.begin(), red.end());
	sort(blue.begin(), blue.end());

	int pairs = 0;
	for (auto p : blue) {
		int selidx = -1;
		for (int i = 0; i < red.size(); i++) if (used[i] == false && red[i].first < p.first && red[i].second < p.second){
			if (selidx == -1) selidx = i;
			else if (red[i].second > red[selidx].second) selidx = i;
		}
		if (selidx != -1) {
			used[selidx] = true;
			pairs += 1;
		}
	}
	cout << pairs << endl;
}

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

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  if(a==b && a==c){
    cout << 1 << endl;
  }
  else if(a!=b && b!=c && c!=a){
    cout << 3 << endl;
  }
  else{
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
int ans;
if(a<b) {
    ans=b;
    b=b-1;
}
else {
    ans=a;
    a=a-1;
}
cout<<ans+max(a,b)<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int S,s;
  double H,M;
  cin >> S;
  H = S/3600;
  int h = H;
  M = (S-3600*h)/60;
  int m = M;
  s = S-3600*h-60*m;
  cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3096
N = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

B = A.copy()
for i in range(N - 1):
    B[i + 1] = gcd(B[i], B[i + 1])

C = A.copy()
C.reverse()
for i in range(N - 1):
    C[i + 1] = gcd(C[i], C[i + 1])
C.reverse()

ans = 0
for i in range(N):
    if i == 0:
        tmp = C[i + 1]
    elif i == N - 1:
        tmp = B[i - 1]
    else:
        tmp = gcd(B[i - 1], C[i + 1])
    ans = max(ans, tmp)
    
print(ans)

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

int main(){
  double w,h,x,y;
  cin>>w>>h>>x>>y;
  double s=w*h/2;
  int ans=0;
  if (2*x==w && 2*y==h){
    ans=1;
  }
  cout<<fixed<<setprecision(9)<<s<<' '<<ans;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

using ll = long long;
using ull = unsigned long long;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;

int main() {
	string s;
	cin >> s;
	ll ans = 0;
	ll tmp = 0;
	for (ll i = 0, len = s.length(); i < len; i++) {
		if (s[i] == 'S') {
			tmp = 0;
		}
		else {
			tmp++;
			if (ans < tmp) {
				ans = tmp;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define for_(i,n) for(int i=0;i<n;++i)
#define for_1(i,n) for(int i=1;i<=n;++i)
const int mod= 1e9 +7;
const int inf=1e7;
int n;


main()
{  
int k;
cin>>n>>k;
vector<vector<int>> a(n+1, vector<int>(n+1));
vector<int> b(n+1);
for(int i=1;i<=n;++i)
{
    for(int j=1;j<=n;++j)
    {
        cin>>a[i][j];
        if(a[i][j]) {b[j]++;} 
    }
    
}




//c=b*a^k for a^k use matrix exponentiation
//int res[n+1][n+1];//= identity matrix;
vector<vector<int>> res(n+1, vector<int>(n+1));
for_1(i,n)
for_1(j,n)
{
    if(i==j) res[i][j]=1;
    else res[i][j]=0;
}
int x= k-1;
while(x>0)
{   vector<vector<int>> temp(n+1, vector<int>(n+1));
    //for_1(i,n) for_1(j,n) temp[i][j]=0;
    if(x%2) 
    {
        for_1(i,n)for_1(j,n){temp[i][j]=0;for_1(k,n)
                 temp[i][j]= (temp[i][j]+ (res[i][k]*a[k][j])%mod)%mod;}
    
        res=temp;
    }
    
    for_1(i,n) for_1(j,n) {temp[i][j]=0; for_1(k,n) temp[i][j]= (temp[i][j]+ (a[i][k]*a[k][j])%mod)%mod;}
    
    a=temp;
    // for_1(i,n){ for_1(j,n) cout<<a[i][j]; cout<<endl;}
    
    x=x/2;
}
vector<int> c(n+1);
for_1(i,1) for_1(j,n) for_1(k,n) c[j]= (c[j]+(b[k]*res[k][j])%mod)%mod;
//b=c;
int ans=0;
for_(i,n)
{   //cout<<c[i+1]<<" ";
    ans= (ans+c[i+1])%mod;
 
}

cout<<ans<<endl;
}























/*
typedef struct structure{
    int x,y;
} pt;
pt p0;
bool cmp(pt a, pt b)
{
    return cw(p0,a,b);
}
bool cw(pt a, pt b, pt c){
    return ((c.y-a.y)*(b.x-a.x)-(b.y-a.y)*(c.x-a.x))>=0
}



convex_hull(vector<pt>& points)
{
   // sort(points.begin(),points.end, cmp);// sorted according to y cordinate
    p0=points[0];
    sort(points.begin(),points.end, cmp);
    vector<pt> convexHull;
    stack<pt> temp;
    convexHull.push_back(points[0]);
    
    temp.push(points[0]);temp.push(points[1]);//temp.push(points[2]);
    pt top,top0;
    for(int it=2;it<points.size();++it)
    {   
        top=temp.top(); temp.pop(); top0=temp.top();
        pt next=points[it];
        if(cw(top0,top,next))
        {
            convexHull.push_back(top);
            temp.push(top);
            top0=top;
            top=next;
        }
        else
        {
          temp.push(next);  
        }
        
    }
    
}*/












Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

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

    if(a < 10 && b < 10){
        cout << a * b << endl;
    }
    else{
        cout << -1 << endl;
    }
    
    return 0;
}



Measured memory_bytes: 888
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for p in range(1,4):
    print("{0:.6f}".format(pow(sum([pow(abs(x[i] - y[i]), p) for i in range(n)]) ,1/p)))
print("{0:.6f}".format(pow(pow(max([abs(x[i] - y[i]) for i in range(n)]),n),1/n)))

Measured memory_bytes: 7744
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
using namespace std;

vector<int> v[100100];

struct sol {
	long long black;
	long long white;
};

sol solve(int start, int parent) {
	vector<sol> sols;
	for (int i : v[start]) {
		if (i != parent) {
			sols.push_back(solve(i, start));
		}
	}

	long long black = 1; 
	long long white = 1; 

	for (sol s : sols) {
		black = (black * s.white) % MOD;
		white = (white * ((s.white + s.black) % MOD)) % MOD;
	}

	return { black, white };
}

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

	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}

	sol s = solve(1, -1);
	cout << (s.black + s.white) % MOD << endl;

	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  string S;
  cin >> S;
  
  char numel[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
  
  int flag = 1;
  
  if (S[A] != '-') flag = 0;
  
  for(int i = 0; i < A; i++) {
    if (count(numel, numel + 10, S[i]) == 0 )
        flag = 0;
  }
  for(int i = A+1; i < A + B + 1; i++) {
    if (count(numel, numel + 10, S[i]) == 0 )
      flag = 0;
  }
  
  if (flag == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

a, p = wi()
print((3 * a + p) // 2)

Measured memory_bytes: 6476
#include <iostream>
#include<iomanip>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
using namespace std;
LL x[N],y[N];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%lld",&x[i]);
    for(int j=1;j<=m;j++)
        scanf("%lld",&y[j]);

    LL sx=0;
    for(int i=1;i<=n;i++){
        sx=(sx+x[i]*(i-1))%MOD;
        sx=(sx-x[i]*(n-i))%MOD;
    }
    LL sy=0;
    for(int i=1;i<=m;i++){
        sy=(sy+y[i]*(i-1))%MOD;
        sy=(sy-y[i]*(m-i))%MOD;
    }
    LL res=(sx*sy)%MOD;
    printf("%lld\n",res);

    return 0;
}


Measured memory_bytes: 1792
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
start, end = min(A), max(A) + 1
for v in range(start, end):
    ans = max(C[v - 1] + C[v] + C[v + 1], ans)
print(ans)

Measured memory_bytes: 20968
#include <iomanip>
#include "algorithm"
#include "cmath"
#include "iostream"
using namespace std;
typedef long long ll;

float to_deg(long double r) {
  return (long double)r * 180.0 / ((long double)atanf(1.0) * 4.0);
}

int main() {
  ll a, b, x;
  cin >> a >> b >> x;

  float res;

  if (x >= a * a * b / 2) {
    res = to_deg(atan2f(2 * a * a * b - 2 * x, a * a * a));
  } else {
    res = to_deg(atan2f(a * b * b, 2 * x));
  }

  cout << setprecision(10);
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll X, N;
  cin >> X >> N;
  ll p;
  map<ll, ll> num;
  rep(i, N){
    cin >> p;

    num[p] = 1;
  }

  rep(i, 1000){
    if(num[X - i] == 0){
      cout << X - i << "\n";
      return 0;
    }
    if(num[X + i] == 0){
      cout << X + i << "\n";
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3612
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  rep(x, a, b+1){
    if (x%10 == x / 10000 and (x / 10)%10 == (x / 1000)%10) ans++;
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 


*/

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);
		int a = sc1.nextInt();
		int b = sc1.nextInt();
		int c = sc1.nextInt();
		int temp = 0;
		int ans = 0;

		//123
		ans += Math.abs(b-a);
		ans += Math.abs(c-b);

		//132
		temp += Math.abs(c-a);
		temp += Math.abs(b-c);
		if (ans > temp) {
			ans = temp;
		}

		//213
		temp = 0;
		temp += Math.abs(a-b);
		temp += Math.abs(c-a);
		if (ans > temp) {
			ans = temp;
		}


		//231
		temp = 0;
		temp += Math.abs(c-b);
		temp += Math.abs(a-c);
		if (ans > temp) {
			ans = temp;
		}

		//312
		temp = 0;
		temp += Math.abs(a-c);
		temp += Math.abs(b-a);
		if (ans > temp) {
			ans = temp;
		}

		//321
		temp = 0;
		temp += Math.abs(b-c);
		temp += Math.abs(a-b);
		if (ans > temp) {
			ans = temp;
		}


		System.out.println(ans);

		sc1.close();

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define PP pair<P,P>
using namespace std;

//const int mod = 998244353;
const int mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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*(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;
  }
};

// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


ll ni(ll a,ll b){
    if(b<=0) return 1;
    else if(b%2==0) return ni(a,b/2)*ni(a,b/2);
    else return ni(a,b-1)*a;
}

mint dp[109][10];

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

  rep(i,109)rep(j,10) dp[i][j]=0;
  dp[0][0]=1;

  auto nijou=[&](int num){
    mint ans;
    if(num<=0) ans= 1;
    if(num==1) ans= 2;
    if(num==2) ans= 3;
    if(num==3) ans= 5;
    if(num==4) ans= 8;
    if(num==5) ans= 13;
    if(num==6) ans= 21;
    return ans;
  };

  for(int i=1; i<=h; i++){
    rep(j,w){
      if(j==0){
        dp[i][j]=dp[i-1][j]*nijou(w-2);
        dp[i][j]+=dp[i-1][j+1]*nijou(w-3);
      }
      else if(j==w-1){
        dp[i][j]=dp[i-1][j]*nijou(w-2);
        dp[i][j]+=dp[i-1][j-1]*nijou(w-3);
      }
      else{
        mint tmp=dp[i-1][j];
        tmp*=nijou(j-1);
        tmp*=nijou(w-j-2);
        dp[i][j]+=tmp;
        tmp=dp[i-1][j+1];
        tmp*=nijou(j-1);
        tmp*=nijou(w-j-3);
        dp[i][j]+=tmp;
        tmp=dp[i-1][j-1];
        tmp*=nijou(j-2);
        tmp*=nijou(w-j-2);
        dp[i][j]+=tmp;
        //dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j+1];
      }
    }
  }
  cout << dp[h][k-1].x << endl;
return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define maxk 100010
using namespace std;

struct Node{
	int dis,pos;
	bool operator <(const Node &x)const{
		return x.dis<dis;
	}
};

struct Node_e{
	int v,w,next;
};

Node_e edge[maxk*4];
int dist[maxk],vis[maxk],head[maxk*4];
int num=0;
int k;

void addedge(int x,int y,int z)
{
	edge[++num].v=y;
	edge[num].w=z;
	edge[num].next=head[x];
	head[x]=num;
}

priority_queue<Node> q;

void dijkstra()
{
	memset(vis,0,sizeof(vis));
	memset(dist,0x3f3f3f3f,sizeof(dist));
	while(!q.empty())q.pop();
	dist[1]=1;
	q.push((Node){0,1});
	while(!q.empty()){
		Node tmp=q.top();q.pop();
		int u=tmp.pos;
		if(vis[u])continue;
		for(int i=head[u];i;i=edge[i].next){
			int v=edge[i].v;
			if(dist[v]>dist[u]+edge[i].w){
				dist[v]=dist[u]+edge[i].w;
				if(!vis[v]){
					q.push((Node){dist[v],v});
				}
			}
		}
	}
}

int main()
{
	scanf("%d",&k);
	for(int i=1;i<k;i++){
		addedge(i,(i+1)%k,1);
		addedge(i,10*i%k,0);
	}
	dijkstra();
	printf("%d",dist[0]);
	return 0;
}

Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


void solve(long long N, long long K){
    ll ans = K;
    for(ll i=1; i< N; i++)
    {
        ans *= (K-1);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n;
  cin >> n;
  if(n%2==1){
    cout << 0 << endl;
  }else{
    ll ans = 0;
    while(n>9){
      ans += n/10;
      n /= 5;
    }
    cout << ans << endl;
  }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define esort(s) sort((s).begin(),(s).end())

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

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

int H,W;
int A[80][80];
/*
bitset<160*176> B[80][80];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	rep(y,H) rep(x,W) cin>>A[y][x];
	rep(y,H) rep(x,W) {
		cin>>r;
		A[y][x]=abs(A[y][x]-r);
	}
	B[0][0][80*165+A[0][0]]=1;
	rep(y,H) rep(x,W) {
		if(y+1<H) {
			B[y+1][x] |= B[y][x]<<A[y+1][x];
			B[y+1][x] |= B[y][x]>>A[y+1][x];
		}
		if(x+1<W) {
			B[y][x+1] |= B[y][x]<<A[y][x+1];
			B[y][x+1] |= B[y][x]>>A[y][x+1];
		}
	}
	
	int mi=101010;
	rep(i,160*176) if(B[H-1][W-1][i]) mi=min(mi,abs(i-80*165));
	cout<<mi<<endl;
	
}
*/
bitset<160*180> dp[80][80];

void solve(){
    int H,W; cin>>H>>W; 
    // cout<<H<<" "<<W<<"\n";
    int A[80][80],B[80][80];
    // rep(i,80){
    //     rep(j,80){
    //         A[i][j]=B[i][j]=0;
    //     }
    // }
    rep(i,H){
        rep(j,W){
            cin>>A[i][j];
        }    
    }
    rep(i,H){
        rep(j,W){
            cin>>B[i][j];
        }    
    }
    int dt[H][W];
    rep(i,H){
        rep(j,W){
            dt[i][j]=abs(A[i][j]-B[i][j]);
            // cout<<dt[i][j]<<" ";
        }
        // cout<<"\n";
    }
    dp[0][0][80*165+dt[0][0]]=1;
    rep(i,H){
        rep(j,W){
            if(i+1<H){
                dp[i+1][j]|=dp[i][j]<<dt[i+1][j];
                dp[i+1][j]|=dp[i][j]>>dt[i+1][j];
            }
            if(j+1<W){
                dp[i][j+1]|=dp[i][j]<<dt[i][j+1];
                dp[i][j+1]|=dp[i][j]>>dt[i][j+1];
            }
        }
    }
    int mi=INF;
    rep(i,160*180){
        if(dp[H-1][W-1][i]) mi=min(mi,abs(i-80*165));
    }
    cout<<mi<<"\n";
    return;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 22912
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [a;b] = reads int
    [
        a + b
        a - b
        a * b
    ]
    |> List.max
    |> printfn "%i"
    0

Measured memory_bytes: 14044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
 
int main() {
  ll N,K; cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
 
  vector<ll> B(40);
  rep(i,N) {
    bitset<40> s(A[i]);
    rep(j,40) {
      if (s.test(j)) B[j]++;
    }
  }
  ll X = 0;
  rep(i,40) {
    if (N - B[39 - i] > N / 2) {
      if (X + pow(2,39-i) <= K) X += pow(2,39-i);
    } 
  }
 
  ll ans = 0;
  rep(i,N) ans += (X ^ A[i]);
 
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    string S;
    cin >> S;
    if (S == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
    for (int i = 0; i < S.length(); ++i) {
        for (int j = i; j < S.length(); ++j) {
            string a = "";
            if (i != 0) {
                a = S.substr(0, i);
            }
            string b = "";
            if (i != S.length()-1) {
                b = S.substr(j + 1, S.length() - (j + 1));
            }
            string chk = a + b;
            if (chk == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
r, c = map(int, input().split())

ss = [[ 0 for j in range(c+1)] for i in range(r+1)]

for i in range(r):
    buff = input()
    lst = [int(x) for x in buff.split()]
    for j in range(c):
        ss[i][j] = lst[j]
    ss[i][c] = sum(lst)
    ss[r][c] += ss[i][c]

for j in range(c): 
    for i in range(r):
        ss[r][j] += ss[i][j]
        

for row in ss:
    print(" ".join(map(str, row)))


Measured memory_bytes: 5696
#include <stdio.h>

int main(){

    long long int angka;
    long long int total = 1;
    long long int N[100005];
	bool lanjut = true;
	bool printtotal = true;
    scanf("%lld", &angka);
    //printf("test");
    
    //angka apapun yang dikali 0 akan menjadi 0
    
    for (long long int i = 1; i <= angka; i++){
        scanf("%lld", &N[i]);
        if(N[i]==0){
        	printf("0\n");
			lanjut = false;
        	break;
		}
	}
	
  	if(lanjut){
  		for(int i = 1; i<=angka;i++){
  			//printf("%lld\n",total);
  			if(1000000000000000000/total >= N[i]){
  				total *= N[i];
			}
			else{
				printf("-1\n");
				printtotal = false;
				break;
			}	
		}	
		if(printtotal){
			printf("%lld\n",total);
		}
	}
    return 0;
}

Measured memory_bytes: 2476
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[1000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int b,e;
    cin>>b>>e;
    int mi=1e9+1,ma=-1e9-1;
    for(int i=0;i<(e-b)/2;i++){
      swap(a[i+b],a[e-1-i]);
    }
  }
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<cstring>
using namespace std;
int n, i, k, nr, nr2;
long long sol;
char s[105];
int main(){
    cin>> s + 1;
    n = strlen(s + 1);
    cin>> k;
    if(s[1] == s[n]){
        for(i = 2; i <= n + 1; i++){
            if(s[i] != s[1]){
                nr = i - 1;
                break;
            }
        }
        for(i = n; i >= 1; i--){
            if(s[i] != s[n]){
                nr2 = n - i;
                break;
            }
        }
        if(nr == n){
            sol = n * 1LL * k / 2;
        }
        else{
            sol = (nr + nr2) / 2 * 1LL * (k - 1);
            sol += nr / 2 + nr2 / 2;
            i = nr + 2;
            nr = 1;
            for(; i <= n - nr2 + 1; i++){
                if(s[i] != s[i - 1]){
                    sol += (nr / 2) * 1LL * k;
                    nr = 1;
                }
                else{
                    nr++;
                }
            }
        }
    }
    else{
        nr = 1;
        for(i = 2; i <= n; i++){
            if(s[i] != s[i - 1]){
                sol += (nr / 2) * 1LL * k;
                nr = 1;
            }
            else{
                nr++;
            }
        }
        sol += (nr / 2) * 1LL * k;
    }
    cout<< sol;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::vector<int> a(3);
    std::cin >> a[0] >> a[1] >> a[2];

    std::sort(a.begin(),a.end());

    int ans = 0;
    while(true){
        if(a[2]-a[1]>1){
            a[1]+=2; ans++;
        }else if(a[1]-a[0]>1){
            a[0]+=2; ans++;
        }else if(a[2]-a[1]>0 && a[1]-a[0]>0){
            a[0]++; a[1]++; ans++;
        }else if(a[2]-a[1]==0 && a[1]-a[0]>0){
            a[2]++; a[1]++; ans++;
        }else if(a[2]-a[1]>0 && a[1]-a[0]==0){
            a[1]++; a[0]++; ans++;
        }else{
            break;
        }
    }

    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3644
n,m=map(int,input().split())
root=[[] for _ in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    root[a].append(b)
    root[b].append(a)
s=[0]*(n+1)
s[0]=1
s[1]=1
ans=0
def f(a,x):
    global ans
    for i in root[a]:
        if x[i]==0:
            x[i]=1
            f(i,x)
            x[i]=0
    if x.count(1)==n+1:
        ans+=1
f(1,s)
print(ans)



Measured memory_bytes: 8780
MOD = int(1e9) + 7
N = int(input())
A = list(map(int, input().split()))

A.sort()
ansflag = True
if N % 2 == 0:
	for i in range(N):
		if A[i] != (i // 2) * 2 + 1:
			ansflag = False
			break
else:
	if A[0] != 0:
		ansflag = False
	for i in range(1, N):
		if A[i] != ((i+1) // 2) * 2:
			ansflag = False
			break

if ansflag:
	def repeatSquares(x, n):  # x^n
		res = 1
		while n != 0:
			if n % 2 == 1:
				res *= x
				res %= MOD  # MOD演算ないなら消していい
			x *= x
			n //= 2
			x %= MOD      # MOD演算ないなら消していい
		return res

	print(repeatSquares(2, N // 2))
else:
	print(0)


Measured memory_bytes: 14008
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b, c, d;
	string ans;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		ans = "Left";
	}
	else if (a + b < c + d) {
		ans = "Right";
	}
	else ans = "Balanced";
	cout << ans;
	return 0;
}

//Ctrl+Aを使わない

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

using str = string;
using ss = stringstream;

#define N 500000

// fenwick tree
int f[26][N];
void init(){for(int i=0;i<=N;i++)for(int j=0;j<26;j++)f[j][i]=0;}

void add(int a, int i, int x){for(;i<=N;i+=i&-i)f[a][i]+=x;}

int sum(int a, int i)
{
    int ret=0;
    for(;i>0;i-=i&-i)ret+=f[a][i];
    return ret;
}

int rangesum(int a, int l, int r){return sum(a,r)-sum(a,l-1);}
// fenwick tree

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

    int n;cin>>n;
    str s;cin>>s;
    int q;cin>>q;

    for(int i=0;i<n;i++)
    {
        add(s[i]-'a',i+1,1);
    }

    for(int qq=0;qq<q;qq++)
    {
        int type;cin>>type;
        if(type==1)
        {
            int ii;cin>>ii;
            char ic;cin>>ic;

            add(s[ii-1]-'a',ii,-1);
            add(ic-'a',ii,1);

            s[ii-1]=ic;
        }
        else
        {
            int l,r;cin>>l>>r;
            int sum=0;
            for(int i=0;i<26;i++)if(rangesum(i,l,r)>0)sum++;
            cout<<sum<<"\n";
        }        
    }

    return 0;
}


Measured memory_bytes: 54664
rank = {}

while str = STDIN.gets

  (a, b) = str.chomp.split(/,/).map(&:to_i)

  break if a == 0 && b == 0

  rank[a] = b

end

ranks = rank.values.uniq.sort{|a, b| b <=> a}.map.with_index(1){|v, i| [v, i]}.to_h

while str = STDIN.gets

  break if str == "\n"

  n = str.chomp.to_i
  puts ranks[rank[n]]

end

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

int main() {
  int H, W;
  cin >> H >> W;
  char pixel[H+2][W+2];
  rep(i,H+2) {
    pixel[i][0] = '#';
    pixel[i][W+1] = '#';
  }
  rep(i,W+2) {
    pixel[0][i] = '#';
    pixel[H+1][i] = '#';
  }
  rep(i,H) rep(j,W) cin >> pixel[i+1][j+1];
  rep(i,H+2) {
    rep(j,W+2) {
      cout << pixel[i][j];
    }
    cout << endl;
  }
  return 0;
}


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


Measured memory_bytes: 2052
n=int(input())
a=tuple(map(int, input().split()))
b=tuple(map(int, input().split()))
cnta=0
cntb=0
li=[i for i in range(1,n+1)]
import itertools
k=0
for i in itertools.permutations(li):
    if tuple(i)==a:
        cnta=k
    if tuple(i)==b:
        cntb=k
    k+=1
print(abs(cnta-cntb))

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
#define MX 200000

using namespace std;
using ll = long long;
using ldb = long double;

vector<ll> fac;
ll mypow(long long k, long long n) {
	long long temp = 1;
	k = k % DIV;
	while (n) {
		if (n % 2) temp = temp * k % DIV;
		k = k * k % DIV;
		n = n / 2;
	}
	return temp % DIV;
}

ll cmb(ll n, ll r) {
	if (n < r) return 0;
	ll inv = mypow(fac[r] * fac[n - r] % DIV, DIV - 2);
	return (fac[n] * inv) % DIV;
}


int main() {
	ll N, M, K; cin >> N >> M >> K;
	fac = vector<ll>(MX + 1, 1);
	for (int i = 2; i <= MX; i++) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= DIV;
	}
	ll ans = 0;
	for (ll i = 0; i <= K; i++) {
		ans += ((M*cmb(N-1,i)%DIV)*mypow(M-1,N-i-1))%DIV;
		ans %= DIV;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4812