akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string txt = Console.ReadLine();

            if (txt.Length<=0) {
                Console.Write(txt);
            }

            string strTxt = strRight(txt, 1);
            if (strTxt == "s") {
                Console.WriteLine(txt + "es");
            } else if (strTxt!="s") {
                Console.WriteLine(txt + "s");
            }

        }

        public static string strRight(string strText, int intCount) {
            if (strText.Length >= intCount) {
                return strText.Substring(strText.Length - intCount);
            }

            return strText;
        }
    }
}

Measured memory_bytes: 25896
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, ans = 1000; cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n - 1; i++) if(a[i] < a[i + 1])
		ans = ans/a[i] * a[i + 1] + (ans % a[i]);
	cout << ans;

	return 0;
}

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

int main(){
  int a,b,sum;
  cin >>a>>b;
  sum = 0;
  for (int i = a;a <=b;a++){
    int o,p,q,r,s;
    o = a%10;
    p = (a/10)%10;
    q = (a/100)%10;
    r = (a/1000)%10;
    s = a/10000;
    if (o ==s && p == r){
      sum += 1;
    }
  }
  cout << sum <<endl;
}
    

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
d = [[0, 0] for _ in range(m)]
for i in range(m):
    d[i] = list(map(int, input().split()))
d.sort(key=lambda x: x[1])
ans = 0
target = 0
for dd in d:
    if target == 0:
        ans += 1
        target = dd[1]
    else:
        if dd[0] >= target:
            ans += 1
            target = dd[1]
print(ans)


Measured memory_bytes: 67616
n=int(input())
ini=5000
dic={
    "a":ini,
    "b":ini,
    "c":ini,
    "d":ini,
    "e":ini,
    "f":ini,
    "g":ini,
    "h":ini,
    "i":ini,
    "j":ini,
    "k":ini,
    "l":ini,
    "m":ini,
    "n":ini,
    "o":ini,
    "p":ini,
    "q":ini,
    "r":ini,
    "s":ini,
    "t":ini,
    "u":ini,
    "v":ini,
    "w":ini,
    "x":ini,
    "y":ini,
    "z":ini,
}

for _ in range(n):
    s=input()
    for i,v in dic.items():
        dic[i]=min(s.count(i), v)
ans=""
for i,v in sorted(dic.items()):
    ans+=i*v
print(ans)


Measured memory_bytes: 3064
import numpy as np
from bisect import bisect_left

A, B, Q = map(int, input().split(' '))
S = [-np.inf] + [int(input()) for _ in range(A)] + [np.inf]
T = [-np.inf] + [int(input()) for _ in range(B)] + [np.inf]
X = [int(input()) for _ in range(Q)]

def solve(x):

    Si, Ti = bisect_left(S, x), bisect_left(T, x)
    Sw, Se = abs(x-S[Si-1]), abs(x-S[Si])
    Tw, Te = abs(x-T[Ti-1]), abs(x-T[Ti])
    return min(max(Sw, Tw), max(Se, Te), 2*Tw+Se, 2*Sw+Te, 2*Se+Tw, 2*Te+Sw)

for x in X:
    print(solve(x))

Measured memory_bytes: 25164
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int ansWat = 0, ansSug = 0;

    for(int i = 0; i <= F; i+=B*100) {
        for (int k = 0; k <= F - i; k+=A*100) {
            int wat = i + k;
            if (wat > F) break;

            double allow = min((double)F - wat, (k/100.0) * E + (i/100.0) * E);
            for (int ds = 0; ds <= allow; ds += D) {
                for (int cs = 0; cs <= allow - ds; cs += C) {
//                    if (ds + cs > allow) continue;
                    int sug = ds + cs;
                    if (wat + sug == 0) continue;
                    double kosa = 100 * sug / (wat + sug);
//                    cout << i + k << " " <<  ds + cs << " " << allow << endl;
//                    if (kosa > maxKosa) {
                    if (sug * (ansWat + ansSug) >= ansSug * (wat + sug)) {
//                        cout << "k" << endl;
                        ansWat = wat;
                        ansSug = sug;
                    }
                }
            }
        }
    }

    cout << ansWat + ansSug << " " << ansSug << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
while 1:
    n = int(raw_input())
    if n == 0: break
    L = [0]*n
    D = [0]*n
    for man in xrange(n):
        m,l = map(int,raw_input().split())
        L[man] = l
        t = 0
        for date in xrange(m):
            s,e = map(int,raw_input().split())
            for s in xrange(s-6,e-6):
                t |= 1 << s
        D[man] = t

    dp = [defaultdict(int) for i in xrange(n)]
    dp[0][D[0]] = L[0]
    for i in xrange(1,n):
        for bit in dp[i-1].keys():
            if bit&D[i] == 0:
                dp[i][bit|D[i]] = max(dp[i][bit|D[i]], dp[i-1][bit]+L[i])
            dp[i][bit] = max(dp[i][bit],dp[i-1][bit])
        dp[i][D[i]] = max(dp[i][D[i]], L[i])
        
    ans = max(max(dp[i].values()) for i in xrange(n))
    print ans

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

