akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int NUM = 2e5 + 5;

int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        ll n; cin>>n;
        ll ans=1;
        n--;
        ans+=(n)*(n+1)/2;
        ans-=1;
        cout<<ans;
    }
}


Measured memory_bytes: 256
/// You just can't beat the person who never gives up
/// ICPC next year


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
void offset(vector<int>&a,int x) {
    for(int i = 0; i < sz(a);i++) {
        a[i] = x;
    }
}
struct cmp {
    bool operator() (const pair<int,int>& lhs, const pair<int,int>& rhs) const {
        return lhs.ff * rhs.ss < lhs.ss * rhs.ff;
    }
//for map<pii,int>
};


// auto cmp = [](pair<int,int>a,pair<int,int>b) {if(a.first==b.first)return a.second>b.second;
//      else return a.first > b.first;
//  };
//  multiset<pair<int,int>,decltype(cmp)>fc(cmp);
double distform(int x, int y, int z, int w) {//(x1,y1,x2,y2)
    return sqrt(1. * pow(x-z,2) + 1. * pow(y-w,2));
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    //unordered_map<long long, int, custom_hash> safe_map;
};

const int MAXN = 2e5+ 10;

#define int long long
bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss > p2.ss;
}
int cnt[MAXN];
int32_t main() {
    fio
    int h,n;
    cin >> h >> n;
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if(sum>=h)
        cout << "Yes"<< endl;
    else cout << "No"<< endl;

    cerr << endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






Measured memory_bytes: 4632
import sys

sys.setrecursionlimit(2000000000)


class Node:
    def __init__(self, index):
        self.index = index
        self.connected_indices = set()

    def __repr__(self):
        return '{}: {}'.format(self.index, self.connected_indices)


def build_graph(nodes, curr_index, connected_indices, reached_indices):
    # already reached
    if curr_index in connected_indices or curr_index in reached_indices:
        return

    connected_indices |= {curr_index}
    reached_indices |= {curr_index}

    unreached_indices = nodes[curr_index].connected_indices - connected_indices

    for i in unreached_indices:
        build_graph(nodes, i, connected_indices, reached_indices)

    return connected_indices


# if True:
#     line_index = 0
#
#
#     def input():
#         global line_index
#         lines = ['10 8',
#                  '5 3 6 8 7 10 9 1 2 4',
#                  '3 1',
#                  '4 1',
#                  '5 9',
#                  '2 5',
#                  '6 5',
#                  '3 5',
#                  '8 9',
#                  '7 9']
#
#         line = lines[line_index]
#         line_index += 1
#         return line

if __name__ == '__main__':
    N, M = map(int, input().split())
    p = [int(v) - 1 for v in input().split()]

    nodes = [Node(i) for i in range(N)]
    for _ in range(M):
        xy_str = input().split()
        x, y = int(xy_str[0]) - 1, int(xy_str[1]) - 1

        nodes[x].connected_indices |= {y}
        nodes[y].connected_indices |= {x}

    reached_indices = set()
    all_connected_indices = [None] * N
    for i in range(N):
        connected_indices = build_graph(nodes, i, set(), reached_indices)
        if connected_indices is None:
            continue

        for c in connected_indices:
            all_connected_indices[c] = connected_indices

    answer = sum([p[i] in all_connected_indices[i] for i in range(N)])
    print(answer)
    # print(desirable_swaps)
    # print(nodes)


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a) int((a).size())
#define pb push_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n)               \
  for (int vari = 0; vari < (n)-1; ++vari) \
    for (int varj = vari + 1; varj < (n); ++varj)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair

ll gcd(ll a, ll b) {
  while (a) swap(a, b %= a);
  return b;
}

