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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i,n) cin >>a[i];
	map<int, int> mp;
	rep(i, n) mp[a[i]]++;
	
	for(auto& x: mp){
		if(x.second >=3){
			if(x.second %2) x.second =1;
			else x.second =2;
		}
	}

	VI cc(3);
	for(auto x: mp){
		cc[x.second]++;
	}
	//dbg(cc[0], cc[1], cc[2]);
	cout << cc[1] + cc[2] - (cc[2]%2? 1:0) <<"\n";
	
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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


int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
        cout<<"x";
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int T,P,R;
int team;
int pro;
int times;
string mess;
int main(){
	while(cin>>T>>P>>R,T||P||R){
		vector<pair<pii,int> > teams(T);//(チームの正解数,チームのペナルティ累計)とチーム番号
		map<pii,int> ma;//(チーム番号、問題番号)、ペナルティの累計
		for(int i =0;i <T;i++){
			teams[i] =mp(mp(R,0),i);
		}
		for(int i = 0;i < R;i++){
			cin>>team>>pro>>times>>mess;
			if(mess=="WRONG"){
				ma[mp(team-1,pro-1)] +=1;
			}else if(mess=="CORRECT"){
				int k =ma[mp(team-1,pro-1)];
				int sum = k*1200+times;
				teams[team-1].first.first--;
				teams[team-1].first.second += sum;
			}
		}
		sort(teams.begin(),teams.end());
		for(int i = 0;i <T;i++){
			cout <<teams[i].second+1<<" "<<R-teams[i].first.first<<" "<<teams[i].first.second<<endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1244
n = int(input())
a = list(input().split())
b = list(input().split())
a = [int(i) for i in a]
b = [int(i) for i in b]

c = 0
for i in range(len(b)):
        #i
        if b[i] > a[i]:
                c += a[i]
                b[i] -= a[i]
                a[i] = 0
                # i+1
                if b[i] > a[i+1]:
                        c += a[i+1]
                        b[i] = 0
                        a[i+1] = 0
                else:
                        c += b[i]
                        a[i+1] -= b[i]
                        b[i] = 0
        else:
                c += b[i]
                a[i] -= b[i]
                b[i] = 0
print(c)

Measured memory_bytes: 22972
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

bool contains(vector<int> v, int target){
    return find(v.begin(), v.end(), target) != v.end();
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> d;
    int a;
    for(int i = 0; i < k; i++){
        cin >> a;
        d.push_back(a);
    }
    int m = n;
    while(true){
        string s = to_string(m);
        vector<int> l;
        for(int i = 0; i < s.size(); i++){
            int c = s[i] - '0';
            l.push_back(c);
        }
        sort(l.begin(), l.end());
        l.erase(unique(l.begin(), l.end()), l.end());
        bool ans = true;
        for(int i = 0; i < l.size(); i++){
            ans &= !contains(d, l[i]);
        }
        if(ans){
            break;
        }
        m++;
    }
    cout << m << endl;
    return 0;
}


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

money = 1000
stock = 0
for i in range(N - 1):
    if A[i] == A[i + 1]:
        continue
    elif A[i] > A[i + 1]:
        money += A[i] * stock
        stock = 0
    elif A[i] < A[i + 1]:
        buy = money // A[i]
        money -= A[i] * buy
        stock += buy
money += A[N - 1] * stock
stock = 0

print(money)

Measured memory_bytes: 9200
#include <stdio.h>

int main(){
	
	int n,m,a[1001];

	int i,i2;
	int price,max=0;

	for(;;){
		scanf("%d %d",&n,&m);
		if(n==0 && m==0)break;

		max=0;

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

		for(i=1;i<=n;i++){
			for(i2=i+1;i2<=n;i2++){
				if(i==i2)continue;
				price=a[i]+a[i2];
				if(price>max && price<=m)max=price;
			}

		}


		if(max==0){
			printf("NONE\n");
			continue;
		}
		printf("%d\n",max);
	}





	return 0;
}


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

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

    auto compare = [](int a, int b) {
      return a < b;
    };

    priority_queue<int, vector<int>, decltype(compare)> p {compare};

    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        p.push(t);
    }

    for(int i = 0; i < m; i++){
        int t = p.top();
        p.pop();
        t /= 2;
        if(t != 0){
            p.push(t);
        }

        if(p.empty()){
            break;
        }
    }

    ll ans = 0;
    while(!p.empty()){
        ans += p.top();
        p.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main(){
	int W, H, x, y, r;
	cin >> W;
	cin >> H;
	cin >> x;
	cin >> y;
	cin >> r;

	int lowerLimmit = r;
	int upperLimmitX = W - r;
	int upperLimmitY = H - r;

	if (	lowerLimmit <= x && x <= upperLimmitX 
		&&	lowerLimmit <= y && y <= upperLimmitY ) {
		cout << "Yes" << endl;
	
	} else {
		cout << "No" << endl;		
	}
}

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

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const double PI = acos(-1.0);
const int MOD = pow(10, 9) + 7;

#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (size_t i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

class Pos {
public:
	double x, y;
	Pos(double x, double y) {
		this->x = x;
		this->y = y;
	}
	Pos() {
		x = 0.0;
		y = 0.0;
	}
};

class Mod {
	static inline ll Add(ll a, ll b) {
		return (a + b) % MOD;
	}

	static inline ll Sub(ll a, ll b) {
		ll ans = (a - b) % MOD;
		return (ans < 0) ? (ans + MOD) : ans;
	}

	static inline ll Mul(ll a, ll b) {
		return (a * b) % MOD;
	}
	
	static inline ll Div(ll a, ll b) {
		return (a % MOD) * modinv(b, MOD) % MOD;
	}
};

inline double distance(Pos p1, Pos p2) {
	return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
}

inline int Kaijo(int n) {
	int ans = 1;
	for (int i = 2; i <= n; ++i) {
		ans *= i;
	}
	return ans;
}

template <typename T>
inline int keta(T num) {
	return to_string(num).length();
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
		cout << endl;
	}
}

int main() {
	bool debug = false;
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	if (debug) {
		cout << "\x1b[41m" << "Debug Mode このまま提出すると死" << endl;
	}
	try {
		(debug) ? DebugMain() : Main();
	}
	catch (exception& e) {
		cout << e.what() << endl;
	}
	return 0;
}

inline void Main(){
	int N;
	cin >> N;

	int zeikomi = 0;
	for (int i = 1; i < 100000000; ++i) {
		zeikomi = (int)(i * 1.08);
		if (zeikomi == N) {
			cout << i;
			return;
		}
		if (zeikomi > N) {
			break;
		}
	}
	cout << ":(";
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

start = -1
end = A[-1] * F[0]

def check(now):
    cnt = 0
    for a, f in zip(A, F):
        eatable = now//f
        if eatable < a:
            cnt += a - eatable
    if cnt > K:
        return False
    return True

while end > start + 1:
    now = (start + end) // 2
    if check(now):
        end = now
    else:
        start = now

print(end)


Measured memory_bytes: 119500
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int st,e;
    string s;
    cin>>s;
    int l=s.length();
    for(int i=0;i<l;i++)
    {
        if(s[i]=='A')
        {
            st=i+1;
            break;
        }
    }
    for(int i=0;i<l;i++)
    {
        if(s[i]=='Z')
        {
            e=i+1;
        }
    }
    cout<<e-st+1<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>  
#include <cstdio>  
#include <algorithm>
#include <vector>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <math.h>
#include <sstream>
using namespace std;
#define lld long long
int main() {
	int N, T;
	cin >> N >> T;
	int num, last_num;
	if (N == 0) {
		cout << 0 <<endl;
		return 0;
	}
	cin >> last_num;
	int sum = 0;
	for (int i = 1; i < N; i++) {
		cin >> num;
		sum += min(T, num - last_num);
		last_num = num;
	}
	sum += T;
	cout << sum << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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; }
// 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 m,d; cin >> m >> d;
	if(d<11){
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	FOR(i,11,d){
		int tmp = i;
		int da,db;
		db = tmp%10;
		da = tmp/10;

		if(da*db<=m && da>1 && db>1) ++ans;
	}

	cout << ans << endl;


}


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

using namespace std;

typedef long long ll;

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    string ans = "";
    for (int i = 0; i < n; ++i) {
        if (s.substr(i, n - i) == t.substr(0, n - i)){
            break;
        }else{
            ans.push_back(s[i]);
        }
    }

    ans += t;

    cout << ans.size() << endl;
}

Measured memory_bytes: 256
T = input()
# T = "xaaxxxx"
K = int(input())
# S = T*K
S_ = T*2
N = len(T)
last = T[-1]
mod = 10**9+7
"""
後ろを前につなげて、一番長くなるのはいくつ？
cooooooooonteeeeeeeeeest
3
"""
def check(S):
    S += "1"
    cnt = 1
    pre = "-1"
    flg = False
    ret = 0
    for i, s in enumerate(S):
        if pre == s:
            cnt += 1
            flg = True
        else:
            if flg:
                ret += cnt // 2
                flg = False
            cnt = 1
        pre = s
    return ret

s = 0
for i in range(N):
    if last != T[i]:
        s = i
        break
e = 0 
for i in range(N):
    if last != T[-i]:
        e = -i
        break
# 一回
if K == 1:
    print(check(T))
    exit()
# 同じ文字の連続
if len(set(T)) == 1:
    ans = check(T*2)*(K//2)+check(T)*(K%2)
    print(ans)
    exit()
# 最初と最後が違う
if s == e:
    print(check(T)*K)
    exit()


# その他
pre, mid, end = T[:s], S_[s:s+N], S_[s+N:]
# pre = S_[:s]
# mid = S_[s:e+2*N]
# end = S_[e+2*N:]
a = check(pre)    
b = check(mid)    
c = check(end)
# print(pre,mid,end)
print(a+b*(K-1)+c)



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

/* define const */

/* finish defineing const */

int n, m;
long cnt = 0;
int a[100] = {};
int b[100] = {};
pair<int, int> p[100];

bool allt(bool *b)
{
    bool f = true;
    for (int i = 1; i <= n; i++)
    {
        if (b[i] == false)
        {
            f = false;
        }
    }
    return f;
}

void solve(int a, bool *b)
{
    bool tmp[10];
    for (int i = 1; i <= n; i++)
    {
        tmp[i] = b[i];
    }
    // コピー
    tmp[a] = true;

    if (allt(tmp))
    {
        cnt++;
        return;
    }
    else
    {
        for (int i = 0; i < m; i++)
        {
            if (p[i].first == a)
            {
                if (tmp[p[i].second] == false)
                {
                    // tmp[p[i].second] = true;
                    solve(p[i].second, tmp);
                }
                else
                {
                    //  continue;
                }
            }
            else if (p[i].second == a)
            {
                if (tmp[p[i].first] == false)
                {
                    // tmp[p[i].first] = true;
                    solve(p[i].first, tmp);
                }
                else
                {
                    // continue;
                }
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        p[i] = make_pair(a[i], b[i]);
    }
 //   sort(p, p + m);
    bool b[10] = {false, true};
    solve(1, b);

    cout << cnt << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = {1: 0}
log = {0: 1}
current = 1
move = 0
roop_exist = False
while True:
    move += 1
    current = A[current - 1]
    if current in visited:
        roop = move - visited[current]
        roop_start = current
        roop_exist = True
        break
    if move == K:
        print(current)
        break
    visited[current] = move
    log[move] = current
if roop_exist:
    remain = (K - move) % roop
    print(log[visited[roop_start] + remain])

Measured memory_bytes: 34188
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    cnt = 0
    for i in range(1, n // 2 + 1):
        if n - i != i:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39024
package main

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

var (
	N int
	a []int
	s int
)

func readVariables() {
	N = nextInt()
	a = make([]int, N)

}

func main() {
	readVariables()
	for i := 0; i < N; i++ {
		s += nextInt()
		a[i] = 2 * s
	}
	answer := 12345678901234
	for i := 0; i < N-1; i++ {
		cand := AbsInt(s - a[i])
		answer = MinInt(cand, answer)
	}
	fmt.Println(answer)
}

/* 以下、テンプレート*/

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt は、2つの整数を受け取り、最大値を返します。
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt は、整数の絶対値を返します。
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow は整数の累乗関数で、剰余もサポートします。
//base^exponentの値をmoduleで割った余りを返します。
//moduloが1以下の場合には、剰余演算をしません。
//baseが負の値である場合には、返す値が負になることがあります。
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd は、引数の整数全ての最大公約数を返します。
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm は、与えられた整数の最小公倍数を返します。
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 3584
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n = 0;
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		HashSet<Integer> set = new HashSet<Integer>();
		boolean isDistinct = true;
		for(int i = 0; i < n; i++) {
			Integer x = scan.nextInt();
			if(set.contains(x)) isDistinct = false;
			set.add(x);
		}
		if(isDistinct) System.out.println("YES");
		else System.out.println("NO");
		scan.close();
	}

}


Measured memory_bytes: 102132
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int N = 2e5 + 10 , Max = 50 + 10;
const ll  MOD = 998244353 , OO = 1e14 + 2;
ll dp[N];
ll w[N] , v[N];
ll n , weight ;
int main() {

    cin >> n  >> weight;
    int sum =0 ;
    for(int i = 1;i<=n;++i) {
        cin >> w[i] >> v[i];
        sum+=v[i];
    }
    for(int i = 0;i<=sum;++i) dp[i] = OO;
    dp[0] = 0;

    for(int i = 1;i<=n;++i) {
        for(int j = sum - v[i];j>=0;--j) {
            dp[j + v[i]]  = min(dp[j + v[i]] , dp[j] + w[i]);

        }
    }
    ll ans = 0;
    for(ll i = 1 ;i <=sum;++i) {
        if(dp[i] <= weight) ans = max(ans,i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2304
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))

n = inN()
a = inL()

kab = 0
mon = 1000
f = []
i=0
state = 0
while(i < n-1):
    if state == 1:
        while(i<n-1):
            #print(a[i],a[i+1])
            if a[i+1]>=a[i]:
                f.append(0)
                i+=1
            else:
                f.append(2)
                #i+=1
                break
        state = 0
    elif state == 0:
        while(i<n-1):
            if a[i+1]<=a[i]:
                f.append(0)
                i +=1
            else:
                f.append(1)
                #i += 1
                state = 1
                break
    else:
        f.append(0)
    i += 1
f.append(2)
    
#print(f)   
for i in range(n):

    if f[i] == 1 :
        kab += mon//a[i]
        mon = mon % a[i]
    elif f[i] == 2:
        mon += a[i]*kab
        kab = 0
    
print(mon)



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

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

  int a, b;
  cin >> a >> b;

  cout << (a + b + 1) / 2 << '\n';

  return (0);
}


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

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int ans = max({A+B,A-B,A*B});
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, H;
    cin >> N >> H;
    vector<ll> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];

    ll aMax = *max_element(ALL(a));
    sort(ALL(b));
    reverse(ALL(b));
    ll ans = 0;
    rep(i, N) {
        if(aMax < b[i]) {
            H -= b[i];
            ans++;
            if(H <= 0) break;
        }
    }
    if(H > 0) ans += (H + (aMax - 1)) / aMax;
    COUT(ans);
}


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

using namespace std;

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

	int counter = 0;
	n = n - k;
	while (n>0) {
		n = n - k + 1;
		counter++;
	}
	cout << counter + 1 << endl;
}

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

int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  for(int i=0;i<s.size()-1;i++)if(s.at(i)==s.at(i+1)){
    cout << "no" << endl;
    return 0;
  }
  cout << "yes" << endl;
}


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

int main(){
    int N;
    cin >>N;
    vector<int> a(N);
    int ans;
    for (int i=0;i<N;i++){
        cin >> a[i];
    }
    int odd=0;
    for(int i:a){
        if (i%2==1){
            odd++;
        }
    } 
    if (odd%2==1){
        cout << "NO" <<endl;
    }else{
        cout << "YES" <<endl;
    }
}

Measured memory_bytes: 640
#include <stdio.h>
#define MAX 25

struct node{
  int parent;
  int left;
  int right;
};

struct node u[MAX];

int preParse(int);
int inParse(int);
int postParse(int);

int main(){
  int i,n,id,left,right,root;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    u[i].parent=-1;
    u[i].left=-1;
    u[i].right=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&left,&right);
    u[id].left=left;
    u[id].right=right;
    if(left!=-1) u[left].parent=id;
    if(right!=-1) u[right].parent=id;
  }

  for(i=0;i<n;i++){
    if(u[i].parent==-1) root=i;
  }

  printf("Preorder\n");
  preParse(root);
  printf("\nInorder\n");
  inParse(root);
  printf("\nPostorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

int preParse(int x){
  if(x==-1) return;
  printf(" %d",x);
  preParse(u[x].left);
  preParse(u[x].right);
}

int inParse(int x){
  if(x==-1) return;
  inParse(u[x].left);
  printf(" %d",x);
  inParse(u[x].right);
}

int postParse(int x){
  if(x==-1) return;
  postParse(u[x].left);
  postParse(u[x].right);
  printf(" %d",x);
}

Measured memory_bytes: 616
class Vector2:
    """
    A simple 2D vector class.
    @Author:whitestone0811(Vir_MeL0)
    """
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def __add__(self,other):
        return Vector2(self.x+other.x,self.y+other.y)
    def __sub__(self,other):
        return Vector2(self.x-other.x,self.y-other.y)
    def __mul__(self,other):
        if isinstance(other, Vector2):
            return self.x*other.x+self.y*other.y
        else:
            return Vector2(self.x*other,self.y*other)
    def __rmul__(self,other):
        if not isinstance(other,Vector2):
            return Vector2(self.x*other,self.y*other)
    def abs(self):
        return (self.x**2+self.y**2)**0.5
    def cos(self,other):
        return (self*other)/(self.abs()*other.abs())
    def __str__(self):
        return "[{0},{1}]".format(self.x,self.y)
    def __neg__(self):
        return Vector2(-self.x,-self.y)
#  
import sys  
lines=sys.stdin
for _in in lines:
    cors=[float(cor)for cor in _in.split(',')]
    vAB=Vector2(cors[2]-cors[0],cors[3]-cors[1])
    vBC=Vector2(cors[4]-cors[2],cors[5]-cors[3])
    vCD=Vector2(cors[6]-cors[4],cors[7]-cors[5])
    vDA=Vector2(cors[0]-cors[6],cors[1]-cors[7])
    cnv_a=True if(vAB-vDA)*(vAB+vBC)>0 else False
    cnv_b=True if(vBC-vAB)*(vBC+vCD)>0 else False
    cnv_c=True if(vCD-vBC)*(vCD+vDA)>0 else False
    cnv_d=True if(vDA-vCD)*(vDA+vAB)>0 else False
    print("YES" if cnv_a and cnv_b and cnv_c and cnv_d else "NO")

Measured memory_bytes: 7496
# -*- coding: utf-8 -*-
a = int(input());
b = int(input());
c = int(input());
x = int(input());
n = 0;
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            re = 500 * i + 100 * j + 50 * k;
            if ( re == x ):
                n += 1;
            if ( re >= x ):
                re = 0;
                continue;

print(n);

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    vector<int> canUse(10, true);
    int n, k; cin >> n >> k;
    for(int i = 0; i < k; i++){
        int d; cin >> d;
        canUse[d] = false;
    }

    for(int x = n;;x++){

        int num = x;
        bool flag = true;
        while(num > 0){
            if(!canUse[num % 10]) flag = false;
            num /= 10;
        }
        if(flag){
            cout << x << endl;
            break;
        }
    }
    return 0;
}

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