using namespace std;

#define F first
#define S second

int N, K;
int H[100005];
int dp[100001];

int main() {
	cin >> N; 
	H[0] = INT32_MAX; // to avoid RTE
	for (int i = 1; i <= N; i++) cin >> H[i];
	for (int i = 0; i <= N; i++) dp[i] = INT32_MAX;
	int ans = 0;
	
	dp[N] = 0;
	for (int i = N; i > 1; i--) {
		for (int j = 1; j <= 2; j++) {
			dp[i - j] = min(dp[i - j], abs(H[i] - H[i - j]) + dp[i]);
		}
	}

	cout << dp[1] << endl;

	return 0;
}

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

int main() {
  int n, ans = 1000000;
  string s, r="";
  cin >> n >> s;
  vector<int> west(n), east(n);
  west.at(0) = 0;
  east.at(0) = 0;
  for (int i=0; i<n; ++i) {
    r+=s.at(n-1-i);
  }
  // cout << r << endl;
  for (int i=1; i<n; ++i) {
    if (s.at(i-1) == 'W') west.at(i) = west.at(i-1)+1;
    else west.at(i) = west.at(i-1);
    if (r.at(i-1) == 'E') east.at(i) = east.at(i-1)+1;
    else east.at(i) = east.at(i-1);
  }
  for (int i=0; i<n; ++i) {
    ans = min(ans, west.at(i) + east.at(n-1-i));
   // cout << ans << endl;
   // if (i == 1) cout << east.at(4);
  }
  cout << ans << endl;
  /*for (int i=0; i<west.size(); ++i) {
    cout << west.at(i) << endl; 
  } */
}

