akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
 
int main() {
	int n;
	cin >> n;
	vector<int> L(n);
	rep(i, n) cin >> L.at(i);
	int sum = 0;
	sort(L.begin(), L.end());
	for (int i = 0; i < n - 2; i += 1) {
		int a = L.at(i);
		for (int j = i + 1; j < n - 1; ++j) {
			int b = L.at(j);
			for (int k = j + 1; k < n; ++k) {
				int c = L.at(k);
				if (abs(b - c) < a) sum++;
				else break;
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF){
		if(a>b){
			int t=a;
			a=b;b=t;
		}
		if(a>c){
			int t=a;
			a=c;c=t;
		}
		if(b>c){
			int t=c;
			c=b;b=t;
		}
		int sum=0;
		int n1,n2;
		n1=a-b;n2=c-b;
		if(n1<0){
			n1=-n1;
		}
		if(n2<0){
			n2=-n2;
		}
		sum=n1+n2;
		printf("%d\n",sum);
		
	}

	
	
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    set<string> st;
    REP(i, n){
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 19260
n = int(input())

import collections

s = [0]*n
for i in range(n):
    s[i] = input()
c = collections.Counter(s)

D = []
for k, v in sorted(c.items(), key=lambda x: -x[1]):
    D.append([k,v])
sortsecond = lambda val : -val[1]
D.sort(key=sortsecond)

E = []
for i in range(len(D)):
    if D[0][1] == D[i][1]:
        E.append(D[i][0])
    else:
        break
E = sorted(E)
for i in range(len(E)):
    print(E[i])


Measured memory_bytes: 65000
use v6;

my $n = get().chomp;
my @arr = get().chomp.split(' ');
my $c = 0;
my $f = 0;

while $f != 1 {
    loop (my $i = 0; $i < $n; $i++) {
        if @arr[$i] % 2 == 0 {
            @arr[$i] /= 2;
        } else {
            $f = 1;
            $c--;
            last;
        }
    }
    $c++;
}
say $c;

exit;


Measured memory_bytes: 78596
#include<bits/stdc++.h>
using namespace std;
int n,cnt,mx,ans,x,xx;
int main()
{
    cin>>n;
    for(x=1; x<=n; x++)
    {
        xx=x;
        cnt=0;
        while(xx)
        {
            if(xx%2==0)
            {
                cnt++;
                xx=xx/2;
            }
            else break;
        }
        if(cnt>=mx)
        {
            mx=cnt;
            ans=x;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)

function main()
	n = parseInt(readline())
	x = zeros(Int,n,26)
	for i in 1:n
		k = chomp(readline())
		for j in 1:length(k)
			x[i,Int[k[j]]-96] += 1
		end
	end
	for i in 1:26
		k = minimum(x[:,i])
		for j in 1:k
			print(Char(96+i))
		end
	end
end

main()

Measured memory_bytes: 116528
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    int n,a=0,b=0,c=0,d=0;
    char s[100000][4];
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%s",s[i]);
    for(int i=0;i<n;i++){
        if(strcmp(s[i],"AC")==0) a++;
        else if(strcmp(s[i],"WA")==0) b++;
        else if(strcmp(s[i],"TLE")==0) c++;
        else if(strcmp(s[i],"RE")==0) d++;
        
    }
    printf("AC x %d\n",a);
    printf("WA x %d\n",b);
    printf("TLE x %d\n",c);
    printf("RE x %d\n",d);
    return 0;
}

Measured memory_bytes: 2540
#include<stdio.h>
#include<math.h>
int main()
{
  int n,i,j,pri=0;
  scanf("%d",&n);

  int N[n];
  for(i=0; i<n; i++){
    scanf("%d",&N[i]);
    
    int k=0;
    if((N[i]==2) || (N[i]==3)) pri++;
 
    else if((N[i]%2)!=0){
      for(j=3;j<=sqrt(N[i]);j+=2){	
	if((N[i]%j)==0){
	  k=1;
	  break;
	}
      }
      if(k==0) pri++;
    }
  }
  printf("%d\n",pri);
  return 0;
}



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

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

  int n;
  string s;
  cin >> n;
  cin >> s;

  int w, e;
  w = 0;
  e = 0;
  for (char c : s) {
    c == 'W' ? w++ : e++;
  }

  int lw, re;
  lw = 0;
  re = e;

  int ans = n;
  for (char c : s) {
    if (c == 'E') {
      re--;
    }

    ans = min(ans, lw + re);

    if (c == 'W') {
      lw++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int &x : h) 
    cin >> x;
  h[0]--;
  for (int i = 1; i < n; i++) {
    if (h[i - 1] > h[i]) {
      cout << "No\n"; return 0;
    }
    if (h[i - 1] < h[i]) h[i]--;
  }
  cout << "Yes\n";
  return 0; 
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int n,m;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%d",&n,&m);

	if(n<m) for(int i=1;i<=m;i++) printf("%d",n);
	else for(int i=1;i<=n;i++) printf("%d",m);

	printf("\n");

	return 0;

}

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

#define debug(a) cerr << #a << " = " << (a) << endl; 
#define get(t, i) get<(i)>((t))
#define fst first
#define snd second

template<typename T> ostream& operator<<(ostream& o, const vector<T>& v) {
  int b = 0; for (const auto& a : v) o << (b++ ? " " : "") << a; return o;
}

template<typename T, typename U> ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << p.fst << ' ' << p.snd; return o;
}

int n;
vector<int> A;
int dp[101010];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> n;
  A.assign(n, 0);
  for (auto& a : A) cin >> a;

  dp[0] = 0;
  dp[1] = abs(A[0] - A[1]);
  for (int i = 2; i < n; i++)
    dp[i] = min(dp[i-1] + abs(A[i-1] - A[i]), dp[i-2] + abs(A[i-2] - A[i]));

  cout << dp[n-1] << endl;

}



Measured memory_bytes: 1024
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n');
const args = input[0].split(' ').map(x => +x);
let cnt = 0;
while (args[0] > 0) {
    args[0] -= args[1];
    cnt++;
}
console.log(cnt);


Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

// Using https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/

// cmp function to sort queries according to r 
bool cmp(const pair<pair<ll, ll>,ll> &x, const pair<pair<ll,ll>,ll> &y) 
{ 
    return x.first.second < y.first.second; 
} 
  
// updating the bit array 
void update(int idx, int val, vector<ll> &bit, int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
ll query(ll idx, vector<ll> &bit, ll n) 
{ 
    ll sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(vector<ll> &arr, ll n, vector <pair<pair<ll,ll>,ll> > &queries, ll q) 
{ 
    // initialising bit array 
    vector <ll> bit(n+1,0);  
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    vector <int> last_visit(n+1, -1);  
  
    // answer for each query 
    vector<int> ans(q); 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].first.second == i) 
        { 
            ans[queries[query_counter].second] = 
                     query(queries[query_counter].first.second + 1, bit, n)- 
                     query(queries[query_counter].first.first, bit, n); 
            query_counter++; 
        } 
    }
    for (int i=0; i<q; i++) 
        cout << ans[i] << "\n";  
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,Q; 
    cin >>N >> Q;
    vector <ll> c(N);
    loop(i,0,N) cin >> c[i];
    vector < pair<pair <ll, ll>,ll> > queries(Q);
    for (int i=0; i<Q; ++i)
    {
        ll l,r; cin >> l >> r;
        l--; r--;
        queries[i]={{l,r},i};
    }
    sort(queries.begin(), queries.end(), cmp);
    answeringQueries(c, N, queries, Q);
    return 0;
}

Measured memory_bytes: 27168
// 10進数から26進数への基数変換と同様に考えれば良い
// 但し, 番号は1から始まるので注意
void main(){
	long n = _scan!long();
	string ans;
	while(n>0){
		int rem = (n%26==0)?26:n%26;
		ans ~= ( ('a'-1) + rem );
		n = (n -1)/26;
	}
	ans.retro.array.to!string.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range, std.array;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(void) {
    int a, b, c, x, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    REP(i, a + 1) {
        REP(j, b + 1) {
            REP(k, c + 1) {
                if (x == i * 500 + j * 100 + k * 50) {
                    ans++;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
while true
  n = gets.chomp.to_i
  break if n == 0

  max_l = 0
  pl = (0..n).map{0}

  n.times.each do
    hl = gets.chomp.split("").map{|s| s == "."}

    pl0 =[0]

    for i in (0...n)
      l = pl0[i + 1] = hl[i] ? [pl0[i], pl[i], pl[i + 1]].min + 1 : 0
      max_l = l if max_l < l
    end

    pl = pl0
  end

  puts max_l
end

Measured memory_bytes: 6176
n = input()
n = int(n)

s_list = []
k_list = []
for i in range(n):
  si, ki = input().split()
  s_list.append(si)
  k_list.append(int(ki))

x = input()
index = s_list.index(x)

time = 0
for i in range(index+1, n):
  time += k_list[i]

print(time)

Measured memory_bytes: 38384
#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>;
const double PI=acos(-1);

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

    set<int> s;
    bool ok = true;

    rep(i,n){
        int a;
        cin >> a;
        if (s.count(a)) ok = false;
        s.insert(a); 
    }

    if(ok) cout << "YES" << endl;
    if(!ok) cout << "NO" << endl;

    return 0;
    
}

Measured memory_bytes: 9600
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
const int N=3050;
typedef long long ll;
const ll mod=1000000007;
const ll inv=500000004;
int n,q,ai[N];
ll dp[N][N],ans,pl;

inline ll KSM(ll a,ll p){
	ll ret=1;
	while(p){
		if(p&1) ret=ret*a%mod;
		a=a*a%mod;
		p>>=1;
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&q);
	pl=KSM(2,q);
	for(int i=1;i<=n;i++)
		scanf("%d",&ai[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(ai[i]>ai[j])
				dp[i][j]=1;
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		if(x>y) swap(x,y);
		dp[x][y]=dp[y][x]=((dp[x][y]+dp[y][x])%mod)*inv%mod;
		for(int i=1;i<=n;i++){
			if(i==x || i==y) continue;
			dp[i][x]=dp[i][y]=((dp[i][y]+dp[i][x])%mod)*inv%mod;
			dp[x][i]=dp[y][i]=((dp[y][i]+dp[x][i])%mod)*inv%mod;
		}
//		for(int i=1;i<=n;i++)	
//		{
//			for(int j=1;j<=n;j++)
//				cout<<dp[i][j]<<" ";
//			cout<<endl;
//		}
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans=(dp[i][j]+ans)%mod;
	ans=ans*pl%mod;
	ans=(ans+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 75300
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from collections import defaultdict


def find_ans(dp, mod):
    nex = defaultdict(int)
    for key, val in dp.items():
        for c in ["A", "G", "C", "T"]:
            if (key[1:] == "AG" and c == "C")\
                or (key[1:] == "AC" and c == "G")\
                or (key[1:] == "GA" and c == "C")\
                or (key[:1] == "A" and key[2:] == "G" and c == "C")\
                or (key[:1] == "A" and key[1:2] == "G" and c == "C"):
                continue
            else:
                nex[key[1:] + c] += val
                nex[key[1:] + c] %= mod

    return nex

n = ni()
dp = defaultdict(int)
mod = 10**9 + 7

dp["TTT"] = 1

for _ in range(n):
    dp = find_ans(dp, mod)

ans = 0
for key, val in dp.items():
    ans += val
    ans %= mod

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  int N;
  cin >> N;
  int wild = 0;
  set<int> st;
  rep(i, 0, N) {
    int a;
    cin >> a;
    a /= 400;
    if (a < 8) st.insert(a);
    else wild++;
  }

  int mi = max(1, (int)st.size());
  int ma = (int)st.size() + wild;

  cout << mi << " " << ma << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int C[10][10];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<=N;i++) {
		y=i%10;
		x=i;
		while(x>=10) x=x/10;
		C[x][y]++;
	}
	
	ll ret=0;
	FOR(x,10) FOR(y,10) ret+=1LL*C[x][y]*C[y][x];
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,x,y;
 cin >> x >> y;
 for(i=0;i<=x;i++)
 {
  if((i*2+(x-i)*4)==y)
  {
   cout << "Yes";
   return 0;
  }
 }
 cout << "No";
 return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

std::string solve(int a)
{
  if (a % 10 == 7) return "Yes";
  if (a / 10 % 10 == 7) return "Yes";
  if (a / 100 % 10 == 7) return "Yes";
  return "No";
}

int main()
{
  int a;
  std::cin >> a;

  std::cout << std::setprecision(20);
  std::cout << solve(a) << std::endl;
}


Measured memory_bytes: 3620
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 101010
void build(){

}
bool gg;
int n , m , cnt[ N ] , clr[ N ];
vector<int> v[ N ];
void init(){
  n = getint();
  m = getint();
  for( int i = 0 ; i < m ; i ++ ){
    int ui = getint();
    int vi = getint();
    v[ ui ].push_back( vi );
    v[ vi ].push_back( ui );
  }
}
void go( int now , int tclr ){
  clr[ now ] = tclr;
  cnt[ tclr ] ++;
  for( int u : v[ now ] ){
    if( clr[ u ] ){
      if( clr[ u ] == tclr )
        gg = true;
      continue;
    }else
      go( u , 3 - tclr );
  }
}
void solve(){
  go( 1 , 1 );
  LL all = (LL)n * (LL)(n - 1) / 2;
  if( not gg )
    all = (LL)cnt[ 1 ] * cnt[ 2 ];
  cout << all - m << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 6400
s = list(input())
q = int(input())

n = len(s)
rev = False
fwd = []

for i in range(q):
    t = input()
    if len(t) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        q2, f, c = t.split()
        if rev:
            if int(f) == 2:
                fwd.append(c)
                n += 1
            else:
                s.append(c)
                n += 1
        else:
            if int(f) == 1:
                fwd.append(c)
                n += 1
            else:
                s.append(c)
                n += 1

fwd = list(reversed(fwd))

s = fwd + s

if rev:
    s = "".join(list(reversed(s)))
else:
    s = "".join(s)

print(s)


Measured memory_bytes: 8592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    multiset<ll> s;
    for(int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        s.insert(a);
    }

    int ans = 0;
    while(!s.empty())
    {
        ll cand = *(s.rbegin());
        ll x = 1;
        while(x <= cand)
        {
            x *= 2;
        }
        s.erase(s.find(cand));
        auto itr = s.find(x-cand);
        if(itr == s.end())
        {
            continue;
        }
        else
        {
            ans++;
            s.erase(itr);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool visited[225816];

std::vector<int> g[225816];
std::queue<int> que;

int main(void){
	int n,m,a,b,ans=0,i,j,tmp;
	std::cin >> n >> m;
	for(i=0; i<m; ++i){
		std::cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(i=0; i<n; ++i){
		que.push(i);
		tmp = 0;
		while(!que.empty()){
			a = que.front();
			que.pop();
			if(visited[a]){
				continue;
			}
			visited[a] = true;
			++tmp;
			for(j=(g[a].l_ength()-1); j>=0; --j){
				b = g[a][j];
				if(visited[b]){
					continue;
				}
				que.push(b);
			}
		}
		ans = std::max(ans,tmp);
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 15668
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int n, m;
	cin >> n >> m;
	vector<LL> x(n + 1), y(m + 1);
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> y[i];
	}

	LL v = 0;
	for (int i = 1; i <= n; i++) {
		v += (i + i - n - 1) * x[i];
		v %= (LL)1e9 + 7;
	}

	LL d = 0;
	for (int i = 1; i <= m; i++) {
		d += (i + i - m - 1) * y[i];
		d %= (LL)1e9 + 7;
	}

	cout << (v * d) % (MOD) << endl;
}

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

int main(){
  int N;
  int A;
  int coin500;
  cin >> N >> A;
  coin500 = N/500;
  if (N-500*coin500 > A){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=2000100;
int k,n;
int a[maxn];
int ans=0;
int main()
{
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		ans=max(ans,a[i]-a[i-1]);
		//printf("%d\n",ans);
	}
	ans=max(ans,k-a[n]+a[1]);
	printf("%d\n",k-ans);
	return 0;
}


Measured memory_bytes: 4580
n=int(input())
a=list(map(int,input().split()))
b={}
s=0
ans=0
for i in range(n):
  s+=a[i]
  if s not in b:
    if s==0:
      b[s]=1
      ans+=1
    else:
      b[s]=0
  else:
    b[s]+=1
    ans+=b[s]
print(ans)

Measured memory_bytes: 38644
def main():
    k,s=map(int,input().split())
    ans = 0
    for i in range(k+1):
        x = i
        for j in range(k+1):
            y = j
            z = s - x - y
            if z <= k and z >= 0:
                ans += 1
                # print(x,y,z)
    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int sum = a + b + c;

	if (sum >= 22) {
		cout << "bust" << endl;
	} else {
		cout << "win" << endl;
	}
	
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        if [k[j:m+j] for k in a[i:m+i]] == b:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3060
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int n;
int a[N][3];

int cache[N][4];

int dp(int idx, int prev){
    if(idx>n) return 0;
    int &ans=cache[idx][prev];
    if(ans!=-1) return ans;
    ans=0;
    for(int i=1; i<=3; i++){
        if(prev!=i) ans=max(ans,dp(idx+1,i)+a[idx][i]);
    }
    return ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    rep(i,1,n+1) rep(j,1,4) cin >> a[i][j];
    mst(cache,-1);
    int res=dp(1,0);
    cout << res;
    return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int t=0,k,n,cnt=0; cin>>n;
  multiset<int> a;
  for(int i=0; i<n; ++i){ cin>>k; a.insert(k); t=max(t,k);}
  vector<int> b(t+1,0);
  for(auto itr=a.begin(); itr!=a.end();){
    cnt=a.count(*itr);
    for(int i=1; i*(*itr)<=t; ++i) b[i*(*itr)]+=cnt;
    while(cnt--) ++itr;
  }
  int res=0;
  for(auto itr=a.begin(); itr!=a.end(); ++itr) if(b[*itr]==1) ++res;
  cout<<res;
  return 0;
}

Measured memory_bytes: 16372
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < int(n); i++)
using namespace std;

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

constexpr ll mod = 1e9 + 7;

ll mpow(ll x, ll n) {
    ll ans = 1; x %= mod;
    while (n != 0) {
        if (n & 1) ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
    vector<ll> fac;
    vector<ll> ifac;
public:

    Factorial(ll N) {
        fac.push_back(1);
        for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
        ifac.resize(N + 1);
        ifac[N] = inv_mod(fac[N]);
        for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
    }

    ll fact(ll a) { return fac[a]; }
    ll ifact(ll a) { return ifac[a]; }

    ll cmb(ll a, ll b) {
        if (a == 0 && b == 0) return 1;
        if (a < b || a < 0 || b < 0) return 0;
        ll tmp = ifact(a - b) * ifact(b) % mod;
        return tmp * fac[a] % mod;
    }
    ll per(ll a, ll b) {
        if (a == 0 && b == 0) return 1;
        if (a < b || a < 0 || b < 0) return 0;
        return fac[a] * ifac[a - b] % mod;
    }
};


int main() {
	int n, m;
    cin >> n >> m;
    if (abs(n - m) > 1) {
        cout << 0 << endl;
    }
    else if (abs(n - m) == 0) {
        Factorial f(n + m);
        auto a = f.per(n, n) * f.per(m, m) * 2;
        cout << a % mod << endl;
    }
    else {
        Factorial f(n + m);
        auto a = f.per(n, n)* f.per(m, m);
        cout << a % mod << endl;
    }
	return 0;
}


Measured memory_bytes: 6236
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int n;
vi zr(3),l;
int dfs(int id,int a,int b,int c){
  if(id==n){
    if(a<=0||b<=0||c<=0) return MOD;
    int res = abs(a-zr.at(0))+abs(b-zr.at(1))+abs(c-zr.at(2)) - 30;
    return res;
  }
  int rs0 = dfs(id+1,a,b,c);
  int rs1 = dfs(id+1,a+l.at(id),b,c)+10;
  int rs2 = dfs(id+1,a,b+l.at(id),c)+10;
  int rs3 = dfs(id+1,a,b,c+l.at(id))+10;
  rs0 = min(rs0,rs1);
  rs2 = min(rs2,rs3);
  return min(rs0,rs2);
}
signed main(){
  cin >> n >> zr[0] >> zr[1] >> zr[2];
  l.resize(n);
  REP(i,n) cin >> l.at(i);
  cout << dfs(0,0,0,0) << endl;
}


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

int main() {
  int n;
  cin >> n;
  
  int ds[4];
    
  for (int i = 0; i < 4; i++) {
    ds[3 - i] = n % 10;
    n /= 10;
  }
  
  if (ds[0] == ds[1] && ds[1] == ds[2] || ds[1] == ds[2] && ds[2] == ds[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  std::vector<long long int> digit_count(3);
  std::vector<long long int> one(10), ten(10), hundred(10);

  // read problem
  long long int N;
  std::string S;
  scanf("%lld", &N);
  std::cin >> S;
  
  std::vector<long long int> S2;
  for(long long int i = 0; i < N; i++){
    S2.push_back((long long int)S[i] - '0');
  }

  std::cerr << "S2:" << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << S2[i];
  }std::cerr << std::endl;

  // solve problem
  for(long long int i = 0; i < N; i++){
    // hundred digit

    if(digit_count[1] > hundred[S2[i]]){
      digit_count[2] += digit_count[1] - hundred[S2[i]];
      hundred[S2[i]] = digit_count[1];
    }

    // ten digit
    if(digit_count[0] > ten[S2[i]]){
      digit_count[1] += digit_count[0] - ten[S2[i]];
      ten[S2[i]] = digit_count[0];
    }

    // one digit
    if(one[S2[i]] == 0){
      one[S2[i]] = 1;
      digit_count[0]++;
    }
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << digit_count[2] << std::endl;

  return 0;

  
}


Measured memory_bytes: 656
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999

int main() {
	int a,b,n,c = 0;
	cin >> n;
	REP(i, n) {
		cin >> a >> b;
		c += b - a + 1;
	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;
 
int main()
{
  ll h,w;
  cin>>h>>w;
  if(h==1||w==1)
  {
    cout<<1<<endl;
    return 0;
  }
  cout<<((h*w%2==0)? h*w/2:h*w/2+1)<<endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    cout<<3*n*n<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#define fr first
#define sc second
#define INF (2LL << 58)
using namespace std;

typedef long long ll;
typedef pair<ll, int> iP;
struct edge{
  int to, cost; edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

int n, m, x;
ll h[100001], costed[100001];
vector<vector<edge> > graph;

ll Dijkstra(){

  for(int i = 1; i <= n; i++) costed[i] = -INF;
  priority_queue<iP, vector<iP> > que;
  que.push(iP(x, 1)); costed[1] = x;
  while(!que.empty()){
    iP p = que.top(); que.pop();
    int now = p.sc;
    ll dist = p.fr;
    if(now == n) return -(dist * 2);
    for(int i = 0; i < graph[now].size(); i++){
      ll sub = 0;
      edge &e = graph[now][i];
      if(dist - e.cost > h[e.to-1]) sub = dist-e.cost-h[e.to-1];
      if(dist - e.cost - sub > costed[e.to] && h[now-1] >= e.cost){
        costed[e.to] = dist - e.cost - sub;
        que.push(iP(dist - e.cost - sub, e.to));
      }
    }
  }
  return -INF;
}

int main(){

  cin >> n >> m >> x;
  graph.resize(n + 2);
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    graph[a].push_back(edge(b, c));
    graph[b].push_back(edge(a, c));
  }
  
  ll d = Dijkstra();
  if(d == -INF) cout << -1 << endl;
  else cout << d + h[n-1] + x << endl;
}

Measured memory_bytes: 14668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	ll n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000 << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ls x<<1
#define rs x<<1|1
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+100;
int vis[maxn],ans1,ans2,flag[maxn];
char s[maxn];
void solve(){
	int n,m;
	scdd(n,m);
	rep1(i,m){
		int x;
		scanf("%d%s",&x,s+1);
		if(s[1]=='A'&&!vis[x]){
			ans2+=flag[x];
			vis[x]=1;
			ans1++;
		}
		else flag[x]++;
	}
	printf("%d %d\n",ans1,ans2);
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX], n;

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> R[i];

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

    return 0;
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}

void solution() {
  int n;
  cin >> n;
  n = n % 10;
  if (n == 3)
    cout << "bon" << endl;
  else if (n == 0 || n == 1 || n == 6 || n == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}

int32_t main() {
  DESYNC;
  solution();
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   cin>>s;
   int n=s.size();
   int cnt=0;
   for(int i=0;i<n;i++)
   {
       if(s[i]=='o') cnt++;
   }
  if(cnt + 15-s.size() >=8){
		printf("YES");
	}else {
		printf("NO");
	}
	return 0;
}

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

using namespace std;
using ll = long long;

vector<int> prime;

void factorize(ll a) {
    if (a % 2 == 0) prime.push_back(2);
    while (a % 2 == 0) a /= 2;
    for (int i = 3; i <= sqrt(a); i += 2) {
        if (a % i == 0) prime.push_back(i);
        while (a % i == 0) a /= i;
    }
    if (a > 2) prime.push_back(a);
}

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    ll g = __gcd(a, b);
    factorize(g);
    cout << (int) prime.size() + 1 << '\n';
}

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

int main (){
  int N, sum=0;
  cin >> N;
  
  for(int i=1 ; i<100000000 ; i*=10){
    int n=N;
    sum+=n/i%10;
  }
  if(N%sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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 main(){
    ll a, b;
    cin >> a >> b;

    ll x = a * b;
    ll tmp;
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

    cout << x / b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int x;
  scanf("%d", &x);

  int ans = 1;
  for (int b = 2; b <= sqrt(x); b++) {
    int num = b;
    while ( num <= x ) num *= b;
    ans = max(ans, num / b);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <array>
#include <string>
#include <vector>

using namespace std;

constexpr int SURFACE_NUM = 6;
enum {TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM};

class Dice {
private:
    array<int, SURFACE_NUM> m_surface;

public:
    // constructor
    Dice(array<int, SURFACE_NUM> surface)
        : m_surface(surface) {}

    // getter
    int surface(int i) const
    {
        return m_surface.at(i);
    }

    // roll and spin
    void roll(char direction)
    {
        switch (direction) {
        case 'N':
            roll(TOP, FRONT, BOTTOM, BACK);
            break;
        case 'S':
            roll(TOP, BACK, BOTTOM, FRONT);
            break;
        case 'E':
            roll(TOP, LEFT, BOTTOM, RIGHT);
            break;
        case 'W':
            roll(TOP, RIGHT, BOTTOM, LEFT);
            break;
        }
    }

    void roll(int i, int j, int k, int l)
    {
        int tmp = m_surface.at(i);
        m_surface.at(i) = m_surface.at(j);
        m_surface.at(j) = m_surface.at(k);
        m_surface.at(k) = m_surface.at(l);
        m_surface.at(l) = tmp;
    }

    void spin()
    {
        int tmp = m_surface.at(FRONT);
        m_surface.at(FRONT) = m_surface.at(LEFT);
        m_surface.at(LEFT) = m_surface.at(BACK);
        m_surface.at(BACK) = m_surface.at(RIGHT);
        m_surface.at(RIGHT) = tmp;
    }

    // is equal
    bool isEqual(const Dice& dice)
    {
        for (int i = 0; i < 6; i++) {
            (i % 2)? (*this).roll('E'): (*this).roll('N');
            for (int j = 0; j < 4; j++) {
                (*this).spin();
                if (*this == dice) {
                    return true;
                }
            }
        }
        return false;
    }

    bool operator==(const Dice& dice)
    {
        for (int i = 0; i < SURFACE_NUM; i++) {
            if (m_surface.at(i) != dice.surface(i)) {
                return false;
            }
        }
        return true;
    }

    // debug
    void printDice() const
    {
        cout << surface(TOP) << surface(FRONT)
             << surface(RIGHT) << surface(LEFT)
             << surface(BACK) << surface(BOTTOM) << endl;
    }
};

array<int, SURFACE_NUM> inputDice();

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

    vector<Dice> dices;
    dices.reserve(dice_num);
    for (auto i = 0; i < dice_num; i++) {
        Dice dice(inputDice());
        dices.push_back(dice);
    }

    bool is_diff_all = true;
    for (int i = 0; i < dice_num - 1 && is_diff_all; i++) {
        for (int j = i + 1; j < dice_num; j++) {
            if (dices.at(i).isEqual(dices.at(j))) {
                is_diff_all = false;
                break;
            }
        }
    }

    cout << (is_diff_all? "Yes": "No") << endl;
}

array<int, SURFACE_NUM> inputDice()
{
    array<int, SURFACE_NUM> init;
    for (auto i = 0; i < SURFACE_NUM; i++) {
        cin >> init.at(i);
    }
    return init;
}

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

int main(){
  string S;
  cin>>S;
  int c=0;
  for(int i=0;i<S.size();i++)
    if(S.at(i)=='x')
      c++;
  
  if(c<8)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
let input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n")[0].split(' ').map(i => parseInt(i))

const A = input[0]
const B = input[1]
const C = input[2]

// const ABC = [
//     [1, input[0]],
//     [0, input[1]],
//     [-1, input[2]]
// ]
const K = input[3]

count = 0
result = 0

if (K - count - A >= 0) {
    count += A
    result += A * 1
} else {
    console.log(K)
    return
}

if (K - count - B >= 0) {
    count += B
    result += B * 0
} else {
    console.log(result)
    return
}

result += (K - count) * (-1)

console.log(result)


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

using namespace std;

int n;
int data[100];
long long int dp[200][21];

long long int solve(int idx, int sum) {

    if(sum < 0 || sum > 20) return 0;

    if(dp[idx][sum] != -1) return dp[idx][sum];

    if(idx == n - 1) {
        if(sum == data[n - 1]) return 1;
        else return 0;
    }

    long long int ret = 0;

    ret += solve(idx + 1, sum + data[idx]);
    ret += solve(idx + 1, sum - data[idx]);

    return dp[idx][sum] = ret;

}

int main() {

    cin >> n;

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

    memset(dp, -1, sizeof(dp));

    cout << solve(1, data[0]) << endl;

}

Measured memory_bytes: 1200
import math
N=int(input())
L=[]
for i in range(2,int(math.sqrt(N))):
    if N%i==0:
        c=0
        while N%i==0:
            N/=i
            c+=1
        L.append(c)
if N!=1:
    L.append(1)
ans=0
for i in L:
    for n in range(10):
        if (n*(n+1))//2>i:
            ans+=n-1
            break
print(ans)

Measured memory_bytes: 9268
n=int(input())
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as frac  #frac(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########


def Dlist(BIG):
    D=[1]*(BIG+1)
    for p in range(2,BIG+1):
        if D[p]!=1:
            continue
        for i in range(p,BIG+1,p):
            if D[i]==1:
                D[i]=p
    return D
# Dlist(10) -> [1, 1, 2, 3, 2, 5, 2, 7, 2, 3, 2]

def BUNKAI(num,D):
    now=num ; ans=[]
    while now>1:
        ans.append(D[now])
        now//= D[now]
    # return ans
    return Counter(ans)
# print(BUNKAI(3012,Dlist(3012))) -> Counter({2: 2, 3: 1, 251: 1})

def SOINSU(num,D): #素因数だけ列挙(setしただけ)
    now=num ; ans=set()
    while now>1:
        ans.add(D[now])
        now//=D[now]
    return ans
# print(SOINSU(3012,Dlist(3012)))　-> {2, 3, 251}
D=Dlist(n)
ans=0
for i  in range(1,n):
    now=1
    l=BUNKAI(i,D)
    for j in l.values():
        now*=j+1
    ans+=now
print(ans)

Measured memory_bytes: 82088
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;
typedef long long ll;

int gcd(int m, int n);
int lcm(int a, int b);

int main(void){
    using namespace  std;
    int N;
    cin >> N;

    vector<int> A(N);
    bool isApproved = true;
    rep(i, N){ 
        cin >> A[i];
        isApproved &= (A[i] % 2 == 1 || A[i] % 3 == 0 || A[i] % 5 == 0);
    }

    cout << (isApproved ? "APPROVED" : "DENIED") << endl;

    return 0;
}

int gcd(int m, int n){
    int r;
    do{
        r = m % n;
        m = n;
        n = r;
    } while (r != 0);

    return m;
}

int lcm(int a, int b){
    long temp = a * b;
    return temp / gcd(a, b);
}


Measured memory_bytes: 256
N, M = map(int, input().split())
m = {}
for i in range(1, M+1):
    m[i] = 0

for _ in range(N):
    for a in input().split()[1:]:
        a = int(a)
        m[a] += 1

ans = 0
for voted in m.values():
    ans += 1 if voted == N else 0
print(ans)


Measured memory_bytes: 3060