akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans;
  if (k <= a) {
    ans = k;
  }
  else if (a < k && k <= a+b) {
    ans = a;
  }
  else if (a+b <= k && k <= a+b+c) {
    ans = a - (k-(a+b));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  if(N % 1000 == 0) {
    cout << 0 << endl;
  }
  else {
    cout << (N / 1000 * 1000 + 1000) - N;
  }
}

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

int n,a[100005];
signed main() {
	cin>>n;
	rep(i,n)cin>>a[i];
	stack<int>st;
	int k=0,ans=1;
	rep(i,n){
		if(a[i]<k*2+1){
			ans*=(k+1);
			ans%=mod;
		}else {
			st.push(a[i]);
			k++;
		}
	}
	for(int i=1;i<=st.size();i++){
		ans*=i;
		ans%=mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int N, K, tmpd, tmp;
    cin >> N >> K;
    vector<int> A(N, 0);
    for (int count = 0; count < K; count++)
    {
        cin >> tmpd;
        for (int index = 0; index < tmpd; index++)
        {
            cin >> tmp;
            if (A.at(tmp - 1) == 0)
            {
                A.at(tmp - 1) = 1;
            }
        }
    }
    int answer = 0;
    for (int x : A)
    {
        if (x == 1)
        {
            answer++;
        }
    }
    N -= answer;
    cout << N << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	if(n%2 == 0) cout << n << endl;
	else cout << n*2 << endl;
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;

    
    string s;
    cin>>s;
    if(s.back() == 's') cout<<s<<"es\n";
    else cout<<s<<"s\n";
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int table[8];


int main(){

	for(int i = 0; i < 8; i++){

		table[i] = 0;
	}

	int tmp;
	int add = 0;

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d",&tmp);
		if(tmp >= 3200){
			add++;
			continue;
		}

		table[tmp/400]++;
	}

	int count = 0;
	for(int i = 0; i < 8; i++){
		if(table[i] > 0){

			count++;
		}
	}


	printf("%d %d\n",max(1,count),count+add);

	return 0;
}


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

int main() {

	for (int i = 1; i < 10; ++i)
	{
		for (int j = 1; j < 10; ++j)
		{
			cout << i << "x" << j << "=" << i * j << std::endl;
		}

	}

	return 0;
}


Measured memory_bytes: 3068
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		ArrayList<ArrayList<Edge>> g = new ArrayList<>();
		ArrayList<Edge> rev = new ArrayList<>();
		for (int i = 0; i < N; ++i) {
			g.add(new ArrayList<>());
		}
		for (int i = 0; i < M; ++i) {
			int A = Integer.parseInt(sc.next()) - 1;
			int B = Integer.parseInt(sc.next()) - 1;
			int C = Integer.parseInt(sc.next());
			g.get(A).add(new Edge(B, C));
			if (B == N - 1) rev.add(new Edge(A, C));
		}
		PriorityQueue<State> q = new PriorityQueue<>();
		q.add(new State(0, 0));
		int[] time = new int[N];
		Arrays.fill(time, 2_000_000_000);
		boolean[] visited = new boolean[N];
		visited[N - 1] = true;
		time[0] = 0;
		while (!q.isEmpty()) {
			State st = q.poll();
			if (visited[st.pos]) continue;
			visited[st.pos] = true;
			for (Edge e : g.get(st.pos)) {
				if (e.time < st.time) continue;
				if (time[e.next] <= e.time) continue;
				time[e.next] = e.time;
				q.add(new State(e.time, e.next));
			}
		}
		int ans = -1;
		for (Edge e : rev) {
			if (time[e.next] <= e.time) {
				ans = Math.max(ans, e.time);
			}
		}
		System.out.println(ans);
	}

	static class State implements Comparable<State> {
		int time, pos;

		public State(int time, int pos) {
			this.time = time;
			this.pos = pos;
		}

		public int compareTo(State o) {
			return Integer.compare(time, o.time);
		}
	}

	static class Edge {
		int next, time;

		public Edge(int next, int time) {
			this.next = next;
			this.time = time;
		}
	}

}

Measured memory_bytes: 124556
h1,h2=map(int,input().split())
k1,k2=map(int,input().split())
a,b,c,d=map(int,input().split())
h=h1*a+h2*b+h1//10*c+h2//20*d
k=k1*a+k2*b+k1//10*c+k2//20*d
if h>k:
    print('hiroshi')
