akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
using namespace std;
int D[3010][3010], P[3010], Mod = 1000000007;
int S[3010], n, m;
char p[3010];
int main(){
    int i, a, b, j;
    scanf("%d%d",&n,&m);
    scanf("%s",p+1);
    for(i=1;i<=n;i++){
        P[i]=i;
        S[i]=S[i-1]+p[i]-'0';
    }
    for(i=1;i<=m;i++){
        scanf("%d%d",&a,&b);
        for(j=a;j<=b;j++)P[j]=max(P[j],b);
    }
    D[0][0]=1;
    for(i=0;i<n;i++){
        int bb, ee;
        bb = max(0, i - (P[i] - S[P[i]])), ee = min(i, S[P[i]]);
        for(j=bb;j<=ee;j++){
            D[i+1][j]=(D[i+1][j]+D[i][j])%Mod;
            D[i+1][j+1]=(D[i+1][j+1]+D[i][j])%Mod;
        }
    }
    printf("%d\n",D[n][S[n]]);
}

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

int main() {
  string S;
  cin >> S;
  if(S=="RRR"){
    cout << 3 << endl;
  }
  else if(S=="SSS"){
    cout << 0 << endl;
  }
  else if(S=="RRS" || S=="SRR"){
    cout << 2 << endl;
  }
  else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3576
/*********************************************
* 20.05.19 AtCoder Beginner Contest 153
* 
* 
*********************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=1;(i)<=(n);i++)
#define rez(i,n) for(int (i)=0;(i)<(n);i++)
#define et "\n"

class CRun{
private:
    void IO_faster();
public:
    char problem_num;
    
    CRun(){
        problem_num = 'C';
    }; 
    ~CRun(){};
    void build();
    void solve_A(); void solve_B(); void solve_C(); 
    void solve_D(); void solve_E(); void solve_F();
};

void CRun::IO_faster(){
    ios::sync_with_stdio(0); cin.tie(NULL);
}

/*********************************************
A - Serval vs Monster
敵の体力H
味方の攻撃1回で体力をA減らせる
勝つための攻撃回数は？
*********************************************/
void CRun::solve_A(){
    int H; cin >> H;
    int A; cin >> A;
    
    int ans = 0;
    //ans += (H % A > 0 ? H / A + 1 : H / A);
    ans += (H - 1) / A + 1;
    cout << ans;
}

/*********************************************
B - Common Raccoon vs Monster
モンスターの体力H
N種類の攻撃で敵のHPをAN減らせる
同じ攻撃を使わずに敵を倒せるか？
*********************************************/
void CRun::solve_B(){
    
    int H; cin >> H;
    int N; cin >> N;
    int A[N]; rez(i,N) cin >> A[i];
    
    int sum = 0;
    for (auto &ix : A) sum += ix;
    
    string ans[] = {"Yes", "No"};
    if (sum >= H) {
        cout << ans[0];
    }
    else {
        cout << ans[1];
    }
    
}

/*********************************************
C - Fennec vs Monster
N개체의 적, H_N 만큼의 체력
공격 : 적을 1개체 골라서 체력을 1만큼 줄임
필살 : 적을 1개체 골라서 체력을 0으로 만듦
K회만큼 필살기를 쓸 수 있을 때, 승리하는 공격의 최소횟수는?
*********************************************/
void CRun::solve_C(){
    int enemy_num; cin >> enemy_num;
    int ultimate_cnt; cin >> ultimate_cnt;
    int enemy_hp[enemy_num]; rez(i,enemy_num) cin >> enemy_hp[i];
    
    ll ans = 0;
    sort(enemy_hp, enemy_hp + enemy_num, greater<int>());
    for (int ix = ultimate_cnt; ix < enemy_num; ix++) {
        ans += enemy_hp[ix];
    }
    cout << ans;
}

/*********************************************

*********************************************/
void CRun::solve_D(){
    
}

/*********************************************

*********************************************/
void CRun::solve_E(){
    
}

/*********************************************

*********************************************/
void CRun::solve_F(){
    
}

int main(){
    CRun run;
    switch (run.problem_num) {
        case 'A' : run.solve_A();
        case 'B' : run.solve_B();
        case 'C' : run.solve_C();
        case 'D' : run.solve_E();
        case 'E' : run.solve_D();
        case 'F' : run.solve_F();
    }
}



Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N, D = map(int, input().split())

vectors = []
for n in range(N):
    vectors.append(list(map(int, input().split())))

ans = 0
for n1 in range(N - 1):
    for n2 in range(n1 + 1, N):
        v1 = vectors[n1]
        v2 = vectors[n2]
        dist2 = 0
        for e1, e2 in zip(v1, v2):
            dist2 += (e1 - e2) ** 2
        tmp = int(round(math.sqrt(dist2)))
        if tmp * tmp == dist2:
            ans += 1
print(ans)            



Measured memory_bytes: 7976
N, L = map(int, input().split())
ans = L*(N-1) - (N-1)
if L >= 0:
    ans += (N+2)*(N-1)//2
elif L >= (-1*N)+1 :
    ans += (N+1)*N//2 + (L-1)
else:
    ans += N*(N-1)//2
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

const int MAXN = 1e5 + 3;
string a, b;
int q;
int prefix[2][MAXN];

int main() {
  ios_base::sync_with_stdio(false);
	int l1, r1, l2, r2;
	cin >> a >> b;
	for(int i = 1; i <= a.size(); i++) {
		prefix[0][i] = prefix[0][i-1] + (a[i-1] == 'A');
	}
	for(int i = 1; i <= b.size(); i++) {
		prefix[1][i] = prefix[1][i-1] + (b[i-1] == 'A');
	}
	cin >> q;
	while(q--) {
		cin >> l1 >> r1 >> l2 >> r2;
		int cnt[2] = {0};
		cnt[0] = prefix[0][r1] - prefix[0][l1-1];
		cnt[0] += (r1 - l1 + 1 - cnt[0]) * 2;
		cnt[1] = prefix[1][r2] - prefix[1][l2-1];
		cnt[1] += (r2 - l2 + 1 - cnt[1]) * 2;
		cnt[0] %= 3, cnt[1] %= 3;
		if(cnt[0] == cnt[1]) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
  return 0;
}


Measured memory_bytes: 1744
#include <iostream>
#include <stdio.h>
#include <string>
#include <list>
#include <vector>
#include <algorithm>

#define rep(i,n) for(ll i = 0;i < n;i++)
#define REP(i,n,k) for(ll i = n;i < k;i++)
#define P(p) cout << (p) << endl;//print
typedef long long ll;
using namespace std;


int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
        REP(a,n/4,3501){
            REP(b,n/2,3501){
                ll x = 4*a*b -n*a -n*b;
                ll y = n*a*b;
                    if(x>0&&y%x==0){
                        cout << a << " " << b << " " << y/x <<endl;
                        return 0;
                    }
            }
        }
}


Measured memory_bytes: 256
//
//  main.cpp
//  1094
//
//  Created by cfhaiteeh on 2018/4/20.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#define LL long long
using namespace  std;
struct he{
    int ch[12];
}edge[1234];
int T;
int n,m,k;

char ch[12];
LL ans;
bool vis[12];
int ci[12];
LL calsum(int len,int now,int l,int r){
    if(now==len+1){
        return 0;
    }
    if(l>r)return 0;
    int x=ci[now];
   
    int sum1=0,sum2=0;
    for(int i=l;i<=r;i++){
        if(edge[i].ch[x]==1){
            sum1++;
        }
        else{
            sum2++;
        }
    }
    int ee=r;
    for(int i=l;i<=sum1+l-1;i++){
        if(edge[i].ch[x]==2){
            for(int j=ee;j>=1;j--){
                if(edge[j].ch[x]==1){
                    ee=j-1;
                    swap(edge[i],edge[j]);
                    break;
                }
            }
        }
    }
    LL tm1=calsum( len, now+1,l,l+sum1-1);
    LL tm2=calsum(len, now+1,r-sum2+1,r);
    return tm1+tm2+(sum1*sum2);
}
vector<he> V;
void DFS(int depth){
    if(depth==m+1){
        memset(ci,0,sizeof(ci));
        int st=0;
        for(int i=1;i<=m;i++){
            if(vis[i]){
                st++;
                ci[st]=i;
            }
        }
        LL sum=calsum( st, 1,1,n);
        if(sum>=k){
            ans++;
        }
        
        return;
    }
    vis[depth]=1;
    DFS(depth+1);
    vis[depth]=0;
    DFS(depth+1);
    
}
int main() {
    // insert code here...
    while(scanf("%s",ch+1)!=EOF){
        int len=strlen(ch+1);
        if(ch[1]!='A'){
            printf("WA\n");
            continue;
        }
        
        int p=0;
        for(int i=3;i<=len-1;i++){
            if(ch[i]=='C')p++;
            
        }
        if(p!=1){
            printf("WA\n");
            continue;
        }
        bool flag=1;
        for(int i=2;i<=len;i++){
            if(ch[i]=='C')continue;
            if(ch[i]>='A'&&ch[i]<='Z'){
                flag=0;
                break;
            }
        }
        if(flag)printf("AC\n");
        else printf("WA\n");
    }
    return 0;
}


Measured memory_bytes: 256
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <ios>
#include <iomanip>

using namespace std;

int main(){
    int N,H,W;
    cin >> N;
    cin >> H;
    cin >> W;

    cout << (N-W+1)*(N-H+1) << endl;
    return 0;
     
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define I insert
#define bull bool
#define Max(a,b) ((b<a)?a:b)
#define Min(a,b) ((a<b)?a:b)

const LL N = 100005, mod = 1000000007;

using namespace std;

LL n, m, i, j, k, l, r, t, fix[N], fiy[N], xx, yy, ans;
vector < LL > x[N], y[N];

LL getint(){
	char c = getchar();
	LL t = 0;
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)){
		t = (t << 3) + (t << 1);
		t += c - '0';
		c = getchar();
	}
	return t;
}

