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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define getBit(x,i) (x&(1<<i))
#define setBit(x,i) (x|(1<<i))
#define mem(A,N) memset(A,N,sizeof(A))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define rep(i, x, y)  for(int i = x; i < y; ++i)
#define Rep(i, x, y)  for(int i = x; i <= y; ++i)
#define srep(i, x, y) for(int i = x; i > y; --i)
#define sRep(i, x, y) for(int i = x; i >= y; --i)
#define all(v) v.begin(),v.end()
#define Sort(x) sort(x.begin(), x.end())
#define f1(i,n) for (int i=1; i<=n; i++)
#define f0(i,n) for (int i=0; i<n; i++)
#define sz(x) ((int)(x).size())
#define len(x) ((int)(x).length())
#define fi first
#define se second

#define linf 0x7FFFFFFFFFFFFFFF
#define inf 0x7FFFFFFF
#define mod 1000000007
#define eps 1e-9
#define Pi 3.14159265358979323846

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define write(x) cerr << #x << " = " << (x) << ", "
#define writeI0 cerr << "i = " << 0 << ", "
#define dumpI0 cerr << "i = " << 0 << endl
#define printSet(x) for(auto it = s.begin(); it!=s.end(); it++) (it==s.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printVector(x) for(auto it = x.begin(); it!=x.end(); it++) (it==x.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printArray(a,x,y) for(auto it = a+x; it != a+y; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;
#define PrintArray(a,x,y) for(auto it = a+x; it != a+y+1; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;

// ***************** End Of Template ********************

