akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int cnt[1000005], mark[1000005], a[1000005];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	
	for (int i = 1; i <= 1000000; i++) {
		if (!cnt[i]) continue;
		if (cnt[i] >= 2) mark[i]++;
		for (int j = 2; j * i <= 1000000; j++) mark[j * i]++;
	}
	
	int res = 0;
	
	for (int i = 0; i < n; i++) {
		if (mark[a[i]] == 0) res++;
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 12156
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int train = N * A;
    cout << ((train < B) ? train : B) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c=0,d=0,m,e=0;
  cin>>a>>b>>c;
  for(int i=1;i<=a;i++){
    m=i;
    d=0;
    while(m){
      d=d+m%10;
      m=m/10;
    }
    if(d>=b && d<=c) e=e+i;
  }
  cout<<e<<"\n";
  return(0);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
 
public class Main {
	long get(int[] Wi, int T) {
		long s1 = 0;
		long s2 = 0;
		
		for (int i=0; i<Wi.length; i++) {
			if (i <= T) {
				s1 += Wi[i];
			} else {
				s2 += Wi[i];
			}
		}
		
		return Math.abs(s1-s2);
	}
	
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] Wi = new int[N];
		for (int i=0;i<N; i++) {
			Wi[i] = in.nextInt();
		}
		in.close();
		
		long min = Integer.MAX_VALUE;
		
		for (int i=0; i<N; i++) {
			long x = get(Wi, i);
			min = Math.min(min, x);
		}
		
		System.out.println(min);
		
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
 
}


Measured memory_bytes: 22612
import sys

class alphabet: #Trueなら大文字
    def __init__(self, capitalize):
        self.num = dict() #アルファベットを数字に変換
        self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\
            ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        if capitalize: 
            for i in range(26): self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc): self.num[a] = i


def solve():
    a = input()
    AB = alphabet(False)
    if a in AB.abc: print("a")
    else: print("A")

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9084
#include<iostream>
#include<vector>
#include<bitset>
using namespace std;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    int c[n];
    int a[n][m];
    
    for(int i=0;i<n;i++){
        cin >> c[i];
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }

    int ans=100000000;
    for(int bit=0;bit<(1<<n);bit++){
        bitset<12> B(bit);
        int cnt=0;
        int sum=0;
        vector<int> val(n);
        for(int i=0;i<n;i++){
            if(B[i]){
                sum+=c[i];
                for(int j=0;j<m;j++){
                    val[j]+=a[i][j];
                }
            }
        }
        for(int i=0;i<m;i++){
            if(val[i]>=x) cnt++;
        }
        if(cnt==m) ans = min(ans,sum);
    }
    if(ans==100000000){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 3636
import Control.Monad (replicateM)
import Data.Functor ((<$>))
import Data.List ((\\))

readCard :: String -> (String, Int)
readCard s = let [suit, rank] = words s
            in (suit, read rank)

showCard :: (String, Int) -> String
showCard (suit, rank) = suit ++ " " ++ show rank

main :: IO ()
main = do
    n <- read <$> getLine
    cards <- replicateM n (readCard <$> getLine)
    let all_cards = [(suit, rank) | suit <- ["S", "H", "C", "D"], rank <- [1 .. 13]]
    putStr . unlines . map showCard $ all_cards \\ cards



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

#define pi 3.14159265358979323846264338327950L
int main()
{
    long double a, b, h, m;
    cin >> a >> b >> h >> m;

    long double angle = pi * 2 * ( h / 12.0 + ( m / 60.0 ) / 12.0 - m / 60.0 );

    long double ans = ( a * a + b * b ) - 2 * a * b * cosl( angle );

    printf( "%20.20Lf\n", sqrt( ans ));
    return 0;
}

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

using namespace std;
#define int long long
#define double long double
#define rep(i, n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
#define FI first
#define SE second
typedef pair<int, int> pii;
#define l_b lower_bound
#define u_b upper_bound

int N, K;

signed main() {
    cin >> N >> K;
    int ans = 0;
    if (K == 0) {
        cout << N * N << endl;
        return 0;
    }
    for (int b = K + 1; b <= N; ++b) {
        ans += (b - K) * (N / b);
        int mod = N % b;
        if (mod >= K) {
            ans += mod - K + 1;
        }
    }
    cout << ans << endl;
}


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

static const std::vector<int> map{ 0, 1, 2, 3, 5, 7, 8, 9 };
void oct(const int &num) {
	if (num != 0) {
		oct(num / 8);
		std::cout << map.at(num % 8);
	}
}
int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		oct(n);
		std::cout << "\n";
		std::cin >> n;
	}
}

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


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && b == c) cout << "No"  << endl;
    else if(a == b || b == c || c == a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            int minPeople = N;
            var W = new int[N + 1];
            W[0] = 0;

            for(int i = 1; i <= N; i++)
            {
                if (S.Substring(i - 1, 1) == "W")
                {
                    W[i] = W[i - 1] + 1;
                }else
                {
                    W[i] = W[i - 1];
                }
            }

            var E = new int[N + 1];
            E[0] = 0;

            for (int i = 1; i <= N; i++)
            {
                if (S.Substring(i - 1, 1) == "E")
                {
                    E[i] = E[i - 1] + 1;
                }
                else
                {
                    E[i] = E[i - 1];
                }
            }

            for (int i = 1; i <= N; i++)
            {
                int countPeople = 0;
                countPeople += W[i - 1];
                countPeople += E[N] - E[i];
                if (countPeople < minPeople) minPeople = countPeople;
            }

            Console.WriteLine(minPeople);
        }
    }
}