#define ll long long
#define P pair<int, int>
#define F first
#define S second

const ll mod = 1000000007LL;

ll n, h[100005], dp[100005];
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

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

  cout << dp[n - 1];
}

int main(int argc, char const *argv[]) {
/*
#ifndef ONLINE_JUDGE
  freopen("practice/input.txt", "r", stdin);
  freopen("practice/output.txt", "w", stdout);
#endif
*/
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int T = 1;
  while (T--) {
    solve();
  }

  return 0;
}

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

using namespace std;

map<string, int> a;

int main()
{
    string t;
    string longest = "";
    string highest;
    int ma = 0;
    while (cin >> t) {
        if (ma < ++a[t]) ma = a[t], highest = t;
        if (longest.size() < t.size()) longest = t;
    }
    cout<<highest<<" "<<longest<<endl;
}

Measured memory_bytes: 1192
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D):
    s.append(list(map(int,input().split())))
t = []
for i in range(D):
    t.append(int(input()))

def last(d,la):
    s = 0
    for i in range(26):
        s += c[i] * (d - la[i])
    return s

lastday = [0]*26
a = 0
for d in range(D):
    lastday[t[d]-1] = d + 1
    a += s[d][t[d]-1]- last(d+1,lastday)
    print(a)

Measured memory_bytes: 9328
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 510000;
const int MOD =  1000000007;
const int INV2 = (MOD+1)/2;
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
     signed main(){
   int n,q;
   cin>>n>>q;
   int a[n];
   for(int i=0;i<n;i++)cin>>a[i];
   int dp[n][n],x0=modpow(2,q,MOD);
   for(int i=0;i<n;i++)fill(dp[i],dp[i]+n,0);
   for(int i=0;i<n;i++){
     for(int j=0;j<n;j++){
       if(a[i]>a[j])dp[i][j]=(dp[i][j]+x0)%MOD;
     }
   }
   int x,y;
   for(int p=0;p<q;p++){
     cin>>x>>y;x--;y--;
     int tmp=(dp[y][x]+dp[x][y])%MOD*INV2%MOD;
      dp[y][x]=tmp;dp[x][y]=tmp;
     for(int i=0;i<n;i++)if(i!=x&&i!=y){
      tmp=(dp[i][x]+dp[i][y])%MOD*INV2%MOD;
       dp[i][x]=tmp;dp[i][y]=tmp;
       tmp=(dp[x][i]+dp[y][i])%MOD*INV2%MOD;
       dp[x][i]=tmp;dp[y][i]=tmp;
     }
   }
   int ans=0;
   for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)ans=(ans+dp[i][j])%MOD;
   cout<<ans<<endl;
   
                  
}


        


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M), c(M);
    vector<vector<int>> d(N, vector<int> (N, inINF));

    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    for (int i = 0; i < N; i++) {
        d[i][i] = 0;
    }
    

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }   
    int ans = 0;
    for (int i = 0; i < M; i++) {
        if(d[a[i]][b[i]] < c[i]){
            ans++;
        }
    }
    printf("%d\n", ans);



}