int a[1000][5][2];
int b[1000][10];
int n;
ll dp[100][1024];
ll f(int i, int mask) {
    if(i == n) return 0;
    if(dp[i][mask] != -1) return dp[i][mask];

    ll sol;
    int c = 0;
    rep(j, 0, 5)
        rep(k, 0, 2) {
            if(a[i][j][k] == 1 && (mask&(1<<(j*2+k)))) {
                c++;
            }
        }
    sol = b[i][c] + f(i+1, mask);
    return dp[i][mask] = sol;

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    rep(i, 0, n)
        rep(j, 0, 5)
            rep(k, 0, 2)
                cin >> a[i][j][k];
    rep(i, 0, n)
        rep(j, 0, 11)
            cin >> b[i][j];

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

    ll sol = -1e9;
    rep(i, 1, 1<<10)
        sol = max(sol, f(0, i));
    cout << sol;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main(void) {

	int n, amin = 0, tmp;
	cin >> n;
	
	int a[n];

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

		for (int j = 0; j < i; j++)
		{
			tmp = abs(a[i] - a[j]);
			amin = max(amin, tmp);
		}
	}

	cout << amin << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
int ans = 0;
  string s;
  cin >> s;
  if (s[0] == '1'){ans++;}
  if (s[1] == '1'){ans++;}
  if (s[2] == '1'){ans++;}
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
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 N,K,Q;
    cin>>N>>K>>Q;
    vector<int> a(Q);
    rep(i,Q) cin>>a[i];
    vector<int> ans(N,0);
    rep(i,Q){
        ans[a[i]-1]++;
    }
    rep(i,N){
        ans[i]+=K-Q;
        if(ans[i]<=0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}

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

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

    for(int i = 0; i < n; i++) {
        if(s[i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 0; i < (n - 1) / 2; i++) {
        if(s[i] != s[(n-1)/2 - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
        if(s[i + (n+1)/2] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    
    return 0;
}

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

int toInt(char a){
	return (int)a - 48;
}

int main()
{
	string S;
  cin >> S;
	ll y = toInt(S[0])*1000+toInt(S[1])*100+toInt(S[2])*10+toInt(S[3]);
	ll m = toInt(S[5])*10+toInt(S[6]);
	ll d = toInt(S[8])*10+toInt(S[9]);
	if(y==2019){
		if(m==4){
			if(d>30){
				cout << "TBD" << endl;
			}else{
				cout << "Heisei" << endl;
			}
		}else if(m>4){
			cout << "TBD" << endl;
		}else{
			cout << "Heisei" << endl;
		}
	}else if(y>2019){
		cout << "TBD" << endl;
	}else{
		cout << "Heisei" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import math
import re
import random

tableA = {
    "A": "00000",
    "B": "00001",
    "C": "00010",
    "D": "00011",
    "E": "00100",
    "F": "00101",
    "G": "00110",
    "H": "00111",
    "I": "01000",
    "J": "01001",
    "K": "01010",
    "L": "01011",
    "M": "01100",
    "N": "01101",
    "O": "01110",
    "P": "01111",
    "Q": "10000",
    "R": "10001",
    "S": "10010",
    "T": "10011",
    "U": "10100",
    "V": "10101",
    "W": "10110",
    "X": "10111",
    "Y": "11000",
    "Z": "11001",
    " ": "11010",
    ".": "11011",
    ",": "11100",
    "-": "11101",
    "'": "11110",
    "?": "11111"}

tableB = {
    "101": " ",
    "000000": "'",
    "000011": ",",
    "10010001": "-",
    "010001": ".",
    "000001": "?",
    "100101": "A",
    "10011010": "B",
    "0101": "C",
    "0001": "D",
    "110": "E",
    "01001": "F",
    "10011011": "G",
    "010000": "H",
    "0111": "I",
    "10011000": "J",
    "0110": "K",
    "00100": "L",
    "10011001": "M",
    "10011110": "N",
    "00101": "O",
    "111": "P",
    "10011111": "Q",
    "1000": "R",
    "00110": "S",
    "00111": "T",
    "10011100": "U",
    "10011101": "V",
    "000010": "W",
    "10010010": "X",
    "10010011": "Y",
    "10010000": "Z"}

def my_solve(s):
    lst = []
    for c in s:
        lst.append(tableA[c])
    s = ''.join(lst)

    tmp, ans = '', ''
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ''
    return ans

for s in sys.stdin:
    s = s.strip('\n')

    #if s == '':
    #    break

    print(my_solve(s))

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

  int n;
  cin >> n;

  int ans = INF;
  FOR(a, 1, n) {
    int ret = 0;
    int b = n-a;
    string s = to_string(a), t = to_string(b);
    REP(j, s.size()) {
      ret += s[j]-'0';
    }
    REP(j, t.size()) {
      ret += t[j]-'0';
    }
    chmin(ans, ret);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n; cin >> n;
	for (int bit = 0; bit < (1 << n); bit++) {
		VI s;
		rep(i, n) {
			if (bit&(1 << i))s.pb(i);
		}
		cout << bit << ":";
		for (auto x : s) {
			cout << " " << x;
		}
		puts("");
	}
}


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

temp = [ [0 for _ in range(n)] for _ in range(n)]
tables = [ [0 for _ in range(n)] for _ in range(n)]

if n == 1:
    print('1')
    exit()

for _ in range(m):
    l, r = map(int, input().split())
    temp[l - 1][r - 1] += 1

pq = [tuple(int(x) - 1 for x in input().split()) for _ in range(q)]

hoge = 0
for j in range(n):
    hoge += temp[0][j]
    tables[0][j] = hoge

for i in range(1, n):
    hoge = 0
    for j in range(n):
        hoge += temp[i][j]
        tables[i][j] = tables[i - 1][j] + hoge

for p, q in pq:
    if p == 0:
        print(tables[q][q])
    else:
        print(tables[q][q] - tables[p - 1][q] - tables[q][p - 1] + tables[p - 1][p - 1] )

Measured memory_bytes: 26124
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    int x=0,y=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') x++;
        else{
            if(x>y){
                y=x;
                x=0;
            }
        }
    }
    cout << (x>=y?x:y) << endl;
}


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

namespace Rectangle
{
    class Rectangle
    {
        public static void Main()
        {
            string[] c = Console.ReadLine().Split(' ');
            int a = int.Parse(c[0]);
            int b = int.Parse(c[1]);
            Console.WriteLine("{0} {1}", a*b, 2 * (a+b));
        }
    }
}



Measured memory_bytes: 17992
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<ull, ull> P; //ペア　タイプでふ
constexpr ll bigNum = 1000000007;

int main(void)
{
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    //ここから本体
    int n, m;
    cin >> n;
    m = log10(n) + 1;
    switch (m)
    {
    case 6:
        cout << 90909;
        break;
    case 5:
        cout << 909 + (n - 10000 + 1);
        break;
    case 4:
        cout << 909;
        break;
    case 3:
        cout << 9 + (n - 100 + 1);
        break;
    case 2:
        cout << 9;
        break;
    case 1:
        cout << n;
        break;
    }
}

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


using namespace std;
const int MOD = 1000000007;

int main() {
#define int long long

	int N;
	int power = 1;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		power = (power * i) % MOD;
	}

	cout << power << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char const *argv[])
{
  int n;
  scanf("%d",&n);
  char s[n];
  scanf("%s",&s);
  int i;
  int c=1;
  for(i=0;i<n-1;i++){
    if(s[i]!=s[i+1]) c++;
  }
  printf("%d",c);
  return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    unordered_map<string,int> mp;
    rep(i, N) {
        string s;
        cin >> s;
        ++mp[s];
    }
    
    printf("AC x %d\n",mp["AC"]);
    printf("WA x %d\n",mp["WA"]);
    printf("TLE x %d\n",mp["TLE"]);
    printf("RE x %d\n",mp["RE"]);
}


Measured memory_bytes: 3724
from itertools import permutations


def resolve():
    n, k = map(int, input().split())
    a = list(map(lambda x :int(x)-1, input().split()))
    visited = [-1 for i in range(n)]
    route = [0 for i in range(n)]

    now = 0
    cnt = 0
    while visited[now] == -1 and cnt <= k:
        visited[now] = cnt
        route[cnt] = now
        now = a[now]
        cnt += 1
    route[cnt] = now
        

    loop = cnt - visited[now]
    tt = (k - visited[now]) % loop
    print(route[visited[now] + tt] + 1)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 108740
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define INF 1000000007
using namespace std;
typedef long long ll ;

int n,m,c;

int b[25];
int cont = 0;
int main(){
    fastio;
    cin>>n>>m>>c;

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

	for(int i=0; i<n;i++){
		int ans = 0;
		int aj;
		for(int j=0; j<m;j++){
			cin>>aj;
			ans+= aj * b[j];
		}
		ans+=c;
		
		if(ans>0) cont++;
	}

	cout<<cont<<"\n";
		
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    private static int[][][] dp;

    private static int[] rec(int i, int[][] treasure, int limit) {
        int[] result;
        if (i == treasure.length) {
            result = new int[2];
            result[0] = 0;
            result[1] = limit;
        } else if (dp[i][limit] != null) {
            result = dp[i][limit];
        } else if (limit < treasure[i][1]) {
            result = rec(i + 1, treasure, limit);
            dp[i][limit] = result.clone();
        } else {
            int[] a = rec(i + 1, treasure, limit - treasure[i][1]);
            int[] b = rec(i + 1, treasure, limit);
            a[0] += treasure[i][0];
            if (a[0] > b[0]) {
                result = a;
            } else if (a[0] < b[0]) {
                result = b;
            } else if (a[1] > b[1]) {
                result = a;
            } else {
                result = b;
            }
            dp[i][limit] = result.clone();
        }
        return result;
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in).useDelimiter("[,\\s]+");

        for (int i = 0; ; i++) {
            int maximum = scanner.nextInt();
            if (maximum == 0) {
                break;
            }
            int n = scanner.nextInt();
            int[][] treasure = new int[n][2];
            for (int j = 0; j < n; j++) {
                treasure[j][0] = scanner.nextInt();
                treasure[j][1] = scanner.nextInt();
            }
            dp = new int[n][maximum + 1][];
            int[] result = rec(0, treasure, maximum);
            System.out.println("Case " + (i + 1) + ":");
            System.out.println(result[0]);
            System.out.println(maximum - result[1]);
        }
    }

    public static void main(String... args) {
        solve();
    }
}

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

int main()
{
    int n, m; cin >> n >> m;
    vector<int> a(m);
    rep(i,m) cin >> a.at(i);

    for(int x: a) {
        n -= x;
    }

    if(n>=0) cout << n << endl;
    else cout << "-1" << endl;
}

Measured memory_bytes: 3648
import random
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for k in range(D)]

def score(t):
    ret = 0
    last = [0]*26
    for k in range(D):
        last[t[k]-1] = k+1
        ret += s[k][t[k]-1]
        for i in range(26):
            ret -= c[i]*(k+1-last[i])
    return ret

ans = [1+k%26 for k in range(365)]
print(*ans,sep="\n")


Measured memory_bytes: 77884
#!/usr/bin/env python3
import sys

from itertools import chain


class BinarySearcher(object):
    def __init__(self, condition, initial_values):
        self.condition = condition
        self.initial_values = initial_values
        # all True
        if self.condition(initial_values[0]):
            self.first_solution = 0
        # all False
        elif not self.condition(initial_values[1]):
            self.first_solution = None
        else:
            self.first_solution = self.search_first_solution(
                *self.initial_values)

    def search_first_solution(self, lower, upper):
        if upper - lower <= 1:
            return condition(n)
        n = (lower + upper) // 2
        if self.condition(n):
            if not self.condition(n - 1):
                return n
            return self.search_first_solution(lower, n)
        else:
            return self.search_first_solution(n, upper)


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A = sorted(A)
    bc = sorted(zip(B, C), key=lambda x: x[1], reverse=True)
    D = []
    for b, c in bc:
        D.extend([c] * b)
        if len(D) >= N:
            break
    length = min(len(A), len(D))
    r = BinarySearcher(lambda x: A[x] > D[x], (0, length - 1)).first_solution
    if r is None:
        r = length
    print(sum(A[r:]) + sum(D[:r]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25884
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 998244353;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

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


	int N;
	cin >> N;
	int D[200000];
	rep(i, N) cin >> D[i];

	//ちくしょー
	if (D[0] != 0) {
		co(0);
		return 0;
	}

	sort(D, D + N);
	int saidai = D[N - 1];
	int kazu[200001] = {};
	rep(i, N) kazu[D[i]]++;

	ll kotae = 1;

	if (kazu[0] != 1) {
		co(0);
		return 0;
	}
	if (saidai > N - 1) {
		co(0);
		return 0;
	}

	int mae = 1;
	rep1(i, saidai) {
		if (kazu[i] == 0) kotae = 0;
		rep(j, kazu[i]) kotae = kotae * mae % mod;
		mae = kazu[i];
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void)
{
	int i;
	int hb, mb, sb;
	int ha, ma, sa;
	int after, before;
	int h, m, s;
	int time;
	
	for (i = 0; i < 3; i++){
		scanf("%d %d %d %d %d %d", &hb, &mb, &sb, &ha, &ma, &sa);
		before = sb + (mb * 60) + (hb * 3600);
		after = sa + (ma * 60) + (ha * 3600);
		time = after - before;
		h = time / 3600;
		time %= 3600;
		m = time / 60;
		s = time % 60;
		printf("%d %d %d\n", h, m, s);
	}
	
	return (0);
}

Measured memory_bytes: 596
from collections import deque

h ,w = map(int, input().split())
s = ['$'*(w+2)] * (h+2)
cnt = 0
for i in range(1,h+1):
    s[i] = '$' + input() + '$'
    cnt += s[i].count('.')

dist = [[-1]*(w+2) for _ in range(h+2)] # スタートからの距離の記録をするリスト
dist[1][1] = 0 # スタート地点を0 にする
q = deque()
q.append((1,1))
while q:
    x, y = q.popleft() # 探索地点を取り出す

    vx = [-1,0,1,0]
    vy = [0,-1,0,1]
    for i in range(4):
        nx = x + vx[i]
        ny = y + vy[i]
        if s[nx][ny] == '$' or s[nx][ny] == '#': continue # 壁なら通れないね！
        if dist[nx][ny] != -1: continue # もう最短距離がわかってるなら飛ばす
        dist[nx][ny] = dist[x][y] + 1
        q.append((nx, ny)) # 新しい地点の周りも探索したいからキューに入れておく

if dist[h][w] == -1:
    print(-1)
else:
    print(cnt - dist[h][w]-1)

Measured memory_bytes: 3316
N, M = map(int, input().split())
a = [True] * (N+1)
for _ in range(M):
  i = int(input())
  a[i] = False
dp = [0] * (N+1)
dp[0] = 1
for now in range(N):
  for next in range(now+1,min([N,now+2])+1):
  	if a[next]:
          dp[next] += dp[now]
          dp[next] %= 10**9+7
print(dp[N])

Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(void)
{
    int N, M;
    cin >> N >> M;
    int cost;
    rep(i,M){
        cin >> cost;
        N -= cost;
    }
    if (N < 0) cout << "-1" << endl;
    else cout << N << endl;
    return 0;
}

Measured memory_bytes: 3676
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

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

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	int a = h * W, b = w * H;
	cout << H*W - a - b + h*w << endl;


}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int n;
    while (cin >> n) {
        bool ans = false;
        FOR(i,0,25) FOR(j,0,14) {
            if (4*i + 7*j == n)
                ans = true;
        }
        if (ans)
            cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		HashSet<Integer> aSet = new HashSet<>();
		HashSet<Integer> bSet = new HashSet<>();

		for(int i=0; i<m; i++){
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());

			if (a == 1){
				bSet.add(b);
			}
			if (b == n){
				aSet.add(a);
			}
		}

		for(int i=1; i<=n; i++){
			if(aSet.contains(i) && bSet.contains(i)){
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
		return;

	}
}


Measured memory_bytes: 81688
#include<bits/stdc++.h>
#define PI acos(-1)
using namespace std;
int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double x,y,z,v;
    x=0.5*((60*h)+m);
    y=6*m;
    z=abs(x-y);
    v = z * PI / 180.0;
    double ans = a * a + b * b - 2 * a * b * cosl(v);
    cout << setprecision(14)<<sqrt(ans)<<endl;
}


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

char ss[15];
char ans[15];

int main(){
  cin>>ss;
  int ind = 0;
  for(int i=0;ss[i];i++){
    if(ss[i] == 'B'){
      if(ind != 0)
	ind--;
    }
    else ans[ind++]=ss[i];
  }
  for(int i=0;i<ind;i++) cout<<ans[i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll X; cin >> X;
    ll A = -1, B = -1;
    for (ll a = 0; a <= 64; ++a) if (A == -1) {
        for (ll b = 0; b <= a; ++b) {
            if (a*a*a*a*a + b*b*b*b*b == X) {
                A = a, B = -b;
                break;
            }
        }
    }
    for (ll a = 0; a <= 119; ++a) if (A == -1) {
        for (ll b = 0; b <= a; ++b) {
            if (a*a*a*a*a - b*b*b*b*b == X) {
                A = a, B = b;
                break;
            }
        }
    }
    cout << A << ' ' << B << endl;

    return 0;
}


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

int main(){
        int x; cin>>x;
        int maxnum = 1;
        for(int i = 2; i<sqrt(x); i++) {
                int j = i;
                for(; j*i<=x; j*=i) {}
                maxnum = max(maxnum,j);
        }
        cout << maxnum << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  rep(i,19){
    char c;
    cin>>c;
    if(i!=5 && i!=13)
       cout<<c;
    else cout<<" ";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,h,w;
int g[105][105];
int main(){
  int k=-1,x;
  scanf("%d%d%d",&h,&w,&N);
  for(int i=1;i<=N;i++)
  {
  	scanf("%d",&x);
  	while(x--) 
	  k++,g[(k/h)&1?h-1-k%h:k%h][k/h]=i;
  }
   for(int i=0;i<h;i++)
     {
     	for(int j=0;j<w;j++)
     	  printf("%d ",g[i][j]);
     	printf("\n");
	 }
	return 0;
	
}

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

    h = (x / 500) * 1000;
    x -= (x / 500) * 500;
    h += (x / 5) * 5;
    
    cout << h << endl;

    return 0;
}

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

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;
const int MAX = 2 * 1e5 + 1;

typedef pair<int, int> P;

int n, q;
vector<int> edge[MAX];
int v_cost[MAX];
bool visited[MAX];

void bfs() {
    queue<P> que;
    que.push(P(1, v_cost[1]));
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        int v = p.first;
        v_cost[v] = p.second;
        rep(edge[v].size(), i) {
            int u = edge[v][i];
            if (visited[u]) continue;
            que.push(P(u, v_cost[v] + v_cost[u]));
        }
        visited[v] = true;
    }
}


signed main() {
    int n, q;
    cin >> n >> q;
    rep(n - 1, i) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    rep(q, i) {
        int p, x;
        cin >> p >> x;
        v_cost[p] += x;
    }
    bfs();
    rep2(1, n + 1, i) {
        cout << v_cost[i];
        cout << ((i < n) ? " " : "\n");
    }
    return 0;
}

Measured memory_bytes: 17776
#include <iostream>

using namespace std;

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b,a % b);
}

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

  int tmp;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if(i == 0) tmp = a;
    tmp = gcd(tmp,a);
  }

  cout << tmp << endl;
    
  return 0;
}


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

ll dp[51][51][2501];
int main()
{
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    int max = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
        max += x[i];
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            for (int k = 0; k <= max; k++)
            {
                if (k < x[i - 1] || j == 0)
                    dp[i][j][k] = dp[i - 1][j][k];
                else
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i * a <= max && i <= n; i++)
    {
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;
}


Measured memory_bytes: 29644
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let line = stdin.lock().lines().next().unwrap().unwrap();
    let mut split = line.split(' ').map(|x| x.parse::<usize>().unwrap());
    let (n, k) = (split.next().unwrap(), split.next().unwrap());
    let mut edges = Vec::new();
    let mut nbrs = vec![Vec::new(); n];
    for line in stdin.lock().lines().take(n - 1).map(|x| x.unwrap()) {
        let mut split = line.split(' ').map(|x| x.parse::<usize>().unwrap());
        let (a, b) = (split.next().unwrap() - 1, split.next().unwrap() - 1);
        edges.push((a, b));
        nbrs[a].push(b);
        nbrs[b].push(a);
    }

    let mut max_count = 0;
    if k % 2 == 0 {
        for center in 0..n {
            let count = count_in_radius(&nbrs, center, n, k / 2 + 1);
            if max_count < count {
                max_count = count;
            }
        }
    } else {
        for center in edges {
            let count =
                count_in_radius(&nbrs, center.0, center.1, k / 2 + 1) +
                count_in_radius(&nbrs, center.1, center.0, k / 2 + 1);
            if max_count < count {
                max_count = count;
            }
        }
    }
    println!("{}", n - max_count);
}

fn count_in_radius(nbrs: &Vec<Vec<usize>>, v: usize, prev: usize,
                   radius: usize) -> usize {
    if radius == 0 {
        return 0;
    }
    let mut count = 1;
    for &next in &nbrs[v] {
        if next != prev {
            count += count_in_radius(nbrs, next, v, radius - 1);
        }
    }
    count
}


Measured memory_bytes: 4352
n,h,*d=map(int,open(0).read().split());a=max(d[::2]);b=sorted(d[1::2]);c=0
while b and(h>0)*(b[-1]>a):h-=b.pop();c+=1
while b and b[-1]>a>0<h:h-=b.pop();c+=1
print(c-(-h//a)*(h>0))

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

int main() {
  int N,K;
  cin >> N >>K;
  vector<int>a(N);
  rep(i,N)cin >> a.at(i);
  int count=0;
  rep(i,N) if(a.at(i)>=K)count++;
  cout << count << endl;
  }  

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int L = scanner.nextInt();
    int sum = N * (N + 1) / 2 + N * (L - 1);
    if (L >= 0) sum -= L;
    else if (L + N - 1 <= 0) sum -= L + N - 1;
    System.out.println(sum);
  }
}


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

using namespace std;
typedef long long int ll;
ll N1097 = 1000000007LL;

int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        scanf("%d", &d[i]);
    }
    sort(d.begin(), d.end());
    cout << d[N/2]-d[N/2-1] << endl;
}




Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;
int main()
{
	int n;
	cin >> n;
	int row = 0;
	bool win = false;
	while (n--)
	{
		int a, b;
		cin >> a >> b;
		if (a == b)row++;
		else row = 0;
		if (row == 3)
		{
			win = true;
		}
	}
	if (win)cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 3132
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        double a = scanner.nextDouble();
        double b = Math.sqrt(a);
        int c = (int)b;
        double d = Math.pow(c, 2);
        System.out.println((int)d);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x = max(x, y)
#define chmin(x,y) x = min(x, y)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int k;
    cin >> k;
    queue<ll> q;
    repl(i, 1, 10) {
        q.push(i);
    }
    ll ans = 0;
    rep(i, k) {
        ll x = q.front();
        if(i == k - 1) ans = (ll) x;
        q.pop();
        if(x % 10) {
            ll u = 10 * x + (x % 10) - 1;
            q.push(u);
        }
        ll v = 10 * x + (x % 10);
        q.push(v);
        if(x % 10 != 9) {
            ll w = 10 * x + (x % 10) + 1;
            q.push(w);
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  string s;
  cin >> s;
  string ret;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) {
      ret.push_back(s.at(i));
    }
  }

  cout << ret << endl;
}


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

