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

using pint = pair<int, int>;
#define x first
#define y second

ostream& operator<<(ostream &st, const pint p) {
    st << "(" << p.x << ", " << p.y << ")";
    return st;
}

const int mod = 1610612741, x1 = 921, x2 = 1209;

string s;
int n, a[250004];
pint p[250004];

int add(int x, int y) { return (x+(long long)y+mod) % mod; }
int mul(int x, int y) { return (x*(long long)y) % mod; }
int power(int x, int k) {
    if (k<0) k += mod-1;
    if (k==0) return 1;
    if (k%2) return mul(x, power(x, k-1));
    int t = power(x, k/2);
    return mul(t, t);
}

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

    s = " " + s;

    for (int i=1; i<=n; i++) {
        a[i] = a[i-1];
        if (s[i] == '>') a[i]++;
        if (s[i] == '<') a[i]--;
    }

    int k1 = 0, k2 = 0;
    for (int i=1; i<=n; i++) {
        if (s[i] == '+') k1 = add(k1, power(x1, a[i])), k2 = add(k2, power(x2, a[i]));
        if (s[i] == '-') k1 = add(k1,-power(x1, a[i])), k2 = add(k2,-power(x2, a[i]));
        p[i] = pint(k1, k2);
    }

    map<pint, int> m;
    long long ans = 0;
    for (int i=0; i<=n; i++) {
        if (i) ans += m[p[i]];
        m[pint(add(p[i].x, mul(p[n].x, power(x1, a[i]))), add(p[i].y, mul(p[n].y, power(x2, a[i]))))] += 1;
    }

    cout << ans << '\n';
}

Measured memory_bytes: 34700
#include<iostream>
#define ll long long
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_set>
#include <iomanip>
using namespace std;
ll dp[400][400] = {0};
vector<ll> elements;


ll sum(int start, int last)
{
    ll ans = 0;
    for(int i = start; i<=last; ++i)
    {
        ans+=elements[i];
    }
    return ans;

}


ll check(int start, int last)
{
    //cout<<start<<"\t"<<last<<endl;
    if(start == last)
    {
        dp[start][start] = 0;
        return 0;
    }

    if(dp[start][last] != -1)
    {
        return dp[start][last];
    }

    ll ans = 1e18+5;
    ll x = sum(start, last);
    for(int i=start; i< last; ++i)
    {
       // cout<<ans<<" "<<" "<<start<<" "<<last<<endl;
        ans = min( (check(start, i) + check(i+1, last) + x),ans);
    }
    dp[start][last] = ans;
    return ans;


}


int main()
{

    string s,t;
    cin>>s>>t;
    if(s == t.substr(0, s.size()))
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
    char a[1000] = {'0'};
    int b=0,j=0;
    
    while(1){
        for(j=0;j<=1000;j++){
            scanf("%c",&a[j]);
            if(a[j]=='\n'){break;}
            b = b+(a[j]-'0');
        }
        if(a[0] == '0'){break;}
        printf("%d\n",b);
        b=0;
    }
    return 0;
}



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

