akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	string N;
	cin >> N;
	ll s=N.size();
	int tmp;
	tmp=N[s-1]-'0';
	ll dp[s+1][2];
	dp[s][0]=10-tmp;
	dp[s][1]=tmp;
	ll i;
	for(i=s-2;i>=0;i--){
		tmp=N[i]-'0';
		dp[i+1][0]=min(10-tmp-1+dp[i+2][0],10-tmp+dp[i+2][1]);
		dp[i+1][1]=min(tmp+dp[i+2][1],tmp+1+dp[i+2][0]);
	}
	cout << min(1+dp[1][0],dp[1][1]);
	return 0;
}

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

using namespace std;

const int maxn=1e5+5;

int a[maxn];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	}
	int ans=0;int cnt=1;
	for(int i=1;i<n;i++){
		if(a[i]<=a[i-1]){
			cnt++;
		}
		else cnt=1;
		ans=max(ans,cnt-1);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
 
int main(){
	int a1, a2, a3;
	
	scanf("%d %d %d", &a1, &a2, &a3);
	if (a1 + a2 + a3 >= 22){
		printf("bust\n");	
	}
	else {
		printf("win\n");
	}
	return 0;
}

Measured memory_bytes: 1640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    int win =0, lose =0;
    while (true) {
      C -= B;
      if (C <= 0) {
        win++;
        break;
      }
      A -= D;
      if (A <= 0) {
        break;
      }
    }
    if (win != 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 27020
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll sx = in(), sy = in(), tx = in(), ty = in();
	REP(i, tx - sx) {
		cout << 'R';
	}
	REP(i, ty - sy) {
		cout << 'U';
	}
	REP(i, tx - sx) {
		cout << 'L';
	}
	REP(i, ty - sy + 1) {
		cout << 'D';
	}
	REP(i, tx - sx + 1) {
		cout << 'R';
	}
	REP(i, ty - sy + 1) {
		cout << 'U';
	}
	cout << "LU";
	REP(i, tx - sx + 1) {
		cout << 'L';
	}
	REP(i, ty - sy + 1) {
		cout << 'D';
	}
	cout << 'R' << endl;
}

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

/*
    uses Stern-Brocot Sequence
*/

typedef long long ll;

const int MOD=1000000007;
ll n;
map<ll,ll> dp;

ll solve(ll x){
    if(x<=1)
        return x;
    if(dp[x])   return dp[x];

    ll res;

    if(x%2==0)
        res=2*solve(x/2)+solve(x/2 - 1);
    else
        res=2*solve(x/2)+solve(x/2 + 1);
    return dp[x]=res%MOD;
}

int main(){
    cin >> n;

    cout << solve(n+1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(20)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 998244353;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int N, D; cin >> N;
  map<int, int> mp;
  int mx = -1;
  REP(i, N){
    cin >> D; mp[D]++;
    chmax(mx, D);
    if(i == 0 and D != 0){
      cout << 0 << endl;
      return 0;
    }
    if(i != 0 and D == 0){
      cout << 0 << endl;
      return 0;
    }
  }

  int ans = 1, tmp = mp[0];
  for(int i = 1; i <= mx; i++){
    if(mp[i] == 0){
      cout << 0 << endl;
      return 0;
    }
    REP(j, mp[i]){
      ans *= tmp; ans %= MOD;
    }
    tmp = mp[i];
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << ' ' << b;
    return 0;
}

Measured memory_bytes: 256
import itertools

def calc_time(dishes):
    time_sum = 0
    for t in dishes[:len(dishes) - 1]:
        time_sum += ((t - 1) // 10) * 10 + 10
    time_sum += dishes[-1]

    return time_sum

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dishes_list = [A, B, C, D, E]

min_time = 10000
for dishes in itertools.permutations(dishes_list):
    if min_time > calc_time(dishes):
        min_time = calc_time(dishes)

print(min_time)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
string s;
int ans;
int main() {
    getline(cin, s);
    for (int i = 1; i < s.size(); ++i) if (s[i] != s[i - 1]) ans++;
    cout << ans << "\r\n";
    return 0;
}

Measured memory_bytes: 512
import heapq

n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    g[a-1].append((b-1, c))
    g[b-1].append((a-1, c))
q, k = map(int, input().split())
qs = [tuple(map(int, input().split())) for i in range(q)]

INF = float('inf')
dist = [INF for i in range(n)]
dist[k-1] = 0
hq = [(0, k-1)]
heapq.heapify(hq)
while hq:
    cost, node = heapq.heappop(hq)
    for n_node, n_cost in g[node]:
        d = dist[node] + n_cost
        if d < dist[n_node]:
            dist[n_node] = d
            heapq.heappush(hq, (dist[n_node], n_node))

for i in range(q):
    print(dist[qs[i][0]-1] + dist[qs[i][1]-1])

Measured memory_bytes: 59688
from itertools import accumulate

N=int(input())
s=str(input())


a = accumulate(c=='W' for c in 'X'+s[:-1])
b = reversed(list(accumulate(c=='E' for c in 'X'+s[-1:0:-1])))
print(min(x + y for x, y in zip(a, b)))

Measured memory_bytes: 16160
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;

  if(n==1){
    cout<<1<<endl<<0<<endl;
    return 0;
  }

  if(n==2){
    cout<<2<<endl<<0<<endl<<11<<endl;
    return 0;
  }

  cout<<n-1<<endl;
  for(Int i=2;i<=n;i++){
    string s(i,'0');
    s.front()=s.back()='1';
    cout<<s<<endl;
  }

  return 0;
}



Measured memory_bytes: 3232
N , M = (map(int , input().split()))
if M % 2 != 0:
    print("No")
elif (N*2) > M:
    print("No")
elif (M % 4 == 0 or M % 4 == 2) and M <= (N*4):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
package main

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

func nextInt(s *bufio.Scanner) (n int) {
	s.Scan()
	n, _ = strconv.Atoi(s.Text())
	return
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func solve(a []int, n int, k int) int {
	const mod int = 1000000007
	dp := make([][]int, n)
	dp[0] = make([]int, k+1)

	for i := 0; i <= a[0]; i++ {
		dp[0][i] = 1
	}

	for i := 1; i < n; i++ {
		dp[i] = make([]int, k+1)
		s := 0
		for j := 0; j <= k; j++ {
			s = (s + dp[i-1][j]) % mod
			if j > a[i] {
				s = (s + (mod - dp[i-1][j-a[i]-1])) % mod
			}
			dp[i][j] = s
		}
	}

	return dp[n-1][k]
}

func main() {
	s := bufio.NewScanner(bufio.NewReader(os.Stdin))
	s.Split(bufio.ScanWords)

	n := nextInt(s)
	k := nextInt(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(s)
	}

	fmt.Println(solve(a, n, k))
}


Measured memory_bytes: 81536
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

static const int MOD = 1e9 + 7;

int main() {

    int A, B;
    cin >> A >> B;
    int ans = 0;
    if (A > B * 2)ans = A - B * 2;

    cout << ans;
}

Measured memory_bytes: 256
def gcd(a,b):
    big,small=max(a,b),min(a,b)
    while big%small!=0:
        big,small=small,big%small
    return small
 
def lcm(a,b):
    return int(a*b/gcd(a,b))
  
def main():
    while True:
        try:
            IN=input()
            val=IN.split()
            g=gcd(int(val[0]),int(val[1]))
            l=lcm(int(val[0]),int(val[1]))
 
            print(g,l)
        except:
            break
if __name__ == '__main__':
    main()

Measured memory_bytes: 7596
#include <stdio.h>

int main(void){

 int a, b;

 scanf( "%d %d", &a, &b );

 if( a > b)
	 printf( "a > b\n" );
 else if( a < b )
	 printf( "a < b\n" );
 else
	 printf( "a == b\n" );

 return 0;

}


Measured memory_bytes: 1788
#ifdef debug
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
//#include "optimization.h"

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

const int N = 55;

int n;
int a[N];
int b[N];

bool check(ll mask) {
    vec< vec< int > > g(N, vec< int >(N));
    for(int i = 0;i < N;i++) {
        for(int k = 1;k < N;k++) {
            if((1ll << k) & mask) {
                g[i][i % k] = 1;
            }
        }
    }
    for(int i = 0;i < N;i++) {
        g[i][i] = 1;
    }
    for(int k = 0;k < N;k++) {
        for(int i = 0;i < N;i++) {
            for(int j = 0;j < N;j++) {
                g[i][j] |= (g[i][k] & g[k][j]);
            }
        }
    }
    for(int i = 1;i <= n;i++) {
        if(!g[a[i]][b[i]]) {
            return false;
        }
    }
    return true;
}

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    cin >> n;

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

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

    ll ost = (1ll << N) - 1;
    ll res = 0;

    for(int i = N - 1;i >= 0;i--) {
        ost ^= (1ll << i);
        if(check(res | ost)) {
            continue;
        }else {
            res |= (1ll << i);
        }
    }

    if(check(res)) {
        cout << res << "\n";
    }else {
        cout << "-1\n";
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int[] P = new int[N];
    	P[0] = sc.nextInt();
    	int error = 0;
    	boolean asc = true;
    	boolean once = true;
    	for (int i = 1; i < N; i++) {
    		P[i] = sc.nextInt();
    		if (once && !asc && error - 1 == P[i - 1]) {
    			asc = true;
				once = false;
    		} else if (P[i] < P[i - 1]) {
    			error = P[i - 1];
    			asc = false;
    		}
    	}
    	System.out.println(asc ? "YES" : "NO");
    }
}

Measured memory_bytes: 21844
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    YES(n >= 30);
}

Measured memory_bytes: 3640
s = input()
t = input()
s2 = s.replace('?', 'a')

ans = 'z' * 99
for i in range(len(s) - len(t)+1):
    u = s2[0:i] + t + s2[i + len(t):]

    ok = True
    for x, y in zip(s, u):
        if x != '?' and x != y:
            ok = False
            break
    if ok:
        ans = min(ans, u)

if ans == 'z' * 99:
    ans = 'UNRESTORABLE'

print(ans)


Measured memory_bytes: 3060
N, M = gets.chomp.split(" ").map(&:to_i)
route = []
M.times do |n|
  route[n] = gets.chomp.split(" ").map(&:to_i)
end
count = Array.new(N,0)
M.times do |n|
  count[route[n][0]-1] += 1
  count[route[n][1]-1] += 1
end
N.times do |n|
  print("#{count[n]}\n")
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int a, b, t;

int main() {
	cin >> a >> b >> t;
	
	cout << t / a * b << endl;
	
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n,x[1000],nokori[1000];
vector<int> G[1000];
bool flag = true;

void dfs(int v){
	int ok[5001] = {};
	for(int i = 1;i <= x[v];i++) ok[i] = INF;
	for(int to : G[v]){
		dfs(to);
		int next[5000];
		for(int i = 0;i <= x[v];i++) next[i] = INF;
		for(int i = 0;i <= x[v];i++){
			if(ok[i] == INF) continue;
			if(i + x[to] <= x[v]) next[i + x[to]] = min(next[i + x[to]],ok[i] + nokori[to]);
			if(i + nokori[to] <= x[v]) next[i + nokori[to]] = min(next[i + nokori[to]],ok[i] + x[to]);
		}
		for(int i = 0;i <= x[v];i++) ok[i] = next[i];
	}
	int mi = INF;
	for(int i = x[v];i >= 0;i--){
		mi = min(mi,ok[i]);
	}
	if(mi == INF) flag = false;
	nokori[v] = mi;
	return;
}

signed main(){
	cin >> n;
	for(int i = 1;i < n;i++){
		int p;
		cin >> p; p--;
		G[p].push_back(i);
	}
	for(int i = 0;i < n;i++) cin >> x[i];
	dfs(0);
	if(flag) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 30080
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		System.out.println(B % A == 0 ? A+B : B-A);
	}
	
}


Measured memory_bytes: 22228
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		call(Integer.parseInt(scan.next()));
		return;
	}
	
	public static void call(int n){
		int i = 1;
		while( ++i <= n ){
			int x = i;
			if( x % 3 == 0 ){
				System.out.printf(" %d", i);
			}else{
				for( int j = 0; x != 0; j++ ){
					if( x % 10 == 3 ){
						System.out.printf(" %d", i);
						break;
					}else{
						x /= 10;
					}
				}
			}
		}
		System.out.println();
		return;
	}
}