int main(){
  int n;
  cin >> n;
  int a[2000];
  for (int i=0; i<n; i++) cin >> a[i];
  sort(a,a+n);
  int s=0;
  for (int i=0; i<n-1; i++){
    for (int j=i+1; j<n-1; j++){
      int x = lower_bound(a, a+n, a[i]+a[j]) -a-j-1;
      s += x;
      //cout << x << endl;
    }
  }
  cout << s;
 }

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

using namespace std;
using ll = long long;
int main()
{
ll k,n;
cin>>k>>n;
std::vector<ll> v(n);
std::map<ll, ll> mp;
for (ll i = 0; i < n; ++i)
{
cin>>v[i];
mp[v[i]] = i;
}
ll x=k,y=k;
if(mp.find(k) == mp.end()){
cout<<k<<endl;
return 0;
}
for (ll i = 1; ; i++)
{
x = x - i;
y = y + i;
//cout<<x<<" "<<y<<endl;
if(mp.find(x) == mp.end()){
cout<<x<<endl;
break;
}else if(mp.find(y) == mp.end()){
cout<<y<<endl;
break;
}
x = k;
y = k;
}
return 0;
}

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

int main(){
	int n,sum;
	while(cin >> n){
		sum=0;
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					for(int l=0;l<10;l++){
						if(i+j+k+l==n){
							sum++;
						}
					}
				}
			}
		}
		cout << sum <<"\n";
	}