Measured memory_bytes: 3588
/*
Educational DP Contest - C - Vacation
https://atcoder.jp/contests/dp/tasks/dp_c
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
 
int main()  
{ 
    FAST_INP;
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++) {
    	cin >> a[i] >> b[i] >> c[i];
	}
    // dp[i][j] means max point we can gain by doing activity j on i-th day
	int dp[n][3];
	// base cases
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    // day 1 .. n-1
    for(int i=1;i<n;i++){
    	dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);	
	}
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
} 


Measured memory_bytes: 5920
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int N=100005;
int vis[N],dis[N];
stack<int> s;
vector<int> g[N];
void dfs(int cu){
	vis[cu]=1;
	for(auto u:g[cu]){
		if(vis[u]==0){
			dfs(u);
		}
	}
	s.push(cu);
}
int main(){
	int n,m;cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;
		g[x].push_back(y);
	}
	memset(vis,0,sizeof(vis));
	memset(dis,0,sizeof(dis));
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			dfs(i);
		}
	}
	int mx=0;
	while(s.size()>0){
		int cu=s.top();
	//	cout<<cu<<" ";
		s.pop();
		for(auto u:g[cu]){
			dis[u]=max(dis[cu]+1,dis[u]);
			mx=max(dis[u],mx);
		}
	}
//	cout<<endl;
	cout<<mx<<endl;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define ff first
#define ss second
#define loop(i,k,n) for(int i=k;i<n;++i)
#define rloop(i,n,k) for(int i=n;i>=k;i--)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define all(v) v.begin(),v.end()
#define mset(a,i) memset(a,i,sizeof(a))
#define mii map<int,int>  
#define pii pair<int,int>
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define mp make_pair
#define pb push_back
#define mod 1000000007  
#define endl "\n"
#define inf 1e18

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds1;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { if(0) return; cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args){   
    if(0) return; 
    const char* comma = strchr (names + 1, ',');
    cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
void get_it_done(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int gcd(int a,int b){
    if(b==0) return a;
    if(a<b) return gcd(b,a);
    return gcd(b,a%b);
}
const int N = 1e5+5;
int dp[N][2];
int n;
vi adjList[N];

int dfs(int node,int color,int par){
    if(dp[node][color]!=-1){
        return dp[node][color];
    }
    int ans = 0;
    int sum1 = 1,sum2 = 1;
    if(!color){
        for(auto x:adjList[node]){
            if(x!=par){
                sum1 = (sum1*dfs(x,1,node))%mod;
            }
        }
    }else{
        sum1 = 0;
    }
    for(auto x:adjList[node]){
        if(x!=par){
            sum2 = (sum2*dfs(x,0,node))%mod;
        }
    }
    ans = (sum1+sum2)%mod;
    return dp[node][color] = ans;
}

void solve(){
    cin>>n;   
    loop(i,0,n-1){
        int u,v;
        cin>>u>>v;
        adjList[u].pb(v);
        adjList[v].pb(u);
    }
    mset(dp,-1); 
    int ans = (dfs(1,0,-1))%mod;
    cout<<ans<<endl;
}

int32_t main(){
    get_it_done(); 
    int tc=1;
    // cin >> tc;
    while (tc--){
        solve();        
    }
}


Measured memory_bytes: 14208
K,N = map(int,input().split())
A = list(map(int,input().split()))
Max = A[1] - A[0]
for i in range(N-1):
    if Max< A[i+1] - A[i]:
        Max = A[i+1] - A[i]
a = K + A[0] - A[N-1]
if a > Max:
    print(K-a)
else:
    print(K-Max)

Measured memory_bytes: 25840
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
	string s;
	cin >> s;
	
	bool b = true;
	if(s[2] != s[3]) b = false;
	if(s[4] != s[5]) b = false;
	
	cout << (b ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
long long f[500010][3],ans;
int n;
char s[500010];
main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	if (n<3)
	{
		puts("0");
		return 0;
	}
	s[0]='0',s[n+1]='0',s[n+2]='0';
	int pre=0,now=1;
	while (now<=n+2)
	{
		while(s[now]!='0')
			now++;
		if(now==pre+1)
		{
			ans+=max(f[pre][0],max(f[pre][1],f[pre][2]));
			pre=now;
			now++;
			continue;
		}
		f[now][0]=max(f[pre][0],max(f[pre][1],f[pre][2]));
		if(s[now+1]=='1')
			if(now==pre+2)
				f[now][1]=f[pre][0]+now-pre-1;
			else
				f[now][1]=max(f[pre][1]+now-pre-2,f[pre][0]+now-pre-1);
		if(s[now-1]=='1')
		{
			int pos=now;
			while(pos+1<=n&&s[pos+1]=='1')
				pos++;
			if(now==pre+2)
				f[now][2]=f[pre][0]+pos-now;
			else
				f[now][2]=max(max(f[pre][0],f[pre][1]),f[pre][2]-1)+pos-now;
		}
		pre=now;
		now++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 12416
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

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

using namespace std;

typedef long long int lli;

int main() {
    string s;
    cin >> s;
    cout << s.substr(0, s.size() - 8) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, i;

    scanf("%d", &n);

    int list[n];

    for (i = 0; i < n; i++)
    {
        scanf("%d", &list[n - 1 - i]);
    }

    for (i = 0; i < n; i++)
    {
        printf("%d", list[i]);
        if (i != n - 1)
        {
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 2660
N,M = map(int,input().split())
steps = [1,1,2]
for i in range(3,N+1):
    steps.append(steps[i-1]+steps[i-2])
ans = 1
a = 0
mod = 10**9+7
for i in range(M):
    b = int(input())
    b -=1
    if(b<a):
        print(0)
        exit()
    else:
        ans = ans*steps[b-a]%mod
    a = b+2
ans = ans*steps[N-a]%mod
print(ans)

Measured memory_bytes: 460020
N, K = map(int, input().split())
p = list(map(int, input().split()))
p_sum = [0]
max = 0

for i in range(len(p)):
    p_sum.append(p_sum[i] + (p[i]+1)/2) 

for i in range(K,N+1):
    sum = p_sum[i] - p_sum[i-K]
    if(max < sum):
        max = sum
# for i in range(N-K+1):
#     tmp = p[i]
#     # print("i:" + str(i))
#     for j in range(i+1,i+K):
#         tmp += p[j]

#     # print(tmp)
#     if(max < tmp):
#         max = tmp 
#         maxStartIndex = i
# ans = 0
# for i in range(maxStartIndex, maxStartIndex+K):
#     sum = p[i] * (p[i]+1) / 2
#     ans += sum/p[i]
print('{:.12f}'.format(max))
# 1 2 3 
# 3 2 1


# n, n-1, n-2
# n(n + 1)/2 

Measured memory_bytes: 25060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        String ans = "";
        for (int i = 0; i < s.length(); i++) {
            ans += "x";
        }
        System.out.println(ans);
    }
}

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

int main() {
  int N, M; cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  vector<pair<int, int>> BC(M);
  for (int i = 0; i < M; i++) {
    int b, c; cin >> b >> c;
    BC.at(i).first = c;
    BC.at(i).second = b;
  }
  sort(BC.begin(), BC.end(), greater<pair<int, int>>());
  vector<int> D;
  int cnt = N;
  for (auto p : BC) {
    bool flag = false;
    for (int i = 0; i < p.second; i++) {
      D.push_back(p.first);
      cnt--;
      if (cnt == 0) {
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
  long long sum = 0;
  int sizeofD = D.size();
  for (int i = 0; i < min(N, sizeofD); i++) sum += max(A.at(i), D.at(i));
  for (int i = min(N, sizeofD); i < N; i++) sum += A.at(i);
  cout << sum << endl;
}


Measured memory_bytes: 2044
import bisect

N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
C.sort()

count=0
i=0
for i in range(N):
    countA = bisect.bisect_left(A, B[i])
    #print(bisect.bisect_left(A, B[i]))

    countB = N - bisect.bisect_right(C, B[i])
    #print(bisect.bisect_right(C, B[i]))

    count += countA * countB

print(count)


Measured memory_bytes: 23292
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  ll n;
  ll ans=0;
  cin >> n;
  ll s=n;
  bool flag=true;
  int cnt=0;
  for(int i=0; s>0; i++){
    if(s%10!=0)flag=false;
    s/=10;
    cnt++;
  }

  if(flag){
    for(int i=0; n/10!=0; i++){
      ans+=9;
      n/=10;
    }
    cout << ans << endl;return 0;
  }

  string t;
  t=to_string(n);
  for(int i=0; i<t.size(); i++){
    if(t[i]!='9'){flag=false;break;}
    else{flag=true;}
  }
  if(flag){
    cout << t.size()*9 << endl;return 0;
  }
  ll nans=0;
  nans+=n%10;
  for(int i=0; n>=10; i++){
    ans+=9;
    n/=10;
    nans+=n%10;
  }
  cout << max(ans+n-1,nans) << endl;

}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int a[300];
int b[300];

void mainmain(){
	int n;
	rep(i,26){
		a[i]='a'+i;
		a[i+26]='A'+i;
		b['a'+i]=i;
		b['A'+i]=i+26;
	}
	while(cin>>n,n){
		vint v(n);
		rep(i,n){
			cin>>v[i];
		}
		string s;
		cin>>s;
		int cnt=0;
		stringstream ss;
		rep(i,s.size()){
			cnt%=v.size();
			char t=b[s[i]];
			t=a[(t-v[cnt++]+52)%52];
			ss<<t;
		}
		string ans;
		ss>>ans;
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1224
n = gets.chomp.chars
arr = []
res = 0
if n[0] === n[1] && n[1] === n[2]
  puts n.join.to_i
else
  9.times do |i|
    new_i = arr.fill((n[0].to_i + i).to_s, 0, 3).join.to_i
    if new_i >= n.join.to_i
      res = new_i
      break
    end
  end
  puts res
end

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int max(int x, int y){return x > y ? x : y;}
int main(){
	int n; cin >> n;
	int h[n];
	int ans = 0, tmp = 0;
	for(int i=0;i<n;i++) cin >> h[i];
	for(int i=0;i<n-1;i++){
		if(h[i] >= h[i+1]) tmp++;
		else{
			ans = max(ans, tmp);
			tmp = 0;
		}
	}
	ans = max(ans, tmp);
	cout << ans << endl;
}


Measured memory_bytes: 640
/* long long or int & the MAX_INT or MIN_INT */
/* the size of a[] & inline */
/* xx 396*/