Measured memory_bytes: 3720
#include <stdio.h>

void change(int, int data[100]);

main(){
  int n, data[100];
  int i, temp, count;


  while(1){
    scanf("%d", &n);
    if(n==0) break;
    
    count=0;

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

    while(n>1){
      for(i=0;i<n-1;i++){
	if(data[i]>data[i+1]){
	  change(i,data);
	  count++;
	}
      }
      n-=1;
    }
    printf("%d\n", count);
  }
  return 0;
}


void change(int i, int data[]){
  int temp;

  temp=data[i+1];
  data[i+1]=data[i];
  data[i]=temp;
}

Measured memory_bytes: 0
from math import *
def gcd(n,m):
    while m != 0:
        n,m=m,n%m
    return n
def main():
    a,b=map(int,input().split(' '))
    g=gcd(a,b)
    cnt = 1
    g2 = int(sqrt(g))
    for i in range(2,g2+1):
        if g%i ==0:
            while g%i ==0:
                g //= i
            cnt += 1
    if g > 1:
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N;
    cin >> N;
    int a[3*N];
    rep(i,3*N)  cin >> a[i];
    sort(a,a+3*N);
    long long ans=0;
    for(int i=N;i<3*N;i+=2) ans+=a[i];

    cout << ans << endl;



}