return 0;
}

Measured memory_bytes: 1160
def p_facto(n):
    ret = []
    nc = n
    for i in range(2, nc):
        if i*i > nc:
            break
        if n % i == 0:
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            ret.append([i, ex])
    if n != 1:
        ret.append([n, 1])
    return ret


def main(N):
    ans = 0
    for p, e in pf:
        ex = 1
        while e >= ex:
            z = p**ex
            if N % z == 0:
                ans += 1
                N //= z
            else:
                break
            e -= ex
            ex += 1
    print(ans)


if __name__ == "__main__":
    N = int(input())
    pf = p_facto(N)
    main(N)


Measured memory_bytes: 9032
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = input()
    if sum(int(c) for c in N)%9 == 0:
        return 'Yes'
    return 'No'


if __name__ == '__main__':
    print(solve())


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

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

    int N;
    string S;
    cin >> N >> S;
    if (N % 2 != 0)
        cout << "No\n";
    else {
        bool ans = true;
        for (int i = 0, j = N / 2; j < N; i++, j++) {
            if (S[i] != S[j]) {
                ans = false;
                break;
            }
        }
        cout << (ans ? "Yes\n" : "No\n");
    }

    return 0;
}

Measured memory_bytes: 256
program main
	implicit none
    character::s
    read(*,*)s
    if(s=='G')then
    	write(*,*)'C'
    else if(s=='C')then
    	write(*,*)'G'
    else if(s=='A')then
    	write(*,*) 'T'
    else
    	write(*,*) 'A'
        
    end if
    stop