bool solve(vi& a) {
  int n = a.size()-1;
    if (a[n] == 1) return false;
    if (a[1] == 0) return false;
    rep1(i, n - 1) if (a[i] != a[n - i]) return false;

    vector<ii> conn;

    int h = n / 2;
    int pre = 1, last_good = 1;
    for (int i=2; i<=n; ++i) {
#ifdef DEBUG
        fprintf(stderr, "a[%d] = %d\n", i, a[i]);
#endif
        conn.pb(ii(pre, i));
        if (last_good >= 0) {
          pre = last_good + 1;
          last_good = -1;
        }
        if (i<=h && a[i]) {
          last_good = i;
        }
    }

    for (ii p: conn) {
        printf("%d %d\n", p.first, p.second);
    }
    return true;
}

#define N_MAX 100000

int main() {
  char buf[N_MAX + 3];
  fgets(buf, N_MAX + 3, stdin);

  vi a;
  a.reserve(N_MAX+1);
  a.pb(0);
  rep(i, N_MAX + 1) {
    if (buf[i] < '0') {
      buf[i] = 0;
      break;
    }
    a.pb(buf[i] - '0');
  }
#ifdef DEBUG
  cerr << a << endl;
#endif

  if (!solve(a)) {
      cout << -1 << endl;
  }
  return 0;
}


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


int main() {
    string S;
    cin >> S;

    if (S[1] == 'B') cout << "ARC" << endl;
    else if (S[1] == 'R') cout << "ABC" << endl;
    else cout << "pigimaru" << endl;

    return 0;
}

Measured memory_bytes: 3628
S = input()
K = int(input())

count = 0
cont = 0