elif k>h:
    print('kenjiro')
else:
    print('even')



Measured memory_bytes: 5596
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   int d[N];
   for (int i = 0; i < N; i++) cin >> d[i];
   sort(d, d + N);
   int d1 = d[N / 2 - 1];
   int d2 = d[N / 2];
   cout << d2 - d1 << endl;
   return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { ll A, B, N;
  cin >> A >> B >> N;
  ll a = min(B - 1, N);
  cout << floor(A * a / B) - A * floor(a / B) << endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
    #define mp make_pair
    #define F first
    #define S second
    #define mem(a) memset(a, 0, sizeof(a))
    #define memm(a) memset(a, -1, sizeof(a))
    #define INF 0x3f3f3f3f
    #define maxn 1000005
    using namespace std;
    typedef long long LL;
    typedef pair <int,int> PP;
    LL n,k;
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        while(cin >> n >> k){
            LL ans=0;
            if(k==0){cout << n*n << endl;continue;}
            for(LL i=k+1;i<=n;i++){
                ans+=n/i*(i-k)+max(1ll*0,n%i-k+1);
            }
            cout << ans << endl;
        }
        return 0;
    }

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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> a;
	a.resize(n);

	vector<int> sum;
	sum.resize(n);

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

		--a[i];

		++sum[a[i]];
	}

	long long ans = 0;

	for(int i = 0; i < n; ++i) {
		ans += 1LL * sum[i] * (sum[i] - 1) / 2;
	}

	for(int i = 0; i < n; ++i) {
		long long tmp = ans;

		tmp -= 1LL * sum[a[i]] * (sum[a[i]] - 1) / 2;
		tmp += 1LL * (sum[a[i]] - 1) * (sum[a[i]] - 2) / 2;

		cout << tmp << '\n';
	}

	return 0;
}


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


int A, B, C;


void input() {
    cin >> A >> B >> C;
}