Measured memory_bytes: 18516
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) (c).begin(),(c).end()
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N,K;
string S;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> K >> S;
  int l = 0, r = 0;
  int ans = 0;
  while (r < N) {
    while (r < N && S[r] == '1') r++;
    CHMAX(ans, r-l);
    while (r < N && S[r] == '0') r++;
    K--;
    if (K < 0) {
      while (l < N && S[l] == '1') l++;
      while (l < N && S[l] == '0') l++;
      K++;
    }
    CHMAX(ans, r-l);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
typedef long long ll;
using Graph = vector<vector<int>>;

int N;

int main() {
  cin >> N;
  int count = 0;
  FOR(i,1,N+1) {
    count += (N-1)/i;
  }
  cout << count << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int n,k;
double a;
long long int cnt=0;
long long int cnt1=0;
long long int sum=0;

int main(void){
 cin>>n>>k;
 for(int i=1; i<=n; i++){
  if(i%k==0)cnt++;
  a=i-k/2.0;
  if((int)a%k==0)cnt1++;
 }
 if(k%2==0)sum=cnt*cnt*cnt+cnt1*cnt1*cnt1;
 else sum=cnt*cnt*cnt;
 printf("%lld",sum);
 return 0;
}
 

Measured memory_bytes: 256
n=int(input())
s=input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(0,n-2):
    for j in range(1,int((n-i)/2)+1):
        if i + j + j <= n-1:
            if s[i] != s[i+j] and s[i] != s[i+j+j] and s[i+j] != s[i+j+j] :
                ans = ans - 1

print(ans)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}





void solve(){
	ll n,k;
	cin>>n;
	string a;
	
	while(n>0){
        --n;
        a += 'a' + (n%26);
        n/=26;
    }
    reverse(a.begin(),a.end());
    cout<<a<<endl;




return;
}




int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    ll t;
    t=1;
  //  cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

Measured memory_bytes: 3620
N=int(input())
if 1<=N and N<=9:
	print(N)
elif N<=99:
	print(9)
elif N<=999:
	print(N-90)
elif N<=9999:
	print(909)
elif N<=99999:
	print(N-9090)
elif N==100000:
	print(90909)

Measured memory_bytes: 2940
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
A = []
B = []
L = [LIST() for i in range(N)]

# 1からi番目の料理で，j分以内に完食できるおいしさの合計の最大値
# dp1[i][j]
dp1 = [[0] * (T) for i in range(N+1)]
# # iからN番目の料理で，j分以内に完食できるおいしさの合計の最大値
# # dp2[i][j]
# dp2 = [[0] * (T) for i in range(N+1)]
# print(L)
# 昇順にする
L.sort()
for a, b in L:
    A.append(a)
    B.append(b)

for i in range(N):
    for j in range(T):
        if j - A[i] >= 0:
            dp1[i+1][j] = max(dp1[i][j-A[i]] + B[i], dp1[i+1][j])
        dp1[i+1][j] = max(dp1[i][j], dp1[i+1][j])

ans = 0
# 最後に一番時間のかかるものをT-1秒目に食べればいい
for k in range(1, N+1):
    ans = max(dp1[k-1][T-1] + B[k-1], ans)
print(ans)




exit()
for i in range(N):
    for j in range(T):
        if j - A[i] >= 0:
            dp1[i+1][j] = max(dp1[i][j-A[i]] + B[i], dp1[i+1][j])
        dp1[i+1][j] = max(dp1[i][j], dp1[i+1][j])
# やりやすく
L = L[::-1]
for i in range(N):
    for j in range(T):
        if j - A[i] >= 0:
            dp2[i+1][j] = max(dp2[i][j-A[i]] + B[i], dp2[i+1][j])
        dp2[i+1][j] = max(dp2[i][j], dp2[i+1][j])
# 戻す
L = L[::-1]
print(L)
ans = 0
for i in range(1, N+1):
    tmp = 0
    for j in range(T):
        tmp = max(tmp, dp1[i-1][j] + dp1[N-i][T-1-j])
    ans = max(ans, tmp+L[i-1][1])
print(ans)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  queue<long long> q;
  for (int i = 1; i <= 9; i++) {
    q.push(i);
  }
  long long n;
  while (k--) {
    n = q.front();
    q.pop();
    if (n % 10 != 0) {
      q.push(10 * n + n % 10 - 1);
    }
    q.push(10 * n + n % 10);
    if (n % 10 != 9) {
      q.push(10 * n + n % 10 + 1);
    }
  }
  cout << n << '\n';
  return 0;
}