void go ( LL z, bull t ){
	if ( t ){
		if ( fix[z] ) return;
		fix[z] = 1;
		xx++;
		for ( LL i = 0; i < x[z].size(); ++i ){
			go ( x[z][i], 0 );
		}
	}
	else{
		if ( fiy[z] ) return;
		fiy[z] = 1;
		yy++;
		for ( LL i = 0; i < y[z].size(); ++i ){
			go ( y[z][i], 1 );
		}
	}
}

int main(){
	/*/
	freopen ( "detectivein.txt", "r", stdin);
	freopen ( "detectiveout.txt", "w", stdout);
	/**/
	
	cin >> n;
	for ( i = 0; i < n; ++i ){
		cin >> l >> r;
		x[l].PB(r);
		y[r].PB(l);
	}
	for ( i = 0; i < N; ++i ){
		if ( !x[i].size() || fix[i] ) continue;
		xx = 0;
		yy = 0;
		go ( i, 1 );
		ans += xx * yy;
	}
	cout << ans - n << endl;
	
	return 0;
}
/**/
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O       O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE ___ KAPANADZE

Measured memory_bytes: 11520
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;


int main() {
  int n, m;
  scanf("%d %d", &n, &m);

  vector<int> a;
  int x;
  for (int i=0;i<n;++i) {
    scanf("%d", &x);
    a.push_back(x);
  }

  sort(a.begin(), a.end(), greater<int>());

  int sum = accumulate(a.begin(), a.end(), 0);


  if (a[m - 1] * 4 * m < sum)
    printf("No");
  else
    printf("Yes");

  return 0;
}


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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int d,t,s;
    cin >> d >> t >> s;

    if(t*s>=d) print("Yes");
    else print("No");
    return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = 1; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define DEBUG(x) cerr << x << "\n"