Measured memory_bytes: 33692
#include <iostream>
#include <vector>
#include <algorithm>

using ll=long long;
using namespace std;
int main()
{
    int n;
    cin >> n;

    vector<ll> h;
    for (int i=0; i < n; i++)
    {
        ll val;
        cin >> val;
        h.push_back(val);
    }
    reverse(h.begin(), h.end());
    
    ll prev = h[0];
    for (int i=1; i < n; i++)
    {
        ll d = h[i] - prev;
        if (d > 1)
        {
            cout << "No" << endl;
            return 0;
        }
        else if (d == 1)
        {
            h[i]--;
        }

        prev = h[i];
    }    

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


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

int main()
{
	int n,m,d;
	double ans;
	scanf("%d %d %d",&n,&m,&d);
	if (d==0) ans=1.0*(m-1)/n;
	else if (n<d) ans=0;
	else ans=1.0*(n-d)/n*2/n*(m-1);
	printf("%.10f\n",ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
dct_t = {}

for _ in range(N):
    tmp = input().rstrip()
    if tmp in dct_t:
        dct_t[tmp] += 1
    else:
        dct_t[tmp] = 1

M = int(input())
dct_s = {}

for _ in range(M):
    tmp = input().rstrip()
    if tmp in dct_s:
        dct_s[tmp] += 1
    else:
        dct_s[tmp] = 1

result = 0

for t in list(dct_t.keys()):
    for s in list(dct_s.keys()):
        if t in dct_s:
            tmp = dct_t[t] - dct_s[t]
            if result < tmp:
                result = tmp
        elif result < dct_t[t]:
            result = dct_t[t]

print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#include <iomanip>
#include<numeric>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
const long long INF = 1LL << 60;
ll mod=1e9+7;
using namespace std;
int n;
int X[100010]; int Y[100010];
vector<pair<int,int> > XX;
vector<pair<int,int> > YY;
vector<pair<int,pair<int,int> > > XY;
class UnionFind{
public:
	vector<int> par,num;

	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
int main(){
	cin >>n;
	UnionFind uf(n);
	for(int i=0;i<n;i++){
		cin >> X[i] >> Y[i];
		XX.push_back(make_pair(X[i],i));
		YY.push_back(make_pair(Y[i],i));
	}
	sort(XX.begin(),XX.end());
	sort(YY.begin(),YY.end());
	for(int j=0;j<n-1;j++){
		XY.push_back(make_pair(XX[j+1].first-XX[j].first,make_pair(XX[j+1].second,XX[j].second)));
		XY.push_back(make_pair(YY[j+1].first-YY[j].first,make_pair(YY[j+1].second,YY[j].second)));
	}
	ll cnt=0;
	sort(XY.begin(),XY.end());
	for(auto e:XY){
		if(!uf.same(e.second.first,e.second.second)){
			uf.unite(e.second.first,e.second.second);
			cnt+=e.first;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 8808
from bisect import bisect


def main():
    S = input()
    T = input()

    pos = {}
    for i, c in enumerate(S):
        if c not in pos.keys():
            pos[c] = []
        pos[c].append(i)

    ret = 0
    tmp = -1
    for c in T:
        if c not in pos.keys():
            print(-1)
            return
        idx = bisect(pos[c], tmp)
        if idx == len(pos[c]):
            ret += len(S)
            tmp = pos[c][0]
        else:
            tmp = pos[c][idx]

    ret += tmp + 1
    print(ret)
    return


if __name__ == "__main__":
    main()


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

int main(){
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k) cout<<s;
    else{
        rep(i,k) cout<<s.at(i);
        cout<<"...";
    }
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll T[100005];
bool isPrime[100005];

void solve()
{
    REP(i, 100005)
    {
        isPrime[i] = true;
        T[i] = 0;
    }
    isPrime[0] = isPrime[1] = false;
    FOR(i, 100005, 2)
    {
        if (!isPrime[i])
            continue;
        if (isPrime[(i + 1) / 2])
            T[i]++;
        for (int j = i * 2; j < 100005; j += i)
            isPrime[j] = false;
    }

    FOR(i, 100005, 1)
    {
        T[i] += T[i - 1];
    }
}

int main()
{
    solve();
    int Q;
    cin >> Q;
    REP(i, Q)
    {
        int l, r;
        cin >> l >> r;
        cout << T[r] - T[l - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<math.h>
#include<vector>
 
using namespace std;
 
 
int main(){
        int a,b,c;
        cin>>a>>b>>c;
        if(a==b && c==b){
                cout<<"Yes"<<endl;
        }else{
                cout<<"No"<<endl;
        }
 
        return 0;
 
}

Measured memory_bytes: 256
def main(n, x, y):
    d_s = [0] * (n-1)

    for i in range(n-1):
        for j in range(i + 1, n):
            d = min(abs(i-j), abs(i-x) + abs(j-y) + 1, abs(i-y) + abs(j-x) + 1)
            d_s[d-1] += 1

    print("\n".join(str(d) for d in d_s))


if __name__ == "__main__":
    n, x, y = map(int, input().split())

    main(n, x-1, y-1)


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N, M;
    cin >> N >> M;

    vector<int> bit(M, 0), check(M);
    rep(i, M) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            bit[i] += pow(2, s-1);
            //cout << bit[i] << ":" << s << ":" << (2^(s-1)) << endl;
        }
    }
    rep(j, M) {
        cin >> check[j];
    }

    int ans = 0;

    for (int i = 0; i < (1 << N); i++) {
        bool flag = true;
        rep(j, M) {
            int num = bit[j] & i;
            int bit_j = 0;
            for (int j = 1; j < (1 << N); j = j << 1) {
                if (num & j) bit_j++;
            }
            if (bit_j % 2 != check[j]) {
                flag = false; 
                break;
            }
        }
        if (flag) ans++;
    }

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

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]


c = 0
ac = 0
bc = 0
abc = 0
for i in range(n):
    c += s[i].count('AB')
    if(s[i][-1] == 'A' and s[i][0] == 'B'):abc += 1
    elif(s[i][-1] == 'A'):ac += 1
    elif(s[i][0] == 'B'):bc += 1

if(abc == 0):
    print(c + min(ac,bc))
elif(ac + bc == 0):
    print(c + abc - 1)
else:
    print(c + abc + min(ac,bc))



Measured memory_bytes: 3700
#include <stdio.h>
#include <string.h>
//a 97
int main(void) {
	int check[26] = {0};
	char s[1000001];
	scanf("%s", s);
	for (int i = 0; i < strlen(s); ++i) {
		check[s[i] - 97] = 1;
	}
	int none = 1;
	for (int i = 0; i < 26; ++i) {
		if (check[i] == 0) {
			none = 0;
			printf("%c", i + 97);
			break;
		}
	}
	if (none) {
		printf("None");
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double[]x = new double[N];
    String[]y = new String[N];
    
    double all = 0;
    for(int i=0; i<N; i++){
        x[i] = sc.nextDouble();
        y[i] = sc.next();
        if(y[i].equals("JPY")){
        	all += x[i];
        }else {
        	all += x[i]*380000.0;
        }
    }       
        System.out.println(all);
    }
}

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

// #define int long long
#define rep(i, n) for (ll i = (ll)(0); i < (ll)(n); ++i)
#define reps(i, n) for (ll i = (ll)(1); i <= (ll)(n); ++i)
#define rrep(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define rreps(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define irep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); ++i)
#define ireps(i, m, n) for (ll i = (ll)(m); i <= (ll)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) ll(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  ll R,S,P; cin>>R>>S>>P;
  string t; cin>>t;
  map<char,ll> m;
  m['s']=R;
  m['p']=S;
  m['r']=P;
  vb check(n+k+5);
  ll ans=0;
  rep(i,n){
    if(check[i]) continue;
    ans+=m[t[i]];
    if(t[i+k]==t[i]) check[i+k]=true;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        sc.close();
        char[] c = new char[n];
        for(int i = 0 ; i < n ; i++){
            c[i] = s.charAt(i);
        }
        boolean ebishu = true;
        for(int i = 0 ; i < n ; i++){
            if(c[0] != c[i]) ebishu = false;
        }
        if(ebishu){
            System.out.println(0);
        }else{
            int[] a = new int[n];
            for(int i = 0 ; i < n ; i++){
                if(c[i] == 'R'){
                    a[i] = 0;
                }else{
                    a[i] = 1;
                }
            }
            int[] b = new int[n];
            for(int i = 0 ; i < n ; i++){
                b[i] = a[i];
            }
            Arrays.sort(b);
            int yono = 1;
            for(int i = 0 ; i < n ; i++){
                if(a[i] != b[i]){
                    yono++;
                }
            }
            System.out.println(yono / 2);
        }
    }
}

Measured memory_bytes: 42916
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,x;
    cin>>n;
  cout<<n/3<<"\n";
}


Measured memory_bytes: 3576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader buf= new BufferedReader(new InputStreamReader(System.in));
		String str =buf.readLine(); //入力する桁数
		int count=Integer.parseInt(str);
		
		int[] a=new int[count];
		int[] b=new int[count];
		int[] c=new int[count];
		
		for(int i=0;i<count;i++){
			str=buf.readLine();
			a[i]=Integer.parseInt(str.split(" ")[0]);
			b[i]=Integer.parseInt(str.split(" ")[1]);
			c[i]=Integer.parseInt(str.split(" ")[2]);
		}
		buf.close();
		for(int i=0;i<count;i++){
			if(
				(a[i]< (b[i]+c[i]) )&& /*三角形の成立条件（一つの辺は、他の２辺の長さの和よりも小さい）*/
				(b[i]< (a[i]+c[i]) )&&
				(c[i]< (a[i]+b[i]) )
			){
				if(
					(a[i]*a[i]+b[i]*b[i]==c[i]*c[i])|| /*直角三角形の成立条件（ピタゴラスの定理、a＾2 + b＾2 = c＾2）*/
					(a[i]*a[i]+c[i]*c[i]==b[i]*b[i])||
					(b[i]*b[i]+c[i]*c[i]==a[i]*a[i])
				){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
			}else{
				System.out.println("NO");
			}

		}
	}
}

Measured memory_bytes: 23692
import sys
N,M=map(int,input().split())
edge=[]
for i in range(M):
    a,b,c=map(int,input().split())
    edge.append([a-1,b-1,-c])
inf=10**30
dist=[inf]*N
dist[0]=0
for i in range(N+1):
    for x,y,z in edge:
        if dist[y]<= dist[x]+z:
            continue
        dist[y]=dist[x]+z
        if i==N and y==N-1:
            print('inf')
            sys.exit()
print(-dist[N-1])

Measured memory_bytes: 46696
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] astr = str.split(" "); //状況に合わせて
        Boolean flag = true;
        int[] in_data = Stream.of(astr).mapToInt(x -> {
            try {
                return Integer.parseInt(x);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 0;
        }).toArray();
        sc.close();

        int p = in_data[0];
        int q = in_data[1];
        int r = in_data[2];
        int ans =0;

        int max = max(p,q,r);
        if(max == p){
            ans = q + r;
        }
        if(max == q){
            ans = p + r;
        }
        if(max == r){
            ans = p + q;
        }
        System.out.println(ans);
    }

    public static int max(int a,int b,int c){
        int tmp = a;
        if(tmp < b){
            tmp = b;
        }
        if(tmp < c){
            tmp = c;
        }
        return  tmp;
    }
}

Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    string s; cin>>s;
    cout<<s.substr(0,3)<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    string a;
    string b;
    string c;
    cin >> a >> b >> c;
    char turn = a[0];
    a.erase(a.begin());
    if(a.empty()) {
        cout << 'A' << endl;
        return 0;
    }

    while(1){
        if(turn == 'a'){
            if(a.empty()) {
                cout << 'A' << endl;
                return 0;
            }
            turn = a[0];
            a.erase(a.begin());
        }

        if(turn == 'b'){
            if(b.empty()) {
                cout << 'B' << endl;
                return 0;
            }
            turn = b[0];
            b.erase(b.begin());
        }

        if(turn == 'c'){
            if(c.empty()) {
                cout << 'C' << endl;
                return 0;
            }
            turn = c[0];
            c.erase(c.begin());
        }   
    }    
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(void){
    int a[3][3];
    int i,j,k;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&a[i][j]);
        }
    }

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

    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            for(k=0;k<3;k++){
                if(b[i]==a[j][k]){
                    a[j][k]=0;
                }
            }
        }
    }/*存在の判定*/

    int result=0;

    for(i=0;i<3;i++){
        if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0){
            result=1;
        }
    }/*縦の判定*/

    for(i=0;i<3;i++){
        if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0){
            result=1;
        }
    }/*横の判定*/

    if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0){
        result=1;
    }
    if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0){
        result=1;
    }/*斜めの判定*/

    switch (result) {
      case 0:printf("No\n");  break;
      case 1:printf("Yes\n"); break;
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
using ll = long long;

ll sat_calc(vector<vector<ll>>& s, vector<ll>& c, vector<ll>& last, ll day, ll contest);

int main()
{
    ll d;
    cin >> d;
    vector<ll> c;
    vector<vector<ll>> s;
    vector<ll> last(26, 0);

    for (ll i = 0; i < 26; i++) {
        ll tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    for (ll i = 0; i < d; i++) {
        vector<ll> tmp_v;
        for (ll j = 0; j < 26; j++) {
            ll tmp;
            cin >> tmp;
            tmp_v.push_back(tmp);

        }
        s.push_back(tmp_v);
    }


    ll sat = 0;
    vector<ll> index_vec;
    for (ll i = 0; i < d; i++) {
        vector<ll> contest_sat;
        for (ll contest = 0; contest < 26; contest++) {
            ll tmp = sat_calc(s, c, last, i, contest);
            contest_sat.push_back(tmp);
        }
        std::vector<ll>::iterator iter = std::max_element(contest_sat.begin(), contest_sat.end());
        size_t index = std::distance(contest_sat.begin(), iter);
        sat += s[i][index];
        last[index] = i + 1;
        index_vec.push_back(index + 1);
    }
    for (auto a : index_vec) {
        cout << a << endl;
    }
    return 0;

}

ll sat_calc(vector<vector<ll>>& s, vector<ll>& c, vector<ll> &last, ll day,ll contest) {
    ll sat = s[day][contest];
    for (ll j = 0; j < 26; j++) {
        sat -= (day + 1 - last[j]) * c[j];
    }
    return sat;
}

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

int n,k,a[100001],ans=2147483647;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	for(int i=1;i<=n-k+1;++i)
	{
		int l=a[i],r=a[i+k-1];
		if((l<=0 && r<=0) || (l>=0 && r>=0))ans=min(ans,max(abs(l),abs(r)));
		else ans=min(ans,min(abs(l),abs(r))*2+max(abs(l),abs(r)));
	}
	printf("%d\n",ans);
}

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

int main() {
  
  int N; cin >> N; int64_t sum = 0;
  
  for (int i = 0; i < N; i++) {
    
    int a; cin >> a;
    
    a--; sum += a;
    
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=gc();}
	}
};
using io::gi;
#define ll long long
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}