Measured memory_bytes: 4760
h,w=map(int,input().split())
g=[input() for _ in range(h)]
a=[[0]*w for _ in range(h)]
for x in range(h):
  for y in range(w):
    if g[x][y]=='.': continue
    a[x][y]='#'
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1),(1,1),(-1,1),(-1,-1),(1,-1)]:
      nx,ny=x+dx,y+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.':
        a[nx][ny]+=1
for l in a:
  print(*l,sep='')

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace  std;
int main(){
    int x[2];cin>>x[0]>>x[1];
    int group[2]={0,0};
    for(int i=0;i<2;i++){
        if(x[i]==1||x[i]==3||x[i]==5||x[i]==7||x[i]==8||x[i]==10||x[i]==12){
            group[i]=1;
        }
        else if(x[i]==4||x[i]==6||x[i]==9||x[i]==11){
            group[i]=2;
        }
        else{
            group[i]=3;
        }
    }
    if(group[0]==group[1]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
N=int(input())
X=input()
a=int(X,2)

def popcount(x):
  return bin(x).count("1")
p=X.count('1')

pl=a%(p+1)
if p!=1:
  mi=a%(p-1)

def f(x):
  if x==0:
    return 1
  else:
    return f(x%popcount(x))+1

for i in range(N):
  if X[i]=='0':
    b=pl
    b+=pow(2,N-i-1,p+1)
    b%=p+1
  else:
    if p!=1:
      b=mi
      b-=pow(2,N-i-1,p-1)
      b%=p-1
    else:
      print(0)
      continue
  print(f(b))

Measured memory_bytes: 79760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int n, z, w;
vector<int> a;


int main(){
    cin >> n >> z >> w;
    a.resize(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    if(n == 1) cout << abs(a[n-1] - w) << endl;
    else {
        int ans = max(abs(a[n-1]-a[n-2]), abs(a[n-1] - w));
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {
	
	ll N;
	string S;
	cin >> N >> S;

	vector<ll> vec(1000,0);

	vector<ll> pre(10,0);
	vector<ll> fst(10,0);

	rep(i, N) {
		if (fst[S[i]-'0'] == 1) continue;
		if (i == N - 2) break;
		pre = vector<ll>(10, 0);
		for (ll j = i + 1; j < N; j++) {

			rep(k, 10) {
				if (pre[k] == 1) vec[(S[i]-'0') * 100 + k * 10 + S[j]-'0'] = 1;
			}
			pre[S[j]-'0'] = 1;
		}
		fst[S[i]-'0'] = 1;
	}

	ll ans = 0;
	rep(i, 1000) {
		if (vec[i] == 1) {
			ans++;
		}
	}
	cout << ans;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


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

int main(){
  string S; cin >> S;
  int firstnum = S.at(0) - '0';
  int secondnum = S.at(1) - '0';
  int thirdnum = S.at(2) - '0';
  int forthnum = S.at(3) - '0';

  int front = firstnum*10 + secondnum;
  int back = thirdnum*10 + forthnum;

  if(front>=1 and front<=12 and back>=1 and back<=12) cout << "AMBIGUOUS";
  else if(front>=1 and front<=12) cout << "MMYY" << endl;
  else if(back>=1 and back<=12) cout << "YYMM" << endl;
  else cout << "NA" << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1<<16;
int n,m,v[20][20];
long long ans,in[maxn],f[maxn][20];
vector<int>d[20];
int main(){
	read(n),read(m);
	for(rg int i=1,x,y,z;i<=m;i++){
		read(x),read(y),read(z),v[x][y]=v[y][x]=z;
		ans+=z;
		d[x].push_back(y),d[y].push_back(x);
	}
	int tot=1<<n;
	for(rg int i=0;i<tot;i++){
		for(rg int j=1;j<=n;j++)
			if(!(i&(1<<(j-1)))){
				int w=d[j].size(),sum=in[i];
				for(rg int k=0;k<w;k++)
					if(i&(1<<(d[j][k]-1)))sum+=v[j][d[j][k]];
				in[i|(1<<(j-1))]=sum;
		}
	}
	memset(f,-1,sizeof f);
	f[1][1]=0;
	for(rg int i=0;i<tot;i++)
		for(rg int k=1;k<=n;k++){
			if(f[i][k]==-1)continue;
			if(i&(1<<(k-1))){
				for(rg int j=1;j<=n;j++)
					if(!(i&(1<<(j-1)))&&v[k][j])
						f[i|(1<<(j-1))][j]=max(f[i][k]+v[k][j],f[i|(1<<(j-1))][j]);
				int now=((tot-1)^i)|(1<<(k-1));
				for(rg int j=now;j;j=(j-1)&now)
				    f[i|j][k]=max(f[i][k]+in[j],f[i|j][k]);
			}
		}
	printf("%lld\n",ans-f[tot-1][n]);
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
//vector
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pp pop_back
//pair
#define pi pair<int ,int >
#define mk make_pair
#define ff first
#define ss second
//set
#define si set<int>
#define sit set<int>::iterator 
using namespace std;
int main()
{
fast;
long double a,b;cin>>a>>b;
long double ans=1;
ans=a*b;
ll ans1=ans;
cout<<ans1;

return 0;
}

Measured memory_bytes: 3752
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 998244353

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    Q = int(input())

    D = dict()
    for a in A:
        D[a] = D.setdefault(a, 0) + 1
    res = [""] * Q
    S = sum(A)
    for q in range(Q):
        B, C = read_values()
        S += (C - B) * D.setdefault(B, 0)
        D[C] = D.setdefault(C, 0) + D[B]
        D[B] = 0
        res[q] = str(S)
    print("\n".join(res))


if __name__ == "__main__":
    main()



Measured memory_bytes: 93992
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
vs ans;
int n;
void dfs(string s)
{
	if(s.size()==n)
	{
		ans.pb(s);
		return;
	}
	rep2(i,SZ(s)+1)
	{
		string t=s;
		bool flag=0;
		rep2(j,SZ(s))
		{
			if(s[j]=='a'+i-1)
			{
				flag=true;
				break;
			}
		}
		if(!flag&&i)
		{
		    continue;
		}
		s+=(char)(i+'a');
		dfs(s);
		s=t;
	}
}
int main()
{
	cin>>n;
	dfs("a");
	string t="";
	rep(i,n)
	{
		t+=(char)('a'+i);
	}
	ans.pb(t);
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	rep(i,SZ(ans))
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

ll n,ans1,ans2,k,kk,p,pp;
cin>>n;
ll a[n],b[n],c[n],d[n];
for(int i=0;i<n;i++)
{
    cin>>a[i]>>b[i];
    c[i]=a[i]+b[i];
    d[i]=a[i]-b[i];
}
sort(c,c+n);
k=*max_element(c,c+n);
kk=*min_element(c,c+n);
p=*max_element(d,d+n);
pp=*min_element(d,d+n);
ans1=k-kk;
ans2=p-pp;
cout<<max(ans1,ans2)<<endl;
}


Measured memory_bytes: 9832
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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


	int n;
	cin >> n;

	vector<int> a(n);
	for (auto &v : a) {
		cin >> v;
		v--;
	}

	int cnt = 0;
	for (int i = 0; i < (int)a.size(); i++) {
		int love = a[i];
		if (i == a[love]) {
			cnt++;
		}
	}

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


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

void seek_lcs(int a,int b,int dp[10+1][10+1],int* num,int* base,vector<int>& idx){
	if(a==0 || b==0){
		return;
	}

	if(num[a] == base[b]){
		seek_lcs(a-1,b-1,dp,num,base,idx);
		idx.push_back(num[a]);
	}
	else{
		if(dp[a-1][b] >= dp[a][b-1]){
			seek_lcs(a-1,b,dp,num,base,idx);
		}
		else{
			seek_lcs(a,b-1,dp,num,base,idx);
		}
	}

}

int main()
{
	int T;
	cin >> T;
	for(int t=0;t<T;t++){

		int num[10+1];
		int base[10+1];
		int dp[10+1][10+1];

		memset(dp,0,sizeof(dp));

		for(int i=1;i<=10;i++){
			scanf("%d",num+i);
			base[i]=i;
		}
		num[0]=0;
		base[0]=0;

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(num[i+1]==base[j+1]){
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]+1));
				}
				else{
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]));
				}
			}
		}

		vector<int> idx;
		stack<int> stk;
		seek_lcs(10,10,dp,num,base,idx);

		for(int i=1;i<=10;i++){
			if(find(idx.begin(),idx.end(),num[i]) != idx.end()){
				continue;
			}

			if(stk.empty() || stk.top() < num[i]) stk.push(num[i]);
		}

		printf("%s\n",idx.size() + stk.size() == 10 ? "YES" : "NO");
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

#define TRUE 1
#define FALSE 0
#define LEN 100005

typedef struct q{
  int y;
  int x;
}QUEUE;

//int x = 0;
QUEUE *Q;
//P Q[LEN + 1];
int head = 0;
int tail = 0;
int n;

void initialize(int a){
  head = 0;
  tail = 0;
  Q = (QUEUE *)calloc(a, sizeof(QUEUE));
  if(Q == NULL){
    printf("メモリが確保できません\n");
    exit(EXIT_FAILURE);
  }
}

void finalize(){
  if(Q != NULL){
    free(Q);
    Q = NULL;
  }
}

int isEmpty(){
  if(head == tail){
    return TRUE;
  }else{
    return FALSE;
  }
}

int isFull(){
  if(head == (tail + 1) % LEN){
    return TRUE;
  }else{
    return FALSE;
  }
}

void enqueue(QUEUE x){
  fprintf(stderr, "enqueue() point.y:%d point.x:%d\n", x.y, x.x);
  if(isFull() != FALSE){
      printf("Overfllow\n");
  }else{
    Q[tail] = x;
    if((tail + 1) == LEN){
      tail = 0;
    }else{
      tail++;
    }
  }
}

QUEUE dequeue(){
  QUEUE x;
  //  fprintf(stderr, "-> dequeue\n");
  if(isEmpty() != FALSE){
    printf("Undrtfllow\n");
  }else{
    x = Q[head];
    if((head + 1 == LEN)){
      head = 0;
    }else{
      head++;
    }
  }
  return x;
}


// min
int main(void){
  long int x = 0;
  int y[6] = {100, 101, 102, 103, 104, 105};
  int total = 0;

  scanf("%ld", &x);

  if(x > 2000){
    printf("1\n");
    return 0;
  }
  
  x %= 2000;
  //  fprintf("%x")
  if(1 <= x && x < 100){
    printf("0\n");    
  }else if(106 <= x && x < 200){
    printf("0\n");
  }else if(211 <= x && x < 300){
    printf("0\n");
  }else if(316 <= x && x < 400){
    printf("0\n");
  }else if(421 <= x && x < 500){
    printf("0\n");
  }else if(526 <= x && x < 600){
    printf("0\n");
  }else if(631 <= x && x < 700){
    printf("0\n");
  }else if(736 <= x && x < 800){
    printf("0\n");
  }else if(841 <= x && x < 900){
    printf("0\n");
  }else if(946 <= x && x < 1000){
    printf("0\n");
  }else if(1051 <= x && x < 1100){
    printf("0\n");
  }else if(1156 <= x && x < 1200){
    printf("0\n");
  }else if(1261 <= x && x < 1300){
    printf("0\n");
  }else if(1366 <= x && x < 1400){
    printf("0\n");
  }else if(1471 <= x && x < 1500){
    printf("0\n");
  }else if(1576 <= x && x < 1600){
    printf("0\n");
  }else if(1681 <= x && x < 1700){
    printf("0\n");
  }else if(1786 <= x && x < 1800){
    printf("0\n");
  }else if(1891 <= x && x < 1900){
    printf("0\n");
  }else if(1996 <= x && x < 2000){
    printf("0\n");
  }else{
    printf("1\n");
  }
  return 0;

}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val h = readLine()!!.split(" ").map { it.toInt() }
    println(n - (1..m).map {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() - 1 }
        if (h[a] > h[b]) listOf(b) else if (h[a] < h[b]) listOf(a) else listOf(a, b)
    }.flatten().toSet().size)
}