int main(){
    int n, x, input;
    vector<int> donuts;
    cin >> n >> x;
    int ans = n;
    REP(i, n){
        cin >> input;
        donuts.push_back(input);
    }
    x -= accumulate(donuts.begin(), donuts.end(), 0);
    DEBUG(x);
    ans += (x / *min_element(donuts.begin(),donuts.end()));
    cout << ans << "\n";
    return 0;
}

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

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

    vector<int64_t> v(3*n);
    rep(i,3*n){
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    int64_t ans = 0;
    for(int i=n; i<3*n; i+=2){
        ans += v[i];
    }
    cout << ans;
}

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007
var inf int = 1000000000000

type lazysegtree struct {
	n    int
	node []int
	lazy []int
}

func newlazySegtree(v []int) *lazysegtree {
	sz := len(v)
	_n := 1
	for _n < sz {
		_n *= 2
	}
	_node := make([]int, 2*_n-1)
	_lazy := make([]int, 2*_n-1)
	for i := 0; i < sz; i++ {
		_node[i+_n-1] = v[i]
	}
	for i := _n - 2; i >= 0; i-- {
		_node[i] = _node[2*i+1] + _node[2*i+2]
	}
	return &lazysegtree{
		n:    _n,
		node: _node,
		lazy: _lazy,
	}
}

// k番目のノードについて遅延評価を行う
func (u lazysegtree) eval(k int, l int, r int) {
	if u.lazy[k] != 0 {
		u.node[k] += u.lazy[k]
		if r-l > 1 {
			u.lazy[2*k+1] += u.lazy[k] / 2
			u.lazy[2*k+2] += u.lazy[k] / 2
		}
		u.lazy[k] = 0
	}
	return
}

func (u lazysegtree) add(a int, b int, x int, k int, l int, r int) {
	if r < 0 {
		r = u.n
	}
	u.eval(k, l, r)
	if b <= l || r <= a {
		return
	}
	if a <= l && r <= b {
		u.lazy[k] += (r - l) * x
		u.eval(k, l, r)
	} else {
		u.add(a, b, x, 2*k+1, l, (l+r)/2)
		u.add(a, b, x, 2*k+2, (l+r)/2, r)
		u.node[k] = u.node[2*k+1] + u.node[2*k+2]
	}
}