if 1 == len(S):
    print(K // 2)
    exit()

#すべて同じ文字の場合の処理
if len(S) == S.count(S[0]):
    count += (len(S) * K) // 2
    print(count)
    exit()

#最初のブロックの連続数える
firstword = 0
first_index = 0
if S[0] == S[-1]:
    for i in range(len(S) - 1):
        if S[i] == S[i+1]:
            cont += 1
        else:
            firstword = cont
            cont = 0
            first_index = i
            break 

#末尾からの連続を数える。
lastword = 0
last_index = 0
for i in reversed(range(len(S))):
    if i == 0:
        break
    if S[i] == S[i-1]:
        cont += 1
    else:
        lastword = cont
        cont = 0
        last_index = i
        break

#中間部分を数える。
middleword = 0
for i in range(first_index, last_index):
    if S[i] == S[i+1]:
        cont += 1
    else:
        middleword += (cont + 1) // 2
        cont = 0


if S[0] == S[-1]:
    count += middleword * K
    count += ((firstword + lastword + 2) // 2 ) * (K-1)
    count += (firstword + 1) // 2 + (lastword + 1) // 2
else:
    count += middleword * K
    count += ((firstword + 1) // 2 + (lastword + 1) // 2) * K

print(count)

Measured memory_bytes: 38384
s=list(input())
q=int(input())
rv=False
right=[]
left=[]
for _ in range(q):
  query=input()
  if query[0]=='1':
    rv=not rv
  else:
    _,f,c=query.split()
    if f=='1' and rv==False:
      left.append(c)
    elif f=='1' and rv==True:
      right.append(c)
    elif f=='2' and rv==False:
      right.append(c)
    elif f=='2' and rv==True:
      left.append(c)
if not rv:
  left.reverse()
  print(''.join(left)+''.join(s)+''.join(right))
else:
  right.reverse()
  s.reverse()
  print(''.join(right)+''.join(s)+''.join(left))


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

int main(void){
    long long n, k, x[100010], ans = 500001000, minus=-1;
    cin >> n >> k;
    for(int i=0;i<=n;++i) x[i] = 300001000;
    for(int i=0;i<n;++i){
        cin >> x[i];
        if(x[i] < 0) minus = i;
    }
    int sum = 0, r[100010], l[100010], p=1;
    for(int i=0;i<=n;++i){
        r[i] = 300001000;
        l[i] = 300001000;
    }
    r[0] = 0;l[0] = 0;
    for(int i=minus+1;i<n;++i){
        r[p] = x[i];
        ++p;
    }
    p = 1;sum = 0;
    for(int i=minus;i>=0;--i){
        l[p] = abs(x[i]);
        ++p;
    }
    for(int i=0;i<=k;++i){
        long long mi = min(r[i]+l[k-i]*2, r[i]*2+l[k-i]);
        if(mi < ans)ans = mi;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<iostream>
#include<list>

using namespace std;

int main()
{
	list<int> S,T;
	int number,n,q,i,x,countn=0;


	cin >> n;
	for(i=0;i<n;i++){
		cin >> x;
		S.push_back(x) ;
	}

	cin >> q ;
	for(i=0;i<q;i++){
		cin >> x ;
		T.push_back(x);
	}

	while(!T.empty()){
		number = static_cast<int>( count( S.begin(), S.end(), T.front() ) );
		
		if(number != 0) countn++ ;
		T.pop_front();
	}

	cout << countn << endl;

	return 0;
}

Measured memory_bytes: 1504
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] T = new int[N];
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			T[i] = in.nextInt();
			A[i] = in.nextInt();
		}
		in.close();
		long t, a, multiplyer;
		t = T[0];
		a = A[0];

		for (int i = 1; i < N; i++) {
			multiplyer = calcMultiplyer(t, a, T[i], A[i]);
			t = multiplyer * T[i];
			a = multiplyer * A[i];
		}
		System.out.println((t + a));
	}

	public static long calcMultiplyer(long a, long b, long ratio_a, long ratio_b) {
		long ma, mb;
		ma = a / ratio_a;
		mb = b / ratio_b;
		if (a % ratio_a != 0)
			ma++;
		if (b % ratio_b != 0)
			mb++;
		return Math.max(ma, mb);
	}

}


Measured memory_bytes: 13308
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;

const double PI=acos(-1.0);

int main()
{
	double a,b,x;
	scanf("%lf%lf%lf",&a,&b,&x);
	x/=a;
	double v=a*b/2.0;
	double ans;
	if(x>=v)
	{
		// x=(y+b)*a/2
		double y=2.0*x/a-b;
		y=b-y;
		ans=atan(y/a);
	}
	else
	{
		// x=b*y/2
		double y=2.0*x/b;
		ans=atan(b/y);
	}
	ans=ans/PI*180;
	printf("%.8f\n",ans);
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e5+5;

int n,m;
vector<vector<int>> adj;
vector<int> vis(N);

int dp[N];

int dfs(int x) {
    if(vis[x])
        return dp[x];
    vis[x]=1;
    int m = 0;
    for(int i: adj[x]) {
        int a = dfs(i);
        m=max(a,m);
    }
    dp[x]=(m+1);
    return dp[x];
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;
    adj.resize(n+1);
    int u,v;
    for(int i=0;i<m;i++) {
        cin>>u>>v;
        adj[u].pb(v);
    }
    int ans = 0;
    for(int i=1;i<=n;i++) {
        if(!vis[i]) {
            ans=max(ans,dfs(i));
        }
    }

    cout<<ans-1;

    return 0;
}


Measured memory_bytes: 9344
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int p[N];
  int i;
  for(i=0;i<N;i++){
   cin >> p[i];
    p[i]--;
  }
  
  int num=0;
  for(i=0;i<N;i++){
    if(p[i]!=i) num++;
  }
  
  if(num == 0){
   cout << "YES" << endl; 
  }
  if(num == 2){
   cout << "YES" << endl; 
  }
  if(num != 0 && num != 2){
   cout << "NO" << endl; 
  }
  
return 0;
} 






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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
ll a[222222];
ll b[222222];

int main() {
   cin >> n;
   rep (i, n) {
      cin >> a[i];
      b[i+1] = a[i];
      b[i+1] += b[i];
   }

   ll ans = 0;
   map<ll, ll> mp;
   rep (i, n+1) {
      mp[b[i]]++;
   }

   for (auto itr = mp.begin(); itr != mp.end(); itr++) {
      // int a = itr->first;
      ans += itr->second * (itr->second-1) / 2;
   }

   cout << ans << endl;


   return 0;
}

Measured memory_bytes: 15872
def c_lower():
    N = int(input())
    H = [int(i) for i in input().split()]
    can_move = [0] * N
    for i in range(N - 1):
        if H[i] >= H[i + 1]:
            can_move[i] = 1
    cnt = 0
    for i in range(N - 1, -1, -1):
        if can_move[i] != 0:
            cnt += 1
            can_move[i] = cnt
        else:
            cnt = 0
    return max(can_move)

print(c_lower())

Measured memory_bytes: 14224
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	int n;
	cin >> n;
	vector<int> t(n + 1), x(n + 1), y(n + 1);
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	rep(i, n) cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
	bool flag = true;
	rep(i, n) {
		int ti = t[i + 1] - t[i];
		int xi = abs(x[i + 1] - x[i]);
		int yi = abs(y[i + 1] - y[i]);
		if (xi + yi > ti) flag = false;
		if ((xi + yi) % 2 != ti % 2) flag = false;
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int a = n / 100;
    int b = (n - a * 100) / 10;
    int c = n - a * 100 - b * 10;
    if(a == 7 || b == 7 || c == 7) pr("Yes");
    else pr("No");
    return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	long long res = 0;
	scanf("%d%d", &n, &m);
	if (n >= 2) {
		res += (n - 1) *n / 2;
	} 
	if (m >= 2) {
		res += (m - 1) * m /2;
	}
	printf("%lld", res);
}	

Measured memory_bytes: 256
#include <stdio.h>

int Max(int A, int B, int C){
  int a[3];
  if(A >= B){
    if(A >= C){
      a[0] = A;
      a[1] = B;
      a[2] = C;
    }else{
      a[0] = C;
      a[1] = A;
      a[2] = B;
    }
  }else{
    if(B >= C){
      a[0] = B;
      a[1] = A;
      a[2] = C;
    }else{
      a[0] = C;
      a[1] = B;
      a[2] = A;
    }
  }
  return a[0] * 10 + a[1] + a[2];
}

int main(void){
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);
  printf("%d\n", Max(A, B, C));
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;

//dark power
#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
/*
vector<int> d(100000);
vector<int> b(100000);
class UnionFind{
	public:
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	signed find(signed x){
		if(d[x]==x){
			return x;
		}else{
			return d[x]=find(d[x]);
		}
	}
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(b[x]<b[y]){
			d[x]=y;
		}else{
			d[y]=x;
			if(b[x]==b[y])b[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
};
*/
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int sum=1;
	rep(i,1,n+1)sum=(i*sum)%MOD;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

#define MAX_V 100010

struct edge { int to; long long cost; };
int V;

vector<edge> tree[MAX_V];
long long d[MAX_V];
int N;

// s: 開始地点の頂点
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + N, LINF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) { continue; }
        for (int i = 0; i < tree[v].size(); i++) {
            edge e = tree[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}


int main(){
    int r;
    cin >> N >> V >> r;
    rep(i, V){
        int s, t;
        ll D;
        cin >> s >> t >> D;
        tree[s].push_back((edge){t, D});
    }

    dijkstra(r);

    rep(i, N){
        if (d[i] < 1e+18) cout << d[i] << endl;
        else cout << "INF" << endl;
    }

    return 0;
}


Measured memory_bytes: 19564
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
        Scanner Input=new Scanner(System.in);
        String a = Input.next(), b = Input.next();
        if(a.equals(b))
        System.out.println("H");
        else
        System.out.println("D");
    }
}