Measured memory_bytes: 67960
import bisect

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()

ans = 0
for b in B:
    i = bisect.bisect_left(A,b)
    j = bisect.bisect_right(C,b)
    ans += (N-j) * i
print(ans)


Measured memory_bytes: 23232
#include "bits/stdc++.h"
using namespace std;
#define shandom_ruffle random_shuffle
#define pb push_back
#define nl puts("")
using ll = long long;
using pii = pair<ll,ll>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vlll = vector<vll>;
using mpll = map<ll,ll>;
using stch = stack<char>;
using stvll = stack<vll>;
const ll nax = 1000*1007;
const ll mno = 1007;
const ll mod = 1e9 + 7;
const ll mxN = 1e5;
const ll rc = 64;
const ll MOD = 998244353; 
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for(int i = 1; i <= n; ++i) {
     if(i % 3 != 0 && i % 5 != 0) sum += i;
  }
  cout << sum;
}

Measured memory_bytes: 3648
import numpy as np

N = int(input())
A = []
B = []

for i in range(N):
    a, b = [int(x) for x in input().split()]
    A.append(a)
    B.append(b)

C = np.array(A)
D = np.array(B)

m_inf = np.median(C)
m_sup = np.median(D)

if N % 2 == 0:
    ans = 2 * m_sup - 2 * m_inf + 1