int main() {
    input();
    vector<int> w{A, B, C};
    sort(w.rbegin(), w.rend());
    int ans = w[0] * 10 + w[1] + w[2];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N, M; cin >> N >> M;
    vector<ll> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a.begin(), a.end());

    vector<pair<ll, ll>> cb(M);
    for(int i=0; i<M; i++) cin >> cb[i].second >> cb[i].first;
    sort(cb.begin(), cb.end(), greater<pair<ll,ll>>());

    // for(int i=0; i<cb.size(); i++) cout << cb[i].second << " ";
    // cout << endl;

    vector<ll> can;
    int id = 0;
    
    for(int i=0; i<cb.size(); i++){
        for(int j=0; j<cb[i].second; j++) can.push_back(cb[i].first);
        id += cb[i].second;
        if(id >= N) break;
    }
    
    // for(int i=0; i<can.size(); i++) cout << can[i] << " ";
    // cout << endl;

    ll ans = 0;
    id = 0;
    for(int i=0; i<N; i++){
        if(id < can.size() && a[i] < can[id]) { ans += can[id]; id++; }
        else ans += a[i];
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 4724
#include <iostream>
using namespace std;
int main(void){
    int n,m,cnt = 0;
    cin >> n;
    m = n;
    while(n > 0){
        cnt += n % 10;
        n /= 10;
    }
    if(m % cnt == 0){
     cout << "Yes" << endl;   
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

int a[100];
int b[100];
long long dp[100001];

int main() {
    int n, w, i, j;
    long long ans = 0;
    
    scanf("%d %d", &n, &w);
    
    for (i = 0; i < n; i++) scanf("%d %d", &a[i], &b[i]);
    
    for (i = 0; i < n; i++) {
        for (j = w; j >= 0; j--) {
            if (j + a[i] <= w) dp[j + a[i]] = max(dp[j + a[i]], dp[j] + b[i]);
        }
    }
    
    for (i = 0; i <= w; i++) ans = max(ans, dp[i]);
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 896
import sys
n = input()
a = [[[0]*10 for i in range(3)] for i in range(4)]
for i in xrange(n):
	b = map(int, raw_input().split())
	a[b[0]-1][b[1]-1][b[2]-1] += b[3]

for i in range(4):
	for j in range(3):
		for k in range(10):
			sys.stdout.write(' %s' % a[i][j][k])
		print ""
	if i != 3:
		print '#'*20

Measured memory_bytes: 6400
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
        int n, q;
        scanf("%d%d", &n, &q);
        n = 2 * n;
        vector<long long> a(n), b(n);
        for (int i = 0; i < n; i ++) scanf("%lld", &a[i]);
        for (int i = 0; i < n; i ++) scanf("%lld", &b[i]);
        multiset<long long> positive, negative;
        long long psum = 0, nsum = 0;
        for (int i = 0; i < n; i ++) {
                if (i == 0 || i == n - 1) psum += a[i];
                else {
                        long long c = a[i] - b[i];
                        if (c >= 0) positive.insert(c), psum += a[i];
                        else negative.insert(- c), nsum += b[i];
                }
        }
        while (q --) {
                long long p, x, y;
                scanf("%lld%lld%lld", &p, &x, &y); p --;
                if (p == 0 || p == n - 1) psum -= a[p], psum += x;
                else {
                        long long c = a[p] - b[p];
                        if (c >= 0) positive.erase(positive.find(c)), psum -= a[p];
                        else negative.erase(negative.find(-c)), nsum -= b[p];
                        long long z = x - y;
                        if (z >= 0) positive.insert(z), psum += x;
                        else negative.insert(-z), nsum += y;
                }
                a[p] = x, b[p] = y;
                long long ans;
                if (positive.size() % 2 == 0) ans = psum + nsum;
                else ans = psum + nsum - min(*positive.begin(), *negative.begin());
                printf("%lld\n", ans);
        }
        return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 2004;
int l[N][N],r[N][N],u[N][N],d[N][N];

int main(){
	fast_io();
	bool g[N][N] = {};
	int h,w;
	scanf("%d%d",&h,&w);
	fu(i,1,h){
		fu(j,1,w){
			char c;
			scanf(" %c",&c);
			g[i][j] = c == '.';
		}
	}
	fu(i,1,h){
		fu(j,1,w){
			if(!g[i][j])l[i][j] = 0;
			else l[i][j] = l[i][j-1] + 1;
		}
	}
	fu(i,1,h){
		fd(j,w,1){
			if(!g[i][j])r[i][j] = 0;
			else r[i][j] = r[i][j+1] + 1;
		}
	}
	fu(j,1,w){
		fu(i,1,h){
			if(!g[i][j])u[i][j] = 0;
			else u[i][j] = u[i-1][j] + 1;
		}
	}
	fu(j,1,w){
		fd(i,h,1){
			if(!g[i][j])d[i][j] = 0;
			else d[i][j] = d[i+1][j] + 1;
		}
	}
	int ans = 0;
	fu(i,1,h){
		fu(j,1,w){
			ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 66944
a = []
b = []
n,m = gets.chomp.split(" ").map{|x| x.to_i}
for i in 1..n do
  a[i-1] = gets.chomp.split(" ").map{|x| x.to_i}
end
for j in 1..m do
  b[j-1] = gets.chomp.to_i
end

for i in 1..n do
  c = 0
  for j in 1..m do
    c += a[i-1][j-1] * b[j-1]
  end
  printf("%d\n",c)
end


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

int main() {
  char grid[52][52];
  for (int i=0 ; i<52 ; i++) {
    for (int j=0 ; j<52 ; j++) {
      grid[i][j] = '.';
    }
  }
  int H, W;
  cin >> H >> W;
  for (int i=1; i<=H ; i++) {
    string str;
    cin >> str;
    for (int j=1 ; j<=W ; j++) {
      grid[i][j] = str[j-1];
    }
  }
  int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1,0}};
  for (int i=1 ; i<=H ; i++) {
    for (int j=1 ; j<=W ; j++) {
      if (grid[i][j] == '#') {
        bool lonely = true;
        for (int k=0 ; k<4 ; k++) {
          int dh = dir[k][0];
          int dw = dir[k][1];
          if (grid[i+dh][j+dw] == '#') lonely = false;
        }
        if (lonely) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}


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

const int N = 1e5 + 10;
int n, sg[N];
vector<int> nxt[N];

void dfs(int x, int fa) {
    for (int i = 0; i < nxt[x].size(); i++) {
        int y = nxt[x][i];
        if (y == fa) continue;
        dfs(y, x);
        sg[x] ^= (sg[y] + 1);
    }
}

int main() {
    cin >> n;
    rep(i, 1, n - 1) {
        int x, y; scanf("%d%d", &x, &y);
        nxt[x].push_back(y), nxt[y].push_back(x);
    }
    dfs(1, 0);
    puts(sg[1] ? "Alice" : "Bob");
    return 0;
}


Measured memory_bytes: 17196
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

struct Connection {
	vector<int>friends;
	vector<int>block;
	vector<int>friendable;
	Connection() {};
};

int main() {

	ll X;
	cin >> X;

	ll fhc = X / 500;
	X -= 500 * fhc;
	ll fc = X / 5;

	ll ans = fhc * 1000 + fc * 5;
	cout << ans << endl;
}



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

#define MOD 1000000007LL

using namespace std;

long long fact(long long n){
    long long ret = 1;
    for(long long i = 1; i <= n; i++){
        ret *= i;
        ret %= MOD;
    }
    return ret;
}

long long exp(long long b, long long e){
    if(e == 0) return 1;
    if(e == 1) return b;
    long long ret = exp(b, e / 2);
    ret *= ret;
    ret %= MOD;
    if(e % 2 == 1) ret *= b;
    return ret % MOD;
}

long long inv(long long n){
    return exp(n, MOD - 2);
}

int main(void){
    // cout << fact(999999) << endl;
    int X, Y;
    cin >> X >> Y;
    if((X + Y) % 3 != 0 ||
        Y > 2 * X || X > 2 * Y){
        cout << 0 << endl;
        return 0;
    }
    int s = X + Y;
    int d = X - Y;
    long long x = (s / 3 + d) / 2;
    long long y = (s / 3 - d) / 2;
    long long ans = fact(x + y);
    ans *= inv(fact(x));
    ans %= MOD;
    ans *= inv(fact(y));
    ans %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define endl "\n"
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef long long ll;
#define MOD 1000000007;
 
int main() 
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    double n; cin >> n;
    ll ans = 0;
    for(double i = 1; i <=n ; i++){
        ll k = i/2 *(floor(double(n/i)))* (floor((double)(1+n/i)));
        ans+=k;
    }
    cout << ans << endl;
    
    
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s;cin >> s;
    bool a = true;
    bool b = true;
    bool c = true;
    bool d = true;
    for(auto ss : s){
        if(ss == 'N') a = false;
        if(ss == 'W') b = false;
        if(ss == 'S') c = false;
        if(ss == 'E') d = false;
    }
    cout << ((a == c && b == d) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
n, h = map(int, input().split())
dat = []
dat1 = []
dat2 = []
for i in range(n):
    a,b = map(int, input().split())
    dat.append( [a,b,i])
    dat1.append( [a, i] )
    dat2.append( [b, i] )

dat1.sort(reverse=True)
dat2.sort(reverse=True)

#print(dat1)
#print(dat2)

normax = dat1[0][0]
count = 0
for i in range(n):
    #print("special" + str(dat2[i][0]))
    if dat2[i][0] > normax:
        count = count + 1
        h = h - dat2[i][0]
    if h <= 0:
        break
        #print("special" + str(dat2[i][0]))
#print(h)
if h > 0:
    import math
    count = count + math.ceil(h / normax)
print(count)

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<pair<int, int>> ab(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    
    ab.at(i) = make_pair(b, a);
  }
  sort(ab.begin(), ab.end());
  
  int ans = 0;
  int last = 0;
  for (int i = 0; i < M; i++) {
    int a = ab.at(i).second;
    int b = ab.at(i).first;
    
    if (a >= last) {
      ans++;
      last = b;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M/* your task */; }
int h2(int key){ return 1+(key%(M-1));/* your task */; }

int find(char str[]){
  /* your task */
  long long key,i=0,h;

  key=getKey(str);

  while(1){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0) return 0;
    i++;
  }
  return 0;
}

int insert(char str[]){
  /* your task */
  long long key, i=0, h;

  key=getKey(str);

  while(1){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h], str);
      return 0;
    }
    i++;
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
#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 w = in(), a = in(), b = in();
	cout << (
		a + w < b ? b - (a + w)
		: b + w < a ? a - (b + w)
		: 0
		) << endl;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<i32> = read_as_vec();
    let (a, b, c) = (line[0], line[1], line[2]);

    if (a < c && c < b) || (b < c && c < a){
        println!("Yes");
    }else{
        println!("No");
    }
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

signed main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int ans = 0;
    X -= Z;
    while(X > 0) {
        if(X >= Y + Z) {
            ans++;
        }
        X -= Y + Z;
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, V, B, W, T; cin >> A >> V >> B >> W >> T;
    string ans = "NO";
    if (W < V){
        if (abs(A - B) <= (V - W) * T){ans = "YES";}
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3624
N = int(input())
S = ['']

res = []

for _ in range(N):
    A = int(input())
    s = []
    for _ in range(A):
        s.append(list(map(int, input().split())))
    S.append(s)

allp = 2**N - 1

for i in range(allp, -1, -1):
    pat = bin(i).replace('0b', '')
    pat = pat.zfill(N)
    h_list = []
    l_list = []
    for (i, p) in enumerate(pat):
        t = i + 1
        if p == '1':
            if t in l_list:
                break
            h_list.append(t)
            for s in S[t]:
                if s[1] == 1:
                    if s[0] in l_list:
                        break
                    h_list.append(s[0])
                else:
                    if s[0] in h_list:
                        break
                    l_list.append(s[0])
            else:
                continue
            break
        else:
            if t in h_list:
                break
            l_list.append(t)
            # for s in S[t]:
            #     if s[1] == 1:
            #         if s[0] in h_list:
            #             break
            #         l_list.append(s[0])
            #     else:
            #         if s[0] in l_list:
            #             break
            #         h_list.append(s[0])
            # else:
            #     continue
            # break
    else:
        res.append(pat)

maxA = 0
for r in res:
    maxA = max(maxA, r.count('1'))
print(maxA)


Measured memory_bytes: 54768
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

constexpr LL mod = 1e9 + 7;

int main() {

    LL N;
    cin >> N;

    vector<LL> p(4);
    for (int i = 0; i < 4; i++) cin >> p[i];

    vector<LL> t(4);
    for (int i = 0; i < 4; i++) cin >> t[i];

    LL ans = LONG_LONG_MAX;

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= N; k++) {
                LL money = p[0] * i + p[1] * j + p[2] * k;
                LL tea = i * t[0] + j * t[1] + k * t[2];
                if (tea < N) {
                    LL buy = (N - tea);
                    money += ((buy + t[3] - 1) / t[3]) * p[3];
                }
                ans = min(ans, money);
            }
        }
    }

    cout << ans << endl;

}


































Measured memory_bytes: 3104
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  long long n, s;
  cin>>n>>s;
  long long a[n];
  REP(i, n) cin>>a[i];
  vector<vector<long long>> dp(n, vector<long long>(s+1, 0));
  REP(i, n){
    if(i == 0){
      dp[i][0] = 2;
      if(a[i] <= s) dp[i][a[i]] = 1;
      continue;
    }
    REP(d, s+1){
      dp[i][d] = mod(dp[i-1][d] * 2);
      if(d-a[i] >= 0){
        dp[i][d] += dp[i-1][d-a[i]];
        dp[i][d] = mod(dp[i][d]);
      }
    }
  }
  long long ans = dp[n-1][s];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 73644
# AOJ_osaki.py
def calc_imos(one_day):
    day = []
    cum_sum = 0
    for i in one_day:
        cum_sum += i
        day.append(cum_sum)
    return max(day)

def calc_time(time):
    h,m,s = map(int,time.split(":")) 
    return h*60*60 + m*60 + s

while True:
    N = int(input())
    if N==0:break
    one_day = [0]*(24*60*60+1) # 秒数で1日を管理する
    for i in range(N):
        start, end = input().split()
        # 時間を1日の秒数に直す
        # one_dayに累積和を登録していく
        start = calc_time(start)
        end = calc_time(end)
        one_day[start+1] += 1
        one_day[end+1] -= 1
    print(calc_imos(one_day))
# 累積和を計算して本数を計算する


Measured memory_bytes: 10192
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n;
long long ans;
long long a[211111];

int main(){
  ios_base::sync_with_stdio(false);
  
  a[0] = 0; 

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

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

  sort(a, a+n+1); 
  
  /* 
  for(int i=0;i<=n;i++){
    cout << a[i] << " ";
  }
  cout << endl;
  */

  for(int i=0;i<=n;i++){
    int cnt = i + 1;
    while(a[i] == a[cnt] && cnt <= n){
      //cout << i << " " << cnt << endl;
      cnt++;
    }
    long long m = cnt - i;
    ans += ((m-1)*m)/2;
    i = cnt - 1;
  }

  cout << ans << endl; 

  return 0;
}



Measured memory_bytes: 1792
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <utility>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
const int N=1e5+10;
int main(){
    int n,m,now=0,ans=0,last=N;
    pi a[N];
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&a[i].F,&a[i].S);
        a[i].S--;
    }
    sort(a,a+m);
    for(int i=1;i<n;i++){
        while(now<m){
            if(a[now].F<=i){
                last=min(last,a[now].S);
                now++;
            }
            else break;
        }
        if(last==i){
            last=N;
            ans++;
        }
        //if(now>=m)break;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 896
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	int n;
	cin >> n;

	vector<string> S(n);
	FOR(i, 0, n) cin >> S[i];
	sort(S[0].begin(), S[0].end());

	if (n == 1) {
		cout << S[0];
		return 0;
	}

	string ans = "";

	FOR(i, 0, S[0].length()) {
		FOR(j, 1, n) {

			if (S[j].find_first_of(S[0][i]) != string::npos) {
				S[j].erase(S[j].find_first_of(S[0][i]), 1);
			}
			else break;

			if (j == n - 1) ans += S[0][i];
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    ans=0
    for _ in range(N):
        l, r = MI()
        ans += r - l + 1
    print(ans)
if __name__ == '__main__':
    main()

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

using namespace std;
int main(){
	char c;
	int y=0,m=0,d=0;
	
	cin >> c; y=y*10+(c-'0');
	cin >> c; y=y*10+(c-'0');
	cin >> c; y=y*10+(c-'0');
	cin >> c; y=y*10+(c-'0');
	cin >> c;
	cin >> c; m=m*10+(c-'0');
	cin >> c; m=m*10+(c-'0');
	cin >> c;
	cin >> c; d=d*10+(c-'0');
	cin >> c; d=d*10+(c-'0');
	if (y<2019 || (y==2019 && m<4) || (y==2019 && m==4 && d<=30)) cout<<"Heisei";
	else cout<<"TBD";
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
using namespace std;
int main()
{
	string a;
	int k;
	cin >> a;
	cin >> k;
	int t = a.length();
	int cnt = 0;
	for (int i = 0; i < t; i++)
	{
		if (a[i] != '1')
		{
			cout << a[i];
			return 0;
		}
		else
			cnt++;
		if (cnt == k) {
			puts("1");
			return 0;
		}
	}
}

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

int main()
{
  int n, k;
  string s;
  cin >> n >> k >> s;
  int i;
  for(i = 0; i < n; i++)
  {
    if(i != k-1)cout << s.at(i);
    else cout << (char)(s.at(i) + 32);
  }
  cout << endl;
}

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

int n;
int v[29],c[29];
int ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&v[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);
	}
	for(int i=1;i<=n;i++){
		if(v[i]-c[i]>0){
			ans+=v[i]-c[i];
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}


signed main()
{
	//IOS();
	int X,K;
	cin>>X>>K;
	vector<int>r(K+1,0);
	r[0]=0;
	int now = 0;
	vector<int>s(K+1,0);
	vector<int>ma(K+1);
	vector<int>mas(K+1,0);
	vector<int>mi(K+1);
	vector<int>mis(K+1,0);
	ma[0]=X;
	mi[0]=0;
	for(int i = 0;i < K;i++){
		cin>>r[i+1];
		if(i%2){
			ma[i+1]=min(X,ma[i]+r[i+1]-r[i]);
			mi[i+1]=min(X,mi[i]+r[i+1]-r[i]);
		}else{
			ma[i+1]=max(0ll,ma[i]-(r[i+1]-r[i]));
			mi[i+1]=max(0ll,mi[i]-(r[i+1]-r[i]));
		}
		if(i%2)s[i+1]+=(r[i+1]-now)*-1;
		else s[i+1]+=(r[i+1]-now);
		now=r[i+1];
		s[i+1]+=s[i];
		chmax(mas[i+1],max(mas[i],s[i+1]));
		chmin(mis[i+1],min(mis[i],s[i+1]));
	}
	int Q;
	cin>>Q;
	vector<int>t(Q),a(Q);
	rep(i,0,Q)cin>>t[i]>>a[i];
	for(int i = 0;i < Q;i++){
		auto itr = upper_bound(all(r),t[i])-r.begin();
		if(a[i]<=mas[itr-1]){
			cout<<min(X,max(0ll,mi[itr-1]+(t[i]-r[itr-1])*(int)pow(-1,itr%2)))<<endl;
		}else if(X-a[i]<=abs(mis[itr-1])){
			cout<<min(X,max(0ll,ma[itr-1]+(t[i]-r[itr-1])*(int)pow(-1,itr%2)))<<endl;
		}else{
			cout<<min(X,max(0ll,a[i]-s[itr-1]+(t[i]-r[itr-1])*(int)pow(-1,itr%2)))<<endl;
		}
		
	}
}


Measured memory_bytes: 7424
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

int main()
{
	int N;
	cin >> N;
	unordered_map<string, int> vote;
	rep(i, N)
	{
		string s;
		cin >> s;
		auto it = vote.find(s);
		if (it == vote.end())
		{
			vote.insert(pair<string, int>(s, 1));
		}
		else
		{
			(*it).second++;
		}
	}
	vector<string> ans;
	int m = 0;
	for (auto it : vote)
	{
		if (it.second == m)
		{
			ans.push_back(it.first);
		}
		else if (it.second > m)
		{
			ans.clear();
			ans.push_back(it.first);
			m = it.second;
		}
	}

	sort(all(ans));

	for (auto s : ans)
	{
		cout << s << endl;
	}
	return 0;
}


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

#define ll long long
#define mx  100005
#define mod 1000000009
#define lim 10000000
#define inf 1000000000
#define N 18

using namespace std;
map<int,ll>mp;

int main(){
	ios_base::sync_with_stdio(false);
     int n,m;cin>>n>>m;
     ll psum=0;
     mp[0]++;

     for(int i=1;i<=n;i++)
	{
		int can;cin>>can;
		psum+=can;
		int rem=int(psum%m);
		mp[rem]++;
	}
	ll ans=0;
	for(auto u : mp)
	{
		     ll er=u.second;
			ans+=((er-1)*er/2);
	}

	cout<<ans<<"\n";

     return 0;
}





Measured memory_bytes: 4224
def main():
    N = int(input())
    S = input()
    if len(S)!=N or len(S)==1:
        print("No")
    else:
        index = len(S)/2
        half1 = S[:int(index)]
#        print("1:",half1)
        half2 = S[int(index):]
#        print("2:",half2)
        if half1 == half2:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

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

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

using ll=long long;

int main(){
   int s,w;
   cin>>s>>w;
   if(w>=s)cout<<"unsafe";
   else cout<<"safe";
   cout<<endl;
   return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, A, B, C;
int kad[8], use[1 << 8];

int cal(int n, int m) {
    int ret = -10, sum = 0;
    for(int i = 0; i < N; ++i) {
        if((m >> i) & 1) {
            sum += kad[i];
            ret += 10;
        }
    }
    ret += abs(n - sum);
    return ret;
}

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

    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; ++i) cin >> kad[i];
    int res = INF;
    for(int i = 1; i < (1 << N); ++i) for(int j = 1; j < (1 << N); ++j) for(int k = 1; k < (1 << N); ++k) {
        if((i & j) || (i & k) || (j & k)) continue;
        int sum = 0;
        sum += cal(A, i);
        sum += cal(B, j);
        sum += cal(C, k);
        chmin(res, sum);
    }
    cout << res << endl;
    return 0;
} 

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

using namespace std;

void print(vector<int> &a)
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<(i==a.size()-1?'\n':' ');
    }
}

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

    vector<int> arr(n);
    for(int i=0;i<n;i++) arr[i]=i+1;

    do
    {
        print(arr);
    }while(next_permutation(arr.begin(),arr.end()));

    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,ans=0,b=0;
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2) >> n;
    sort(a.begin(), a.end());
    int k=n/a.at(2);
    for (int i=0;i<k+1;i++){
        while (a.at(2)*i+a.at(1)*b<=n){
            if ((n-(a.at(2)*i+a.at(1)*b))%a.at(0)==0) ans++;
            b++;
        }
        b=0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256