#include<bits/stdc++.h>
using namespace std;

const int MAX_N=2e3+10;

int has[MAX_N],sum[MAX_N],N;
long long ans=0;

signed main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>N;
	for(int i=0;i<N;i++){
		int x; cin>>x; has[x]++;
	}
	for(int i=1;i<MAX_N;i++) sum[i]=sum[i-1]+has[i]; 
	for(int i=1;i<=1000;i++) for(int j=i+1;j<=1000;j++){
		int Max=i+j-1,Min=j+1;
		int now=sum[Max]-sum[Min-1];
		ans+=1ll*has[i]*has[j]*now;
	}
	for(int i=1;i<=1000;i++){
		int Max=i+i-1;
		int now=sum[Max]-has[i];
		ans+=1ll*has[i]*(has[i]-1)/2*now;
	}
	for(int i=1;i<=1000;i++)
		ans+=1ll*has[i]*(has[i]-1)*(has[i]-2)/6;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//ABC096A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if(a <= b){
		cout << a << endl;
	}else{
		cout << a-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
N=int(input())
h=list(map(int,input().split()))
dp=[0]*N
dp[1]=abs(h[1]-h[0])
for i in range(2,N):
    dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]))
print(dp[-1])

Measured memory_bytes: 13980
#include <iostream>
#include <string>

using namespace std;

int N;
string str;

const int NMAX = 100000 + 10 + 5;
bool type[NMAX];

int main()
{
    cin >> N;
    cin >> str;
    str = " " + str;

    str += str[1];

    for (int i = 0; i < 2; ++ i)
        for (int j = 0; j < 2; ++ j) {
            type[1] = i;
            type[2] = j;

            for (int k = 2; k <= N + 1; ++ k)
                if (type[k] == 0) {
                    if (str[k] == 'o')
                        type[k + 1] = type[k - 1];
                    else
                        type[k + 1] = type[k - 1] ^ 1;
                }
                else {
                    if (str[k] == 'o')
                        type[k + 1] = type[k - 1] ^ 1;
                    else
                        type[k + 1] = type[k - 1];
                }
            if (type[1] == type[N + 1] && type[2] == type[N + 2]) {
                for (int k = 1; k <= N; ++ k)
                    if (type[k] == 0)
                        cout << 'S';
                    else
                        cout << 'W';
                cout << '\n';
                return 0;
            }
        }

    cout << "-1\n";
    return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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;
};

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int X, Y, Z; cin >> X >> Y >> Z;
  cout << (X - Z) / (Y + Z) << endl;


  return 0;
};


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