else:
    ans = m_sup - m_inf + 1

print(int(ans))

Measured memory_bytes: 47408
gets;s=gets;t=gets;n,m=s.size-1,t.size-1;($><<-1;exit)if s[0]!=t[0];e=n.lcm m;h={};n.times{|i|h[i*e/n]=s[i]};m.times{|i|w=h[i*e/m];($><<-1;exit)if w&&w!=t[i]};$><<e

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

int gcd(int m, int n) { 
    if(n == 0)
        return m; 
    else
        return gcd(n, m % n);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> k;
 long long  int r = 0;
  for(int a=1; a< k+1; a++){
      for(int b=1;b<k+1;b++)
        for(int c=1; c<k+1;c++)
            r+=gcd(gcd(a,b),gcd(b,c));
  }   
cout << r;
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    for(ll i=m/n;i>0;i--){
        if(m%i==0){
            if(m/i>=n){
                cout << i << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias t = Tuple!(string, "name", long, "y");

void main()
{
    auto n = lread();
    auto a = aryread();
    ulong check;
    foreach(e; a)
    {
        check ^= e;
    }
    if(check)
        writeln("No");
    else
        writeln("Yes");
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 4476
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	double ans = 0;
	double x;
	string t;
	string s = "BTC";
	rep(i, n) {
		cin >> x;
		cin >> t;
		if (t == s) {
			ans += 380000 * x;
		}
		else {
			ans += x;
		}
	}
	printf("%.10f\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long gcd(long a, long b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
int main() {
	long a, b, c, d, e, f;
	cin >> a;
	for (int i = 0; i < a; ++i) {
		cin >> b >> c >> d >> e;
		if (b < c || e < c) {
			cout << "No" << endl;
		}
		else if (d >= c) {
			cout << "Yes" << endl;
		}
		else {
			f = gcd(c, e);
			if (c - f + (b%f) > d) cout << "No" << endl;
			else cout << "Yes" << endl;
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <ll, ll> ii;
typedef vector <ii> vii;
typedef vector <vii> graph;

bool comp(ll a, ll b) {
	return a > b;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    ll n;
    cin >> n;
    ll arr[n];
    map <ll, ll> kika;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i < n; i++) {
        kika[arr[0] + arr[i] - i]++;
    }
    ll cont = kika[0];
    ll ac = 0;
    for (ll i = 1; i < n - 1; i++) {
        kika[arr[0] + arr[i] - i]--;
        ac = arr[0] - arr[i] - i;
        cont += kika[ac];
    }
    cout << cont << "\n";
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
	return 0;
}

Measured memory_bytes: 27848
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int a, al, ar, i, x, y, count = 0;
    char[] c;
    String s;

    s = sc.next();
    c = new char[s.length() + 1];
    c[0] = '0';
    for(i = 0;i < s.length();i++)c[i + 1] = s.charAt(i);
    for(i = 0;i < s.length();i++){
      if(c[i + 1] != '0'){
        al = readint(c, 0, i + 1); ar = readint(c, i + 1, s.length() + 1);
        x = al + ar; y = ar - al;
        if(x % 2 == 0 && y % 2 == 0 && y >= 0)count++;
      }
    }
    out.println(count);

    sc.close();
  }
  private static int readint(char[] ch, int l, int r){
    int i, d, res, s;
    d = 1; res = 0; s = 1;
    if(ch[l] == '-'){ s = -1; l++; }
    for(i = r - 1;i >= l;i--){
      res += d * (int)(ch[i] - '0');
      d *= 10;
    }
    return res * s;
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

ll ss;
ll gcd(ll a, ll b){
	if(a<b)swap(a,b);

	ll r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}

	ss=b;
}

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

	ll s=b-a+1;
	gcd(c,d);

	

	ll e=(c*d)/ss;
	

	cout<<s-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/e-(a-1)/e)<<endl;


	return 0;
}


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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int h[5];
  while(cin >> h[0], h[0]) {    
    int rps[3] = {0};
    rps[--h[0]]++;
    reps(i, 1, 5) cin >> h[i], rps[--h[i]]++;
    int win = 3;
    if(rps[0] && rps[1] && rps[2]) win = 3;
    else if(rps[0] && rps[1]) win = 0;
    else if(rps[1] && rps[2]) win = 1;
    else if(rps[2] && rps[0]) win = 2;
    rep(i, 5) {
      if(win == 3) cout << 3 << endl;
      else if(h[i] == win) cout << 1 << endl;
      else cout << 2 << endl;
    }
  }  
  return 0;
}

Measured memory_bytes: 3220
package main

import (
	"fmt"
)

func main() {
	var n, ans uint
	fmt.Scan(&n)
	//もし与えられた数値が偶数だった場合
	if n%2 == 0 {
		ans = n/2 - 1
		fmt.Println(ans)
		//もし与えられた数値が奇数だった場合
	} else {
		//ansはint型のため小数点切り捨て
		ans = n / 2
		fmt.Println(ans)
	}
}

Measured memory_bytes: 512
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int barrier[2][200000];
int ok[2][200000];
void solve(){
	int w;
	cin >> w;
	vector<int> inputs;
	REP(i, w) {
		int a;
		cin >> a;
		inputs.push_back(a);
	}
	REP(i, 200000) {
		barrier[0][i] = 2e9;
		barrier[1][i] = 2e9;
	}
	REP(i, w) {
		if (inputs[i] == 0) {
			ok[0][i] = 1;
			barrier[0][i] = 2e9;
		}
		ok[0][i + 1] = ok[0][i];

		if (inputs[i] < 0) {
			barrier[0][i] = min(barrier[0][i], llabs(inputs[i]));
		}
		barrier[0][i + 1] = min(barrier[0][i + 1], barrier[0][i] - 1LL);
	}

	for (int i = w - 1; i >= 0; --i) {

		if (inputs[i] == 0) {
			ok[1][i] = 1;
			barrier[1][i] = 2e9;
		}
		if(i != 0)
		ok[1][i - 1] = ok[1][i];

		if (inputs[i] < 0) {
			barrier[1][i] = min(barrier[1][i], llabs(inputs[i]));
		}
		if (i != 0) {
			barrier[1][i - 1] = min(barrier[1][i - 1], barrier[1][i] - 1LL);
		}
	}
	int ans = 0;
	for (int i = 0; i < w; ++i) {
		int hoge = 0;
		if (ok[0][i]) {
			hoge = max(hoge, barrier[0][i]);
		}
		if (ok[1][i]) {
			hoge = max(hoge, barrier[1][i]);
		}
		hoge = min(hoge, inputs[i]);
		ans += max(hoge, 0LL);
	}
	cout << ans << endl;
}

#undef int

int main() {
	init();
	solve();
}


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

string str1, str2;

signed main(){
    int flag=0;
    cin >> str1 >> str2;
    for(int i=0;i<str1.size();i++){
        if(str1[i]!=str2[i]) flag = 1;
    }
    if(str1.size()+1!=str2.size()) flag=1;
    if(flag) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ccatcoder
{
    class Program
    {
        public static int Max(params int[] nums)
        {
            // 引数が渡されない場合
            if (nums.Length == 0) return 0;

            int max = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                max = max > nums[i] ? max : nums[i];
                // Minの場合は不等号を逆にすればOK
            }
            return max;
        }
        static void Main(string[] args)
        {
            int[,] dp = new int[3001,3001];
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int slen = s.Length, tlen = t.Length;
            for (int i = 0;i < 3001; i++)
            {
                for (int j = 0; j < 3001; j++)
                {
                    dp[i,j] = 0;
                }
            }
            for(int i = tlen-1;i > -1; i--)
            {
                for(int j = slen-1;j > -1; j--)
                {
                    if (s[j] == t[i])
                    {
                        dp[i,j] = Max(dp[i + 1,j], dp[i,j + 1], dp[i + 1,j + 1] + 1);
                    }
                    else
                    {
                        dp[i,j] = Max(dp[i + 1,j], dp[i,j + 1]);
                    }
                }
            }
            string ans = "";
            int k = 0, l = 0;
            while (k<tlen && l < slen)
            {
                if (dp[k,l] == dp[k + 1,l])
                {
                    ++k;
                } 
                else if (dp[k,l] == dp[k,l + 1])
                {
                    ++l;
                }
                else
                {
                    ans += s[l];
                    ++k;++l;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 50188
import java.io.*;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    try {
      // 標準入力受け取り
      Scanner scan = new Scanner(System.in);      
      Long cookie_a     = Long.parseLong(scan.next()); //takahashi cookie
      Long cookie_b     = Long.parseLong(scan.next()); //aoki cookie
      Long play         = Long.parseLong(scan.next()); //kaisu
      
      //算出
      if (cookie_a >= play) {
        cookie_a -= play;
      } else {
        cookie_b = cookie_b - (play - cookie_a);
        cookie_a = 0L;
      }
      
      if (cookie_b < 0) cookie_b = 0L;
      
      System.out.print(cookie_a + " " + cookie_b);
      
    } catch (Exception e) {     
      System.out.print("error");
    }
  }
}


Measured memory_bytes: 21844
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <bitset>
#include <cmath>
#include <tuple>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 型
#define ll long long

// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// for文
#define forn(i, size) for (long long(i) = 0; (i) < (size); (i)++)
#define for0(size) for (long(i) = 0; (i) < (size); (i)++)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length, type_name) sort(array, array + length, std::greater<type_name>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#define println(str) cout << str << endl;

#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}

#pragma region 最大公約数 
ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}
#pragma endregion

#pragma region 最小公倍数
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
#pragma endregion
#pragma endregion

#pragma region 連想配列のkeyが存在するか
template <typename T>
bool containsKey(map<string, T> map, string key)
{
    if (map.count(key) == 0)
    {
        return false;
    }
    return true;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    ll A, B;
    cin >> A >> B;

    println(lcm(A, B));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef double long db;
ll a[200005],b[200005];
int main(){
    int k;cin>>k;
    int sum=0;
    for(int i=1;i<=k;i++){
        sum=(sum*10+7)%k;
        if(sum==0) {cout<<i<<endl;return 0;}
    }
    cout<<"-1"<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[4][4],b[4][4]={0};
	for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) cin>>a[i][j];
	int n;
	cin>>n;
	int s[n+1];
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<=3;i++) {
		for(int j=1;j<=3;j++) {
			for(int l=1;l<=n;l++) {
				if(a[i][j]==s[l]) b[i][j]=1;
			}
		}
	}
//	for(int i=1;i<=3;i++) {
//		for(int j=1;j<=3;j++) cout<<b[i][j]<<" ";
//		cout<<endl;
//	}
	if     (b[1][1] && b[2][2] && b[3][3]) cout<<"Yes"<<endl;
	else if(b[1][3] && b[2][2] && b[3][1]) cout<<"Yes"<<endl;
	else if(b[1][1] && b[2][1] && b[3][1]) cout<<"Yes"<<endl;
	else if(b[1][2] && b[2][2] && b[3][2]) cout<<"Yes"<<endl;
	else if(b[1][3] && b[2][3] && b[3][3]) cout<<"Yes"<<endl;
	else if(b[1][1] && b[1][2] && b[1][3]) cout<<"Yes"<<endl;
	else if(b[2][1] && b[2][2] && b[2][3]) cout<<"Yes"<<endl;
	else if(b[3][1] && b[3][2] && b[3][3]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>
#include<stdio.h>
typedef long long ll;

using namespace std;

ll f1(ll n, ll p) {
	if (n == 0)return 0;
	return n / p + f1(n / p, p);
}

ll f2(ll n, ll p) {
	if (n % 2 == 1) return 0;
	return f1(n / 2, p);
}

int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	ans = f2(n, 5);
	cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
d = {str(i + 1): 0 for i in range(m)}
for _ in range(n):
  for item in input().split()[1:]:
    d[item] += 1

ans = 0
for key in d:
  if d[key] == n:
    ans += 1
print(ans)

Measured memory_bytes: 3060