int main(){
	int a,b,l,r,i;
	scanf("%d%d",&a,&b);
	l=max(-1000000,b-a+1);
	r=min( 1000000,b+a-1);
	for(i=l;i<=r;++i)printf("%d ",i);
	return 0;
}

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

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

    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int n = 1; n < N; ++n) {
        map<char, int> mp;
        for (int i = 0; i < n; ++i) {
            mp[S.at(i)] = 1;
        }
        int cnt = 0;
        for (int i = n; i < N; ++i) {
            if (mp[S.at(i)]) {
                mp[S.at(i)] = 0;
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {

  int i, len, c = 0;
  char w[11], t[1001];

  scanf("%s", w);
  while(1) {
    scanf("%s", t);
    if(strcmp(t, "END_OF_TEXT") == 0) break;
  
  len = strlen(t);
  for(i = 0; i < len; i++) {
    if(t[i] >= 'A' && t[i] <= 'Z') {
      t[i] -= 'A' - 'a';
    }
  }

  if(strcmp(t, w) == 0) {
    c += 1;
  }
  }
  printf("%d\n", c);

  return 0;
}

Measured memory_bytes: 544
//完全二分木
#include <iostream>
using namespace std;

int parent(int i) {return i / 2;}
int left(int i) {return i * 2;}
int right(int i) {return i * 2 + 1;}

int main() {

    int H, A[100001];

    cin >> H;

    for (int i = 1; i <= H; i++)
        cin >> A[i];
    
    for (int i = 1; i <= H; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
        if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
        cout  << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>


struct Answer {
    int yen_10000;
    int yen_5000;
    int yen_1000;
    
    bool is_valid() { 
        return yen_10000 != -1;
    }
    
    void print() {
        std::printf(
            "%d %d %d\n",
            yen_10000, yen_5000, yen_1000
        );
    }
};

struct Cond {
    bool use_10000 = true;
    bool use_5000  = true;
    bool use_1000  = true;
};


// n枚で1000*y円作る組み合わせを返す
Answer solve(const int n, const int ky, Cond cond) {
    //
    if(n == 0 && ky == 0) {
        return {0, 0, 0};
    }
    if(ky == 0) {
        return {-1, -1, -1};
    }
    if(ky == n) {
        return {0, 0, n};
    }
    
    //
    if(cond.use_10000) {
        for(int num = ky / 10; num >= 0; --num) {
            auto ans = solve(
                n - num, ky - num*10,
                {false, cond.use_5000, cond.use_1000}
            );
            if(ans.is_valid()) {
                ans.yen_10000 += num;
                return ans;
            }
        }
    }
    if(cond.use_5000) {
        for(int num = ky / 5; num >= 0; --num) {
            auto ans = solve(
                n - num, ky - num*5,
                {cond.use_10000, false, cond.use_1000}
            );
            if(ans.is_valid()) {
                ans.yen_5000 += num;
                return ans;
            }
        }
    }
    
    return {-1, -1, -1};
}

int main(void) {
    int N, Y;
    std::cin >> N >> Y;

    solve(N, Y/1000, {}).print();
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int H, W;
    std::cin >> H >> W;

    int S[H + 2][W + 2];
    for (int i = 0; i < H + 2; ++i) {
        for (int j = 0; j < W + 2; ++j) {
            S[i][j] = 0;
        }
    }

    for (int i = 0; i < H; ++i) {
        std::string line;
        std::cin >> line;
        for (int j = 0; j < W; ++j) {
            S[i + 1][j + 1] = (line[j] == '.') ? 0 : 1;
        }
    }

    for (int i = 1; i < H + 1; ++i) {
        for (int j = 1; j < W + 1; ++j) {
            if (S[i][j] == 1) {
                std::cout << '#';
            } else {
                std::cout << S[i - 1][j - 1] + S[i - 1][j] + S[i - 1][j + 1] +
                             S[i][j - 1] + S[i][j] + S[i][j + 1] +
                             S[i + 1][j - 1] + S[i + 1][j] + S[i + 1][j + 1];
            }
        }

        std::cout << std::endl;
    }

    return 0;
}

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

typedef long long ll;

int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    vector< vector< int > > vacation(n,vector< int >(3));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> vacation[i][j];
        }
    }
    vector< vector< ll > > DP(n,vector< ll >(3,0));
    for(int i=0;i<3;i++){
        DP[0][i] = vacation[0][i];
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            DP[i][j] = vacation[i][j] + max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3]);
        }
    }
    cout << max(DP[n-1][0],max(DP[n-1][1],DP[n-1][2])) << endl;
}


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

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(d, d + n);

    int abc_max = d[n / 2 - 1];
    int arc_min = d[n / 2];

    cout << max(arc_min - abc_max, 0) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,q;	cin >> n >> k >> q;
  vector<int>	score(n,k-q);
  
  for(int i=0;i<q;i++){
    int num;	cin >> num;	num--;
    score[num]++;
  }
  
  for(int i=0;i<n;i++){
    if(score[i]<=0)	cout << "No" << endl;
    else cout << "Yes" << endl;
  } 
}