//[a,b)内の合計の取得
func (u lazysegtree) getsum(a int, b int, k int, l int, r int) int {
	if r < 0 {
		r = u.n
	}
	if r <= a || b <= l {
		return 0
	}
	u.eval(k, l, r)
	if a <= l && r <= b {
		return u.node[k]
	}
	vl := u.getsum(a, b, 2*k+1, l, (l+r)/2)
	vr := u.getsum(a, b, 2*k+2, (l+r)/2, r)
	return vl + vr
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	a := 1
	b := 1
	c := 1
	for i := 0; i < n; i++ {
		a *= 10
		a %= 1e9 + 7
		b *= 9
		b %= 1e9 + 7
		c *= 8
		c %= 1e9 + 7
	}
	ans := a - 2*b + c
	ans %= 1e9 + 7
	if ans < 0 {
		ans += 1e9 + 7
	}
	fmt.Println(ans)
}

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

int main(){
  int A,B,C;cin>>A>>B>>C;
  int count=0;
  bool can=false;
  for(int i=0;i<101;i++){
    count+=A;
    if(count%B==C) can=true;
  }
  cout<<(can?"YES":"NO")<<endl;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        // 整数の入力
        int a = int.Parse(Console.ReadLine());
        // スペース区切りの整数の入力
        string[] inputv = Console.ReadLine().Split(' ');
        string[] inputc = Console.ReadLine().Split(' ');
        int z = 0, sum = 0;
        for (int i = 0; i < a; i++)
        {
            int v = int.Parse(inputv[i]);
            int c = int.Parse(inputc[i]);
            if((v - c) >=0) sum += (v - c);
        }
        //出力
        Console.WriteLine((sum));
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s;

int main(){
	cin>>s;
	cout<<s[0]<<s.size()-2<<s.back()<<endl;
}

Measured memory_bytes: 256
#include<cstring>
#include <cmath>
#include <cstdio>
#include<cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>
#include<map>
using namespace std;
#define MOD 1000000007
map<long long,long long>m;
map<long long,long long>::iterator it;
vector<long long>v;
vector<long long>::iterator itv;
string s[100005];
bool tree[400005],t1;

int main()
{
    long long n,a[100005],temp,i,flag=0,start,end;
    for(i=0;i<3;i++)
    {
            cin>>a[i];
        m[a[i]]++;
    }
    cout<<m.size();
    
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S,T;
cin >> S >> T;
  int str=S.size();
  int i,c;
 c=0;
 for(i=0;i<str;i++) 
 {
 char s=S.at(i);
 char t=T.at(i);
 if(s==t) c++;
 }
if(c==str) cout << "Yes" << endl;
else  cout << "No" << endl;
return 0;
}

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

using namespace std;


#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),v).end()

#define PB(a) push_back(a)
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  int n;cin>>n;
  for(int i=0;i<n;i++){
      int f=0,s=0,t=0,out=0,point=0;
      string st;
      while(cin>>st){
          if(st=="HIT"){
              if(t) point++;
              if(s) t=1;
              if(f) s=1;
              f=1;
          }
          else if(st=="HOMERUN"){
              point+=(f+s+t+1);
              f=0;s=0;t=0;
          }
          else{
              out++;
              if(out==3){
                  cout<<point<<endl;
                  break;
              }
          }
      }
  }
  
}

Measured memory_bytes: 3120
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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(){
    string s; cin >> s;
    if(s[0]== '7' or s[1]=='7' or s[2] == '7')cout << "Yes" << ln;
    else cout << "No" << ln;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int l=0,r=0;
    while(l<n&&s[l]=='<')l++;
    while(r<n&&s[n-r-1]=='>')r++;
    cout << n-min(l,r) << endl;
}



Measured memory_bytes: 3352
from typing import List

def insertionSort(A: List[int], n: int, g: int) -> None:
	global cnt
	for i in range(g, n):
		value = A[i]
		j = i - g
		while j >= 0 and A[j] > value:
			A[j + g] = A[j]
			j -= g
			cnt += 1
		A[j + g] = value


def shellSort(A: List[int], n: int) -> None:
	G: List[int] = []
	h = 1
	while (h <= n):
		G.append(h)
		h = 3 * h + 1
	G.reverse()
	for i in range(len(G)):
		insertionSort(A, n, G[i])

	print(len(G))
	print(*G)
	

if __name__ == "__main__":
	cnt = 0
	n = int(input())
	a = []
	for _ in range(n):
		a.append(int(input()))
	shellSort(a, n)
	print(cnt)
	for i in range(len(a)):
		print(a[i])


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

using namespace std;