end program main

Measured memory_bytes: 2856
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,a[N],b[N];
int check(int x){
	rep(i,1,n+n-1)b[i]=a[i]>=x;
	int p1=n,p2=n;
	while(p1>1&&b[p1-1]!=b[p1])p1--;
	while(p2<n+n-1&&b[p2+1]!=b[p2])p2++;
	if(n-p1<p2-n)return b[p1];
	return b[p2];
}
int main(){
	read(n);
	rep(i,1,n+n-1)read(a[i]);
	b[0]=b[n+n]=-1;
	int l=1,r=n+n-1,res=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))res=mid,l=mid+1;else r=mid-1;
	}
	cout<<res<<endl;
}

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

using namespace std;

#define pb			push_back
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define hastr(s, c)		((s).find(c) != string::npos)

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {

#ifndef	ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll k, a, b;
    cin >> k >> a >> b;
    bool ok = false;
    for(int i = a; i <= b; ++i) {
    	if(i % k == 0) {
    		ok = true;
    		break;
    	}
    }
    if(ok)
    	cout << "OK";
    else
    	cout << "NG";
    cout << endl;

    return 0;
}


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

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

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

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

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

int main() {
   int n;
   cin >> n;
   vec<int> v(2*n);
   rep (i, 2*n) {
      cin >> v[i];
   }
   sort(all(v), greater<int>());
   int ans = 0;
   for (int i = 1; i < 2*n; i+=2) {
      ans += v[i];
   }
   cout << ans << endl;

   return 0;
}

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