Measured memory_bytes: 3768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#define INF 0x3f3f3f3f

using namespace std;
typedef long long ll;
int x,y;
const int N=1e5+10;
int p[N],q[N],r[N];
int a,b,c;
ll ans;
int main() {
	ios::sync_with_stdio(false);
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	for(int i=1;i<=a;i++) {
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=b;i++) {
		scanf("%d",&q[i]);
	}
	for(int i=1;i<=c;i++) {
		scanf("%d",&r[i]);
	}
	sort(p+1,p+a+1,greater<int>());
	sort(q+1,q+b+1,greater<int>());
	sort(r+1,r+c+1,greater<int>());
	int i=x,j=y,k=1;
	while(i>=1&&j>=1&&k<=c) {
		if(r[k]>p[i]&&r[k]>q[j]) {
			if(p[i]<q[j]) {
				p[i]=r[k];
				i--;
			}
			else {
				q[j]=r[k];
				j--;
			}
		}
		else if(r[k]>p[i]) {
			p[i]=r[k];
			i--;
		}
		else if(r[k]>q[j]) {
			q[j]=r[k];
			j--;
		}
		else {
			break;
		}
		k++;
	}
	if(k<=c) {
		if(i>=1) {
			while(k<=c&&i>=1&&p[i]<r[k]) {
				p[i]=r[k];
				i--;
				k++;
			}
		}
		if(j>=1) {
			while(k<=c&&j>=1&&q[j]<r[k]) {
				q[j]=r[k];
				j--;
				k++;
			}
		}
	}
	for(int i=1;i<=x;i++) {
		ans+=p[i];
		//printf("%d ",p[i]);
	}
//	printf("\n");
	for(int i=1;i<=y;i++) {
		ans+=q[i];
		//printf("%d ",q[i]);
	}
//	printf("\n");
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 1408
def isPal(s):
    s = str(s)
    n = len(s)
    f = 1
    for i in range(n//2):
        f &= s[i] == s[n-i-1]
    return f

a, b = map(int, input().split())

ans = 0
for i in range(a, b+1):
    if(isPal(i)):
        ans += 1

print(ans)



Measured memory_bytes: 9180
#include<stdio.h>
int main() {
	int w, h, a, b, c;
	scanf("%d%d%d%d%d", &w, &h, &a, &b, &c);
	if((a+c<=w && a+c>=0) && (b+c<=h && b+c>=0) && (a>0 && b>0)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}


Measured memory_bytes: 2108
"""
中央値

2 4 4 3
2 3 4 4
真ん中の2つの値を取り出す
⇨
"""

N = int(input())
Xs = list(map(int, input().split()))
X_sort = sorted(Xs)
M1 = X_sort[N//2-1]
M2 = X_sort[N//2]
# print(X_sort,M1,M2)

for x in Xs:
    if x <= M1:
        print(M2)
    else:
        print(M1)


Measured memory_bytes: 26772
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 100010

int n;
int total;
vector<int> G[MX];
int colr[MX];

void DFS(int x,int pre,int c,int &tot)
{
    if (colr[x]==-c) return;
    tot++;
    for (int i=0;i<G[x].size();i++)
        if (G[x][i]!=pre)
            DFS(G[x][i],x,c,tot);
}

void dfs(int u,int pre,int s,int &ok)
{
    if (u==n)
    {
        ok=s;
        return;
    }
    for (int i=0;i<G[u].size();i++)
    {
        if (ok) break;
        if (G[u][i]!=pre)
            dfs(G[u][i],u,s+1,ok);
    }
    if (ok)
    {
        if (u!=1&&s<=ok/2) colr[u]=1;
        if (u!=n&&s>ok/2) colr[u]=-1;
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    colr[1]=1; //hei
    colr[n]=-1;//bai

    int ok=0;
    dfs(1,-10,0,ok);
/*
    for (int i=1;i<=n;i++)
        printf("%d ",colr[i]);
    printf("\n");
*/

    int num_1=0;
    DFS(1,-10,1,num_1);
    int num_2=0;
    DFS(n,-10,-1,num_2);
    if (num_1-num_2>=1)
        printf("Fennec\n");
    else
        printf("Snuke\n");
    return 0;
}


Measured memory_bytes: 13952
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N = arg[0];
    
    let answer = 1;
    
    for(let i=2; i<=N; i++) {
        answer *= i;
        answer %= Math.pow(10, 9) + 7;
    }

    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 10060