akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	map<char,bool> mp;
	for(char val : s)
		mp[val]=true;
	for(char c='a';c<='z';c++)
		if(!mp[c])
		{
			s.push_back(c);
			cout<<s<<endl;
			exit(0);
		}
	bool v = 1;
	char d;
	int res = -1;
	for(int i=s.length()-1;i>=0&&v;i--)
	{
		for(char c=s[i];c<='z';c++)
		{
			if(!mp[c]&&c>s[i])
			{
				v=0;
				d=c;
				res=i;
				break;
			}
		}
		mp[s[i]]=0;
	}
	string ans = "";
	if(res!=-1)
	{
		for(int i=0;i<res;i++)
			ans.push_back(s[i]);
		ans.push_back(d);
		cout<<ans<<endl;
	}
	else cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
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 All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,K;cin >> N >> K;
    vector<int> cnt(N);
    rep(i,N){
        int a;cin >> a;
        cnt[--a]++;
    }
    sort(All(cnt));
    reverse(All(cnt));
    ll sub = 0;
    rep(i,K){
        sub+=cnt[i];
    }
    cout << N-sub << endl;
    return 0;
}

Measured memory_bytes: 1024
from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

s = int(input())
mod = 10 ** 9 + 7


@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif n == 3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod

        return count % mod


ans = dfs(s)
print(ans)


Measured memory_bytes: 10248
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, c = 2, i;
    cin >> n;
    if (n == 2)
        return cout << 1, 0;
    for (i = 2; i * i <= n; i++)
    {
        ll x = n;
        while (x % i == 0)
            x /= i;
        c += (x % i == 1);
        if (n % i == 0 && i * i != n)
        {
            x = n;
            ll b = n / i;
            while (x % b == 0)
                x /= b;
            c += (x % b == 1);
        }
        c += (n % i == 1 && n != i + 1 && (n - 1) != i * i);
    }
    cout << c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const ll mod = 998244353;
int ans[maxn];
ll b[maxn];
struct edge
{
    int from,to,dist;
    edge(int u,int v,int d):from(u),to(v),dist(d){}
};
vector<edge>edges;
vector<int>G[maxn];
int vis[maxn];
void init(int n)
{
    for(int i = 0; i <= n; ++i)G[i].clear();
    memset(ans,0,sizeof(ans));
    memset(vis,0,sizeof(vis));
    edges.clear();
}
void addedge(int from,int to,int dist)
    {
        edges.push_back(edge(from,to,dist));
        int m = edges.size();
        G[from].push_back(m-1);
    }
void dfs(int now,int fa,int dd)
{
    //cout<<fa<<endl;
    for(int i = 0; i < G[now].size(); ++i)
    {
        int ee = G[now][i];
        int v = edges[ee].to;
        if(v == fa) continue;
        if((edges[ee].dist + dd)&1)
            ans[v] = ans[1]^1;
        else
            ans[v] = ans[1];
        
        dfs(v,now,edges[ee].dist + dd);
    }
}
int main()
{
    int n;
    while(cin>>n)
    {
        init(n);
        for(int i = 1; i < n; ++i)
        {
            int x,y,z;
            cin>>x>>y>>z;
            addedge(x,y,z);
            addedge(y,x,z);
        }
        ans[1] = 0;
        dfs(1,-1,0);
        for(int i = 1; i <= n; ++i)
            printf("%d\n",ans[i]);
    }
}




