// AtCorder用のTemplate
namespace Atcoder{
    public class main{

        // 標準入力用汎用関数
        static string readString(){return Console.ReadLine();}
        static int readInteger(){return int.Parse(Console.ReadLine());}
        static long readLong(){return long.Parse(Console.ReadLine());}
        static double readDouble(){return double.Parse(Console.ReadLine());}
        static decimal readDecimal(){return decimal.Parse(Console.ReadLine());}

        static List<char> readCharL(char separator=' '){return Console.ReadLine().Split(separator).Select((x) => Convert.ToChar(x)).ToList();}
        static List<string> readStringL(char separator=' '){return Console.ReadLine().Split(separator).ToList();}
        static List<int> readIntegerL(char separator=' '){return Console.ReadLine().Split(separator).Select((x) => int.Parse(x)).ToList();}

        static void print<T>(T args){Console.WriteLine(args);}
        static void printL<T>(List<T> _list){Console.WriteLine(string.Join(",", _list));}

        public static void Main(string[] args)
        {
            var tmp = readIntegerL();
            int N = tmp[0];
            int M = tmp[1];
            int C = tmp[2];
            var B = readIntegerL();

            int counter = 0;

            foreach(var i in Enumerable.Range(0, N))
            {
                var sum = 0;
                var _list = readIntegerL();
                for(var j = 0; B.Count() > j; j++)
                {
                    var tmp2 = _list[j] * B[j];
                    sum += tmp2;
                }
                if((sum + C) > 0)
                {
                    counter++;
                }
            }
            Console.WriteLine(counter);
        }
    }
}


Measured memory_bytes: 13396
a, b, c, x, y = map(int,input().split())

if x == y:
    ans = min(a * x + b * y, c * x * 2)
elif x > y:
    ans = min(a * x + b * y, c * x * 2, c * y * 2 + a *(x-y))
else:
    ans = min(a * x + b * y, c * y * 2, c * x * 2 + b *(y-x))

print(ans)


Measured memory_bytes: 2940
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

