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

using namespace std;

int main(int argc, char *argv[]) {
  string s;
  cin >> s;
  for (int i = 0; i < 1 << 3; i++) {
    int sum = s[0] - '0';
    for (int j = 0; j < 3; j++) {
      if ((1 << j) & i) {
        sum += s[j + 1] - '0';
      } else {
        sum -= s[j + 1] - '0';
      }
    }
    if (sum == 7) {
      auto putc = [](bool x) {
        return x ? '+' : '-';
      };
      cout << s[0] << putc(1 & i) << s[1] << putc(2 & i) << s[2] << putc(4 & i) << s[3] << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
s = input()
l = len(s)//2
s_ = s[::-1]
s1 = s[:l]
s1_ = s1[::-1]
s2 = s[l+1:]
s2_ = s2[::-1]

if s == s_ and s1 == s1_ and s2 == s2_:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9072
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int dict[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

bool compareNumber(string &s1, string &s2) {
  if (s1.length() > s2.length()) {
    return false;
  } else if (s1.length() < s2.length()) {
    return true;
  } else {
    for (int i = 0; i < s1.length(); i++) {
      if (s1[i] > s2[i]) {
        return false;
      } else if (s1[i] < s2[i]) {
        return true;
      }
    }
    return false;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  
  vector<string> best(N + 1);
  for (int i = 0; i <= N; i++) {
    if (i > 0 && best[i].length() == 0) {
      continue;
    }
    for (int j = 0; j < M; j++) {
      int target = i + dict[A[j]];
      if (target > N) {
        continue;
      }
      string targetNumber = best[i] + (char)('0' + A[j]);
      if (compareNumber(best[target], targetNumber)) {
        best[target] = targetNumber;
      }
    }
  }
   
  cout << best[N] << endl;

  return 0;
}


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

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

    int d[C][C];
    rep(i, C){
        rep(j, C){
            cin >> d[i][j];
        }
    }

    int c[3][30] = {};
    rep(i, n){
        rep(j, n){
            int tmp;
            cin >> tmp;
            c[(i+j)%3][tmp-1]++;
        }
    }

    int ans = 2002002002;
    rep(i, C){
        rep(j, C){
            if(i!=j){
                rep(k, C){
                    if(i!=k && j!=k){
                        int cnt = 0;
                        rep(l, C){
                            cnt += d[l][i]*c[0][l];
                        }
                        rep(l, C){
                            cnt += d[l][j]*c[1][l];
                        }
                        rep(l, C){
                            cnt += d[l][k]*c[2][l];
                        }

                        ans = min(ans, cnt);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
 
int main(){
	
	ll n,d,a; cin>>n>>d>>a;
	d*=2;
	vector<pair<ll,ll>> x(n);
	for(auto &i:x) cin>>i.first>>i.second;
	deque<pair<ll,ll>> damage;
	ll cnt{};
	sort(x.begin(),x.end());
	ll sum{};
	for(int i=0; i<n; i++){
		while(!damage.empty()){
			auto p = damage.front();
			if(x.at(i).first-p.first>d){
				sum -= damage.front().second*a;
				damage.pop_front();
			}
			else break;
		}
		if(x.at(i).second<=sum) continue;
		damage.push_back({x.at(i).first,(x.at(i).second-sum+a-1)/a});
		cnt += (x.at(i).second-sum+a-1)/a;
		sum += (x.at(i).second-sum+a-1)/a*a;
	}
	
	cout << cnt << endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n ;cin >> n;
    vi a(n); rep(i,n) cin >> a[i];

    sort(all(a));
    i32 cnt = 0, tmp = 0;
    for(i32 i = 0; i < n-1; ++i) {
        ++tmp;
        if(a[i] * 2 < a[i+1]) {
            cnt += tmp;
            tmp = 0;
        }
//        debug(a[i] * 2);
//        debug(a[i+1]);
//        debug(cnt);
        a[i+1] += a[i];
    }

    cout << n-cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int s = 0;
  if (A <= C) {
    if (B <= C) s = 0;
    else if (B <= D) s = B - C;
    else s = D - C;
  }
  else {
    if (D <= A) s = 0;
    else if (D <= B) s = D - A;
    else s = B - A;
  }
  cout << s << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

// lcm は最小公倍数を求める関数
func lcm(x int, y int) int {
	return (x * y) / gcd(x, y)
}

// gcd は最大公約数を求める関数
func gcd(x int, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func main() {
	var xNum, yNum int
	fmt.Scanf("%d %d", &xNum, &yNum)

	fmt.Println(lcm(xNum, yNum))
}

Measured memory_bytes: 512
N, M = list(map(int,input().split()))
a = {int(input()) for _ in range(M)}

dp = [0] * (N + 1)
dp[0] = 1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1
    

for i in range(2, N + 1):
    if i in a:
        continue
    dp[i] = dp[i - 1] + dp[i - 2]


print(dp[N] % 1000000007)

Measured memory_bytes: 460020
import sys
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())

lis_31 = [1, 3, 5, 7, 8, 10, 12]
lis_30 = [4, 6, 9, 11]
lis_28 = 2

if M1 in lis_31 and D1 == 31:
    if M2 == M1 + 1 and D2 == 1:
        print(1)
        sys.exit()
if M1 in lis_30 and D1 == 30:
    if M2 == M1 + 1 and D2 == 1:
        print(1)
        sys.exit()
if M1 == 2 and D1 == 28:
    if M2 == M1 + 1 and D2 == 1:
        print(1)
        sys.exit()
print(0)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;


int n;
int h[100010];

int main(){

    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }

    for(int i = n; i > 1; i--){
        if(h[i-1] - h[i] == 1){
            h[i-1] -= 1;
            continue;
        }

        if(h[i-1] - h[i] > 1){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int n,cnt=0;

void print_array(long long elements[]){
    int j;
    for(j=0;j<n;j++){
        printf("%lld",elements[j]);
        if(j<(n-1)) printf(" ");
    }
    printf("\n");
}

void bubble_sort(long long elements[]){
    int i,j;
    long long key;

    for(i=0;i<n;i++){
        for(j=n-1;j>=i+1;j--){
            if(elements[j]<elements[j-1]){
                key = elements[j];
                elements[j] = elements[j-1];
                elements[j-1] = key;
                cnt++;
            }
        }
    }
}

int main(){
    long long elements[100];
    int i;

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

    bubble_sort(elements);
    print_array(elements);
    printf("%d\n",cnt);

    return 0;
}

Measured memory_bytes: 604
//Author: backPacKer_19

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long
 
#define MOD 1000000007
 
ll mod_pow(ll x, ll n){
  if(n==0) return 1;
 
  if(n%2==0){
    return mod_pow(x*x%MOD, n/2) % MOD;
  }else{
    return x * mod_pow(x, (n-1)) % MOD;
  }
}
 
ll mod_pow_r(ll x, ll n){
  if(x==0)
    return 0;
  if(n==0)
    return 1;
 
  ll ret = 1;
  while(n){
    if(n&1) ret=ret*x%MOD;
    n /= 2;
    x=x*x%MOD;
  }
  return ret;
}

ll fac(ll n){
  ll res = 1;
  rep(i, n){
    res *= (i+1);
    res %= MOD;
  }
  return res;
}
 

ll comb(ll n, ll r){
  if(n<0 || n<r || r<0)
    return 0;
  ll fn = fac(n);
  ll fr = fac(r);
  ll fn_r = fac(n-r);
  
  ll d = (mod_pow(fr, MOD-2)*mod_pow(fn_r, MOD-2))%MOD;
  ll u = fn%MOD;
  return u * d % MOD;
}
 
int main(){
  ll x,y;
  cin>>x>>y;
  
  if((x+y)%3!=0){
    cout<<0;
    return 0;
  }
  ll k = x-(x+y)/3;
  ll l = y-(x+y)/3;
  cout<<comb(k+l, k);
  return 0;
}

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

Measured memory_bytes: 13928
n,x = gets.split.map(&:to_i)

arr = gets.split.map(&:to_i).sort


i = 0
n.times{
    
  if arr[0..i].inject(:+)>x
      
     puts i
     
      break
  elsif arr[0..i].inject(:+)==x
      puts i+1
      break
      
  
  
  else
      i+=1
      
  end
    
}


if i==n
    
    puts n-1
end




Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;

  ll ans = 0;
  ll a = n / k;
  ans += a * a * a;

  if(k % 2 == 0) {
    ll count = 0;
    FOR(i, 1, n + 1) {
      if(i % k == k / 2) count++;
    }

    ans += count * count * count;
  }

  cout << ans << endl;
}


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

int main() {
  long long int x, a, b;
  cin >> x >> a >> b;
  if (a - b >= 0) {
    cout << "delicious" << endl;
  } else if (a - b + x >= 0) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}

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

class PG{
    public static void Main(string[] args){
        double[] nums=Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        Console.WriteLine(Math.Sqrt(Math.Pow(nums[0]-nums[2],2)+Math.Pow(nums[1]-nums[3],2)));
        
    }
}


Measured memory_bytes: 16428
n=int(input())
a=list(map(int,input().split()))
a1,a2,s=0,0,0
def cal(a,t):
    ans,x=0,0
    for i in a:
        x+=i
        if t and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(cal(a,True),cal(a,False)))

Measured memory_bytes: 14332
import math

A, B, H, M = map(int, input().split())

theta_long = 360 / (60 * 12) * (60 * H + M)
theta_short = 360 / 60 * M
theta = abs(theta_long - theta_short) * math.pi / 180
print((A**2 + B**2 - 2 * A * B * math.cos(theta))**0.5)


Measured memory_bytes: 9496
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    string S;
    cin >> S;
    ll result = 0;
    {
        int f = 0;
        int l = S.length() - 1;
        while (f <= l){
            if (S[f] == S[l]){ // 'x' == 'x' || 'a' == 'a'
                ++f;
                --l;
            }else if (S[f] == 'x'){
                ++result;
                ++f;
            }else if (S[l] == 'x'){
                ++result;
                --l;
            }else{ // 'a' != 'b'
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
 
int main(){
  int h, w;
  std::cin >> h >> w;
  string s;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      std::cin >> s;
      if(s == "snuke"){
        std::cout << (char)(j + 'A') << i + 1 << std::endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define eni(x) template < class c > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; return * this; }
eni(==) return * this << range(begin(i), end(i)); }
template < class c, class b > debug & operator <<(pair < b, c > d) {
  return * this << "(" << d.first << ", " << d.second << ")";
}
template < class c > debug & operator <<(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  return * this << "]";
}
#else
template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000050
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    int x;
    cin>>x;
    cout<<1-x<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(void){
    ll N,K;
    cin >> N >> K;
    
    ll d,A,B[N+1],sum=0;
    for(ll i=0;i<=N+1;i++){
        B[i]=0;
    }
    for(ll i=0;i<K;i++){
        cin >> d;
        for(ll j=0;j<d;j++){
            cin >> A;
            B[A]++;
        }
    }
    
    for(ll i=1;i<=N;i++){
        if(B[i]==0) sum++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){

  ll m,k;
  cin >> m >> k;
  if(m==1 && k==1){
    cout << -1 << endl;
    return 0;    
  }
  if(pow(2LL,m)<=k){
    cout << -1 << endl;
    return 0;
  }
  if(k==0){
    rep(i,pow(2,m)) cout << i << " ";
    rep(i,pow(2,m)) cout << pow(2,m)-1-i << " ";
    return 0;
  }
  cout << k << " ";
  ll ki=1;
  while(k/((ll) pow(2LL,ki))!=0){
    //    cout << k/pow(2,ki) << endl;
    ki+=1LL;
  }
  //  cout << (1<<(ki-1))-1 << endl;
  for(int i=1<<(ki-1); i<(1<<ki);i++){
    if(i!=k) cout << i << " ";
  }
  rep1(i, pow(2,m)-1){
    if(i==k) continue;
    if(i<(1<<(ki-1)) || i>=(1<<ki) ) cout << i << " ";
  }
  cout << 0 << " " << k << " " << 0 <<" ";
  for(int i= pow(2,m)-1; i>=1; i--){
    if(i==k) continue;
    if(i<(1<<(ki-1)) || i>=(1<<ki) ) cout << i << " ";
  }
  
  /*  for(int i=(1<<(ki-1))-1;i>=1;i--){
    cout << i << " ";
    } */ 
  for(int i=(1<<ki)-1; i>=1<<(ki-1); i--){
    if(i!=k) cout << i << " ";
  }
  cout << ""  << endl;
  
  return 0;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
     Fast();
     ll n,t,x,y,i,j,k,mini=LONG_LONG_MAX,maxi=LONG_LONG_MIN,flag =0 ,sum=0,mul=1;
     vector<ll>vi;
     string s,s1="";
        cin>>s;
    x = (s[0]-'0')*10 + s[1]-'0';
    y =(s[2]-'0')*10 + s[3]-'0';
    if(x==0 || y==0){
    if(x== 0 && y==0)
        cout<<"NA"<<endl;
    else if(x == 0 && y<=12)
        cout<<"YYMM"<<endl;
    else if(y == 0 && x<=12)
        cout<<"MMYY"<<endl;
    else 
        cout<<"NA"<<endl;
    }
    else{
    if(x<=12 && y<=12)
        cout<<"AMBIGUOUS"<<endl;
    else if(x<=12 && y>12 )
        cout<<"MMYY"<<endl;
    else if(x>12 &&y<=12)
        cout<<"YYMM"<<endl;
    else
        cout<<"NA"<<endl;
    }


}



Measured memory_bytes: 384
// Problem : A - Zero-Sum Ranges
// Contest : AtCoder - AtCoder Grand Contest 023
// URL : https://atcoder.jp/contests/agc023/tasks/agc023_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n;
	ll sum=0,ans=0;
	 cin>>n; 
	 vi a(n);
	 map<ll,ll> map;
	 map[0]=1;
	 loop(i,n)
	 {
	 	cin>>a[i];
	 	sum+=a[i];
	 	ans+=map[sum];
	 	map[sum]++;
	 }
	 cout<<ans;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 16368
#include <iostream>
using namespace std;
int main()
{
	int n;
	while(cin >> n)
	{
		int ge=n%10;
		int shi=n/10%10;
		int bai=n/100;
		int x=ge*100+shi*10+bai;
		if(x==n)
		{
			cout << "Yes" <<endl;
		}
		else
		{
			cout << "No" <<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#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 n, pc, qc, cnt = 0;
    cin >> n;
    vector<int> p(n), q(n), s(n);
    rep(i,n) cin >> p.at(i);
    rep(i,n) cin >> q.at(i);
    rep(i,n)  s.at(i) = i+1;

    do{
        bool pf = true, qf = true;
        for(int i=0; i<n; i++){
            if(s[i] != p[i]) pf = false;
            if(s[i] != q[i]) qf = false;
        }
        if(pf) pc = cnt;
        if(qf) qc = cnt;
        cnt++;
    }while(next_permutation(s.begin(),s.end()));
    cout << abs(pc-qc) << endl;
}

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

const ll INF = 1LL << 60;

ll N;
set<string> ans;

void dfs(int cnt, string s = "", char max_c = 'a') {
    if (cnt == N - 1) {
        // cout << cnt << endl;
        // cout << s << endl;
        ans.insert(s);
        return;
    } 

    // s の最後の1文字から1文字後
    // int last = s[s.size() - 1] - 'a';
    int last = max_c - 'a';
    for (int k = 0; k <= last + 1; k++) {
        string target = s;
        target.push_back('a' + k);
        if (max_c < ('a' + k)) {
            dfs(cnt + 1, target, 'a' + k);
        } else {
            dfs(cnt + 1, target, max_c);
        }
    }
}

int main() {
    cin >> N;
    dfs(0, "a");

    for (auto s : ans) {
        cout << s << endl;
    }
}

Measured memory_bytes: 12532
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  cin >> N >> K;
  if (N <= K) {
    cout << 0 << endl;
    return 0;
  }
  int64_t result = 0;
  for (int64_t b = 1; b <= N; ++b) {
    const int64_t p = N / b;
    const int64_t r = N % b;
    int64_t temp = p * max(b - K, 0L) + max(r - K + 1, 0L);
    if (K == 0) {
      --temp;
    }
    result += temp;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


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

    int a = 0;
    rep(i,n){
        a += int(s[i]) - 48;
    }

    if(a%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int ans;
  if(n>k){
    ans = (k * x ) + ((n - k) * y);
    cout << ans << endl;
  }
  else{
    ans = n*x;
    cout << ans << endl;
  }
}
  

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vvi G(2*n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[2*a].pb(2*b+1);
        G[2*a+1].pb(2*b);
        G[2*b].pb(2*a+1);
        G[2*b+1].pb(2*a);
    }
    vb seen(2*n);
    seen[0] = true;
    queue<int> q;
    q.push(0);
    while(q.size()) {
        int v = q.front();
        q.pop();
        for(int u : G[v]) {
            if(seen[u]) continue;
            seen[u] = true;
            q.push(u);
        }
    }
    int a = 0,b = 0,c = 0;
    rep(i,n) {
        if(seen[i*2]) {
            a++;
            if(seen[i*2+1]) c++;
        }
        if(seen[i*2+1]) b++;
    }
    ll ans = (ll)a*b-c-(ll)c*(c-1)/2-m;
    cout << ans << endl;
}


Measured memory_bytes: 14276
n, m = map(int, input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

d = make_divisors(m)
ans = -1
for i in d:
    j = m//i
    if j >= n:
        ans = max(i, ans)
print(ans)


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
const int mxN = 1e5+1;
int f[mxN], b[mxN];
 
// find gcd subsequences forward and backwards
void solve(){
	int n; cin >> n;
	int a[n];
	FOR(n) cin >> a[i];
	f[0] = a[0];
	FOR(i,1,n) f[i] = gcd(a[i],f[i-1]);
	b[n-1] = a[n-1];
	for(int i = n-2; i >= 0; --i) b[i] = gcd(a[i],b[i+1]);
	
	// basically find max gcd after removing 1 element
	int ans = 1;
	FOR(n){
		// dont include i in gcd
		int start = i-1, end = i+1, start_val, end_val;
		if(start < 0) start_val = inf;
		else{
			start_val = f[start];
		}
		if(end >= n) end_val = inf;
		else{
			end_val = b[end];
		}
		if(start_val == inf) ans = max(ans, end_val);
		else if(end_val == inf) ans = max(ans, start_val);
		else ans = max(ans, gcd(start_val,end_val));
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 4792
#include<cstdio>
#include<cstdlib>
#include<cstring>
 
long long n,m;
char s[100010],s1[100010];
long long a[100010],b[100010];
 
long long gcd(long long x,long long y)
{
	if (x%y==0) return y;
	return gcd(y,x%y);
}
 
long long lcm(long long x,long long y)
{
	return x*y/gcd(x,y);
}
 
int main()
{
	scanf("%lld %lld",&n,&m);
	scanf("%s",s+1);
	scanf("%s",s1+1);
	long long z=lcm(n,m);
	a[1]=1;b[1]=1;
	for (int i=2;i<=n;i++)
		a[i]=(i-1)*z/n+1;
	for (int i=2;i<=m;i++)
		b[i]=(i-1)*z/m+1;
	int i=1,j=1;
	while (i<=n && j<=m)
	{
		if (a[i]==b[j])
		{
			if (s[i]!=s1[j])
			{
				printf("-1");
				return 0;
			}
			i++,j++;
		}
		else if (a[i]<b[j]) i++;
		else j++;
	}
	printf("%lld",z);
}

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

using namespace std;

#define ll long long
#define pi 3.1415926535897932384626433
#define MAX 100000000000000000
#define sz = LLONG_MAX;

//char alpha[26] = {'a' ,'b','c', 'd', 'e', 'f' ,'g', 'h', 'i', 'j', 'k', 'm' ,'n' ,'o' ,'p' ,'q', 'r' ,'s', 't', 'u', 'v' ,'w' ,'x' ,'y', 'z'};

//Bits
/*
    Number of leading zeroes: builtin_clz(x)
    Number of trailing zeroes : builtin_ctz(x)
    Number of 1-bits: __builtin_popcount(x)

    1<<0, this means shifting of binary digit 1 by 0 positions to the left and after the operation, the result will be ‘1’
    1<<1, this means shifting of binary digit 1 by 1 position to the left and after the operation, the result will be ‘10’
    1<<2, this means shifting of binary digit 1 by 2 positions to the left and after operation, the result will be ‘100’

    1>>0, this means shifting of binary digit 1 by 0 positions to the right and after operation, the result will be ‘0’
    number>>1, when number = 4 in decimal and 100 in binary, this means shifting of binary representation of number right by 1 position and after the operation, the result will be ‘10’ i.e. 2, in decimal.

*/



//Factorial
ll fac(ll n)
{
    ll p=1;
    for(ll i=n;i>0;i--)
    {
        p*=i;
    }
    return p;
}



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

    ll test_case=1;    //cin>>test_case;

    while(test_case--)
    {
        ll x;
        cin>>x;
        if(x<30)
            cout<<"No\n";
        else
            cout<<"Yes\n";






    //Case_Ends_Here :)
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 1e9 + 7;
const ll maxn = 200005;
ll ans[200005],sum=0;
struct p{
	ll v,num; 
}a[200005];
ll b[200005]={0},x[200005];
int main(){  
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll n;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x[i]);
		a[i].num=i;
		b[x[i]]++;
	} 
	for(int i=1;i<=n;i++){
		sum+=b[i]*(b[i]-1)/2;
	}
	for(int i=1;i<=n;i++){
		ans[i]=sum+1-b[x[i]];
	}
	
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	
    return 0;
}




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

int main(void){
	int n=0, k=0;
	int *a;
	long sum  = 0;
	long msum = 0;
	while(true){
		sum = 0;
		scanf("%d %d", &n, &k);
		if(n==0){break;}
		a = (int*)malloc(sizeof(int) * n);
		for(int i=0; i<n; ++i){
			scanf("%d", a+i);
		}

		for(int i=0; i<k; ++i){
			sum += a[i];
		}
		msum = sum;

		for(int i=0; k<n; ++i,++k){
			sum = sum - a[i] + a[k];
			if(sum > msum){
				msum = sum;
			}
		}
		printf("%d\n", msum);
		free(a);
	}
	return 0;
}

Measured memory_bytes: 0
n,m=[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
mod=10**9+7
dp=[[0]*(m+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n+1):
    for j in range(m+1):
        if i!=0:
            dp[i][j]+=dp[i-1][j]
        if j!=0:
            dp[i][j]+=dp[i][j-1]
        if i!=0 and j!=0:
            if s[i-1]!=t[j-1]:
                dp[i][j]-=dp[i-1][j-1]
        dp[i][j]%=mod
print(dp[-1][-1])

Measured memory_bytes: 73308
import numpy as np

def main():
    args = input().rstrip().split(' ')
    N, M = int(args[0]), int(args[1])
    args = input().rstrip().split(' ')
    hw = np.array([int(i) for i in args])
    sum_hw = np.sum(hw)
    if(sum_hw > N):
        print('-1')
    else:
        print(N - sum_hw)
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 27868
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll x;
    cin >> x;
    ll s = (x / 500) * 1000;
    x %= 500;
    ll t = (x / 5) * 5;
    cout << s + t << endl;
}


Measured memory_bytes: 256
import fractions

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
a, b = map(int, input().split())

ans = prime_factorize(fractions.gcd(a, b))
ans = set(ans)
print(len(ans)+1)

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

ll digits(ll x) {
	return floor(log10(x))+1;
}

int main() {

	ll N;
	cin >> N;
	
	ll ans = N;
	for(ll i=1; i<=sqrt(N); i++)
		if(N%i == 0) ans = min(ans, digits(N/i));

	cout << ans << endl;
}

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


signed main() {
    string s; cin >> s;
    if(s == "SAT") cout << 1 << endl;
    if(s == "SUN") cout << 7 << endl;
    if(s == "MON") cout << 6 << endl;
    if(s == "TUE") cout << 5 << endl;
    if(s == "WED") cout << 4 << endl;
    if(s == "THU") cout << 3 << endl;
    if(s == "FRI") cout << 2 << endl;

}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	if (s[s.length() - 1] == 's') {
		cout << s << "es\n";
	} else {
		cout << s << "s\n";
	}

	return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,a[MAXN];
ll check(ll x)
{
    for(int i=1;i<=n;i++) x-=x%a[i];
    return x;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    ll l=0,r=INF;
    while(r-l>1)
    {
        ll mid=(l+r)/2;
        if(check(mid)<=2) l=mid; else r=mid;
    }
    if(check(l)!=2) {puts("-1"); return 0;}
    ll lb=0,rb=INF;
    while(rb-lb>1)
    {
        ll mid=(lb+rb)/2;
        if(check(mid)>=2) rb=mid; else lb=mid;
    }
    printf("%lld %lld\n",lb+1,l);
    return 0;
}



Measured memory_bytes: 640
n, m = map(int, input().split())
ac = [0] * n
pen = [0] * n
pen_count = 0
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if ac[p] == "AC":
        continue
    elif s == "AC":
        ac[p] = "AC"
    else:
        pen[p] += 1

for i in range(n):
    if ac[i] == "AC":
        pen_count += pen[i]

print(ac.count("AC"), pen_count)

Measured memory_bytes: 48596
import bisect

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]

MAX = 99999999999

s = sorted(s)
t = sorted(t)

#print(s)
#print(t)
#print(x)
for c in x:
    i = bisect.bisect_left(s, c)
    j = bisect.bisect_left(t, c)

    if i == 0:
        sl = MAX
    else:
        sl = c - s[i - 1]

    if i == a:
        sr = MAX
    else:
        sr = s[i] - c

    if j == 0:
        tl = MAX
    else:
        tl = c - t[j - 1]

    if j == b:
        tr = MAX
    else:
        tr = t[j] - c

    print(min(max(sr, tr), max(sl, tl), sr + tl + min(sr, tl), sl + tr + min(sl, tr)))



Measured memory_bytes: 16148
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        String  a = String.valueOf(N);
        char b[] = new char[a.length()];
        for (int i=0;i<a.length();i++){
            b[i] = a.charAt(i);
        }
        int divid =0;
        for (int i=0;i<a.length();i++){
            divid += Integer.parseInt(String.valueOf(b[i]));
        }
        if(N % divid ==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    vector<vector<int>> P(N, vector<int>(11));
    REP (i, N) {
        REP (j, 10) {
            cin >> F[i][j];
        }
    }
    REP (i, N) {
        REP (j, 11) {
            cin >> P[i][j];
        }
    }

    int ans = INT_MIN;
    FOR (bit, 1, 1 << 10) {
        int profit = 0;
        REP (i, N) {
            int cnt = 0;
            REP (j, 10) {
                int open = (bit >> j) & 1;
                if (open == 1 && F[i][j] == 1) {
                    cnt++;
                }
            }
            profit += P[i][cnt];
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r


def solve():
    c=0
    a,b=mp()
    c+=((a-1)*(a))//2
    c+=((b-1)*(b))//2
    print(c)

for _ in range(1):
    solve()
    


Measured memory_bytes: 9316
N, M = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(M)]

lst =[-1]*N

ans = True

for s,c in sc:
    if N>1 and s==1 and c==0:
        ans = False
        break
    if lst[s-1]!=-1 and lst[s-1]!=c:
        ans = False
        break
    lst[s-1] = c
    
if ans:
    if N!=1 and lst[0]==-1:
        lst[0] = 1
    for i in range(N):
        if lst[i]==-1:
            lst[i]=0
    print(*lst, sep='')
else:print(-1)


Measured memory_bytes: 3064
#import random
import numpy as np
def main():
  d=int(input())
  c=np.array(list(map(int,input().split())))
  s=[None]*d
  r0=[None]*d
  r1=[None]*d
  cm=np.array([0]*26)
  cd=np.array([0]*26)
#t=[None]*d
  for i in range(d):
    s[i]=list(map(int,input().split()))
  s=np.array(s)
#for i in range(d):
#  t[i]=int(input())-1
  for j in range(d):  
    #rand = np.random.randint(26, size = 10) 
    #print(np.argmax(s[j])+1)
    r_i=np.argmax(s[j])
    cd=c*cm
    if np.max(cd>s[i][r_i]):
      r_i=np.argmax(cd)
    r0[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
    
  score0=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r0[j]
    score0+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score0+=-np.sum(cd)
  #r_i+=1
  #print(r_i)
  """
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    #print(np.argmax(s[j])+1)
    r_i=r0[j]
    cd=c*cm
    if rand[j]>80:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
#r0=t
  """
    
  testc=(90,80,85,75,70,65,60,55,50,45,40,35,30,25,20,15,99,98,97,96,95)
  for l in testc:
    cm=np.array([0]*26)
    cd=np.array([0]*26)  
    rand = np.random.randint(100, size = d) 
    for j in range(d):  
    #print(np.argmax(s[j])+1)
      r_i=r0[j]
      cd=c*cm
      if rand[j]>l:
        r_i=np.argmax(cd)
      r1[j]=r_i
      for k in range(26):
        cm[k]+=1
      cm[r_i]=0
      
    score1=0
    cm=np.array([0]*26)
    cd=np.array([0]*26)  
    for j in range(d):
      r0_j=r1[j]
        #print(score1)
      score1+=s[j][r0_j]
      for k in range(26):
        cm[k]+=1
        cm[r0_j]=0
      cd=c*cm
      #print(cm)
      score1+=-np.sum(cd)
      #print(score0)
      #print(score1)
    if score1>score0:
      r0=r1
      score0=score1
    
  
  for j in range(d):  
    print(r0[j]+1) 
 
main()

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;


signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // Failed to predict input format
    ll N;
    cin >> N;
    vector<ll> A(N+1);
    rep(i,1,N+1) cin >> A[i];
    unordered_map<ll, ll> aAddB;
    ll answer = 0;
    rep(i,1,N+1) {
        answer += aAddB[i - A[i]];
        aAddB[i + A[i]]++;
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 19976
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int cnt = 0;
int A[1000000];

void insertionSort(int A[], int n, int g) {
	int v, j;
	for (int i = g; i < n; i++) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			swap(A[j + g], A[j]);
			j -= g;
			cnt++;
		}

		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	vector<int> G;
	for (int h = 1; ; ) {
		if (h > n) break;
		G.push_back(h);
		h = h * 3 + 1;
	}

	cout << G.size() << "\n";

	for (int i = 0; i < G.size(); i++) {
		if (i > 0) cout << " ";
		cout << G[G.size() - i - 1];
	}
	cout << "\n";

	for (int i = 0; i < G.size(); i++) {
		insertionSort(A, n, G[G.size() - i - 1]);
	}
	cout << cnt << "\n";

	for (int i = 0; i < n; i++) {
		cout << A[i] << "\n";
	}
}

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

	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	shellSort(A, n);
}



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

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

    long long ans1 = 0LL;
    long long ans2 = 0LL;
    long long sum = 0LL;

    // 偶数インデクスときは正になるように
    for (int i = 0, tmp = 1; i < n; i++, tmp *= -1)
    {
        sum += a[i];
        if (sum * tmp <= 0)
        {
            ans1 += abs(sum - tmp);
            sum = tmp;
        }
    }

    // 奇数インデクスときは正になるように
    sum = 0;
    for (int i = 0, tmp = -1; i < n; i++, tmp *= -1)
    {
        sum += a[i];
        if (sum * tmp <= 0)
        {
            ans2 += abs(sum - tmp);
            sum = tmp;
        }
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int K=scan.nextInt();
		String sinnsuu=Integer.toString(N,K);
		int keta=sinnsuu.length();
		System.out.println(keta);
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
  int n;
  cin >> n;
  VI h(n);
  rep(i,n) cin >> h[i];
  
  bool flag=true;
  int cnt=0;
  while(flag){
    int start=-1,end=n;
    rep(i,n){
      if(h[i] > 0){
        start = i;
        break;
      }
    }
    rep2(i,start,n){
      if(h[i] == 0){
        end = i;
        break;
      }
    }
    if(start == -1){
      flag = false;
    }else{
      rep2(i,start,end){
        h[i]--;
      }
      cnt++;
    }
  }
  
  cout << cnt;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
if 400<=n<=599:
    print(8)
if 600<=n<=799:
    print(7)
if 800<=n<=999:
    print(6)
if 1000<=n<=1199:
    print(5)
if 1200<=n<=1399:
    print(4)
if 1400<=n<=1599:
    print(3)
if 1600<=n<=1799:
    print(2)
if 1800<=n<=1999:
    print(1)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

string S;
cin >> S;
int k = S.size()-7;
rep(i,8) {
    string T = S;
    T.erase(T.begin()+i,T.begin()+i+k);
    if(T == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
}
cout << "NO" << endl;
return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

i = 0
step = []
while i <= len(A) - 2:
    if A[i] > A[i+1]:
        step.append(A[i] - A[i+1])
        A[i+1] = A[i]
        i += 1
    else:
        i += 1

print(sum(step))


Measured memory_bytes: 32048
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int black = 0;
    long ans = 0;
    for(int i=0;i<s.length();i++){
        if(s[i] == 'B')black++;
        else{
            ans += black;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640