int main() 
{
    int n, k; cin >> n >> k;
    vector<bool> seen(n);
    for (int i = 0; i < k; i++) {
        int d; cin >> d;
        while (d--) {
            int ai; cin >> ai;
            --ai;
            seen[ai] = true;
        }
    }
    cout << (n-accumulate(seen.begin(),seen.end(),0)) << '\n';
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <queue>

typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const ll INF=1e12;

using namespace std;
template<class T>
bool chmin(T &a, const T &b) {
    if(a>b) {
        a=b;
        return true;
    }

    return false;
}
int n,m,k,p;
int s[10],t[10];

struct State {

    int v;
    ll cost;
    // ?????£??????,?±??????????
    int S1,S2;

    bool operator<(const State &rhs) const {
        return cost>rhs.cost;
    }
};
struct Edge {
    int to,cost;
};

vector<Edge> G[1003];

ll dp[1003][1<<6][1<<6];
ll dijk() {
    rep(i,1003) rep(j,1<<6) rep(k,1<<6) dp[i][j][k]=INF;
    priority_queue<State> que;
    int tmp=find(s,s+k,p)-s;
    if(tmp!=k) {
        dp[p][1<<tmp][0]=0;
        que.push(State{p,0,1<<tmp,0});
    }
    else {
        dp[p][0][0]=0;
        que.push(State{p,0,0,0});
    }


    while(que.size()) {
        State st=que.top(); que.pop();
        int v=st.v;
        int S1=st.S1;
        int S2=st.S2;
        ll cost=st.cost;

        //printf("%d : %d %d %lld\n",v,S1,S2,cost);
        rep(i,G[v].size()) {
            Edge e=G[v][i];
            //printf("[debug] %d -> %d : %d\n",v,e.to,e.cost);
            int n_S1=S1,n_S2=S2;
            int pos_s=find(s,s+k,e.to)-s;
            int pos_t=find(t,t+k,e.to)-t;

            if(pos_s!=k) n_S1=S1|1<<pos_s;
            if(pos_t!=k&&S1>>pos_t&1) n_S2=S2|1<<pos_t;

            if(chmin(dp[e.to][n_S1][n_S2],dp[v][S1][S2]+e.cost)) {
                que.push(State{e.to,dp[e.to][n_S1][n_S2],n_S1,n_S2});
            }
        }
    }

    ll ret=INF;
    rep(i,n) chmin(ret,dp[i][(1<<k)-1][(1<<k)-1]);

    return ret;
}

int main() {
    cin>>n>>m>>k>>p;
    p--;
    rep(i,m) {
        int x,y,w;
        cin>>x>>y>>w;
        x--,y--;
        G[x].push_back(Edge{y,w});
        G[y].push_back(Edge{x,w});

    }
    rep(i,k) cin>>s[i]>>t[i];
    rep(i,k) s[i]--,t[i]--;

    ll ans=dijk();
    if(ans==INF) cout<<"Cannot deliver"<<endl;
    else cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 37076
/*
   Creator - Glitched
   Yeet!!
*/

#include "bits/stdc++.h"
#include "stdlib.h"
using namespace std;
#define testcases ll t;cin>>t;while(t--)
#define queries ll q;cin>>q;while(q--)
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)

#define ff first
#define ss second
#define pb push_back
#define elif else if
#define flush cout<<"\n"
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{   
    string s;cin>>s;ll n = s.size();
    loop(i,0,n){
        cout<<"x";
    }

    
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    string w;
    cin >> w;
    int s[26] = {};
    rep(i, w.size()){
        s[w[i]-'a']++;
    }
    bool ans = true;
    rep(i, 26){
        if(s[i] % 2 == 1){
            ans = false;
            break;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
a=[0]*N
s={}
for i in range(N):
	a[i] = int(input())
	if a[i] not in s:
		s[a[i]] = 1
	else:
		s[a[i]] += 1

res=0
for key,value in s.items():
#	print(key,value)
	res += (1 if not value % 2 == 0 else 0)

print(res)

Measured memory_bytes: 15836
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		for (int i = 0; i < 15; i++) {
			for (int j = 0; j < 26; j++) {
				if (N == 7 * i + 4 * j) {
					System.out.println("Yes");
					return;
				}

			}
		}
		System.out.println("No");
	}

}

Measured memory_bytes: 22740
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(left(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll a[n];
	for(ll i=0; i<n;i++)
		cin >> a[i];
	sort(a, a+n);
	ll s1=0, s2=0;
	for(ll i=0; i<n; i++){
		if(i&1)
			s2+=a[i];
		else
			s1+=a[i];
	}
	cout << abs(s2-s1);
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;

struct Monster {
  ll x;
  ll h;
  Monster() {}
  Monster(ll x, ll h): x(x), h(h) {}
  bool operator<(const Monster &o) const {
    return x < o.x;
  }
};

int main() {
  ll n, d, a; cin >> n >> d >> a;
  vector<Monster> monsters(n);
  for (int i=0; i<n; i++) {
    ll x, h; cin >> x >> h;
    monsters[i] = Monster(x, h);
  }
  sort(monsters.begin(), monsters.end());

  ll r = 0;
  ll aa = 0;
  queue<int> right;
  queue<int> damage;
  for (int i=0; i<n; i++) {
    ll x = monsters[i].x;
    ll h = monsters[i].h;

    while (!right.empty() && right.front() < x) {
      aa -= damage.front();
      right.pop();
      damage.pop();
    }

    h = max(h - aa, 0ll);
    ll rr = ceil(1. * h / a);
    aa += rr * a;
    right.push(x + d * 2);
    damage.push(rr * a);
    r += rr;
  }

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 4992
B[]={' bh','!%~','!d9','"zX'};*F=" %d %d %d\n\0 pre-meiji\0  taisho\0 showa\0  heisei";y,m,d,e;main(){for(;~scanf(F,&y,&m,&d);e?printf(F,y-B[e-1]/1136+1,m,d,printf(F+e*2+2)):puts(F+3))for(e=0;e<4&&y*1136+m*32+d>=B[e];e++);return 0;}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	double max = 0,min = 0,x;
	int flag = 0;
	
	while(scanf("%lf", &x) != EOF){
		if(flag == 0){
			max = x;
			min = x;
			flag = 1;
		}
		
		if(max < x) max = x;
		if(min > x) min = x;
	}
	
	printf("%.1lf\n", max - min);
	
	return(0);
}

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

int main() {
  long long count =0;
  long long N;
  cin>>N;
  if(N%2==1){
    cout<<0;
  return 0;
  }
  N=N/2;
  while(1){
    count+=N/5;
    N=N/5;
    if(N==0){
      cout<<count;
    return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int N{};
  int cnt{};
  cin >> N;
  for (int i = 1; i <= N ; ++i) {
    int temp;
    cin >> temp;
    if (i%2 == 1 && temp %2 == 1)
      cnt++;
  }
  cout << cnt;

  return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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 long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, X, T;
	cin >> N >> X >> T;
	cout << ((N+X-1)/X) * T << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  char op;
  
  cin >> a >> op >> b;
  
  if (op == '+') {
    cout << a + b << endl;
  }
  
  else {
    cout << a - b << endl;
  }
}

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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];

    ll ans = 0;
    rep(i, 1, n)
    {
        if (a[i] + a[i - 1] > x)
        {
            int r = a[i] + a[i - 1] - x;
            ans += r;
            a[i] = max(0, a[i] - r);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Inf 1000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N, K;
	cin >> N >> K;
	vl H(N + 1);
	rep(i, N + 1) {
		if (i == 0) {
			H[0] = 0;
			continue;
		}
		cin >> H[i];
	}
	vector<vector<vl>> dp(N + 1);
	rep(n, N + 1) {
		dp[n].resize(K + 1);
		rep(k, K + 1) {
			dp[n][k].resize(N + 1);
			rep(r, N + 1) {
				dp[n][k][r] = Inf;
			}
		}
	}
	dp[0][0][0] = 0;
	rep(n, N + 1) {
		if (n == 0)
			continue;
		rep(k, K + 1) {
			rep(r, N + 1) {

				// nを操作しない
				ll Hdiff = max(H[n] - H[r], (ll)0);
				dp[n][k][n] = min(dp[n][k][n], dp[n - 1][k][r] + Hdiff);
				
				// nを操作する(左とそろえる)
				if (k == K)
					continue; // 既に上限
				dp[n][k + 1][r] = min(dp[n][k + 1][r], dp[n - 1][k][r]);
			}
		}
	}
	ll ans = Inf;
	rep(k, K + 1) {
		rep(r, N + 1) {
			ans = min(ans, dp[N][k][r]);
		}
	}

	/*rep(n, N + 1) {
		rep(k, K + 1) {
			rep(r, N + 1) {
				cout << n << " " << k << " " << r << " " << dp[n][k][r] << endl;
			}
		}
	}*/
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 216192
N = gets.to_i
A = gets.to_s.chars
B = gets.to_s.chars
C = gets.to_s.chars

n = N.to_i
ans = 0

n.times do |i|
    ca, cb, cc = A[i], B[i], C[i]
    ans += 1 if ca != cb
    ans += 1 if cb != cc
    ans -= 1 if (ca != cb) && (cb != cc) && (ca == cc) 
end

p ans

Measured memory_bytes: 1788
main = do
  inputs <- readLn
  let h = inputs `div` 60 `div` 60
  let m = (inputs - h * 60 * 60) `div` 60
  let s = inputs - h * 60 * 60 - m * 60
  putStrLn $ (show h) ++ ":" ++ (show m) ++ ":" ++ (show s)

Measured memory_bytes: 3684
import numpy as np
import sys
input = sys.stdin.readline

MOD = 10**9 + 7
N,M = map(int,input().split())
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)

# (n,m) 以前で作れている列
dp = np.zeros((N+1, M+1), dtype = np.int64)
dp[0] = 1

for n in range(1, N+1):
  same = (T == S[n-1])
  dp[n,1:][same] = dp[n-1,:-1][same] # ちょうど(n,m)で終わる
  dp[n] = (dp[n].cumsum() + dp[n-1]) % MOD # cumsumに直す

answer = dp[N,M]
print(answer)


Measured memory_bytes: 43684
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#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, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

vector<int> sieve_of_eratosthenes(int n) {
    vector<bool> is(n + 1, true);
    vector<int> res;
    is[0] = false;
    is[1] = false;
    for (int i = 2; i <= n; i++) if (is[i]) {
        res.emplace_back(i);
        for (int j = i * 2; j <= n; j += i) {
            is[j] = false;
        }
    }
    return res;
}
VI primes;
void solve(int N, int P) {
    int start;
    REP(i, primes.size()) {
        if (primes[i] > N) {
            start = i;break;
        }
    }
    VI v;
    FOR(i, start, start + P + 1) {
        FOR(j, i, start + P + 1) {
            v.EB(primes[i] + primes[j]);
        }
    }
    SORT(v);
    int cnt = 0;
    FORE(e, v) {
        cnt++;
        //cerr << e << " ";
        if (cnt == P) {
            cout << e << endl;
            break;
        }
    }
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    primes = sieve_of_eratosthenes(200000);
    while (cin >> n >> m, n != -1) {
        solve(n, m);
        //return 0;
    }
}

Measured memory_bytes: 3208
def isprime(x):
    if x <= 1:
        return False
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            return False
    return True


n = int(input())

A = []
count = 0
for a in range(55556):
    if a % 5 != 1:
        continue
    if isprime(a):
        A.append(a)
        count += 1
    if count == n:
        break

print(*A)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{
    class Program
    {
        static void Main()
        {

            int Payed = int.Parse(Console.ReadLine());

            int Core = (int)((float)Payed / 1.08);

            if ((int)((float)Core * 1.08) == Payed)
                Console.WriteLine(Core);
            else if ((int)((float)(Core + 1) * 1.08) == Payed)
                Console.WriteLine(Core + 1);
            else
                Console.WriteLine(":(");
        }


    }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    string s;cin >>s;
    ll n=s.size();
    cout <<"2018";
    cout <<s.substr(4,n-4)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	while(~scanf("%d/%2d/%2d",&a,&b,&c))
	{
		a=2018;
		printf("%d/%02d/%02d\n",a,b,c);
	}
	return 0;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

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

string S;

bool isPalindrome(int start, int last) {
	while (start <= last) {
		if (S[start] != S[last]) {
			return false;
		}
		start++;
		last--;
	}
	return true;
}

int main() {
	cin >> S;
	int n = S.length();
	if (isPalindrome(0, n-1) && isPalindrome(0, (n-1)/2 - 1) && isPalindrome((n+3)/2 - 1, n - 1)) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
s = input().split()
n, k = int(s[0]), int(s[1])
 
ss = input().split()
l = [int(i) for i in ss]
 
l.sort()
if n < k:
  print(0)
elif k == 0:
  print(sum(l))
else:
  print(sum(l[:n-k]))

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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a[3][3];
    bool ok[3][3],yes=false;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin>>a[i][j];
            ok[i][j]=false;
        }
    }
    int n;
    cin>>n;
    vector<int> b(n);
    for (int k = 0; k < n; k++)
    {
        cin>>b[k];
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if(b[k]==a[i][j])
                {
                    ok[i][j]=true;
                }
            }
        }
    }
    
    //yoko
    for (int i = 0; i < 3; i++)
    {
        if(ok[i][0]==true && ok[i][1]==true && ok[i][2]==true) yes=true;
        if(ok[0][i]==true && ok[1][i]==true && ok[2][i]==true) yes=true;
    }
    if(ok[0][0]==true && ok[1][1]==true && ok[2][2]==true) yes=true;
    if(ok[0][2]==true && ok[1][1]==true && ok[2][0]==true) yes=true;

    if(yes==true) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
if x>a*a*b/2:
    x=a*a*b-x
    taka=2*x/(a*a)
    ans=math.degrees(math.atan(taka/a))
else:
    taka=2*x/(a*b)
    ans=math.degrees(math.atan(b/taka))
print(ans)

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

int add(int x,int s,int f){
    s+=x;
    for(;;){
        if(s%10!=0&&f==1)s++;
        else break;
    }
    return s;
}

int main(){
    int ma[5],ans=INT32_MAX;
    REP(i,5)cin>>ma[i];
    REP(a,5){
        REP(b,5){
            if(a!=b){
                REP(c,5){
                    if(c!=b&&a!=c){
                        REP(d,5){
                            if(d!=a&&d!=b&&d!=c){
                                REP(e,5){
                                    if(e!=a&&e!=b&&e!=c&&e!=d){
                                        int sum=0;
                                        sum=add(ma[a],sum,1);
                                        sum=add(ma[b],sum,1);
                                        sum=add(ma[c],sum,1);
                                        sum=add(ma[d],sum,1);
                                        sum=add(ma[e],sum,0);
                                        ans=min(ans,sum);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

int w, h;
vector <vector <int>> ice, used;

int rec(int y, int x) {
    if (x < 0 || w <= x || y < 0 || h <= y) return 0;

    int res = 0;

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

    rep (i, 4) {
        int yy = y + dy[i], xx = x + dx[i];
        if (xx < 0 || w <= xx || yy < 0 || h <= yy) continue;
        if (!ice[yy][xx]) continue;
        if (used[yy][xx]) continue;
        used[yy][xx] = true;
        res = max(res, rec(yy, xx) + 1);
        used[yy][xx] = false;
    }

    return res;
}

int main() {
    while(cin >> w >> h, w) {
        ice  = vector <vector <int>> (w, vector <int> (h));
        rep (i, h) rep (j, w) cin >> ice[i][j];
        int ans = 0;
        rep (i, h) rep (j, w) {
            used = vector <vector <int>> (w, vector <int> (h, false));
            used[i][j] = true;
            ans = max(ans, rec(i, j));
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.NoSuchElementException;
import java.io.IOException;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
                Scanner sc = new Scanner(System.in);
		try {
                // get a integer
		int a = sc.nextInt();
		// get two integers separated with half-width break
		int[] b = new int[a];
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt() - 1;
		}
               
		int count = 0;
			
		for (int i = 0; i < a; i++) {
			if ( i < b[i] && (b[b[i]] == i) )
				count++;
		}
				
		System.out.println(count);
                
		}
        catch (NoSuchElementException e) {
             e.printStackTrace();
        }
 
	}
}

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

using namespace std;

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

    for(int i = 0;i < s.size()-1;i++) {
        if(s[i] == 'A' && s[i+1] == 'C')
        {
            cout<<"Yes"<<endl;

            return 0;
        }
    }

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


Measured memory_bytes: 888
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int G = sc.nextInt();
		int p[] = new int[D];
		int c[] = new int[D];
		for(int i = 0; i < D; i++) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		int ans = Integer.MAX_VALUE;
		out : for (int i = 0; i < (Math.pow(2, D)); i++) {
			int temp_ans = 0;
			boolean flag[] = new boolean[D];
			Arrays.fill(flag, false);
			int sum = 0;
			for (int j = 0; j < D; j++) {
				if ((1&i>>j) == 1) {
					sum += p[j] * (j + 1) * 100;
					sum += c[j];
					flag[j] = true;
					temp_ans += p[j];
				}
			}
			if(sum >= G) {
				ans = Math.min(ans, temp_ans);
				continue out;
			}
			in : for(int j = 0; j < D; j++) {
				if(!flag[D - 1 - j]) {
					for(int k = 0; k < p[D - 1 - j]; k++) {
						sum += 100 * (D - j);
						temp_ans++;
						if(sum >= G) {
							ans = Math.min(ans, temp_ans);
							break in;
						}
					}
					break in;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
def dfs(x,s,ans,n):
    if x == len(S):
        ans.append(eval(s))
        return
    dfs(x+1,s,ans,n)
    s = s[:x+n]+'+'+s[x+n:]
    dfs(x+1,s,ans,n+1)

S = input()
ans = [] 
n = 0
dfs(1,S,ans,n)
print(sum(ans))


Measured memory_bytes: 38512
N,A,B,C = (int(i) for i in input().split())  

l = []
for _ in range(N):
    l.append(int(input()))


#N,A,B,C =  5, 100,90,80 

#l = [98,40,30,21,80]

def to_bit(num,digit):
    bit = [0] * digit
    for i in range(digit):
        bit[i] = num % 4
        num = int((num - (num % 4)) / 4)
    return bit

min_cost = 5000

for i in range(4 ** N):
    bit = to_bit(i,len(l))
    #print(bit)
    cost = 0

    #A
    sum_ = 0
    counts = 0
    for j in range(len(l)):
        if bit[j] == 0:
            sum_ += l[j]
            counts += 1
    if counts > 0:
        cost += abs(sum_ - A) + 10 * (counts - 1)
    else:
        cost += 1000000

    #B
    sum_ = 0
    counts = 0
    for j in range(len(l)):
        if bit[j] == 1:
            sum_ += l[j]
            counts += 1
    if counts > 0:
        cost += abs(sum_ - B) + 10 * (counts - 1)
    else:
        cost += 1000000

    #C
    sum_ = 0
    counts = 0
    for j in range(len(l)):
        if bit[j] == 2:
            sum_ += l[j]
            counts += 1
    if counts > 0:
        cost += abs(sum_ - C) + 10 * (counts - 1)
    else:
        cost += 1000000

    if cost < min_cost:
        min_cost = cost
print(min_cost)


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
  ios_base::sync_with_stdio (false);
  cin.tie(NULL);

  ll N;
  cin >> N;

  vl a(N, 0);

  FOR(i, 0, N) cin >> a[i];

  vector<vvl> dp(N+1, vvl(N+1, vl(2, 0)));

  FOR(i, 0, N){
    dp[i][i][0] = a[i];
    dp[i][i][1] = -a[i];
  }

  FOR(l, 1, N) FOR(p, 0, N-l){

    ll i = p;
    ll j = p+l;
    // Taro
    if(dp[i+1][j][1]+a[i] >= dp[i][j-1][1]+a[j]){
      dp[i][j][0] = dp[i+1][j][1]+a[i];
    }
    else{
      dp[i][j][0] = dp[i][j-1][1]+a[j];
    }

    // Other
    if(dp[i+1][j][0]-a[i] <= dp[i][j-1][0]-a[j]){
      dp[i][j][1] = dp[i+1][j][0]-a[i];
    }
    else{
      dp[i][j][1] = dp[i][j-1][0]-a[j];
    }

  }

  cout << dp[0][N-1][0] << endl;

}


Measured memory_bytes: 493056
#create date: 2020-06-27 22:08

import sys
stdin = sys.stdin
from itertools import accumulate
from bisect import bisect_left, bisect_right

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, k = na()
    a = na()
    b = na()
    acum = list(accumulate(a))
    bcum = list(accumulate(b))
    i1, i2 = bisect_right(acum, k), 0
    ans = i1
    ssum = sum(a[:i1])
    #print(ans, i1, i2, ssum)
    while i1 > -1:
        if i2 != m:
            while ssum + b[i2] <= k:
                ssum += b[i2]
                i2 += 1
                if i2 == m:
                    break
        ans = max(ans, i1+i2)
        #print(ans, i1, i2)
        ssum -= a[i1-1]
        i1 -= 1
        
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 49148
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

int main()
{
    int n, m, n_pow = 0, ans = 0;
    cin >> n >> m;
    vector< vector<int> > s(m);
    vector<int> p(m);
    
    for (auto & ss:s)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j)
        {
            int tmp;
            cin >> tmp;
            ss.push_back(tmp-1);
        }
    }
    for (auto &tp : p) cin >> tp;
    n_pow = (1<<n);
     
    for (int i = 0; i < n_pow; ++i)
    {
        bitset<10> bs(i);
        int index = 0;
        bool fail = false;
        for (auto & ss:s) {
            int t = 0;
            for (auto & ts : ss) t+=(int)bs[ts];
            if (t%2 != p[index++]) {
                fail = true;
                break;
            }
        }
      	ans += !fail;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
l = []
for a in range(n-1):
        for b in range(a+1, n): 
                r = 0 
                for c in range(d):
                        r += (x[a][c] - x[b][c])**2
                l.append(math.sqrt(r))
print(sum(i.is_integer() for i in l))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int dp[100005];
vector<vector<int>> mp;

int search(int x)
{
   if(dp[x]!=0)return dp[x];
   if(mp[x].empty())return dp[x] = 1;
   rep(i,mp[x].size())
   {
      //cout<<mp[x][i]<<endl;
      dp[x] = max(dp[x],search(mp[x][i])+1);
   }
  return dp[x];
}

int main()
{
   memset(dp,0,100005*sizeof(int));
   int n;
   cin >> n;
   mp = vector<vector<int>>(n);
   int m;
   cin >> m;
   rep(i,m)
   {
      int foo,fooo;
      cin >> foo >> fooo;
      foo--;fooo--;
      mp[foo].push_back(fooo);
   }
   int ans = 0;
   rep(i,n){ans = max(ans,search(i));}
   //rep(i,n){cout<<dp[i]<<endl;}

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

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

int main(void) {
  int N;
  cin >> N;
  map<long long, long long> ma;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    ma[A]++;
  }
  int ans = 0;
  for (auto m : ma) {
    if ((m.second % 2) != 0) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>

void binarySearch(int,int);

int count=0;
int S[100000];

int main(){
   int n,q,i,j;
  int T[100000];

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
    if(T[i] != T[i-1] || i == 0){
    binarySearch(T[i],n);
    }
  }
  printf("%d\n",count);
  return 0;
}
void binarySearch(int key,int n){
  int left = 0;
  int right = n;
  int mid;
  
  while(left < right){
          mid = (left + right) / 2;
	  if(S[mid] == key){
            count++;
	    break;
	  }  
	  else if (key < S[mid])
	  right = mid;
          else
	  left = mid + 1;
  }
}



Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;


int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n){
    cin >> h[i];
  }
  sort(all(h));
  int ans = 1e9;
  rep(i,n){
    if(i+k-1 < n){
      ans = min(ans,abs(h[i]-h[i+k-1]));
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int n;
	double b = 0,a;
	cin >> n;
	for( int i = 0; i < n; i++ )
	{
		cin >> a;
		b += 1.0 / a;
	}
	cout << setprecision(16) << 1/b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a[10] = {0};
  int i;
  int j;
  
  for (i=0; i <= 9; i++)
    scanf("%d", &a[i]);
  
  
  for ( i = 0; i <= 8; i++ )
    {
      for( j = i+1; j <= 9; j++ )
	{
	  if ( a[i] < a[j] )
	    {
	      int temp = 0;
	      temp = a[j];
	      a[j] = a[i];
	      a[i] = temp;
	    }
	}
    }
  
  for (i=0; i <= 2; i++)
    printf("%d\n", a[i]);
  
  return 0;
  
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const int N = 2e5 + 10;
ll m, n;
 
ll sum[N];
ll a[N];
ll k;
 
map<ll, ll> ma;
// (sum[r] - sum[l -1]) % k == r - l + 1;
 
int main()
{
	scanf("%lld%lld", &n, &k);
	for (int i = 1; i <= n; i ++)
	{
		scanf("%lld", &a[i]);
		a[i] %= k;
		sum[i] = (sum[i - 1] + a[i]) % k;
	}
	for (int i = 1; i <= n; i ++)
	{
		sum[i] = ((sum[i] - i%k ) % k + k) % k;
	}
	ll ans = 0;
	ma[sum[0]] ++;
	for (int i = 1; i <= n; i ++)
	{
		if(i >= k) ma[sum[i - k]]--;
		ans += ma[sum[i]];
		ma[sum[i]] ++;
	}
	cout <<ans << endl;
}

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

int main() {
	string s; cin >> s;
	int k; cin >> k;
	for(int i=0;i<s.size();++i) {
		if(s[i]=='a') continue;
		int c='z'-s[i];
		if(c>=k) continue;
		s[i]='a'; k-=c+1;
	}
	if(k) s[s.size()-1]=((s[s.size()-1]-'a'+k)%26)+'a';
	cout << s << endl;
	
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  int Alice = 0;
  int Bob = 0;
  
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int i=0; i<N; i++){
    if(i%2 == 0)
      Alice += vec.at(i);
    else
      Bob += vec.at(i);
  }
  
  cout << Alice - Bob << endl;
  
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	m := make(map[int]int, n)
	for i := 0; i < n; i++ {
		m[a[i]]++
	}

	var t []int
	for _, v := range m {
		t = append(t, v)
	}
	sort.Ints(t)

	wcount := 0
	for i := 0; i < len(t); i++ {
		if len(t) > k {
			k++
			wcount += t[i]
			continue
		}
		fmt.Println(wcount)
		return
	}
}


Measured memory_bytes: 13952
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): pass
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n, mod = LI()
G = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = LI()
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

dp = [-1] * n
par = [-1] * n
def f(u):
    ret = 1
    for v in G[u]:
        if v == par[u]:
            continue
        par[v] = u
        ret = ret * f(v)
    dp[u] = ret
    if u: return ret + 1

f(0)
ans = [0] * n
ans[0] = dp[0]
par_acc = [1] * n
dp2 = [1] * n
q = deque([0])
while q:
    u = q.pop()
    ans[u] = dp[u] * dp2[u] % mod
    L1 = [1]
    L2 = []
    D = {}
    cnt = 0
    for v in G[u]:
        if par[u] == v:
            continue
        L1 += [dp[v] + 1]
        L2 += [dp[v] + 1]
        D[cnt] = v
        q += [v]
        cnt += 1
    L2 += [1]
    if len(L1) > 2:
        for i in range(len(L1) - 2):
            L1[i + 2] = L1[i + 2] * L1[i + 1] % mod
            L2[-i - 3] = L2[-i - 3] * L2[-i - 2] % mod
    for j in D:
        dp2[D[j]] = (L1[j] * L2[j + 1] * dp2[u] + 1) % mod

print(*ans, sep="\n")




Measured memory_bytes: 163624
N,K=map(int,input().split())
*X,=map(int,input().split())

import bisect

i=bisect.bisect_left(X,0)
L=max(0, bisect.bisect_right(X,0)-K)
R=min(N-1, bisect.bisect_left(X,0)+K-1)

ans=float('inf')

for i in range(L,R-K+2):
    t=0
    l=X[i]
    r=X[i+K-1]
    if r<=0:
        t=abs(l)
    elif 0<=l:
        t=r
    else:
        t=min(abs(l),r)*2+max(abs(l),r) 
    # print(X[i:i+K],t)
    ans=min(ans,t)
print(ans)

Measured memory_bytes: 20336
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  Cinint(k);
  Cinint(a);
  Cinint(b);
  bool flag = true;
  rep1(i, 1001) {
    if (i%k == 0) {
      if ((a <= i) && (i <= b)) {
        cout << "OK" << endl;
        flag = false;
        break;
      }
    }
  }
  if (flag) {
    cout << "NG" << endl;
  }
}


Measured memory_bytes: 3512
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S;
  long long K;
  cin>>S>>K;
  int len=S.size();
  if(len==1){
    cout<<S<<endl;
    return 0;
  }
  int num;
  int count=0;
  for(int i=0;i<len;i++){
    if(S[i]=='1'){
      count++;
    }else{
      num=i;
      break;
    }
  }
  if(K<=count){
    cout<<1<<endl;
  }else{
    cout<<S[num]<<endl;
  }
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int count4 = 0;
    int count2 = 0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a%4 == 0){
            count4 ++;
        }
        else if(a%2==0){
            count2++;
        }
    }
    if(count4 >=n/2 ){
        cout << "Yes" << endl;

    }
    else if(n-count4*2<=count2){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    ll n; cin >> n;
    ll ans = 0;
    FOR(i, 0, n)ans += ll(i + 1) * (n - i);
    FOR(i, 0, n - 1) {
        ll a, b; cin >> a >> b;
        if (a > b)swap(a, b);
        ans -= a * (n - b + 1);
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A[3], B[3], res;
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<3;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(res=0;res<1000;res++){
    if(A[0]%2 || A[1]%2 || A[2]%2){
      break;
    }
    {
      int KL2GvlyY;
      for(KL2GvlyY=0;KL2GvlyY<(2) + 1;KL2GvlyY++){
        B[KL2GvlyY] = A[(KL2GvlyY - (0) + (1))%3]/2 + A[(KL2GvlyY - (0) + (2))%3]/2;
      }
    }
    {
      int Q5VJL1cS;
      for(Q5VJL1cS=0;Q5VJL1cS<(2) + 1;Q5VJL1cS++){
        A[Q5VJL1cS] = B[Q5VJL1cS];
      }
    }
  }
  if(res==1000){
    res = -1;
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170506-1 [beta]

// --- original code ---
// {
//   int A[3], B[3], res;
//   rd(A(3));
//   rep(res,1000){
//     if(A[0]%2 || A[1]%2 || A[2]%2) break;
//     B[0..2] = A[(1..)%3]/2 + A[(2..)%3]/2;
//     A[0..2] = B[0..];
//   }
//   if(res==1000) res = -1;
//   wt(res);
// }


Measured memory_bytes: 256
package main

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

func main() {
	sc := newInputScanner(true, 1024)
	N, A, B := sc.nextInt(), sc.nextInt(), sc.nextInt()
	distance := B - A
	var answer int
	if distance%2 == 0 {
		answer = distance / 2
	} else {
		if A-1 > N-B {
			answer = N - B
		} else {
			answer = A - 1
		}
		answer += (B-A)/2 + 1
	}
	fmt.Println(answer)
}

type inputScanner struct {
	*bufio.Scanner
}

func newInputScanner(enabledScanWords bool, sizeInKB int) *inputScanner {
	scanner := bufio.NewScanner(os.Stdin)
	if enabledScanWords {
		scanner.Split(bufio.ScanWords)
	}
	capacity := sizeInKB * 1024
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)
	return &inputScanner{
		Scanner: scanner,
	}
}

func (inputSc *inputScanner) nextInt() int {
	i, e := strconv.Atoi(inputSc.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextUInt64() uint64 {
	i, e := strconv.ParseUint(inputSc.nextStr(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextStr() string {
	inputSc.Scan()
	return inputSc.Text()
}

type debuggable struct {
}

const (
	DEBUG_ON = false
)

func (d *debuggable) debug(f func()) {
	if DEBUG_ON {
		f()
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;

int main(){
  string s; cin >> s;
  cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << endl;
  return 0;
}


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

int sum(int n) {
    int ans = 0;
    while (n) {
        ans += n%10;
        n /= 10;
    }
    return ans;
}

int main() {

    int n;  cin >> n;
    int ans = 1e9;
    for (int x = 1; x < n; x++) ans = min(ans, sum(x) + sum(n-x));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def DFS(S):
    word_list = ["dreamer", "dream", "eraser", "erase"]
    stack = ["dream", "dreamer", "erase", "eraser"]
    while stack:
        word = stack.pop()
        if word == S[0]:
            return "YES"
        for i in word_list:
            next_word = word + i
            check = S[0][:len(word + i)]
            if next_word != check:
                continue
            if next_word == check:
                stack.append(next_word)
    return "NO"
 
 
 
 
 
 
if __name__ == "__main__":
    S = [input()]
    print(DFS(S))

Measured memory_bytes: 166464
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for(int i = 0; i < n - 1; i++){
    sum += v[i];
  }
  if(sum > v[n - 1]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256