char a[60];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    scanf("%s", a);
    int r = 0;
    for (int i = 0; i < n-2; i++)
        if (a[i] == 'A' && a[i+1] == 'B' && a[i+2] == 'C')
            r++;
    printf("%d\n", r);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n;
    cin>>n;
    int t[n];
    int sum=0;
    rep(i,n) {cin>>t[i];sum+=t[i];}
    int m;cin>>m;
    int p[m],x[m];
    rep(i,m){
        cin>>p[i]>>x[i];p[i]--;
    }
    rep(i,m){
        cout<<sum-t[p[i]]+x[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=5e5+10;
const ll MOD=1e9+7;
ll Frac[MAXN],InF[MAXN],Sum;
inline ll fpow(ll a,ll x){
    ll ans=1;
    for(;x;x>>=1,a=a*a%MOD) if(x&1) ans=ans*a%MOD;
    return ans;
}
inline void pre(){
    Frac[0]=1;
    for(int i=1;i<=5e5;i++)
        Frac[i]=Frac[i-1]*i%MOD;
    InF[int(5e5)]=fpow(Frac[int(5e5)],MOD-2);
    for(int i=5e5-1;i>=0;i--)
        InF[i]=InF[i+1]*(i+1)%MOD;
}
inline ll A(ll n,ll m) { return Frac[n]*InF[n-m]%MOD; }
inline ll C(ll n,ll m) { return Frac[n]*InF[n-m]%MOD*InF[m]%MOD; }
int main(){
    pre();
    ll Bas=1,N,M;
    cin>>N>>M;
    for(int i=0;i<=N;i++){
        Sum+=C(N,i)*A(M-i,N-i)%MOD*A(M-i,N-i)%MOD*A(M,i)%MOD*Bas;
        Sum=(Sum%MOD+MOD)%MOD;
        Bas*=-1;
    }
    cout<<Sum;
    return 0;
}

Measured memory_bytes: 11392
N, M = map(int, input().split())
p = [0] * M
s = [0] * M
for i in range(M):
    p[i], s[i] = map(str, input().split())
    p[i] = int(p[i])

'''
a = [0] * M
for i in range(M):
    a[i] = [p[i],s[i]]
'''
maru = [0] * (N+1)
batu = [0] * (N+1)

for i in range(M):
    if s[i] == "AC" and maru[p[i]] == 0:
        maru[p[i]] += 1 
    elif s[i] == "AC" and maru[p[i]] != 0:
        continue
    elif s[i] == "WA" and maru[p[i]] != 0:
        continue
    elif s[i] == "WA" and maru[p[i]] == 0:
        batu[p[i]] += 1

batu_ans = 0
for i in range(1, N+1):
    if maru[i] != 0:
        batu_ans += batu[i]

print(sum(maru), batu_ans)

Measured memory_bytes: 14924
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int D,G;
int p[15],c[15];
int dp[15][1500];
signed main(){
    scanf("%lld %lld",&D,&G);
    int maxp=0;
    rep(i,D){
        scanf("%lld %lld",&p[i],&c[i]);
        maxp=max(maxp,p[i]);
    }
    rep(i,D+1)rep(j,D*maxp+1)dp[i][j]=-INF;
    rep(i,D){
        rep(j,D*maxp+1){
            if(i==0&&j==0)dp[i][j]=0;
            rep(p_num,p[i]+1){
                if(p_num!=p[i])dp[i+1][j+p_num]=max(dp[i+1][j+p_num],dp[i][j]+p_num*(i+1)*100);
                else dp[i+1][j+p_num]=max(dp[i+1][j+p_num],dp[i][j]+p_num*(i+1)*100+c[i]);
            }
        }
    }
    int ans=-1;
    rep(j,D*maxp+1){
        //printf("%lld/",dp[D][j]);
        if(dp[D][j]>=G){ans=j;break;}
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 1860
#include <stdio.h>
#include <stdlib.h>

int main(){
        int n, n2,ans=0;
        scanf("%d",&n);
        int *cursin,*tmp,*tmp2;
        cursin = (int *)malloc(sizeof(int)*n);
        tmp = (int *)malloc(sizeof(int)*n);
        tmp2 = (int *)malloc(sizeof(int)*n);

        for(int i=0;i<n;i++){
                scanf("%d",&n2);
                tmp[i]=n2;
        }
        for(int i=0;i<n;i++){
                scanf("%d",&n2);
                cursin[i]=n2;
        }
        for(int i=0;i<n-1;i++){
                scanf("%d",&n2);
                tmp2[i]=n2;
        }

        for(int i=0;i<n;i++){
                n2=tmp[i];
                ans+=cursin[n2-1];
                if(n2==tmp[i-1]+1&&i)ans+=tmp2[n2-2];
        }

        printf("%d\n",ans);

        return 0;
}

Measured memory_bytes: 128
n,k = map(int, input().split())

if k == 0:
    print(n**2)
    exit()

ans = 0
for b in range(1,n+1):
    one_loop_k = b-k
    if one_loop_k <=  0: continue
    loop_cnt = n//b
    ans += one_loop_k*loop_cnt

    rem = n-loop_cnt*b
    ans += max(0,rem-k+1)
    # print(b,ans)

print(ans)

Measured memory_bytes: 66684
N,H = map(int,input().split())
a,b = [0]*N,[0]*N
for i in range(N):
    a[i],b[i] = map(int,input().split()) 
ma = max(a)
count=0
for bi in sorted(b, reverse=True):
    if bi<ma:
        break
    count += 1
    H -= bi
    if H<=0:
        break
if H > 0:
    if H%ma == 0:
        count += H//ma
    else:
        count += H//ma +1
print(count)



Measured memory_bytes: 12080
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if x < min(a):
    # print('x < min(a)')
    print(0)
    exit()
res = 0  # 喜ぶ子供の人数
cnt = 0  # お菓子を配った子供の数
for i in range(len(a)):
    if x >= a[i]:
        # お菓子を配る
        res += 1
        x -= a[i]
        cnt += 1
        # print('a[i], x = ', a[i], x)
    else:
        break
if x > 0:
    # print('x > 0')
    # まだもらっていない子供がいるならその子供に配る
    # そうでないなら既にもらった子供に配る-->喜ぶ子供が1人減る
    if cnt >= n:
        # print('cnt >= n')
        res -= 1
print(res)


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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}

int nodes = 1;

vec<pii> E;

bool b[Sz];

int n;

void dfs (int v, int sz) {
  if (sz == 1)
    return;
  int nxt = sz-1;
  while (!b[nxt]) {
    nxt--;
    E.pb ({v, ++nodes});
  }
  int to = ++nodes;
  E.pb ({v, to});
  dfs (to, nxt);
}

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap(); 
  char s[Sz];
  cin >> s + 1;
  int n = strlen (s + 1);
  for (int i = 1; i <= n; i++) {
    b[i] = (s[i] - '0');
  }
  for (int i = 1; i <= n; i++) {
    if (b[i] ^ b[n - i]) {
      cout << -1;
      return 0;
    }
  }
  if (!b[1]) {
    cout << -1;
    return 0;
  }

  dfs (1, n);

  for (auto x : E)
    cout << x.x << ' ' << x.y << endl;

  return 0;
}






// Coded by Z..


Measured memory_bytes: 8820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    int V = n*n;
    vector<vector<int>> G(V);
    rep(i, 2*n*n-2*n){
        int a,b;
        cin >>a >>b;
        --a;
        --b;
        G[a].pb(b);
        G[b].pb(a);
    }

    vector<vector<int>> x(n, vector<int>(n,-1));

    rep(i,V)if(G[i].size() == 2){
        x[0][0] = i;
        x[0][1] = G[i][0];
        x[1][0] = G[i][1];
        break;
    }

    for(int i=2; i<n; ++i){
        int pre = x[0][i-2];
        int v = x[0][i-1];
        for(int e:G[v]){
            if(G[e].size()<=3 && e!=pre) x[0][i] = e;
        }
    }

    for(int i=2; i<n; ++i){
        int pre = x[i-2][0];
        int v = x[i-1][0];
        for(int e:G[v]){
            if(G[e].size()<=3 && e!=pre) x[i][0] = e;
        }
    }

    for(int i=1; i<n; ++i)for(int j=1; j<n; ++j){
        int p = x[i-1][j], q = x[i][j-1], r = x[i-1][j-1];
        for(int np:G[p])for(int nq:G[q]){
            if(np==nq && np!=r) x[i][j] = np;
        }
    }

    rep(i,n)rep(j,n) cout << x[i][j]+1 << " \n"[j==n-1];
    return 0;
}



Measured memory_bytes: 3476
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a,b,c,d,x,y,z;
  string s,t,u;
  //

  // ここから
  IN3(s,t,u);
  OUT("A"+gCh(t,0)+"C");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int Maxn = 100000 + 100;
LL A[Maxn], Sum1[Maxn], Sum2[Maxn];
LL N, K;
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%lld%lld", &N, &K);
	for (LL i = 1; i <= N; ++i)
	{
		scanf("%lld", &A[i]);
		Sum1[i] = Sum1[i - 1] + A[i];
		if (A[i] > 0) Sum2[i] = Sum2[i - 1] + A[i];
		else Sum2[i] = Sum2[i - 1];
	}
	LL Ans = 0ll;
	for (LL i = 1; i + K - 1 <= N; ++i)
	{
		LL Sum = Sum2[N] - (Sum2[i + K - 1] - Sum2[i - 1]);
		if (Sum1[i + K - 1] - Sum1[i - 1] > 0) Sum += Sum1[i + K - 1] - Sum1[i - 1];
		Ans = max(Ans, Sum);
	}
	cout<<Ans<<endl;
	return 0;
}

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

