akhauriyash/Code-Regression huggingface dataset:
//Patwari26
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll kk;
    cin>>kk;
    ll ans=0;
    rep(i,1,kk){
        rep(j,1,kk){
            rep(k,1,kk){
                ans+=(gcd(gcd(i,j),k));
            }
        }
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

int main () {
    string I;
    cin >> I;
    int A = I[0] - '0';
    int B = I[1] - '0';
    int C = I[2] - '0';
    int D = I[3] - '0';
    string op[8] {"+++","++-","+-+","+--","---","--+","-++","-+-"};

    for(int i = 0; i<8; i++) {
        int res = 0;
        if(op[i][0] == '+') {
            res = A + B;
        } else {
            res = A - B;
        }
        if(op[i][1] == '+') {
            res += C;
        } else {
            res -= C;
        }
        if(op[i][2] == '+') {
            res += D;
        } else {
            res -= D;
        }
        if(res == 7) {
            cout << A << op[i][0] << B << op[i][1] << C << op[i][2] << D << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

int main(){
    while (true){
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                if (i == 0 || i == h-1 || j == 0 || j == w-1) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
    cout << endl;
    }
    return 0;
}


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


int main(){
	ll N,ans=0;
  cin>>N;
  
  for(ll i=1;i<N+1;i++){

    if(!(i%3==0 || i%5==0)){
    	ans+=i;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
using namespace std;
#define ll long long 
ll mod = 1000000007;
ll n, a, b, c, d;
ll factorial[1005];
ll ifactorial[1005];
ll memo[1005][1005];


ll power(ll a, ll b){ //ok
	a %= mod;
	if (b == 0) return 1;
	if (b == 1) return a;
	ll half = power(a, b/2);
	half *= half;
	half %= mod;
	if (b % 2){
		half *= a;
	}
	return half % mod;
}

ll p(ll n, ll k){ //ok
	return (factorial[n]*ifactorial[n - k])%mod;
}

ll dp(ll index, ll siz){
	if (index == n) return 1;
	if (index > n) return 0;
	if (siz > b) return 0;
	if (memo[index][siz] != -1) return memo[index][siz];
	ll answer = 0;
	for (int i = c; i <= d; i++){
		if (i*siz > n - index) break;
		ll subans = p(n - index, i*siz)*power(ifactorial[siz], i);
		subans %= mod;
		subans *= ifactorial[i];
		subans %= mod;
		subans *= dp(index + i*siz, siz + 1);
		subans %= mod;
		answer += subans;
		answer %= mod;
		//cout << index << " " << siz << " " << answer << endl;
	}
	answer += dp(index, siz + 1);
	answer %= mod;
	return memo[index][siz] = answer;
}

int main(){
	memset(memo, -1, sizeof(memo));
	factorial[0] = 1;
	ifactorial[0] = 1;
	for (int i = 1; i < 1005; i++){
		factorial[i] = i*factorial[i - 1];
		factorial[i] %= mod;
		ifactorial[i] = power(factorial[i], mod - 2);
	}
	
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
	printf("%lld\n", dp(0, a));
}

Measured memory_bytes: 8192
#include <algorithm>
#include <cstdio>

const int MAXN = 100 + 5;

int n;
int a[MAXN];

bool judge(int x, int y, int z) {
    if (x == y or x == z or y == z)
        return false;
    return 0ll + x + y + z > 2ll * std::max(x, std::max(y, z));
}

// x + y + z >= 2max

int main() {
    int i, j, k, ans = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (i = 1; i <= n; i++)
        for (j = i + 1; j <= n; j++)
            for (k = j + 1; k <= n; k++)
                if(judge(a[i], a[j], a[k]))
                    fprintf(stderr, "%d %d %d\n", i, j, k), ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1740
import itertools as it
    
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

s = set()

for i in range(n):
    li= list(it.combinations(A, i+1))
    for j in range(len(li)):
        s.add(sum(li[j]))

for k in range(q):
    print('yes' if m[k] in s else 'no')

Measured memory_bytes: 58128
///****In the name of ALLAH, most Gracious, most Compassionate****//

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

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

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

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

const int N=3e5+5;
const int oo=1e9+7;
int mx[N];

int32_t main()
{
    FastIO;
    int n;
    cin>>n;
    int nn=n;
    int ans  = 0;
    while(n--)
    {
        int a;
        cin>>a;
        mx[a]= max(mx[a] , mx[a-1]+1);
        ans = max(ans , mx[a]);
    }
    cout<<nn-ans<<"\n";
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  ll N; cin >> N;
  printf("%lld:", N);

  ll num = N;
  for (ll i = 2; i * i <= N; i++){
    while (num % i == 0){
      printf(" %lld", i);
      num /= i;
    }
  }
  if (num > 1) printf(" %lld", num);
  cout << endl;
  return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const int MAXK=2000;
const int MAXN=2000;
const LL mods=998244353;
struct M{
	LL x;
	M(){
		x=0;
	}
	M(LL angka){
		if(angka>=mods||angka<=-mods)
			angka%=mods;
		if(angka<0)
			angka+=mods;
		x=angka;
	}
	
	M operator + (const M &other) const{
		return M(x + other.x);
	}
	M operator - (const M &other) const{
		return M(x - other.x);
	}
	M operator * (const M &other) const{
		return M(x * other.x);
	}
	M operator - () const{
		return M(-x);
	}
	
	M DnC(LL pangkat){
		if(pangkat==0)
			return 1;
		
		M ret = DnC(pangkat>>1);
		ret = ret * ret;
		
		if(pangkat&1)
			ret = ret * x;
		
		return ret;
	}
	
	M inverse(){
		return DnC(mods-2);
	}
};

int n,k;
M dp[MAXN+5][MAXK+5];
M fillFunction(){
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			dp[i][j]=0;
			
			if(j!=1)
				dp[i][j] = dp[i][j] + dp[i][j-1];
			
			if(i==1)				//basecase
				dp[i][j] = dp[i][j] + 1;
			else
				dp[i][j] = dp[i][j] + dp[i-	1][j];
		}
	}
}
M f(int n){
	//cout<<"nilainya "<<n<<endl;
	assert(n>=0);
	if(n==0)
		return 1;
	return dp[n][k];
}

M sumComb[MAXK+5][MAXK+5];
M fillComb(){
	M tempInverse[MAXK+5];
	for(int i=1;i<=k;i++)
	{
		tempInverse[i]=i;
		tempInverse[i]=tempInverse[i].inverse();
	}
	for(int i=0;i<=k;i++)
	{
		sumComb[i][i]=1;
		
		M temp = 1;
		for(int j=i+1;j<=k;j++)
		{
			temp = temp * j * tempInverse[j-i];

			sumComb[j][i] = sumComb[j-1][i] + temp;
		}
	}
}
int main()
{
	cin>>k>>n;
	fillFunction();
	fillComb();
	
	for(int i=2;i<=(k<<1);i++)
	{
		//cout<<"printing "<<i<<endl;
		int batas=0;
		for(int j=1;j<=(i-j);j++)
		{
			if(1<=j&&(i-j)<=k)
				batas++;
		}
		
		batas--;
		
		M ans = f(n);
		M temp = 0;
		//cout<<"batasnya "<<batas<<endl;
		for(int i = 0, tanda = 1; i<=batas; i++ , tanda = -tanda)
		{
			if(n-2*(i+1)<0)
				continue;
			temp = temp + sumComb[batas][i] * f(n-2*(i+1)) * tanda;
		}
		//cout<<" at first "<<ans.x<<" dan "<<temp.x<<endl;
		ans = ans - temp;
		cout<<ans.x<<endl;
	}
}


Measured memory_bytes: 63232
import java.util.Scanner


object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val a,b = sc.nextInt()
    val big = Math.max(a,b)
    val small = Math.min(a,b)
    val result =
      if(big >= small + 1) big + (big -1)
      else big + small
    println(result)
  }
}

Measured memory_bytes: 27448
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim L As Integer() = New Integer(2 * N - 1) {}
        For i As Integer = 0 To 2 * N - 1
            L(i) = NextInt()
        Next
        Array.Sort(L)

        Dim ans As Integer
        For i As Integer = 0 To N - 1
            ans += Math.Min(L(2 * i), L(2 * i + 1))
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

template<class T>bool ch1000000(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; }




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}



int main() {
  // ll N;
  // cin >> N;
  // string ans = "";
  // bool z = false;
  // ll a = 1;

  // while(a <= 100){
  //   N = a;
  //   ans = "";
  //   z = false;
  //   cout << a << endl;
  //   while(true){
  //     ll resi = N % 26;
  //     if(resi == 0){
  //       resi = 26;
  //       z = true;
  //     }
  //     char code = resi + 96;
  //     ans += code;
  //     N /= 26;
  //     if(z) N -= 1;
  //     if(N <= 0) break;
  //   }
  //   reverse(all(ans));
  //   cout << ans << endl;
  //   a++;
  // }

  int N;
  cin >> N;
  ll sum = 0;
  vector<int> A(N), cnt(1e5+1, 0);
  rep(i, 0, N){
    cin >> A[i];
    cnt[A[i]]++;
    sum += A[i];
  }

  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  rep(i, 0, Q){
    ll b, c;
    cin >> b >> c;
    B[i] = b;
    C[i] = c;
  }

  rep(i, 0, Q){
    ll Bi = B[i], Ci = C[i];
    sum -= Bi*cnt[Bi];
    sum += Ci * cnt[Bi];
    cnt[Ci] += cnt[Bi];
    cnt[Bi] = 0;
    cout << sum << endl;
  }

  
  

  
  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 4820
#coding:utf-8
import itertools

N,M,R=map(int,raw_input().split())
R=map(int,raw_input().split())
D=[[1145141919810]*300 for _ in range(300)]
for i in range(M):
    a,b,c=map(int,raw_input().split())
    D[a][b]=c;D[b][a]=c

for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            if D[i][j]>D[i][k]+D[k][j]:
                D[i][j]=D[i][k]+D[k][j]
ans=1145141919810
for P in itertools.permutations(R):
    s=P[0]
    l=0
    for t in P[1:]:
       l+=D[s][t]
       s=t
    ans=min(ans,l)
print(ans)    



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

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

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

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

    ll n, m;
    cin >> n >> m;
    ll srt, lng;
    cin >> srt >> lng;
    rep(i, m - 1)
    {
        ll a, b;
        cin >> a >> b;
        srt = max(srt, a);
        lng = min(lng, b);
    }
    cout << max(ll(0), lng - srt + 1) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#include <math.h>

int r[100], c[100];
int m[100][100];

 int main(){
  int n;
  int i, j;
   
  scanf("%d", &n);
  for (i = 0; i < n; i++){
    scanf("%d %d", &r[i], &c[i]);
  }
  for(i = 0; i < 100; i++){
    for(j = 0; j < 100; j++){
      m[i][j] = -1;
    }
  }
  printf("%d\n", matrix(0, n - 1));
  return 0;
}

int matrix(int left, int right)
{
  int result, i;
 
  if (m[left][right] >= 0){
    return m[left][right];
  }
  if (left == right){
    return 0;
  }
  result = INT_MAX;
  for (i = left; i < right; i++){
    result = fmin(result, matrix(left, i) + matrix(i + 1, right) + r[left] * c[i] * c[right]);
  }
  m[left][right] = result;
  return m[left][right];
}

Measured memory_bytes: 644
n = int(input())
t, a = map(int, input().split())

hs = list(map(int, input().split()))
min_i, min_diff = 0, 1e8
for i, h in enumerate(hs):
    ti = t - h * 0.006
    if abs(a - ti) < min_diff:
        min_diff = abs(a - ti)
        min_i = i

print(min_i + 1)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    static public void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int k = scan.nextInt();
        scan.close();

        int max = Math.max(Math.max(a, b), c);

        int remains = 0;
        if (max == a) {
            remains = b + c;
        } else if (max == b) {
            remains = a + c;
        } else {
            remains = a + b;
        }

        int maxResult = max;
        for (int i = 0; i < k; i++) {
            maxResult = maxResult * 2;
        }

        System.out.println(maxResult + remains);

    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define endl '\n'
#define boost                    \
	ios::sync_with_stdio(false); \
	cin.tie(0);                  \
	cout.tie(0);
#define mod 1000000007
#define inf 1e18
#define pf push_front
#define pob pop_back
#define pof pop_front
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define deb3(x, y, z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl;
#define file                          \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>> piii;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;

int32_t main()
{
	// boost
	int t = 1;
	//cin >> t;
	while (t--)
	{
		int h, w, k;
		cin >> h >> w >> k;

		string s[h];

		for (int i = 0; i < h; i++)
			cin >> s[i];

		int powh = pow(2, h);

		int poww = pow(2, w);
		int ans = 0;
		for (int i = 0; i < powh; i++)
		{
			for (int j = 0; j < poww; j++)
			{

				string temp[h];
				for (int k = 0; k < h; k++)
					temp[k] = s[k];
			//	for (int k = 0; k < h; k++)
			//		cout<<temp[k]<<endl;
				
				int ii = i, jj = j;
				int x = 0;
				while (ii)
				{

					int rem = ii % 2;
					if (rem == 1)
					{
						for (int col = 0; col < w; col++)
						{
							temp[x][col] = '/';
						}
					}
					x++;
					ii /= 2;
				}
				x = 0;
				while (jj)
				{
					
					int rem = jj % 2;
					if (rem == 1)
					{
					//	cout<<"hey";
						for (int row = 0; row < h; row++)
						{
							temp[row][x] = '/';
						}
					}
					x++;
					jj /= 2;
				}
				int cnt = 0;
				for (int row = 0; row < h; row++)
				{
					for (int col = 0; col < w; col++)
					{
						if (temp[row][col] == '#')
							cnt++;
					}
				}

				if (cnt == k)
					ans++;

			//	deb(ans);
			}
		}

		cout<<ans<<endl;
	}
}

Measured memory_bytes: 4032
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  long long i,N,T;
  long long sum=0;
  cin >> N >> T;
  long long t[N];
  for(i=0; i<N; i++){
    cin >> t[i];
  }
  for(i=0; i<N; i++){
    if(t[i]+T <= t[i+1]){
      sum += T;
    }else{
      sum += t[i+1] - t[i];
    }
  }
  cout << sum << endl;

  return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    rep(i, 25) ans += n/(ll)(10*pow(5, i));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4136
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

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

	vector<vi> f(h, vi(w)), g(h, vi(w));
	char c;
	for (int i = 0; i < h; i++)	for (int j = 0; j < w; j++) {
		cin >> c;
		if (c == '.') f[i][j] = 0; // white
		if (c == '#') f[i][j] = 1; // black
	}

	int ans = 0;

	int n = h + w;
	int m = pow(2, n);

	for (int b = 0; b < m; b++) {
		g = f;
		int bc = b;

		for (int i = 0; i < h; i++) {
			if (bc % 2) {
				for (int j = 0; j < w; j++) {
					g[i][j] = 2; // red
				}
			}
			bc >>= 1;
		}

		for (int j = 0; j < w; j++) {
			if (bc % 2) {
				for (int i = 0; i < h; i++) {
					g[i][j] = 2; // red
				}
			}
			bc >>= 1;
		}

		int cnt = 0;
		for (int i = 0; i < h; i++)	for (int j = 0; j < w; j++) {
			if (g[i][j] == 1) cnt++;
		}
		if (cnt == k) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4072
n = int(input())
a = []
for _ in range(5):
    a.append(int(input()))
min_num = a[0]
for i in range(5):
    if min_num > a[i]:
        min_num = a[i]
res = n // min_num + 5
if n % min_num == 0:
    res -= 1
print(res)


Measured memory_bytes: 9092
n = int(input())
ans = 10**9
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
for a in range(1,n//2+3):
    b = n-a
    if a>=1 and b>=1:
        
        ans = min(digitSum(a)+digitSum(b),ans)
print(ans)

Measured memory_bytes: 3060
R, C, N = map(int, input().split())
pts = []
for i in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    zs = []
    for x, y in [(x1, y1), (x2, y2)]:
        if y == 0:
            zs.append((x, i))
        elif x == R:
            zs.append((R+y, i))
        elif y == C:
            zs.append((2*R+C-x, i))
        elif x == 0:
            zs.append((2*R+2*C-y, i))
    if len(zs) == 2:
        pts += zs

pts.sort()

stack = []
for z, i in pts:
    if not stack:
        stack.append(i)
    else:
        if stack[-1] == i:
            stack.pop()
        else:
            stack.append(i)

if not stack:
    print('YES')
else:
    print('NO')


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

#define int long long
#define pb push_back
#define ff first
#define ss second

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;
    
    int n=s.length();
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 3800
fun main() {
    val s = readLine()!!
    val arr = Array(2){IntArray(2019)}
    var ans = 0L
    var cur = 0

    // 1817181712114

    for(i in s.indices) {
        val d = s[i] - '0'
        val req = (2019 - d) % 2019
        val ni = (cur + 1) % 2

        ans += arr[cur][req]

        for(j in 0 until 2019) {
            arr[ni][j] = 0
        }
        for(j in 0 until 2019) {
            if(arr[cur][j] > 0) {
                val next = ((j + d) * 10) % 2019
                arr[ni][next] += arr[cur][j]
            }
        }
        arr[ni][d * 10] += 1
        cur = ni
    }
    print(ans)
}


Measured memory_bytes: 39752
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

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


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] vOdd = new int[100001];
		int[] vEven = new int[100001];
		int maxOdd=0,maxEven=0,maxNumOdd=0,maxNumEven=0;
		for( int i=1; i<=N/2; i++ ){
			vOdd[sc.nextInt()]++;
			vEven[sc.nextInt()]++;
		}
		for( int i=1; i<=100000; i++ ){
			if( vOdd[i]>maxOdd ){
				maxOdd = vOdd[i];
				maxNumOdd = i;
			}
			if( vEven[i]>maxEven ){
				maxEven = vEven[i];
				maxNumEven = i;
			}
		}
		Arrays.sort(vOdd);
		Arrays.sort(vEven);
		int ans = 0;
		if( maxNumOdd!=maxNumEven ){
			ans = N - maxOdd - maxEven;
		}else{
			int a = N - maxOdd - vEven[99999];
			int b = N - maxEven - vOdd[99999];
			ans = Math.min(a,b);          
		} 
		System.out.println(ans);     
	}
}


Measured memory_bytes: 50036
def func(H,W):
    if H % 3 == 0:
        return 0

    H_3 = int(H/3)
    S1 = H_3 * W
    S2 = (H - H_3) * int(W/2)
    S3 = H * W - S1 - S2 
    
    res1 = max(S1, S2, S3) - min(S1, S2, S3)
    
    H_3_1 = int(H/3) + 1
    S1 = H_3_1 * W
    S2 = (H - H_3_1) * int(W/2)
    S3 = H * W - S1 - S2 
    
    res2 = max(S1, S2, S3) - min(S1, S2, S3)
    
    return min(res1 ,res2)
H, W = list(map(int, input().split()))
print(min(func(H,W), func(W,H), H, W))

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

import numpy as np

N = int(input())
A = np.array([int(input()) for _ in range(N)])

from_left = np.maximum.accumulate(A)
from_right = np.maximum.accumulate(A[::-1])[::-1]

from_left, from_right

from_left = [0] + from_left.tolist()[:-1]
from_right = from_right[1:].tolist() + [0]

for x,y in zip(from_left, from_right):
    print(x if x > y else y)


Measured memory_bytes: 33932
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;

  int PS=1;
  int ans=0;

  while(PS<b){
    PS--;
    PS+=a;
    ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            dp[i] = Math.min(dp[i - 1] + Math.abs(h[i] - h[i - 1]),
                    dp[i - 2] + Math.abs(h[i] - h[i - 2]));
        }
        System.out.println(dp[n - 1]);
    }

}


Measured memory_bytes: 49744
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

struct too_long {};

vector<string> expand(const vector<string>& v, const map<string, vector<string> >& syntax)
{
  static const string::size_type MAXLEN = 200;
  vector<string> ans;
  for (vector<string>::const_iterator it = v.begin(); it != v.end(); ++it) {
    if ((*it)[0] == '[') {
      // terminal
      ans.push_back(it->substr(1, it->size()-2));
    } else {
      // non-terminal
      const vector<string> w = expand(syntax.find(*it)->second, syntax);
      for (vector<string>::const_iterator jt = w.begin(); jt != w.end(); ++jt) {
        ans.push_back(*jt);
      }
    }
    if (ans.size() > MAXLEN) {
      throw too_long();
    }
  }
  return ans;
}

int solve(const vector<string>& tokens, int A, int T, int G, int C)
{
  static int dp[201][51][51][51];
  dp[0][0][0][0] = 1;
  const int L = A+T+G+C;
  static const int M = 1000000007;

  for (int i = 0; i < L; i++) {
    const string& token = tokens[i];
    const bool has_a = token.find('A') != string::npos;
    const bool has_t = token.find('T') != string::npos;
    const bool has_g = token.find('G') != string::npos;
    const bool has_c = token.find('C') != string::npos;
    for (int a = 0; a <= A; a++) {
      for (int t = 0; t <= T; t++) {
        for (int g = 0; g <= G; g++) {
          const int c = i - a - t - g;
          if (c < 0) {
            continue;
          }
          const int cur = dp[i][a][t][g];
          if (has_a && a+1 <= A) {
            dp[i+1][a+1][t][g] = (dp[i+1][a+1][t][g] + cur) % M;
          }
          if (has_t && t+1 <= T) {
            dp[i+1][a][t+1][g] = (dp[i+1][a][t+1][g] + cur) % M;
          }
          if (has_g && g+1 <= G) {
            dp[i+1][a][t][g+1] = (dp[i+1][a][t][g+1] + cur) % M;
          }
          if (has_c && c+1 <= C) {
            dp[i+1][a][t][g] = (dp[i+1][a][t][g] + cur) % M;
          }
        }
      }
    }
  }
  return dp[L][A][T][G];
}

int main()
{
  int a, t, g, c;
  cin >> a >> t >> g >> c;
  int M;
  cin >> M;
  cin.ignore();
  map<string, vector<string> > syntax;
  vector<string> top;
  for (int i = 0; i < M; i++) {
    string s;
    getline(cin, s);
    replace(s.begin(), s.end(), ':', ' ');
    istringstream iss(s);
    string k;
    iss >> k;
    vector<string> v;
    for (string x; iss >> x;) {
      v.push_back(x);
    }
    if (i == 0) {
      top = v;
    }
    syntax.insert(make_pair(k, v));
  }

  try {
    vector<string> tokens = expand(top, syntax);
    if (tokens.size() != a+g+c+t) {
      cout << 0 << endl;
    } else {
      cout << solve(tokens, a, t, g, c) << endl;
    }
  } catch (const too_long&) {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 101648
L = int(input())
A = [int(input()) for i in range(L)]

DP = [[0 for i in range(5)] for j in range(L+1)]

def cost(s, a):
    if s == 0 or s == 4:
        return a
    elif s == 1 or s == 3:
        if a > 0:
            return a%2
        else:
            return 2
    else:
        return (a+1)%2

for i in range(L):
    DP[i+1][0] = min(DP[i][:1]) + cost(0, A[i])
    DP[i+1][1] = min(DP[i][:2]) + cost(1, A[i])
    DP[i+1][2] = min(DP[i][:3]) + cost(2, A[i])
    DP[i+1][3] = min(DP[i][:4]) + cost(3, A[i])
    DP[i+1][4] = min(DP[i][:5]) + cost(4, A[i])

print(min(DP[L]))

Measured memory_bytes: 74104
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int ceil(int a, int b) { return (a + b - 1) / b; }

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

    int h, w;
    cin >> h >> w;

    if(h==1||w==1){
        cout << 1 << endl;
        return 0;
    }

    const int ans = ceil(h, 2) * ceil(w, 2) + (h / 2) * (w / 2);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int flag=1;
    for(int i=0;i<s.length();)
    {
        string t5=string(s,i,5);
        string t6=string(s,i,6);
        string t7=string(s,i,7);

        if(t7=="dreamer"&&(s[i+7]=='d'||s[i+7]=='e'||i+7==s.length()))
        {
            i+=7;
        }
        else if(t6=="eraser"&&(s[i+6]=='d'||s[i+6]=='e'||i+6==s.length()))
        {
            i+=6;
        }
        else if(t5=="dream"&&(s[i+5]=='d'||s[i+5]=='e'||i+5==s.length()))
        {
            i+=5;
        }
        else if(t5=="erase"&&(s[i+5]=='d'||s[i+5]=='e'||i+5==s.length()))
        {
            i+=5;
        }

        else
        {
          // cout<<i<<endl;
        //   cout<<t5<<endl;
       // cout<<t6<<endl;
          //  cout<<t7<<endl;
            flag=0;
            break;
        }
    }
    if(flag==1)
        puts("YES");
    else
        puts("NO");
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
  print(0)
  exit()
v = 1
for i in range(n):
  v *= a[i]
  if v>1000000000000000000:
    print(-1)
    exit()
if v > 1000000000000000000:
  print(-1)
else:
  print(v)

Measured memory_bytes: 21708
//#include<studio.h>
#include <bits/stdc++.h>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int n;
	cin>>n; // input N of button
	vector <int> v;
	
	for (int i=0;i<n; i++)
	{
		int z;
		cin>>z;	// input route movement
      //cout<<z<<endl;
		z--;
		v.push_back(z); //add inside array
	}
	
	//start the rount searching
	
	int now=0, c=0;//now:current button position,c:count
	
	for(;;)//loop
	{
		if(now==1)//loop w/o reaching 2
		{
		cout<<c;
		break;
		}
		
		if(c>=n)
		{
			cout<<"-1"<<endl;
			break;
		}
		
		/*if(now==2)// reach 2
		{
        //c++;
		cout<<c<<endl;
		break;
		}*/
		
		c++;
		now =v[now];
     // cout<<now<<endl;;
	}
}
	

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,next;
	cin>>n;
	vl v(n),x(n-1),y(n-1);
	bool pl=false,mi=false;
	rep(i,n)cin>>v[i],pl|=(v[i]>=0),mi|=(v[i]<=0);
	if(!pl|!mi){
		sort(all(v),[](auto &a,auto &b){
		return (abs(a)<abs(b));
		});
		swap(v[0],v[1]);
		next=v[0];
		rep(i,n-1){
			if(i!=0){
				if(v[i+1]>0&&next>0)next*=-1;
				else if(v[i+1]<0&&next<0)next*=-1;
			}
			x[i]=next;
			y[i]=v[i+1];
			next=abs(next-v[i+1]);
		}
	}
	else{
		rep(i,n-1){
			if(v[0]>=0&&v[i+1]<=0||v[0]<=0&&v[i+1]>=0)swap(v[1],v[i+1]);
		}
		next=v[0];
		rep(i,n-1){
			if(i!=0){
				if(v[i+1]>0&&next>0)next*=-1;
				else if(v[i+1]<0&&next<0)next*=-1;
			}
			x[i]=next;
			y[i]=v[i+1];
			next=abs(next-v[i+1]);
		}
	}
	rep(i,n-2){
		if(x[i+1]<0&&x[i]>y[i])swap(x[i],y[i]);
		else if(x[i+1]>0&&x[i]<y[i])swap(x[i],y[i]);
	}
	if(x[n-2]<y[n-2])swap(x[n-2],y[n-2]);
	puta(next);
	rep(i,n-1){
		puta(x[i],y[i]);
	}
}


Measured memory_bytes: 4224
def main():
    n, m, c = map(int, input().split())
    b_lst = list(map(int, input().split()))
    a_lst = [0] * n
    for i in range(n):
        a_lst[i] = list(map(int, input().split()))

    count = 0
    for i in range(n):
        ab = 0
        for j in range(m):
            ab += a_lst[i][j] * b_lst[j]
        abc = ab + c

        if abc > 0:
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9116
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int i;
  int N;
  long long a[300010];
  scanf("%d", &N);
  for (i = 0; i < 3*N; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a+3*N);
  /*for (i = 0; i < 3*N; i++) {
    printf("%lld ", a[i]);
    }*/
  long long ans = 0;
  for (i = N; i <= 3*N-2; i += 2) {
    ans += a[i];
  }
  printf("%lld", ans);
  return 0;
}


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

using namespace std;
vector<vector<int>> dp;


int solve(string &s, string &t, int n, int m)
{
	if(n == 0 || m == 0)
	{
		return 0;
	}

	if(dp[n][m] != -1)
	{
		return dp[n][m];
	}

	int ans;
	if(s[n-1] == t[m-1])
	{
		ans = solve(s, t, n-1, m-1)+1;
	}
	else
	{
		ans = max(solve(s, t, n-1, m), solve(s, t, n, m-1));
	}

	dp[n][m] = ans;

	return ans;
}


int main() 
{
	string s, t;
	cin>>s>>t;
	dp.clear();
	// ans.clear();
	int n = s.length(), m = t.length();
	for(int i = 0;i<=n;i++)
	{
		dp.push_back(vector<int> (m+1, -1));
		// ans.push_back(vector<string> (m+1, ""));
	}

	int l = solve(s, t, n, m);
	

	int i = n, j = m;
	char res[l+1];
	res[l] = '\0';
	l--;
	while(i > 0 && j > 0)
	{
		if(s[i-1] == t[j-1])
		{
			res[l--] = s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j] > dp[i][j-1])
			i--;
		else
			j--;
	}

	cout<<res<<endl;
}

Measured memory_bytes: 36096
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	// input1 = input[0].split(' ').map((n) => (parseInt(n)))
	h = input[1].split(' ').map((n) => (parseInt(n)))
	c = input[2].split(' ').map((n) => (parseInt(n)))
	// ans = input.filter((n) => (s <= n)).length

	var ans = 0
	for (var i = 0;i  < h.length; i++) {
		var tmp = h[i] - c[i]
		if (tmp > 0 ) {
			ans += tmp
		}
	}

	//出力
	console.log(ans)
}
// *この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
const int nMax=1e5, MOD=1e9+7;
ULL inv[nMax], Fact[nMax], invF[nMax];
ULL pw(ULL a, ULL n){ ULL b=1; while(n){ if(n&1){ b=(b*a)%MOD; } a=(a*a)%MOD; n>>=1; } return b; }
int main(){
inv[1]=Fact[0]=Fact[1]=invF[0]=invF[1]=1;
for(int i=2; i<nMax; i++){ 
  inv[i]=((MOD-MOD/i)*inv[MOD%i])%MOD;
  Fact[i]=(Fact[i-1]*i)%MOD; invF[i]=(invF[i-1]*inv[i])%MOD;
}
ULL N, ans=0; cin >> N; ULL x[N], p[N-1];
for(int i=0; i<N; i++){ cin >> x[i]; }
p[0]=Fact[N-1];
for(int i=1; i<N-1; i++){ p[i]=(p[i-1]+(Fact[N-1]*pw(i+1, 1e9+5))%MOD)%MOD; }
for(int i=0; i<N-1; i++){ ans=(ans+((x[i+1]-x[i])*p[i])%MOD)%MOD; }
cout << ans << "\n";
}

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

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var intArray = IO.ReadIntArray();
			var N = intArray[0];
			var K = intArray[1];
			long A = N + 1;
			long B = K - 1;
			var allNum = A * (A * A + 5);
			var difNum = -B * ((2 * B * B) + (3 * B) - 5 - (3 * A * (B + 1)));
			var combinationNum = (allNum - difNum) / 6;
			IO.Write(combinationNum % ModNumber);
		}
		private const long ModNumber = 1000000007;
	}

	public static class IO
	{
		public static string   Read()								 { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')		 { return Read().Split(iSplitter); }
		public static int	   ReadInt()							 { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()							 { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static double   ReadDouble()							 { return double.Parse(Read()); }
		public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()						 { return Read().ToCharArray(); }

		public static void Write(string iValue)									   { Console.WriteLine(iValue); }
		public static void Write(int iValue)									   { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue , string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord , iValue)); }
		public static void Write(long iValue)									   { Console.WriteLine(iValue); }
		public static void Write(double iValue)									   { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)								   { Console.WriteLine(iValue); }
		public static void Write(bool iValue)									   { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


Measured memory_bytes: 28296
#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,w;
	vector<pair<lli,lli>> p;

	cin>>n>>w;
	REP(i,0,n){
		lli a,b;
		cin>>a>>b;
		p.push_back(make_pair(a,b));
	}

	map<lli,lli> dp;
	dp[0]=0;

	REP(i,0,n){
		for(auto itr = dp.rbegin(); itr != dp.rend();itr++){
			lli nextW = itr->first + p[i].first;
			if(nextW <= w){
				dp[nextW] = max(dp[nextW],itr->second+p[i].second);
			}
		}
	}

	lli ans=0;
	for(auto e:dp)ans = max(ans,e.second);
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 6400
N = int(input())

ends_with_A = 0
starts_with_B = 0
both = 0

count = 0

for _ in range(N):
  s = input()
  count += s.count('AB')
  if s.endswith('A') and s.startswith('B'):
    both += 1
  elif s.endswith('A'):
    ends_with_A += 1
  elif s.startswith('B'):
    starts_with_B += 1

# 結合した文字が AXXXXXX or XXXXXXXB となるとき     
if ends_with_A + starts_with_B > 0:
  print(count + both + min(ends_with_A, starts_with_B))
else:  
  print(count + max(both - 1, 0) + min(ends_with_A, starts_with_B))
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(n);
    CIN(i);
    cout<<n-i+1<<endl;
}



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

int main()
{
    string S, T;
    int c = 0;
    int t = 0;
    int o;

    cin >> S;
    cin >> T;

    o = T.length();

    for (int i = 0; i < S.length() - T.length() + 1; i++)
    {
        // 文字列比較
        c = 0;
        for (int k = 0; k < T.length(); k++)
        {
            if (S[k + i] == T[k])
                c++;
        }
        t = T.length() - c;
        if (t < o)
            o = t;
    }
    cout << o << endl;
}

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    bool ans = true;

    for (int i=0; i<n; i++) {
        int a; cin >> a;
        if (a % 2 != 0) continue;
        if (a % 3 != 0 && a % 5 != 0) ans = false;
    }

    cout << (ans? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
struct edge { int to, cap, rev; };

vector<edge>g[100];
bool used[100];
int n, a[100+2];
ll ans = 0;

void add_edge(int from, int to, int cap) {
	g[from].push_back(edge{ to, cap, (int)g[to].size() });
	g[to].push_back(edge{ from, 0, (int)g[from].size() - 1 });
}

int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < g[v].size(); i++) {
		edge& e = g[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(int s, int t) {
	ll flow = 0;
	for (;;) {
		//cout << "a" << endl;
		fill(used, used + n, 0);
		int f = dfs(s, t, INT32_MAX);
		if (f == 0)return flow;
		flow += f;
	}
}

void display() {
	for (int i = 0; i < n + 2; i++) {
		cout << "i:" << i << endl;
		for (int j = 0; j < g[i].size(); j++) {
			edge e = g[i][j];
			cout << "  to:" << e.to << " cap:" << e.cap << endl;
		}
	}
}

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

		if (a[i] >= 0) {
			add_edge(i, n+1, a[i]);
			ans += a[i];
		}
		else {
			add_edge(n, i, -a[i]);
		}

		for (int j = 2; (i + 1)*j <= n; j++) {
			add_edge(i, (i + 1)*j - 1, INT32_MAX);
		}
	}

	ll flow = max_flow(n, n + 1);
	cout << ans-flow << endl;
}

Measured memory_bytes: 256