int main() {
  int A[4];
  for (int i = 0; i < 4; i++) {
    char c;
    cin >> c;
    A[i] = c - '0';
  }

  for (int k = 0; k < (1 << 3); k++) {
    int result = A[0];
    for (int i = 0; i < 3; i++) {
      if (k & (1 << i)) {
        result += A[i + 1];
      } else {
        result -= A[i + 1];
      }
    }

    if (result == 7) {
      stringstream ss;
      ss << A[0];
      for (int i = 0; i < 3; i++) {
        if (k & (1 << i)) {
          ss << "+";
        } else {
          ss << "-";
        }
        ss << A[i + 1];
      }
      printf("%s=7\n", ss.str().c_str());
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#define INF 1e5
using namespace std;

int k;
int data[2][11];
int cnt[11];
int nc[11][11];

int func(int f,int t){
	if(f==t)return 0;
	if((data[0][f]+cnt[f])%10==data[1][f])return func(f+1,t);
	int res=INF;
	for(int i=1;i<=9;i++){
		nc[f][t]=(cnt[f]+i)%10;
		if(f<t && (data[0][f]+nc[f][t])%10==data[1][f]){
			for(int j=f;j<t;j++){
				cnt[j]=(cnt[j]+i)%10;
				res=min(res,func(f+1,t));
			}
			for(int j=f;j<t;j++)cnt[j]=(cnt[j]-i+10)%10;
		}
	}
	return res+1;
}

int main(void){
	while(1){
		scanf("%d",&k);
		if(k==0)break;
		string str,str2;
		cin >> str;
		for(int i=0;i<k;i++){
			data[0][i]=str[i]-'0';
		}
		cin >> str2;
		for(int i=0;i<k;i++){
			data[1][i]=str2[i]-'0';
		}
		if(k==1 || str==str2){
			printf("%d\n",data[1][0]==data[0][0]?0:1);
			continue;
		}
		printf("%d\n",func(0,k));
	}
	return 0;
}

Measured memory_bytes: 1248
w,h,n = map(int, input().split())
bl = [0,0]
u = h
r = w
for _ in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        bl[0] = max(bl[0], x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        bl[1] = max(bl[1], y)
    else:
        u = min(u, y)
print(max(u-bl[1], 0) * max(r-bl[0], 0))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i < (int)(n); i++)
typedef long long ll;
#define NP next_permutation
#define MP make_pair

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  vector<int> v(n), p(n), q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  rep(i,n) v[i] = i+1;

  int a = 0;
  int b = 0;
  do{
    if(p <= v) a++;
    if(q <= v) b++;
  }while(NP(v.begin(), v.end()));

  int ans = max(a, b) - min(a, b);
  cout << ans << endl;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    int x[105], y[105];
    i64 h[105];

    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> h[i];
    }

    const auto getH = [](i64 H, int cx, int cy, int x, int y) -> i64 {
        return max<i64>(H - abs(cx - x) - abs(cy - y), 0);
    };

    const auto allPass = [&](i64 H, int cx, int cy) {
        for (int i = 0; i < N; ++i) {
            if (getH(H, cx, cy, x[i], y[i]) < h[i]) return false;
        }
        return true;
    };

    const auto perfect = [&](i64 H, int cx, int cy) {
        for (int i = 0; i < N; ++i) {
            if (getH(H, cx, cy, x[i], y[i]) != h[i]) return false;
        }
        return true;
    };


    for (int cx = 0; cx <= 100; ++cx) {
        for (int cy = 0; cy <= 100; ++cy) {
            i64 ok = INF;
            i64 ng = 0;
            while(ok - ng > 1) {
                i64 mid = (ng + ok) / 2;
                if (allPass(mid, cx, cy)) ok = mid;
                else ng = mid;
            }
            if (perfect(ok, cx, cy)) {
                cout << cx << ' ' << cy << ' ' << ok << endl;
                return 0;
            }
        }
    }

    return 0;
}

// vim: set foldmethod=marker :


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

from collections import Counter
def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    lb = rli()
    lab = []
    for i in range(n):
        lab.append([la[i], lb[i]])

    la.sort()
    lb.sort()
    for i in range(n):
        if la[i] > lb[i]:
            print("No")
            return

    # aでsort
    lab.sort()
    # print(lab)
    for i in range(n):
        lab[i].append(i)
    # bでsort
    lab.sort(key=lambda x: x[1])
    # print(lab)
    length = 1
    fr = 0
    to = lab[0][2]
    while to != 0:
        fr = to
        to = lab[fr][2]
        length += 1
    # cycleが二つ以上ある場合
    if length < n:
        print("Yes")
        return

    # 隣どうしをswapしてcycle二つにできる場合
    for i in range(n-1):
        if lb[i] >= la[i+1]:
            print("Yes")
            return
    
    # どうしようもない場合
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 29344
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
 int n,k;cin >> n >> k;
 int a[50];
 for(int i=0; i<n; i++)cin >> a[i];
 sort(a,a+n);
 int ans=0;
 for(int i=n-1; i>=n-k; i--)ans+=a[i];
 cout << ans << endl;
 return 0;
}


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