int main() {
	char c;
	cin>>c;
	if(c=='A')      cout<<'T'<<endl;
	else if(c=='T') cout<<'A'<<endl;
	else if(c=='G') cout<<'C'<<endl;
	else if(c=='C') cout<<'G'<<endl;
	
	return 0;
}








Measured memory_bytes: 256
import math
n, m = map(int, input().split())
mod = 10**9+7

t = math.factorial(n)*math.factorial(m)
if n == m:
    print((2*t)%mod)
elif abs(n-m) > 1:
    print(0)
elif abs(n-m) <= 1:
    print(t%mod)


Measured memory_bytes: 5184
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

vector<int> solve(int freemask, int a, int b, int mask) {
    const int n = __builtin_popcount(freemask);
    a = a & freemask;
    b = b & freemask;
    const int weight_diff = __builtin_popcount(a ^ b);

    if (weight_diff % 2 == 0) {
        return vector<int>();
    }

    if (n == 1) {
        if (weight_diff != 1) {
            return vector<int>();
        }
        return {mask ^ a, mask ^ b};
    }

    const int msb = 1 << __builtin_ctz(a ^ b);
    const int second_msb = 1 << __builtin_ctz(freemask ^ msb);

    const int first_newmaskbit = msb & a;
    const int second_newmaskbit = msb & b;

    auto first = solve(freemask ^ msb, a, b ^ second_msb, mask ^ first_newmaskbit);
    auto second = solve(freemask ^ msb, b ^ second_msb, b , mask ^ second_newmaskbit);
    first.insert(first.end(), second.begin(), second.end());
    return first;
}

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

    int n, a, b;
    cin >> n >> a >> b;
    auto ans = solve((1 << n) - 1, a, b, 0);
    if (ans.empty()) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
        set<int> distinct;
        for (int i = 0; i < ans.size(); ++i) {
            cout << ans[i];
            distinct.insert(ans[i]);
            if (i + 1 == ans.size()) {
                cout << endl;
            } else {
                cout << " ";
                if (__builtin_popcount(ans[i] ^ ans[i + 1]) != 1) {
                    cerr << "err!!!! at: " << i  << endl;
                    
                }
            }
        }
        if (distinct.size() != (1 << n)) {
            cerr << "size valid failed" << endl;
        }
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> d(60,0),d2(60,0);
  int sum = 0, sqsum = 0;
  for(int i=0; i<n; i++){
    cin >> d[i];
    sum += d[i];
    d2[i] = d[i]*d[i];
    sqsum += d2[i];
  }
  cout << (sum*sum - sqsum)/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n, m;
	cin >> m >> n;
	vector<int> per;
	vector<vector<int> > G;
	G.resize(m);
	bool used[m];
	per.resize(m);
	for (int i = 0; i < m; i++)
		per[i] = 0, used[i] = false;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		per[y]++;
		G[x].push_back(y);
	}
	used[1] = true;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (used[j])
				continue;
			if (!per[j]) {
				used[j] = true;
				cout << j + 1 << endl;
				for (int k = 0; k < G[j].size(); k++)
					per[G[j][k]]--;
			}
		}
	}

	cout << 2 << endl;
	return 0;
}