Measured memory_bytes: 41520
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int P = sc.nextInt();

		P += A*3;

		println(P/2);
	}

	public static void print(Object o) {
		System.out.print(o);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; string S; cin >> N >> S;
    int r=0,b=0;
    rep(i,N){
        if (S[i]=='R') ++r;
        else ++b;
    }
    if (r>b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int s1, s2, s3, x;
  cin >> x;
  s1 = x/100;
  s2 = (x%100)/10;
  s3 = x%10;
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
def incr_lunlun(num):
    num[0] += 1
    if len(num) == 1:
        if num[0] == 10:
            num.append(1)
            num[0] = 0
    
    elif num[0] > num[1] + 1 or num[0] == 10:
        suffix = incr_lunlun(num[1:])
        digit = max(0, suffix[0] - 1)
        num = [digit] + list(suffix)

    return num


def main():
    k = int(input())
    num = [1]
    for i in range(k-1): 
        num = incr_lunlun(num)

    print(int(''.join(str(i) for i in reversed(num))))



main()


Measured memory_bytes: 9196
/*
 * zyrch - Rupanshu Yadav
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

#define forn(i,a,b) for (int i = (a); i < ll(b); ++i)
#define fo(i,a) forn(i,0,ll(a))
#define rforn(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ro(i,a) rforn(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
//#define s second
ll mod = 1000000007;
inline int fast_expo(int base,int power,int modulo=mod){
    base%=modulo;
    if (base<0) base+=modulo;
    ll x=base,cnt=power,ans=1;
    while(cnt){
        if (cnt&1) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1;
    }
    return ans;
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int INF = (int)1e9;
//=========================CODE STARTS HERE=============================//

int main() {

	fast_cin();

	ll n;
	cin >> n;
	
	vl arr(n);
	
	fo(i, n) {
		cin >> arr[i];
	}
	
	ll dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[0] - arr[1]);
	
	forn(i, 2, n) {
		dp[i] = min(dp[i - 2] + abs(arr[i] - arr[i - 2]), dp[i - 1] + abs(arr[i - 1] - arr[i]));
	}
	cout << dp[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int main(void)
{
	int x,y;
	scanf("%d%d",&x,&y);
	
	for(int i=0; i<=x; ++i)
	{
		if(i*2 + (x-i)*4 == y)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 1656
#include <iostream>

#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;
    lint K; cin >> K;

    vector<lint> h;
    vector<lint> h_sum;
    
    lint res = 1000000000;

    REP(_, N) {
      lint a; cin >> a;h.push_back(a);
    }
    SORT(h);


    FOR(i, 0, N-K+1)  {
      res = min(h[i+K-1]-h[i], res);
    }
    PRINT(res);

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int n, a, b;
vector<int> h;

bool check(ll x){
    ll res = 0;
    for(int i = 0; i < n; ++i){
        ll foo = (ll)h[i] - b * x;
        if(foo > 0) res += ceil((double)foo / (a - b));
    }
    return res <= x;
}

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

    cin >> n >> a >> b;
    h.resize(n);
    for(int i = 0; i < n; ++i)  cin >> h[i];
    ll lb = -1, ub = 1e+9;
    while(ub - lb > 1){
        ll mid = (lb + ub) / 2;
        if(check(mid))  ub = mid;
        else    lb = mid;
    }
    cout << ub << endl;
}

Measured memory_bytes: 640
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m,*ab = [int(i) for i in read().split()]

dist = [-1]*n
dist[0] = 0
ans = [-1]*n

g = [[] for _ in range(n)]
M = iter(ab)
for a,b in zip(M,M):
    g[a-1].append(b-1)
    g[b-1].append(a-1)

from collections import deque
q = deque([0])
while q:
    v = q.popleft()
    for c in g[v]:
        if dist[c] == -1:
            dist[c] = dist[v]+1
            ans[c] = v+1
            q.append(c)
    

print("Yes")
print(*ans[1:],sep="\n")











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

using namespace std;

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n;
	cin>>n;
	vector<lli> t(n+2),a(n+2);
	REP(i,0,n){
		cin>>t[i+1];
	}	
	REP(i,0,n){
		cin>>a[i+1];
	}

	
	if(t[n] != a[1]){
		cout<<0<<endl;
		return 0;
	}


	vector<lli> high(n+2),low(n+2);

	t[0] = 0;
	t[n+1] = INF;
	a[0] = INF;
	a[n+1] = 0;

	for(lli i=1; i<=n;i++){
		if(t[i] != t[i-1] && a[i] != a[i+1]){
			if(t[i]!=a[i]){
				if(DEBUG)cout<<"i="<<i<<" t[i]="<<t[i]<<" a[i]="<<a[i]<<endl;
				cout<<0<<endl;
				return 0;
			}
			high[i] = t[i];
			low[i] = t[i];
		}
		else if(t[i] != t[i-1]){
			high[i] = t[i];
			low[i] = t[i];
			if(high[i] > a[i]){
				cout<<0<<endl;
				return 0;
			}
		}
		else if(a[i] != a[i+1]){
			high[i] = a[i];
			low[i] = a[i];
			if(high[i] > t[i]){
				cout<<0<<endl;
				return 0;
			}
		}
		//else(t[i]==t[i-1] && a[i]==a[i+1]){
		else{
			high[i] = min(t[i],a[i]);
			low[i] = 1;
		}
	}

	lli ans = 1;
	for(lli i=1;i<=n;i++){
		if(DEBUG)cout<<"i="<<i<<" high[i]="<<high[i]<<" low[i]="<<low[i]<<endl;
		ans = (ans*(high[i]-low[i]+1) )%MOD;
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 3328
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	int n;
	cin >> n;
	vector < int > a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int id = 0;
	sort(all(a));
	for (int i = 1; i < n - 1; i++)
	{
		if (min(a[n - 1] - a[i], a[i]) > min(a[id], a[n - 1] - a[id]))
			id = i;
	}
	cout << a[n - 1] << ' ' << a[id] << endl;

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

int encode(vector<int> vi){
	int n = vi.size();
	vector<int> idx(8,0);
	int res = 0, cnt = 1;
	for(int i=0;i<n;i++){
		int cur = vi[(i+1)%n];
		if(cur != 0){
			if(idx[cur]==0) idx[cur] = cnt++;
			cur = idx[cur];
		}
		res = 8*res + cur;
	}
	return res;
}

int main(){
	int H, W;
	string s[11];
	while(cin >> H >> W){
		for(int i=0;i<H;i++) cin >> s[i];
		map< int, int > mp[2];
		mp[0][0] = 0;
		int cur = 0, next = 1;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				for(map<int,int>::iterator it=mp[cur].begin();it!=mp[cur].end();it++){
					int val = it->first;
					bool space = (s[i][j]!='#'), wall = (s[i][j]!='.');
					vector<int> state(W);
					for(int k=W-1;k>=0;val/=8) state[k--] = val%8;
					if((i!=0&&state[0]==0)||(j!=0&&state[W-1]==0)) space = false;

					if(W!=1){
						bool flg = state[0]!=0;
						for(int k=1;k<W;k++)
							if(state[0]!=0 && state[0]==state[k]) flg = false;
						if(flg) space = false;
					}

					if(W==1){
						if(i!=0&&state[0]==0&&it->second > 0) wall = false;
					}

					if(i!=0&&j!=0&&state[0]!=0&&state[0]==state[W-1]) wall = false;

					if(space){
						int t = state[0];
						state[0] = 0;
						int tmp = encode(state);
						mp[next][tmp] = max(mp[next][tmp], it->second);
						state[0] = t;
					}
					if(wall){
						if(j!=0&&state[W-1]!=0&&i!=0&&state[0]!=0){
							for(int k=1;k<W;k++) if(state[k]==state[W-1]) state[k] = state[0];
						}
						else if(j!=0&&state[W-1]!=0) state[0] = state[W-1];
						else if(i==0||state[0]==0) state[0] = 7;
						int tmp = encode(state);
						mp[next][tmp] = max(mp[next][tmp], it->second+1);
					}
				}
				mp[cur].clear();
				swap(cur, next);
			}
		}
		int res = -1;
		for(map<int,int>::iterator it=mp[cur].begin();it!=mp[cur].end();it++){
			bool ok = true;
			for(int i=0;i<W;i++)
				if(((it->first>>(3*i))%8) > 1) ok = false;
			if(ok) res = max(res, it->second);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1096
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


const int MAX = 210000;
int N;
int x[MAX];
int L;
int Q;

int ne[30][MAX];


void PreProcess() {
    for (int i = 0; i < N; ++i) {
        int hi = N, lo = i;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if (x[mid] - x[i] > L) hi = mid;
            else lo = mid;
        }
        ne[0][i] = lo;
        //cout << i << ": " << lo << endl;
    }
    
    for (int i = 0; i < 30; ++i) {
        for (int j = 0; j < N; ++j) {
            ne[i+1][j] = ne[i][ne[i][j]];
        }
    }
}



int Query(int a, int b) {
    if (a > b) swap(a, b);
    
    int res = 0;
    for (int bit = 24; bit >= 0; --bit) {
        if (ne[bit][a] < b) {
            res += 1<<bit;
            a = ne[bit][a];
            
            //cout << bit << ", " << (1<<bit) << ": " << a << endl;
        }
        else if (ne[bit][a] == b && bit == 0) {
            res += 1<<bit;
            a = ne[bit][a];
            
            //cout << bit << ", " << (1<<bit) << ": " << a << endl;
        }
        if (a >= b) break;
    }
    if (a < b) res += 1;
    
    return res;
}



int main() {
    while (cin >> N) {
        for (int i = 0; i < N; ++i) {
            scanf("%d", &x[i]);
        }
        x[N] = x[N-1] + 1;
        cin >> L;
        
        PreProcess();
        cin >> Q;
        for (int i = 0; i < Q; ++i) {
            int a, b;
            scanf("%d %d", &a, &b);
            --a, --b;
            cout << Query(a, b) << endl;
        }
    }
}




Measured memory_bytes: 13056
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = range(0, p * 10, p) if c == '?' else (p * int(c),)
    a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])


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

int main(){
    int a,b;
    cin>>a>>b;
    int cnt=0;
    for(int i=a;i<=b;i++){
        if(i%10 == i/10000 && (i%10000)/1000 == (i%100)/10)
        cnt++;
    }
    cout<< cnt <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int arr[3];
    for(int i=0;i<3;i++)
    {
        cin>>arr[i];
    }
    int five=0;
    int seven=0;
    for(int i=0;i<3;i++)
    {
        if(arr[i]==5)
        {
            five++;
        }
        else if(arr[i]==7)
        {
            seven++;
        }
    }
    if(five==2 && seven==1)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}

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

int main()
{
	int r, c;
	int a[101][101];
	int sum_c = 0, sum_r = 0;
	cin >> r >> c;

	for (int i = 0; i<r; i++) {
		for (int j = 0; j<c; j++) {
			cin >> a[i][j];

		}
	}

	for (int i = 0; i<r; i++) {
		for (int j = 0; j<c; j++) {
			sum_c += a[i][j];
			if (j == c - 1) a[i][c] = sum_c;
		}
		sum_c = 0;
	}
	for (int i = 0; i<=c; i++) {
		for (int j = 0; j<=r; j++) {
			sum_r += a[j][i];
			if (j == r - 1) a[r][i] = sum_r;
		}
		sum_r = 0;
	}

	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			cout << a[i][j];
			if (j < c) cout << " ";
			if (j == c) cout << endl;
		}

	}

	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using P = pair<int, int>;

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

    int a[n+10];
    rep (i, n) cin >> a[i];

    bool one = false;
    rep (i, n) {
        if (a[i] == 1) {
            one = true;
            break;
        }
    }
    if (one == false) {
        cout << -1 << endl;
        return 0;
    }

    int cnt = 1;
    rep (i, n) {
        if (a[i] == cnt) {
            cnt++;
        }
    }
    cout << n - cnt + 1 << endl;

}


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (auto &&x : a) cin >> x;

    ll dp[n + 1][n + 1];
    for (int l = 0; l < n; ++l) dp[l][l] = a[l];

    for (int size = 2; size <= n; ++size) {
        for (int l = 0; l + size <= n; ++l) {
            int r = l + size - 1;
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }

    cout << dp[0][n - 1] << endl;

    return 0;
}


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

void swap2(int* array, int i, int j) {
    int tmp = array[i];
    array[i] = array[j];
    array[j] = tmp;
}

int main() {
    // Input
    int N = 0;
    cin >> N;
    int a[N] = {0};
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int count = 0;
    int s1 = 0;
    int s2 = 0;
    bool value = 1;
    for(int i = 0; i < N; i++) {
        if( a[i] != i+1 ) {
            value = 0;
            if( count == 0) {
                s1 = i;
            }else if( count == 1) {
                s2 = i;
                break;
            }
            count++;
        }
    }
    if( !value ) {
        swap2(a, s1, s2);
        value = 1;
        for(int i = 1; i < N; i++) {
            if( a[i-1] > a[i] ) {
                value = 0;
                break;
            }
        }
    }
    if( value ) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<ll> as(n);
    rep(i, n) {
        int a; cin >> a;
        as[i] = a - i -1;
    }
    sort(all(as));
    ll b = as[n/2];
    ll tot = 0; 
    for(ll a : as) tot += abs(a-b);
    cout << tot << endl; 
    return 0;
}

Measured memory_bytes: 1792
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	k := getNextInt(scanner)

	for i := 0; i < n+1; i++ {
		for j := 0; j < m+1; j++ {
			if i*m+j*n-i*j*2 == k {
				fmt.Fprintln(writer, "Yes")
				return
			}
		}
	}
	fmt.Fprintln(writer, "No")
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt() - 1;
        int b = sc.nextInt() - 1;
        int c = sc.nextInt() - 1;
        int d = sc.nextInt() - 1;
        String[] s = sc.next().split("");
        for (int i = a; i < Math.max(c, d) - 1; i++) {
            if ("#".equals(s[i]) && "#".equals(s[i + 1])) {
                System.out.println("No");
                return;
            }
        }
        if (c < d) {
            System.out.println("Yes");
            return;
        }
        boolean canOvertake = false;
        for (int i = b - 1; i < d; i++) {
            if (".".equals(s[i]) && ".".equals(s[i + 1]) && ".".equals(s[i + 2])) {
                canOvertake = true;
            }
        }
        if (canOvertake) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)

string change(int n)
{
    string s = to_string(n);
    while (s.size() < 3)
    {
        s = '0' + s;
    }
    return s;
}

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

    int ans = 0;
    rep(i, 1000)
    {
        vector<int> v = {i / 100, (i / 10) % 10, i % 10};
        int f = 0;
        rep(j, n)
        {
            if (s[j] == ('0' + v[f]))
            {
                f++;
            }
            if (f == 3)
            {
                break;
            }
        }
        if (f == 3)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   int n;
   cin>>n;
   cout<<(n-2)*180<<endl;
}

   


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

int main(){
    int n;
    cin>>n;
    int a[n];
    ll ans=0;
    for(int i=0;i<n;++i){cin>>a[i];ans = ans^a[i];}
    for(int i=0;i<n;++i)cout<<(ans^a[i])<<" ";
    return 0;
}

Measured memory_bytes: 4400
import java.awt.List;
import java.util.ArrayList;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// 標準入力
		Scanner sc = new Scanner(System.in);
		//
		int roop = 0;
		// 答えの配列
		double[] double_array = new double[100];
		// 何個入力があるか
		while (sc.hasNext()) {

			// 値を初期化
			int input_number = 0;
			int points = 0;
			int all_points = 0;
			// 入力数の配列
			ArrayList<Integer> input_array = new ArrayList<Integer>();

			input_number = sc.nextInt();

			// 入力値が0だった場合、結果を出力
			if (input_number == 0)
				break;

			// 入力個数分まわす
			for (int i = 0; i < input_number; i++) {

				//
				while (sc.hasNext()) {
					//
					points = sc.nextInt();
					input_array.add(points);
					break;
				}
				// 合計値
				all_points += points;
			}
			// インスタンスを作る
			Sta_Math obj = new Sta_Math(all_points, input_number, input_array);
			obj.cast_standard();
			//
			double_array[roop] = obj.getStandard();
			roop++;
		}
		for (int i = 0; i < roop; i++) {
			System.out.println(double_array[i]);
		}
	}
}

class Sta_Math {

	// 合計値
	private int all = 0;
	// 入力個数
	private int input_number = 0;
	// 平均
	private double average = 0;
	// 標準偏差
	private double standard = 0;
	// 入力数字列
	ArrayList<Integer> input_arr = null;

	// コンストラクタ
	Sta_Math(int a, int i, ArrayList<Integer> b) {
		all = a;
		input_number = i;
		input_arr = b;
		average = (double) a / i;
	}

	// 標準偏差を計算
	public void cast_standard() {
		double hoge = 0;
		// 分子に使う数
		double namerator = 0;
		// 入っている数列分まわす
		for (int val : input_arr) {
			hoge = (val - average) * (val - average);
			namerator += hoge;
		}

		standard = Math.sqrt(namerator / input_number);
	}

	// ゲッター
	public double getStandard() {
		return standard;
	}

}

Measured memory_bytes: 23480
#include <stdio.h>

int main () {

    int H, W, i, j;

    for (; ; ) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0)
            break;
        for (i = 0; i < H; i++) {
            for (j = 0; j < W; j++) {
                putchar('#');
            }
            puts("");
        }
        puts("");
    }

    return 0;

}


Measured memory_bytes: 2132
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author bhavy seth
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            long n = sc.nextLong();
            long a = sc.nextLong();
            long b = sc.nextLong();
            out.println((n / (b + a)) * a + Math.min(a, n % (b + a)));
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 25044
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

// get longest common subsequence, O(s.length() * t.length())
struct LCS {
    vvi dp;
    string s, t;
    LCS(string s, string t) : s(s), t(t) {
        dp.assign(s.size() + 1, vi(t.size() + 1, 0));
        for (int i = 1; i <= s.size(); ++i) {
            for (int j = 1; j <= t.size(); ++j) {
                if (s[i - 1] == t[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
                chmax(dp[i][j], dp[i][j - 1]);
                chmax(dp[i][j], dp[i - 1][j]);
            }
        }
    }
    int length() { return dp[s.size()][t.size()]; }
    string restore() {
        string ret = "";
        int sidx = s.size();
        int tidx = t.size();
        int retidx = length() - 1;
        while (sidx > 0 && tidx > 0) {
            if (s[sidx - 1] == t[tidx - 1]) {
                ret = s[sidx - 1] + ret;
                --retidx;
                --sidx;
                --tidx;
            } else if (dp[sidx][tidx] == dp[sidx - 1][tidx])
                --sidx;
            else
                --tidx;
        }
        return ret;
    }
};

int main() {
    string s, t;
    cin >> s >> t;
    LCS lcs(s, t);
    cout << lcs.restore() << "\n";
    return 0;
}

Measured memory_bytes: 35584
#include<iostream>
using namespace std;
long long arr[100007],brr[100007];
main()
{
    long long n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        brr[i]=10e17;
    }
    brr[1]=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=i-1;j>0&&i-j<=k;j--)
        {
            brr[i]=min(brr[j]+max(arr[j]-arr[i],arr[i]-arr[j]),brr[i]);
        }
    }
    cout<<brr[n];
}


Measured memory_bytes: 1792
N = int(input())
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for i in range(N):
    p = input()
    b,f,r,v = map(int, p.split())
    count[b-1][f-1][r-1] = count[b-1][f-1][r-1] + v

for i in range(4):
    if i != 0:
        print('####################')
    for j in range(3):
        print(' ', end = '')
        print(' '.join(map(str, count[i][j])))


Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(){
	ll n,m,sum=0,money=0;
	cin>>n>>m;
	vector<pair<ll,ll>>shop(n);
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		shop[i]=make_pair(x,y);
	}
	sort(shop.begin(),shop.end());
	for(int i=0;i<n;i++){
		if(sum+shop[i].second<m){
			sum+=shop[i].second;
			money+=(shop[i].first*shop[i].second);
		}else if(sum==m){
			cout<<money;
			return 0;
		}else{
			for(int j=1;j<=shop[i].second;j++){
				sum++;
				money+=shop[i].first;
				if(sum==m){
					cout<<money;
					return 0;
				}
			}
		}
	}
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  int A, B; cin >> A >> B;

  //main
  
  
  // output
  if(A <= 2*B) {cout << 0 << endl;}
  else{cout << A-2*B << endl;}

  return 0;
}

Measured memory_bytes: 256
from typing import Dict, List


def calc_hash(input_v: List[int], target_len: int, input_len: int) -> set:
    global base, mask
    diff_len = input_len - target_len
    hash_set = set()

    bit_mask = 1
    for _ in range(target_len):
        bit_mask = (bit_mask * base) & mask
    hash_v = 0
    for i in range(target_len):
        hash_v = (hash_v * base + input_v[i]) & mask
    for i in range(diff_len):
        hash_set.add(hash_v)
        hash_v = (hash_v * base - bit_mask * input_v[i]
                  + input_v[i + target_len]) & mask
    hash_set.add(hash_v)

    return hash_set


if __name__ == "__main__":
    base = 123  # Ascii code after 'z'
    mask = (1 << 32) - 1  # Mask.

    input_v = [ord(s) for s in input()]
    input_len = len(input_v)

    checked_dict: Dict[int, set] = {}
    num_target = int(input())

    for _ in range(num_target):
        target_v = [ord(s) for s in input()]
        target_len = len(target_v)
        if input_len < target_len:
            print(0)
            continue
        magic_len = min(19, target_len)  # Magic number to reduce calc time.
        key = calc_hash(target_v, magic_len, target_len)
        if magic_len not in checked_dict:
            checked_dict[magic_len] = calc_hash(input_v, magic_len, input_len)
        if key.issubset(checked_dict[magic_len]):
            print(1)
        else:
            print(0)



Measured memory_bytes: 1074144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll h, w, n;
 	cin >> h >> w >> n;
 	ll temp = max(h, w);
 	if (n % temp == 0) {
 		cout << n / temp << endl;
 	}   
 	else {
 		cout << n / temp + 1 << endl;
 	}
	return 0;
}

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

string st;
bool n,s,e,w;

int main(){
cin>>st;

for (int x = 0; x<st.size(); x++){
    if (st[x]=='N') n = true;
    if (st[x]=='S') s = true;
    if (st[x]=='E') e = true;
    if (st[x]=='W') w = true;
}
if (n!=s || e!=w){
    printf("No");
}
else printf("Yes");

}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j]){
                ans++;
            }
        }
    }
    if(k==1){
        cout << ans << endl;
        return 0;
    }
    ll t1 = ans;
    ans = 0;
    ll t2 = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i]>a[j]){
                t2++;
            }
        }
    }
    ans = k*(k-1)/2;
    ans%=mod;
    ans*=t2;
    ans%=mod;
    t1*=k;
    t1%=mod;
    ans+=t1;
    ans%=mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=2e6+10;
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

LL x[MAXN],y[MAXN],f[MAXN],xa,xi,ya,yi;

LL qp(LL a,LL b)
{
	LL res=1;
	while(b>0){
		if(b&1)res=res*a%MOD;
		b>>=1;
		a=a*a%MOD;
	}
	return res;
}

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v;
	cin>>n;
	repu(i,1,n){
		cin>>x[i];
		if(x[i]>xa)xa=x[i],xi=i;
	}
	repu(i,1,n){
		cin>>y[i];
		if(y[i]>=ya)ya=y[i],yi=i;
	}
	if(xa!=ya || xi>yi)return cout<<"0\n",0;
	ans=1;
	u=1;
	for(i=1;i<=xi;i++){
		if(x[i]>x[i-1]){
			v=i-1-u;
			ans*=qp(x[i-1],v);
			ans=(ans%MOD+MOD)%MOD;
			u=i;
		}
	}
	u=n;
	for(i=n;i>=yi;i--){
		if(y[i]>y[i+1]){
			v=u-i-1;
			ans*=qp(y[i+1],v);
			ans=(ans%MOD+MOD)%MOD;
			u=i;
		}
	}
	v=yi-xi-1;
	ans=ans*qp(xa,v)%MOD;
	ans=(ans%MOD+MOD)%MOD;
	cout<<ans<<endl;
	return 0;
}



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

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int N,M,A[10010]={},sum=0;
    cin>>N>>M;

    for(int i=1;i<=M;i++){
        cin>>A[i];
        sum+=A[i];
    }

    if(sum>N){
        cout<<"-1"<<endl;
    }else{
        cout<<N-sum<<endl;
    }



    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

const double EPS=0.00001;
const long double PI = acos(-1.0);
bool dp[8003][8003];
int main(){
    string s;
    cin>>s;
    int x,y;cin>>x>>y;
    vector<int>dx,dy;
    int tdx=0,tdy=0;
    bool flag=1;
    REP(i,SZ(s)){
        if(flag){
            if(s[i]=='T'){
                dx.PB(tdx);
                tdx=0;tdy=0;
                flag=0;
            }else{
                tdx++;
            }
        }else{//y軸向いてる時
            if(s[i]=='T'){
                dy.PB(tdy);
                tdy=0;tdx=0;
                flag=1;
            }else{
                tdy++;
            }
        }
    }
    if(tdx>0)dx.PB(tdx);
    else if(tdy>0)dy.PB(tdy);
    /*REP(i,SZ(dx))cout<<dx[i]<<" ";
    cout<<endl;
    REP(i,SZ(dy))cout<<dy[i]<<" ";
    cout<<endl;*/
    int dxsum1=0,dysum=0;
    FOR(i,1,SZ(dx))dxsum1+=dx[i];
    FOR(i,0,SZ(dy))dysum+=dy[i];
    x-=dx[0];
    if(x<-dxsum1||x>dxsum1){
        cout<<"No"<<endl;return 0;
    }else if(y<-dysum||y>dysum){
        cout<<"No"<<endl;return 0;
    }
    
    int px=min(abs(-x-dxsum1),abs(-x-dxsum1));
    int py=min(abs(-y-dysum),abs(y-dysum));
    if(px%2!=0||py%2!=0){
        cout<<"No"<<endl;return 0;
    }
    px/=2;py/=2;
    CLR(dp);
    vector<int>dx2;
    FOR(i,1,SZ(dx))dx2.PB(dx[i]);
    dp[0][0] = true;             // dp[0][0] だけ true に
    REP(i,SZ(dx2)){
        for (int j = 0; j <= px;j++) {
            dp[i+1][j] |= dp[i][j];
            if (j >= dx2[i]) dp[i+1][j] |= dp[i][j-dx2[i]];
        }
    }
    if(!dp[SZ(dx2)][px]&&px!=0){
        cout<<"No"<<endl;return 0;
    }
    CLR(dp);
    dp[0][0] = true;// dp[0][0] だけ true に
    REP(i,SZ(dy)){
        for (int j = 0; j <= py;j++) {
            dp[i+1][j] |= dp[i][j];
            if (j >= dy[i]) dp[i+1][j] |= dp[i][j-dy[i]];
        }
    }
    if(!dp[SZ(dy)][py]&&py!=0){
        cout<<"No"<<endl;return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 62976
#include"iostream"
#include <iomanip>
#include"cmath"
using namespace std;
double th = 3.1415926 / 3;
struct point
{
	double x;
	double y;
};
void draw(int n,point p1,point p2)
{
	if (n == 0)return;
	point s, u, t;
	s.x = (2 * p1.x + p2.x) / 3;
	s.y = (2 * p1.y + p2.y) / 3;
	t.x = (2 * p2.x + p1.x) / 3;
	t.y = (2 * p2.y + p1.y) / 3;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
	draw(n - 1, p1, s);
	cout <<fixed<< setprecision(8) << s.x << ' ' << fixed << setprecision(8) << s.y << endl;
	draw(n - 1, s, u);
	cout<< fixed << setprecision(8) << u.x << ' ' << fixed << setprecision(8) << u.y << endl;
	draw(n - 1, u, t);
	cout << fixed << setprecision(8) << t.x << ' ' << fixed << setprecision(8) << t.y << endl;
	draw(n - 1, t, p2);
}
int main()
{
	int n;
	cin >> n;
	point p1, p2;
	p1.x = p1.y = p2.y = 0;
	p2.x = 100;
	cout << fixed << setprecision(8) << p1.x << ' ' << fixed << setprecision(8) << p1.y << endl;
	draw(n, p1, p2);
	cout << fixed << setprecision(8) << p2.x << ' ' << fixed << setprecision(8) << p2.y << endl;
	return 0;
}


Measured memory_bytes: 3488