int main() {
  int n, w; cin >> n >> w;
  vector<long long> ww(n);
  vector<long long> vv(n);
  for (int i=0; i<n; i++) {
    cin >> ww[i] >> vv[i];
  }

  vector<vector<long long> > r(w+1, vector<long long>(n+1, 0));

  for (int i=0; i<n; i++) {
    for (int j=0; j<=w; j++) {
      if (j+ww[i] > w) continue;
      r[j+ww[i]][i+1] = max(r[j+ww[i]][i+1], r[j][i] + vv[i]);
    }
    for (int j=0; j<=w; j++) {
      r[j][i+1] = max(r[j][i+1], r[j][i]);
    }
  }

  long long rr = 0;
  for (int i=0; i<=n; i++) for (int j=0; j<=w; j++) rr = max(rr, r[j][i]);
  cout << rr << endl;
  return 0;
}

Measured memory_bytes: 82304
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	int a, b, h;
	cin >> a >> b >> h;

	int ans = (a + b) * h / 2;

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<set>
#include<string>
#define debug cout<<"debug"<<endl
using namespace std;
string s;
string sub;
set<string> se;
int k;

void debug1(){
    debug;
    set<string>::iterator it=se.begin();
    for(;it!=se.end();it++)
        cout<<*it<<endl;
    debug;
}

int main(){
    //std::ios::sync_with_stdio(false);
        cin>>s;
        cin>>k;
        int len=s.length();
        for(int i=0;i<26;i++){
            if(se.size()>5) break;
            char ch='a'+i;
            for(int j=0;j<len;j++)
            for(int t=1;t<=k;t++){
                if(j+t>len) break;
                sub=s.substr(j,t);
                se.insert(sub);
            }
        }
        set<string>::iterator it=se.begin();
        for(int i=1;i<k&&it!=se.end();i++,it++);
         cout<<*it<<endl;
    //return 0;
}


Measured memory_bytes: 1664
def call(n)
  for i in 1..n do
    x = i
    if x % 3 == 0
      print(" ",i)
    else
      while x>0 && x%10 !=3 do x /= 10 end
      print(" ",i) if x % 10 == 3
    end
  end
end

# n =30
n = gets.to_i
call(n)
puts