Measured memory_bytes: 3108
import sys 
input = sys.stdin.readline
MOD = 10**9 +7
INF = 10**9
from bisect import bisect_right

def main():
    n = int(input())
    a = list(map(int,input().split()))
    dic = {}
    for num in a:
        if num in dic:
            dic[num] += 1
        else:
            dic[num] = 1
    
    tot = 0
    for v in dic.values():
        if v >= 2:
            tot += v * (v - 1)//2
    
    for num in a:
        if dic[num] == 1:
            print(tot)
        elif dic[num] == 2:
            print(tot - 1)
        else:
            l = dic[num]
            print(tot + 1 - l)        



if __name__=='__main__':
    main()

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

int A, B;
string op;

int main() {
    cin >> A >> op >> B;

    if (op == "+") {
        cout << A + B << endl;
    } else {
        cout << A - B << endl;
    }
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};
const main=()=>{
  let n=tn(),[s,t]=tss(2),ans=''
  for(let i=0;i<n;i++){
    ans+=s[i]+t[i]
  }
  to(ans)
}
main()


Measured memory_bytes: 7500
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int x=0;
  
  vector<int> p(n+1);
  p[0]=0;
  
  rep(i,n){
    if(s[i]=='<') x++;
    else x=0;
  p[i+1]=x;
  }
  
  ll sum=p[n];
  x=0;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='>') x++;
    else x=0;
  sum+=max(p[i],x);
  }
  
  cout << sum << endl;
  
}


Measured memory_bytes: 2948
local DBG = false
function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end
function dbgpr_t(tbl)
    if DBG then
        for i,v in ipairs(tbl) do
            io.write("[dbg]")
            print(i,v)
        end
    end
end
function parse_table(N)
    local tbl = {}
    for i=1,N do
        table.insert(tbl, io.read("n"))
    end
    return tbl
end
function getline()
    local k = io.read("n")
    local tbl = parse_table(k)
    io.read("l")
    return tbl
end

function main()
    local n, m = io.read("n","n")
    io.read("l")
    local voted = {}
    for i=1,m do
        voted[i] = 0
    end
    for i=1,n do
        local like = getline()
        --dbgpr("like",i)
        --dbgpr_t(like)
        for i,v in ipairs(like) do
            voted[v] = voted[v] + 1
        end
    end
    local count = 0
    for i=1,m do
        if voted[i] == n then
            count = count + 1
        end
    end
    print(count)
end
main()


Measured memory_bytes: 760
#import<bits/stdc++.h>
using namespace std;
int N,K,S,T,U,i,j;
vector<int>A;
long c[51][51]={1},P[51],a,w;
main()
{
	for(cin>>N>>K>>S>>T;cin>>j;){if(!(~j&S|j&~T))A.push_back(j);for(c[++i][j=0]=1;j++<K;)P[i]+=c[i][j]=c[i-1][j-1]+c[i-1][j];}
	for(;U<1<<18;w=!++U)
	{
		map<int,int>M;
		for(int v:A)M[v&U]++;
		for(auto[p,q]:M)w+=P[q];
		if(!(~U&S|U&~T))a+=__builtin_parity(U&~S)?-w:w;
	}
	cout<<a;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    ll n; cin >> n;
    vector<P> vec;
    for(ll i = 1; i*i <= n; i++) {
        if(n%i == 0) vec.push_back(P(i, n/i));
    }
    ll ans = 1e13;
    for(auto e : vec) {
        ll tmp = 0;
        if(e.first == 0 && e.second == 0) continue;
        tmp += e.first-1;
        tmp += e.second-1;
        ans = min(ans, tmp);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>

int N;
std::map<std::string, bool> cnt;
int main()
{
    std::cin >> N;
    std::string before;
    std::string temp;
    bool ans = true;
    for (int i = 0; i < N; ++i)
    {
        std::cin >> temp;
        if (ans && cnt.find(temp) != cnt.end())
            ans = false;
        if (ans && i > 0 && before[before.size() - 1] != temp[0])
            ans = false;
        if (ans)
            cnt[temp] = true;
        before = temp;
    }

    if (ans)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256