Measured memory_bytes: 22100
/*input
3
1 1
5 1
5 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e15;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}

// default code end
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
vector<pair<pii,int>> v,v2;
int par[maxn],rk1[maxn];
vector<int> x[maxn],y[maxn];
int find(int u){
    return par[u]==u?u:par[u]=find(par[u]);
}
void merge(int u,int v){
    u=find(u),v=find(v);
    if(u==v) return;
    if(rk1[u]>rk1[v]) swap(u,v);
    for(auto z:x[u]) x[v].pb(z);
    for(auto z:y[u]) y[v].pb(z);  
    par[u]=v;
    rk1[v]+=rk1[u];
}
int main(){
	int n;
    cin>>n;
    REP(i,n){
        int a,b;
        cin>>a>>b;
        v.pb({{a,b},i});
        v2.pb({{b,a},i});par[i]=i,rk1[i]=1;
        x[i].pb(a);
        y[i].pb(b);
    }
    sort(ALL(v));
    sort(ALL(v2));
    REP(i,n-1){
        if(v[i].f.f==v[i+1].f.f) merge(v[i].s,v[i+1].s);
    }
    REP(i,n-1) if(v2[i].f.f==v2[i+1].f.f) merge(v2[i].s,v2[i+1].s);
    ll ans=0;
    REP(i,n){
        if(par[i]==i){
            SORT_UNIQUE(x[i]);
            SORT_UNIQUE(y[i]);
            ans+=(ll)sz(x[i])*sz(y[i]);

        }
    }
    cout<<ans-n<<'\n';
}

Measured memory_bytes: 23904
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<int> ans(N);
  rep(i, N) {
    REP(j, i+1, N) {
      ll dst = 0;
      if(i < X) {
	if(j < X) {
	  dst = j - i;
	} else if(X <= j && j <= Y) {
	  dst = (X - i) + min(j - X, Y - j + 1);
	} else {
	  dst = (X - i) + 1 + (j - Y);
	}
      } else if(X <= i && i <= Y) {
	if(X <= j && j <= Y) {
	  dst = min(j - i, Y - X + 1 - (j - i));
	} else {
	  dst = min(Y - i, i - X + 1) + (j - Y);
	}
      } else {
	dst = j - i;
      }
      ans[dst]++;
    }
  }
  rep(i, N) if(i) cout << ans[i] << endl;
  return 0;
}


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

template<class T>
void chmax(T &a, T b) {if (a < b) a = b;}
template<class T>
void chmax(T &a, initializer_list<T> list) {chmax(a, *max_element(list.begin(), list.end()));}
ll dp[1010][1010];
int main(int argc, char **argv)
{
	ll n; cin >> n;
	for (ll i = 0; i < n; ++i)
	{
		string a, b; cin >> a >> b;
		memset(dp, 0, sizeof dp);
		for (ll i = 0; i < a.size(); ++i)
		{
			for (ll j = 0; j < b.size(); ++j)
			{
				
				if (a[i] == b[j])
					chmax(dp[i+1][j+1], dp[i][j]+1);
				chmax(dp[i+1][j+1], {dp[i+1][j], dp[i][j+1]});
			}
		}
		std::cout << dp[a.size()][b.size()] << std::endl;
	}
}



Measured memory_bytes: 11140
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int a[100000];
int main() {
  int N,S,W,q;
  while(cin>>N>>S>>W>>q,N||S||W||q) {
    int g = S;
    for(int i=0; i<N; i++) {
      a[i] = (g/7) % 10;
      if( g%2 == 0 ) { g = (g/2); }
      else           { g = (g/2) ^ W; }
    }
    int ans = 0;
    if (q==2||q==5) {
      int hoge = 0;
      REP(i, N) {
        if (a[i]) hoge++;
        if (a[i]%q == 0) {
          ans += hoge;
        }
      }
    } else {
      map<int,int> mp;
      int now = 0;
      int tens = 1;
      for (int i=N-1; i>=0; --i) {
        now = (now+a[i]*tens) % q;
        tens = tens * 10 % q;
        //cout << now << " ";
        if (a[i])
          ans += mp[now] + (now==0);
        mp[now]++;
      }
      //cout << endl;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL p(n);
    REP(i,n)cin>>p[i];
    LL minp = n+1;
    LL ans = 0;
    REP(i,n){
        if(p[i] < minp)ans++; 
        minp = min(minp, p[i]);
    }
    PUTS(ans);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL INF=100000000000;
string u="abcdefghijklmnopqrstuvwxyz";


int main(){
    string s[]={"eraser","erase","dreamer","dream"};
    string t;
    cin >> t;
    for(int i=0;i<4;i++){
        while(t.find(s[i])!=string::npos){
            t.erase(t.find(s[i]),s[i].length());
        }
    }
    if(t.length()==0)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll x; cin >> x;

  rep2(i, 1, 400) {
    if (x * i % 360 == 0) {
      cout << i << "\n";
      return 0;
    }
  }
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  sort(all(s));
  cout << (s[0] == s[2] ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
	while(1)
	{
		int n;
		cin>>n;
		if(n==-1)break;
		double t=0;
		for(int i=2;i<=n;i++)
		{
			t+=asin(1.0/sqrt((double)i));
		}
		cout<<sqrt((double)n)*cos(t)<<endl<<sqrt((double)n)*sin(t)<<endl;
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int min = a[0], max = a[0];
  for(int i = 0; i < n; i++){
    if(min > a[i]) min = a[i];
    if(max < a[i]) max = a[i];
  }
  cout << max - min << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main(){
	int m,f,r;
	char a;
	while(true){
		a='F';
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1)
			break;
		if(m+f>=80)
			a='A';
		if(m+f>=65&&m+f<80)
			a='B';
		if(m+f>=50&&m+f<65)
			a='C';
		if(m+f>=30&&m+f<50){
			a='D';
			if(r>=50)
				a='C';
		}
		if(m==-1||f==-1)
			a='F';
		cout<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
  int N, K;
  double ans;
  cin >> N >> K;
  for(int i=1; i<=N; i++){
    int score=i;
    double p=1;
    while(score<K){
      score*=2;
      p*=0.5;
    }
    ans+=p/N;
  }
  cout << setprecision(12) << ans << endl;
  
  return 0;
}

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

const int N = 300000 + 10;
int n, sum[N];
char s[N];

int main() {
    scanf("%d %s", &n, s+1);
    int cnt = 0;
    for(int i=1;i<=n;i++) {
        sum[i] += cnt;
        if (s[i] == 'W') cnt ++;
    }
    cnt = 0;
    for(int i=n;i>=1;i--) {
        sum[i] += cnt;
        if (s[i] == 'E') cnt ++;
    }
    int ans=N;
    for(int i=1;i<=n;i++) ans = min(ans, sum[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll S(ll n) {
  int ret=0;
  while(n) {
    ret+=n%10;
    n/=10;
  }
  return ret;
}

void exp(int n) {
  repeat(i,1,n+1) {
      cout << i << " " << i*1.0/(S(i)*1.0) << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
//  int n;
//  cin>>n;
//  exp(n);
  int k;
  cin>>k;
  vector<ll> s;
  vector<ll> cs;
  repeat(i,1,1000) {
    ll x=i;
    cs.push_back(x);
    while(x<=1e15) {
      x*=10;
      x+=9;
      cs.push_back(x);
    }
  }
  sort(cs.begin(),cs.end());
  cs.erase(unique(cs.begin(),cs.end()), cs.end());
  int n = cs.size();
  rep(i,n) {
    bool f = true;
    repeat(j,i+1,n) {
      ll nn = cs[i];
      ll mm = cs[j];
      if(nn*S(mm)>mm*S(nn)) { // n/s(n)<=m/s(m) (where m>n)
        f=false;
        break;
      }
    }
    if(f) {
      s.push_back(cs[i]);
    }
  }
  // ll x=1;
  // rep(i,15) {
  //   ll y=0;
  //   rep(t,i) {
  //     y*=10;
  //     y+=9;
  //   }
  //   repeat(a,1,10) {
  //     s.push_back(a*x+y);
  //   }
  //   x*=10;
  // }
  rep(i,k) {
    // if(s[i]==0)
    //   cout << "s[" << i <<"]=" << s[i] << endl;
    cout << s[i] << endl;
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int d[60];
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            ans += d[i]*d[j];
        }
    }
    cout << ans;
    return 0;
}

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

bool prime(ll p) {
    if (p <= 3) {
        return p > 1;
    }
    if (p % 2 == 0 || p % 3 == 0) {
        return 0;
    }
    ll k = (ll)sqrt(p) + 1;
    for (ll i = 5; i < k; i += 6) {
        if (p % i == 0 || p % (i + 2) == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    ll x;
    cin >> x;
    while (!prime(x)) {
        x++;
    }
    cout << x;

    return 0;
}


Measured memory_bytes: 256
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    t = list(input())
    n = len(t)
    for i in range(n):
        if t[i] == '?':
            t[i] = 'D'
    print(''.join(t))



main()




Measured memory_bytes: 11692
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

int main(){

    string s;
    cin >> s;

    int size = s.size();

    //既知の桁の数が1だったときの13で割った値を求める
    //ex) 1-> 1 -> 1, 2 -> 10 -> 10, 3 -> 100 -> 9
    vector<int> basismod;
    basismod.pback(0);
    basismod.pback(1);

    for(int i = 2; i <= size; i++){
        basismod.pback((basismod[i - 1] * 10) % 13);
    }

    int dp[100001][13] = {};
    dp[0][0] = 1;

    for(int i = 0; i < size; i++){

        if(s[size - 1 - i] == '?'){

            rep(j,10){
                int add = (j * basismod[i + 1]) % 13;

                rep(k,13){
                    dp[i + 1][(k + add) % 13] = (dp[i + 1][(k + add) % 13] + dp[i][k]) % MODN;
                }
            }

        }else{
            int tmpd = (int)(s[size - 1 - i] - '0');
            int add = (tmpd * basismod[i + 1]) % 13;

            rep(j,13){
                dp[i + 1][(j + add) % 13] = dp[i][j];
            }
            
        }
    }

    if(false){
        rep(i,size + 1){
            rep(j,13){
                cerr << dp[i][j] << " ";
            }
            cerr << endl;
        }
    }

    cout << dp[size][5] << endl;

    return 0;
}


Measured memory_bytes: 6008
#include <iostream>
using namespace std;
int main(void){
    int N,A[16];
    int x[16][16], y[16][16];
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i];
        for(int j=1;j<=A[i];j++){
            cin >> x[i][j] >> y[i][j];
        }
    }
    //
    int MAX = 0;
    for(int bit=1;bit<(1<<N);bit++){
        int cnt = 0;
        int judge[16]={0};
        for(int j=1;j<=N;j++){
            if((bit>>(j-1))&1){
                judge[j] = 1;
                cnt++;
            }
        }
        bool flag = 0;
        for(int j=1;j<=N;j++){
            if(judge[j]){
                for(int k=1;k<=A[j];k++){
                    if(y[j][k] != judge[x[j][k]]){
                        cnt = 0;
                        flag = 1;
                        break;
                    }
                }
            }
            if(flag) break;
        }
        MAX = max(MAX,cnt);
    }
    cout << MAX << endl;
}


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

int cnt = 0;
void dfs(string S, string start) {
    if (S.find('7') != string::npos &&
        S.find('5') != string::npos &&
        S.find('3') != string::npos &&
        stoi(S) <= stoi(start)) {
            cnt++;
    }
    if (S.size() == start.size()) return;
    dfs(S + '7', start);
    dfs(S + '5', start);
    dfs(S + '3', start);
}


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

    int N;
    cin >> N;
    string str = to_string(N);
    int digit = str.size();
    dfs("", str);
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 256
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x%y)


a, b = map(int, input().split())
c = list(map(int, input().split()))
c.append(b)
c.sort()
d = 0
for i in range(1, a + 1):
    d = g_c_d(c[i] - c[i-1], d)
print(d)


Measured memory_bytes: 14224
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int r,g;
  cin >> r >> g;
  cout << 2*g - r << endl;
  return 0;
}


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

int main(void) 
{
   int n;
   cin >> n;
   vector<ll> a(n);
   rep(i,n) cin >> a[i];
   sort(a.begin(), a.end());

   if(a[0] == 0)
   {
       cout << 0 << endl;
       return 0;
   }
   ll ans = 1;
   rep(i,n) 
   {
       ans *= a[i];
       if(ans > 1000000000000000000 || ans <= 0)
       {
           cout << -1 << endl;
           return 0;
       }
   }
    cout << ans << endl;
}

Measured memory_bytes: 4052
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int N;
    cin>>N;
    int ans;
    if(N<=104)ans=0;
    else if(N<=134)ans=1;
    else if(N<=164)ans=2;
    else if(N<=188)ans=3;
    else if(N<=194)ans=4;
    else ans=5;

    cout<<ans<<endl;
    return 0;

}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    string CF = "CF.";
    int t = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == CF[t]) t++;
    }
    if (t == 2) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

inline void setmin(int &x, int y) { if (y < x) x = y; }
inline void setmax(int &x, int y) { if (y > x) x = y; }
inline void setmin(ll &x, ll y) { if (y < x) x = y; }
inline void setmax(ll &x, ll y) { if (y > x) x = y; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n)
        cin >> a[i];
    int pref[n + 1], suff[n + 1];
    pref[0] = 0;
    rep(i, 0, n)
        pref[i + 1] = pref[i] + abs(a[i] - (i > 0 ? a[i - 1] : 0));
    suff[n] = 0;
    repb(i, n - 1, -1)
        suff[i] = suff[i +1 ] + abs(a[i] - (i < n - 1 ? a[i + 1] : 0));
    rep(i, 0, n)
        cout << pref[i] + abs((i > 0 ? a[i - 1] : 0) - (i < n - 1 ? a[i + 1] : 0)) + suff[i + 1] << "\n";
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
// C - AB Substrings

using namespace std;

int main() {
    int N,i,j,st,ed,two,ans;
    string s;

    cin >> N;

    ans = 0;
    st = 0;
    ed = 0;
    two = 0;
    for (i = 0;i < N;i++) {
        cin >> s;

        if (s.front() == 'B' && s.back() == 'A')
            two++;
        else if (s.front() == 'B')
            st++;
        else if (s.back() == 'A')
            ed++;

        for (j = 1;j < s.size();j++) {
            if (s[j - 1] == 'A' && s[j] == 'B')
                ans++;
        }
    }

    if (ed > 0 || st > 0)
        ans += two + min(ed,st);
    else
        ans += max(0,two - 1);

    printf("%d\n",ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, x);
    Cins(int, n, l);
    Cusum(int, l, sl);
    //Couts(sl);
    Cout(distance(sl.begin(), upper_bound(Range(sl), x)));
}


Measured memory_bytes: 256
/* ***************************************
Author        :Scau.ion
Created Time  :2016/10/10 20:17:50 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

int main()
{
	int n;
    scanf("%d",&n);
    LL ans=0;
    int last;
    scanf("%d",&last);
    ans=last-1;
    last=1;
    for (int j=2;j<=n;++j)
    {
        int x;
        scanf("%d",&x);
        if (x==last+1) ++last;
        ans+=(x-1)/(last+1);
    }
    cout<<ans<<endl;
	return 0;
}


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

#define ll long long int
ll mod=1e9+7;
#define loop() for(ll i=0;i<n;i++) 


int main()
{ 
      std::ios_base::sync_with_stdio(false);
     // int t;cin>>t;
     /* while(t--)
      {
           
           
      }*/
      
     int n;cin>>n;
     string s;
     cin>>s;
     char comp=s[0];int ans=1;
     for(int i=1;i<n;i++)
     {
           if(s[i]!=comp)
           {
                 ans++;
                 comp=s[i];
                 
           }
     }
     cout<<ans<<'\n';
     
     
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int x;cin>>x;
  int div=x/100, sur=x%100;
  while(div>0){
  	if(div*5>=sur){cout<<1<<endl;return 0;}
    div--;sur+=100;
  }
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
int main(){
	ll N,K;
	cin >> N >> K;
	map<ll,ll> ma;
	FOR(i,0,N){
		ll a;
		cin >> a;
		ma[a]++;
	}
	if(ma.size()<=K){
		cout << 0 << endl;
		return 0;
	}
	priority_queue<ll> Q;
	for(auto x:ma){
		Q.push(-x.second);
	}
	ll ans = 0;
	while(Q.size()>K){
		ans -= Q.top();
		Q.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 14964