Measured memory_bytes: 6872
#include <iostream>
#include <sstream>
#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.timecard", "r", stdin );
	string str = "";

	for (int i = 0; i < 3; ++i){
		int sh, sm, ss, eh, em, es;
		getline (cin, str );
		stringstream s(str);
		s >> sh >> sm >> ss >> eh >> em >> es;

		int st = sh*60*60 + sm*60 + ss;
		int et = eh*60*60 + em*60 + es;

		int diff = et - st;
		cout << (diff/3600 % 24 ) << ' ';
		cout << (diff/60 % 60) << ' ';
		cout << (diff % 60 ) << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main() {
	int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k; cin >> k;
	cout << a[k - 1] << endl;

	return 0;
}

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

using namespace std;

int main() {
    char temp=' ';
    string s,ans;
    cin >> s;
    bool check= false;
    int cnt=0;
    int cnt1=0;
    for(int i =0; i< s.size();i++){
        if(s[i]=='A') break;
        cnt++;
    }
    for(int i = s.size()-1; i >=0; i--){
        if(s[i]=='Z') break;
        cnt1++;
    }
    //cout << cnt << ' ' << cnt1 << ' ' << s.size() << endl;
    cout << (int)s.size()-(cnt+cnt1);
    return 0;
}

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

using namespace std;

int main(){
    int a,b,c,d;
    int t = 1;
    cin >> a >> b >> c >> d;
    
    while(1){
        if(t){
            c -= b;
            t = 0;
        }
        else{
            a -= d;
            t = 1;
        }
        if(a <= 0){
            cout << "No";
            break;
        }
        else if(c <= 0){
            cout << "Yes";
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm> //std::sort
#include <cstdio>

using namespace std;

bool binSearch(int arrN[],int l, int r, int p){
  // int p = the number searched for in arrN
    while(l<=r){
      int mid = l + (r-l)/2;

      if(arrN[mid]==p) return true;

      if(arrN[mid] > p) r = mid -1;

      else l = mid + 1;
      }
      return false;
    }




int main(){
  int n, q;
  int cnt = 0;
  scanf("%d", &n);
  int arrN[n];
  for (int i=0; i< n; i++){
      scanf("%d",&arrN[i]);
  }
  scanf("%d",&q);
  int arrQ[q];
  for (int i=0;i<q;i++){
      scanf("%d",&arrQ[i]);
  }

  sort (arrN, arrN+n);
  sort (arrQ, arrQ+q);

  for (int i=0; i < q; i++){
      if(binSearch(arrN,0,n-1,arrQ[i]) == true){
        cnt++;
      }
    }

  cout << cnt <<endl;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
  long long as[200010];

int main (){
  int N;
  cin>>N;
  while(1){
  if(N==0){
    cout<<0;
    return 0;
  }
  if(N<1000){
    cout<<1000-N;
    return  0;
  }
  if(N>=1000){
    N-=1000;
  }
  }
}


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

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

L1=[]
L2=[]
L3=[]
L4=[]
for x,y in P:
    L1.append(x+y)
    L2.append(-x+y)
    L3.append(x-y)
    L4.append(-x-y)

L1=sorted(L1)
L2=sorted(L2)
L3=sorted(L3)
L4=sorted(L4)

ans=max(L1[-1]-L1[0],L2[-1]-L2[0],L3[-1]-L3[0],L4[-1]-L4[0])
print(ans)


Measured memory_bytes: 152176
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   ll x, a, b;
   cin >> x >> a >> b;
   if (b - a <= 0)
   {
      cout << "delicious" << endl;
   }
   else if (b - a <= x)
   {
      cout << "safe" << endl;
   }
   else
   {
      cout << "dangerous" << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll n, m, x;

	ll cost1 = 0, cost2 = 0;
	REP(i, m)
	{
		inll a_;
		if (a_ < x)
			cost1++;
		else
			cost2++;
	}

	return OUT(min(cost1, cost2));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,k;
ll mp[3005][3005];
ll dp[3005][3005][4];
inline ll dfs(int i,int j,int t)
{
    if(i<1||i>n||j<1||j>m||t>3) return -1e18;
    if(dp[i][j][t]!=-1) return dp[i][j][t];
   // printf("//%d %d %d\n",i,j,t);
    if(i==n&&j==m)
    {
        if(t<3) return mp[i][j];
        return 0;
    }
    ll ans=0;
    ans=max(ans,max(dfs(i+1,j,0),dfs(i,j+1,t)));
    if(mp[i][j]) ans=max(ans,mp[i][j]+dfs(i,j+1,t+1));
    if(mp[i][j]&&t<3) ans=max(ans,mp[i][j]+dfs(i+1,j,0));
    return dp[i][j][t]=ans;
}
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    read(n),read(m),read(k);
    while(k--)
    {
        int x,y,v;
        read(x),read(y),read(v);
        mp[x][y]=v;
    }
    printf("%lld\n",dfs(1,1,0));
    return 0;
}
/*
1 4 4
1 1 1
1 2 2
1 3 3
1 4 4
*/


Measured memory_bytes: 356928
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vpiipi vector<piipi>
#define pb push_back
#define pob pop_back
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 1000000009
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (int i = 0; i < n; i++)
#define repp(i,a,b) for(int i = a ; i<b ; i++)
#define reppr(i,a,b) for(int i = a-1 ; i>=b ; i--)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    int fact[500010], factinv[500010] , coefficientflag = 0;
    void Util_nCr()
    {
        fact[0] = 1 , factinv[0] = 1;
        repp(i,1,500010)
        {
            fact[i] = (fact[i-1] * i)%mod;
            factinv[i] = (factinv[i-1] * inverse(i))%mod;
        }
    }
    int nCr(int n , int r)
    {
        if(!coefficientflag) coefficientflag = 1 , Util_nCr();             
        return ((fact[n] * inverse(fact[n-r]) % mod * inverse(fact[r]))%mod) ;
    }

void solve();
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t; 
    rep(i,t)
    {
        // cout << "Case #" << i+1 << ": ";
        solve();
    }
}

int arr[1000001];

void solve() 
{
    int n;
    cin >> n;
    int a[n];
    rep(i,n)
    {
        cin >> a[i];   
        arr[a[i]]++;
    }
    int ans = 0;
    rep(i,n)
    {
        int flag = 0;
        for(int j = 1 ; j <= sqrt(a[i]) ; j++)
        {   
            if(a[i]%j==0)
            {
                int x = j , y = a[i]/j;
                if(arr[x]>0 && x!=a[i])
                    flag = 1;
                if(arr[x]>1 && x==a[i])
                    flag = 1;
                if(arr[y]>0 && y!=a[i])
                    flag = 1;
                if(arr[y]>1 && y==a[i])
                    flag = 1;
            }
        }
        if(!flag)
            ans++;
    }
    cout << ans << endl;
}

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

int main() {
    long long n, x, y, ans = 0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i) {
        ans += a[i]-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib> 
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

int main() {
	int x, t;
	cin >> x >> t;
	
	if (x > t) {
		cout << x - t << endl;
	}
	else{
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    for (int i = 0; i <= N/4; i++) {
        if ((N - i*4) % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N 200000

int main() {

  int i,j,n,q,a=0,time[N],count=0;
  char name[N][10];

  while(1) {
    scanf("%d %d",&n,&q);
    if(1<=n && n<=N) break;
  }

  for(i=0; i<n; i++) {
    if(scanf("%s %d",name[i],&time[i])!=2) break;
  }

  for(j=0; count!=n; j++) {
    if(i==N) i = 0;
    if(time[j]>q) {
      a += q;
      time[i] = time[j] - q;
      strcpy(name[i],name[j]);
      i++;
    }
    else {
      a += time[j];
      printf("%s %d\n",name[j],a);
      count++;
    }
  }

  return 0;
}

Measured memory_bytes: 3308
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
using namespace std;


int main(int argc, const char * argv[])
{
    while(true){
        int n, m, a;
        cin >> n >> m >> a;
        if(n == 0) return 0;
        
        bool line[1001][102];
        for(int i = 0; i < 1001; i++)
            for(int j = 0; j < 102; j++)
                line[i][j] = false;
        
        for(int i = 0; i < m; i++){
            int h, p, q;
            cin >> h >> p >> q;
            line[h][p] = true;
        }
        
        
        for(int y = 1000; y >= 0; y--){
            if(line[y][a-1]){
                a--;
            }else if(line[y][a]){
                a++;
            }
        }
        
        cout << a << endl;
    }
}

Measured memory_bytes: 1260
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

x,n=mii()
arr0=limii()

if len(arr0)==0:
    print(x)
    exit()

arr=[]
for i in range(0,102):
    if i not in arr0:
        arr.append(i)
arr.sort()
ans=[10**100,10*100]

for i in reversed(arr):
    if abs(i-x)<ans[1]:
        
        if i<ans[0]:
            ans[0]=min(ans[0],i)
            ans[1]=abs(i-x)
    elif abs(i-x)==ans[1]:
        ans[0]=min(ans[0],i)
print(ans[0])



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

int main(){
    int n,A[1000];
    cin >> n;

    for(int i=0;i<n;i++) cin >> A[i];
    for(int i=0;i<n;i++){
        int v = A[i];
        int j = i-1;

        while(j>=0 && A[j]>v){
        A[j+1] = A[j];
        j--;
        }

        A[j+1] = v;

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

        cout << endl;

    }

    return 0;
        
}



Measured memory_bytes: 3112
import java.util.*;


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

        Scanner sc = new Scanner(System.in);
        int person = sc.nextInt();
        int point = sc.nextInt();
        int question = sc.nextInt();
        
        int[] personpoint = new int[person];
        
        for(int i = 0; i < person; i++){
            personpoint[i] = point - question;
        }
        
        for(int i = 0; i < question; i++){
            int answer = sc.nextInt() - 1;
            personpoint[answer]++;
        }
        
        for(int po: personpoint){
            if(po > 0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
        
    }
}

Measured memory_bytes: 69892
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(),b.end());
    int b1 = b[n-1];
    int b2 = b[n-2];
    for(int i=0;i<n;i++){
        if(b[n-1] == a[i]){
            cout << b[n-2] << endl;
        }else{
            cout << b[n-1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
void tos(int a[]);
void ton(int a[]);
void toe(int a[]);
void tow(int a[]);

int main(void){
	int d[6],i;
	char o[101];
	for(i=0;i<6;i++){
		scanf("%d",&d[i]);
	}
	scanf("%s",o);
	for(i=0;o[i]!='\0';i++){
		if(o[i]=='S') tos(d);
		if(o[i]=='N') ton(d);
		if(o[i]=='E') toe(d);
		if(o[i]=='W') tow(d);
	}
	printf("%d\n",d[0]);
	return 0;
}

void tos(int a[]){
	int t=a[0];
	a[0]=a[4];
	a[4]=a[5];
	a[5]=a[1];
	a[1]=t;
}
void ton(int a[]){
	int t=a[0];
	a[0]=a[1];
	a[1]=a[5];
	a[5]=a[4];
	a[4]=t;
}
void toe(int a[]){
	int t=a[0];
	a[0]=a[3];
	a[3]=a[5];
	a[5]=a[2];
	a[2]=t;
}
void tow(int a[]){
	int t=a[0];
	a[0]=a[2];
	a[2]=a[5];
	a[5]=a[3];
	a[3]=t;
}

Measured memory_bytes: 596
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a[100000];
	int b[100000];
	int c, d;
	int k;
	int n, m;
	int s, t;
	int x, y, z;


	scanf("%d", &n);
	c = 0;
	s = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}

	for (int i = 0; i < n; i++){
		if (a[i] != i+1){
			if (c > 0)s = s + ((c + 1) / 2);
			c = 0;
		}
		else c++;
	}
	if (c > 0)s = s + ((c + 1) / 2);

	printf("%d\n", s);

	return 0;
}



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

bool b[31];
int main() {
	rep(i, 28) {
		int a; cin >> a;
		b[a] = true;
	}
	for (int i = 1; i <= 30; i++) {
		if (!b[i])cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1160