#include <string>
#include <set>
int main()
{
    int n;
    cin >> n;
    set<string> products;
    string temp;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        products.insert(temp);
    }

    cout << products.size() << endl;
    
    return 0;
}



Measured memory_bytes: 19260
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    SORT(S);
    string alf = "abcdefghijklmnopqrstuvwxyz";
    FOR(i, 0, 26) {
        int tmp = S.find(alf.at(i));
        if (tmp == string::npos) {
            cout << alf.at(i) << endl;
            exit(0);
        }
    }
    cout << "None" << endl;
}


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

int N;
string S;

int main(){
  cin >> N;
  cin >> S;
  if(N % 2 != 0){
    cout << "No"<< endl;
    return 0;
  }else{
    int half = N / 2;
    for(int i = 0; i <half;i++ ){
      if(S.at(i) != S.at(half+i)){
        cout << "No"<< endl;
        return 0;
      }
    }
  }
  cout << "Yes"<< endl;
}


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

int main(){
	ll h;
	cin >> h;
	ll r_n = 1;
	while(h != 1){
		h /= 2;
		r_n *= 2;
	}
	cout << r_n*2-1 << endl;


	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  string ans = "Three";

  rep(i, N)
  {
    string S;
    cin >> S;
    if (S == "Y")
      ans = "Four";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int MAXN = 1e5 + 5;

int a, n, cnt[MAXN];

int main() {
    int i, x = -1;
    scanf("%d", &n);
    for (i = 1; i <= n; ++i) {
        scanf("%d", &a);
        ++cnt[a + 1]; // all + 1
        ++cnt[a];
        ++cnt[a + 2];
    }
    for (i = 0; i < MAXN; ++i) {
        x = std::max(x, cnt[i]);
    }
    printf("%d", x);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int f[10][10];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
      int x=i;
      while(x>=10)
      x/=10;
     f[x][i%10]++;
  }
  ll ans=0;
  for(int i=1;i<=n;i++)
  { int x=i;
      while(x>=10)
      x/=10;
    ans+=f[i%10][x];
  }
  cout<<ans;
}

Measured memory_bytes: 256
s = input()
t = [s[0], s[1], s[2], s[3]]
u = list(set(t))
v = len(u)
if v != 2:
    print("No")
else:
    w = s.count(u[0])
    x = s.count(u[1])
    if w == 2 and x ==2:
      print("Yes")
    else:
      print("No")

Measured memory_bytes: 3060