Measured memory_bytes: 1408
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
input = input.trim();

// 正規表現は他の正解者のコードを参照
// ^は行の先頭、$は行末
// アルファベットのあとに?をつけるとありでもなしでも通るようになる

let ans = input.match(/^A?KIHA?BA?RA?$/) ? "YES" : "NO";
console.log(ans);



Measured memory_bytes: 11468
fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).ok();
    let mut it = input.trim().split_whitespace();
    let a:u16 = it.next().unwrap().parse().unwrap();
    let b:u16 = it.next().unwrap().parse().unwrap();
    let result = match a {
        e if e < 6 => 0,
        e if e < 13 => b / 2,
        _ => b
    };
    println!("{}",result);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=1e5+5;



int main(){
	int R,C,N;
	cin>>R>>C>>N;
	map<int,int> m;
	rep(i,N){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		bool f=true;
		if(x1!=0 && x1!=R && y1!=0 && y1!=C)f=false;
		if(x2!=0 && x2!=R && y2!=0 && y2!=C)f=false;
		if(!f)continue;
		
		int d1,d2;
		if(y1==0)d1=x1;
		else if(x1==R)d1=R+y1;
		else if(y1==C)d1=R+C+(R-x1);
		else d1=R+C+R+(C-y1);
		if(y2==0)d2=x2;
		else if(x2==R)d2=R+y2;
		else if(y2==C)d2=R+C+(R-x2);
		else d2=R+C+R+(C-y2);
		
		m.insert(make_pair(d1,i));
		m.insert(make_pair(d2,i));
	}
	
	bool a[MAX];
	rep(i,N)a[i]=false;
	stack<int> s;
	map<int,int>::iterator ite;
	ite=m.begin();
	bool ans=true;
	
	while(ite!=m.end()){
		int k=ite->second;
//      	cout<<k<<" ";
		if(!a[k]){
        	s.push(k);
          	a[k]=true;
        }
		else{
			int e=s.top();
			if(k!=e){
				ans=false;
				break;
			}
			else s.pop();
		}
      	ite++;
	}
	
	if(ans)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 9984
import java.util.Scanner;

//Mayan Crucial Prediction
public class Main{

	int[] day = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int MOD = 13*20*20*18*20;
	int B = 20*20*18*20;
	int KA = 20*18*20;
	int T = 18*20;
	int W = 20;
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			String in = sc.next();
			if("#".equals(in))break;
			String[] t = in.split("\\.");
			int n = t.length;
			int[] a = new int[n];
			for(int i=0;i<n;i++)a[i]=Integer.parseInt(t[i]);
			if(n==5)toSeireki(a[0], a[1], a[2], a[3], a[4]);
			else toMayan(a[0], a[1], a[2]);
		}
	}
	
	void toSeireki(int b, int ka, int t, int w, int ki){
		int days = b*B + ka*KA + t*T + w*W + ki;
		int y = 2012, m = 12, d = 21;
		while(0 < days){
			if(m==1 && d==1){
				int yearDay = 365 + (y%4==0 && (y%100!=0 || y%400==0) ? 1 : 0);
				if(yearDay <= days){
					y++;
					days-=yearDay;
					continue;
				}
			}
			if(m==2){
				if(d==day[2]+(y%4==0 && (y%100!=0 || y%400==0) ? 1 : 0)){
					m++; d=1;
				}
				else d++;
			}
			else{
				if(d==day[m]){
					m++; d=1;
					if(m==13){
						y++; m=1;
					}
				}
				else d++;
			}
			days--;
		}
		System.out.printf("%d.%d.%d\n", y, m, d);
	}

	int leap(int y){
		return y%4==0 && (y%100!=0 || y%400==0) ? 1 : 0;
	}
	
	void toMayan(int y, int m, int d){
		int Y = 2012, M = 12, D = 21;
		int days = 0;
		while(Y!=y || M!=m || D!=d){
			if(MOD <= days)days-=MOD;
			if(M==1 && D==1){
				if(Y!=y){
					int year = 365+(Y%4==0 && (Y%100!=0 || Y%400==0) ? 1 : 0);
					days+=year;
					Y++;
					continue;
				}
			}
			if(M==2){
				if(D==day[2]+(Y%4==0 && (Y%100!=0 || Y%400==0) ? 1 : 0)){
					M++; D=1;
				}
				else D++;
			}
			else{
				if(D==day[M]){
					M++; D=1;
					if(M==13){
						Y++; M=1;
					}
				}
				else D++;
			}
			days++;
		}
		if(MOD <= days)days-=MOD;
		int b = days/B; days%=B;
		int ka = days/KA; days%=KA;
		int t = days/T; days%=T;
		int w = days/W; days%=W;
		int ki = days;
		System.out.printf("%d.%d.%d.%d.%d\n", b, ka, t, w, ki);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 29440
def chkSQ(n):
  for i in range(128):
    if n==i**2:
      return 1
  return 0

n,d=map(int, input().split())
x=[[0]*d for _ in range(n)]
for i in range(n):
  x[i]=list(map(int, input().split()))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    k=0
    for a in range(d):
      k+=(x[i][a]-x[j][a])**2
    ans+=chkSQ(k)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <queue>
using namespace std;
int main(void){
    queue<pair<string,int> > v;
    int N,Q,T;
    string s;
    for(cin>>N>>Q;N--;){
        cin>>s>>T;
        v.push(make_pair(s,T));
    }
    for(T=0;!v.empty();){
        pair<string,int> p=v.front();
        v.pop();
        if(p.second>Q){
            T+=Q;
            p.second-=Q;
            v.push(p);
        }else{
            T+=p.second;
            cout<<p.first<<" "<<T<<endl;
        }
    }
    return 0;
}

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

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

bool f[100001];
int c[100001];
int main() {
  FOR(i, 2, 100001) if (!f[i]) for (int j=2*i; j < 100001; j+=i) f[j] = true;
  for (int i = 3; i<100001; i+=2) if (!f[i] && !f[(i+1)/2]) c[i]++;
  FOR(i, 3, 100001) c[i] += c[i-1];
  int q; cin >> q;
  while(q--) {
    int l, r;
    cin >> l >> r;
    cout << c[r] - c[l-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
a_list=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b_list=[int(input()) for _ in range(n)]

ans_list = [0 for _ in range(9)]

import itertools

a_list_flat = list(itertools.chain.from_iterable(a_list))

for i in range(9):
    for j in range(n):
        if a_list_flat[i] == b_list[j]:
            ans_list[i] = 1

count = 0
if ans_list[0] + ans_list[1] + ans_list[2] == 3:
    count += 1
elif ans_list[3] + ans_list[4] + ans_list[5] == 3:
    count += 1
elif ans_list[6] + ans_list[7] + ans_list[8] == 3:
    count += 1
elif ans_list[0] + ans_list[3] + ans_list[6] == 3:
    count += 1
elif ans_list[1] + ans_list[4] + ans_list[7] == 3:
    count += 1
elif ans_list[2] + ans_list[5] + ans_list[8] == 3:
    count += 1
elif ans_list[0] + ans_list[4] + ans_list[8] == 3:
    count += 1
elif ans_list[2] + ans_list[4] + ans_list[6] == 3:
    count += 1

if count == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
using System;
using System.Text;

namespace ALDS1_10_C {
    class Problem {
        private int[,] work = new int[1001, 1001];
        
        public void Run() {
            StringBuilder sb = new StringBuilder();
            int n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++) {
                string s = Console.ReadLine();
                string t = Console.ReadLine();
                sb.AppendLine(GetLCS(s, t).ToString());
            }
            Console.Write(sb);
        }

        private int GetLCS(string s,string t) {
            for(int i = 0; i < s.Length; i++) {
                for(int j = 0; j < t.Length; j++) {
                    work[i + 1, j + 1] = s[i] == t[j] ?
                        work[i, j] + 1 :
                        Math.Max(work[i + 1, j], work[i, j + 1]);
                }
            }
            return work[s.Length, t.Length];
        }
    }

    class Program {
        static void Main(string[] args) {
            Problem p = new Problem();
            p.Run();
        }
    }
}

Measured memory_bytes: 13148
import java.io.*;
import java.util.Scanner;
public class Main{
    public static int cnt;
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        while (true){
            cnt=0;
            int w=sc.nextInt();
            int h=sc.nextInt();
            if (w==0&&h==0) break;
            int grid[][]=new int[h+2][w+2];
            for (int i=0;i<h+2;i++){
                for (int j=0;j<w+2;j++){
                    if (i==0||i==h+1||j==0||j==w+1)
                        grid[i][j]=-1;
                    else
                        grid[i][j]=sc.nextInt();
                }
            }
            for (int i=1;i<h+1;i++){
                for (int j=1;j<w+1;j++){
                    if (grid[i][j]==1){
                        grid=get_island(j, i, grid);
                        cnt++;
                    }
                }
            }
            System.out.println(cnt);
        }
    }
    public static int[][] get_island(int x, int y, int grid[][]){
        grid[y][x]=0;
        if (grid[y+1][x]==1) get_island(x, y+1, grid);
        if (grid[y-1][x]==1) get_island(x, y-1, grid);
        if (grid[y][x+1]==1) get_island(x+1, y, grid);
        if (grid[y][x-1]==1) get_island(x-1, y, grid);
        if (grid[y+1][x+1]==1) get_island(x+1, y+1, grid);
        if (grid[y-1][x-1]==1) get_island(x-1, y-1, grid);
        if (grid[y+1][x-1]==1) get_island(x-1, y+1, grid);
        if (grid[y-1][x+1]==1) get_island(x+1, y-1, grid);
        return grid;
    }
}

Measured memory_bytes: 44384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];
  int ma=0,mi=1000000000;
  for(int i=0;i<n;i++){
    cin>>a[i];
    ma=max(a[i],ma);
    mi=min(a[i],mi);
  }
  if(ma-mi>=2){
    cout<<"No"<<endl;
    return 0;
  }
  if(ma==mi){
    if(a[0]<=n/2||a[0]==n-1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  if(ma==mi+1){
    int k=0;
    for(int i=0;i<n;i++){
      if(a[i]==ma)k++;
    }
    if(ma-1>=n-k&&k<=2*(n-ma))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}
  

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

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

    int cnt = 0;
    for (int i = 0; i < n - 2; i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            cnt++;
        }
    }

    cout << cnt << endl;
}

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

int main() {
	int a, b;
	cin >> a >> b;//縦横把握
	for (int i = 0; i < b + 2; i++) {//最初の行オール＃
		cout << "#";
	}
	cout << endl;
	for (int i = 0; i < a; i++) {//中間行前後に＃あとはそのまま
		cout << "#";
		for (int j = 0; j < b; j++) {
			char x;
			cin >> x;
			cout << x;
		}
		cout << "#" << endl;
	}
	for (int i = 0; i < b + 2; i++) {//最後の行オール＃
		cout << "#";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    fast_io
    
    ll n, a, b;
    cin>>n>>a>>b;
    ll ans;
    if(a==0) {
        cout<<0<<endl;return 0;
    }
    if(a>=n) {cout<<n<<endl;return 0;}
    ll cnt=n/(a+b);
    ans=a*cnt;
    ans+=min(a, n-cnt*(a+b));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;



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

	vector<long> a(n);
	for (long i=0; i<n; i++) cin>>a[i];

	sort(a.begin(), a.end());
	long cn = a.back();
	long r = 0;

	long cm = -1;
	for (long i=0; i<n-1; i++) {
		if (cm < a[i]*(cn-a[i])) {
			cm = a[i]*(cn-a[i]);
			r = a[i];
		}
	}
	cout << cn << " " << r << endl;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()
#define fs first
#define sd second
#define couts(x) cout << (x) << (" ")
#define coutn(x) cout << (x) << ("\n")
#define endl "\n"
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T1, typename T2> std::istream &operator>>(std::istream &is, std::pair<T1,T2> &p){is >> p.first >> p.second; return is; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::deque<T> &vec){ os << "deque["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;
template<class T> using V3 = V<V2<T>>;
constexpr ll MOD = 1000000007;


void solve(){
  string s; cin >> s;
  int n;
  n = (int)s.size();
  reverse(ALL(s));
  ll modu = 1;
  V2<ll> dp(n+1, V<ll>(13,0) );
  dp[0][0] = 1;
  FOR(i,0,n){
    char c = s[i];
    if(c=='?'){
      FOR(j,0,13){
        FOR(k,0,10){
          (dp[i+1][(j+modu*k)%13] += dp[i][j])%=MOD;
        }
      }
    }else{
      FOR(j,0,13){
        (dp[i+1][(j+modu*(c-'0'))%13] += dp[i][j])%=MOD;
      }
    }
    (modu*=10)%=13;
  }
  coutn(dp[n][5]);
}


int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 13648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	int k;
	cin >> k;
	string s;
	cin >> s;
	int len = s.length();
	if (len <= k)
		cout << s << endl;
	else
	{
		for (int i = 0; i < k; i++)
			cout << s[i];
		cout << "..." << endl;
	}
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
const int maxn=1e4+5;
int main()
{
	int n;
	char z[maxn];
	while(~scanf("%d%s",&n,z))
	{
		int l=strlen(z);
		for(int i=0;i<l;i++)
		{
			if(z[i]+n>'Z')
			z[i]='A'+(z[i]+n-'Z')-1;
			else
			z[i]+=n;
		}
		puts(z);
	}
}

Measured memory_bytes: 384