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

const int MAX_N = 300000;

// int left[MAX_N], right[MAX_N], cost[MAX_N];

int main() {
	int N;
	std::string S;
	std::cin >> N >> S;

	// std::vector<int> left(MAX_N), right(MAX_N), cost(MAX_N);
	static int left[MAX_N], right[MAX_N], cost[MAX_N];
	int cnt;

	cnt = 0;
	for(int i = 0; i < N; ++i) {
		left[i] = cnt;
		if(S[i] == 'W') ++cnt;
	}

	cnt = 0;
	for(int i = N - 1; i >= 0; --i) {
		right[i] = cnt;
		cost[i] = left[i] + right[i];
		if(S[i] == 'E') ++cnt;
	}

	// std::sort(cost.begin(), cost.begin() + N);
	std::sort(cost, cost + N);

	std::cout << cost[0] << std::endl;
 }

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

int main () {
    int N ;
    string S ;
    cin >> N ;
    cin >> S ;
    rep(i,S.size()){
        S.at(i) = (S.at(i) - 'A' + N )%26 + 'A' ;
    }
    cout << S << endl;
}



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

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

long N, W, w[110], v[110];
long DP[110][110000] = {};

int main() {
	cin >> N >> W;
	
	for(int i = 0; i < N; i++){
		cin >> w[i] >> v[i];
	}
	
	for(int i = 0; i < N; i++){
		long w_tmp = w[i];
		long v_tmp = v[i];
		for(int j = 0; j < W+1; j++){
			chmax(DP[i+1][j], DP[i][j]);
			if(j - w_tmp >= 0) {
				chmax(DP[i+1][j], DP[i][j - w_tmp] + v_tmp);
			}
		}
	}
	cout << DP[N][W] << endl;
}


Measured memory_bytes: 87424
#include<stdio.h>
#define MX ((int) 2E5)
#define fori1(i, first, end) for(i = first; i<end; ++i)

typedef long long ll;

int main()
{
    ll k, n, *a = new ll[MX], *d = new ll[MX], i, max_index, ans;

    scanf("%lld%lld", &k, &n);

    fori1(i, 0, n) scanf("%lld", a+i);

    fori1(i, 1, n){
        d[i-1] = a[i] - a[i-1];
    }
    d[i-1] = a[0] + (k - a[i-1]);

    max_index = 0;
    fori1(i, 1, n){
        if(d[i]>d[max_index]) max_index = i;
    }
    ans = 0;
    fori1(i, 0, n){
        if(i!=max_index) ans+= d[i];
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

template<typename T>
inline bool chmax(T& t, T f) { if (t >= f) return false; t = f; return true; }

int calc(int p, int x) { return p * (100 + x) / 100; }

int solve(int x, int y, int s) {
    int retval = 0;
    for (int a = 1; a < s; ++a){
        for (int b = a; b < s; ++b){
            if (calc(a, x) + calc(b, x) != s) continue;
            chmax(retval, calc(a, y) + calc(b, y));
        }
    }
    return retval;
}

int main() {
    for (int x, y, s; cin >> x >> y >> s, x|y|s; cout << solve(x, y, s) << endl);
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

#define size_t int

int main(int argc, char const *argv[]) {
  char S[2000000];
  scanf("%s", S);
  long c = 0;
  long r = 0;
  for (long i = 0; S[i] != 0; i++) {
    if (S[i] == 'W') {
      r += i - c;
      c++;
    }
  }
  printf("%ld\n", r);
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<=(n); ++i)

int main() {
    int price, num[4];
    bool sp = false;
    while (cin >> price, price) {
        if (sp) {
            cout << endl;
        } else {
            sp = true;
        }
        int total = 0;
        rep(i,3) {
            cin >> num[i];
            total += num[i];
        }
        int res[4] = {}, mn = 81;
        rep(i,num[0]) rep(j,num[1]) rep(k,num[2]) rep(l,num[3]) {
            int amount = i*10 + j*50 + k*100 + l*500;
            if (price <= amount) {
                int change = amount - price;
                int c3 = change / 500;
                int c2 = (change % 500) / 100;
                int c1 = (change % 100) / 50;
                int c0 = (change % 50) / 10;
                int coins = total - (i + j + k + l) + (c0 + c1 + c2 + c3);
                if (coins < mn && i*c0 + j*c1 + k*c2 + l*c3 == 0) {
                    mn = coins;
                    res[0] = i;
                    res[1] = j;
                    res[2] = k;
                    res[3] = l;
                }
            }
        }
        if (res[0]) cout << 10 << " " << res[0] << endl;
        if (res[1]) cout << 50 << " " << res[1] << endl;
        if (res[2]) cout << 100 << " " << res[2] << endl;
        if (res[3]) cout << 500 << " " << res[3] << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
a, b, c, x = 4.times.map { gets.to_i }
cnt = 0
(0..a).each do |i|
    (0..b).each do |j|
        (0..c).each do |k|
            cnt += 1 if i * 500 + j * 100 + k * 50 == x
        end
    end
end
 
puts cnt

Measured memory_bytes: 1916
#define SORT(v) sort(v.begin(), v.end())
#include <iostream>
#include <map>
#include <vector>
#include <stack>
#include <cstdlib>
#include <algorithm>
#include <cstdarg>
#include <cstdio>
#include <numeric>

// #include "ane.cpp"

#define INF (int)1e9
#define LLINF (long long)1e18
#define NMAX 100000
#define MMAX 200
#define MOD 100000
using namespace std;

// コメントアウトするとdb_printf()を実行しない
#define DEBUG
// デバッグ用printf
void db_printf(const char* format, ...){
    #ifndef DEBUG
    return;
    #endif
    va_list arg;
    va_start(arg, format);
    vprintf(format, arg);  // コンソールに出力
    va_end(arg);
}
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
typedef pair<int, int> p;
typedef long long ll;

ll N,M,K,A[NMAX],B,C,D,E;
int dp[NMAX][MMAX] = {};

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

ll ans = 0;

void solve(){
    // 解答アルゴリズム
    sort(A, A+N);
    ll sum = A[0], chasm = 0;
    for (int i = 1; i < N; ++i)
    {
        if (sum * 2 < A[i])
        {
            chasm = i;
        }
        sum += A[i];
    }
    ans = N - chasm;
}
void debug(){
    // デバッグ用出力
}
void answer(){
    // 解答出力
    printf("%lld\n", ans);
}
int main(int argc, char const *argv[])
{
    // 入力の読み込み，番兵法

    Fill(dp, -1);

    scanf("%lld", &N);
    for (int i = 0; i < N; ++i)
    {
        scanf("%lld", &A[i]);
    }
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();

    return 0;
}

Measured memory_bytes: 79736
#include <bits/stdc++.h>
using namespace std;
bool kaibunn(string s) {
    bool ok = true;
    for(int i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[s.size() - 1 - i])
            ok = false;
    }
    return ok;
}
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    // cout << s.substr(0, (n - 1) / 2) << '\n';
    // cout << s.substr((n + 3) / 2 - 1) << '\n';
    if (kaibunn(s) && kaibunn(s.substr(0, (n - 1) / 2)) && kaibunn(s.substr((n + 3) / 2 - 1)))
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
    
    return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

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


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 200 * 1000 + 13;

int n, m;
vector<pt> g[N];
int a[N];

bool read () {
	if (scanf("%d%d", &n, &m) != 2)
		return false;
	forn(i, n)
		g[i].clear();
	forn(i, n)
		scanf("%d", &a[i]);
	forn(i, m){
		int v, u;
		scanf("%d%d", &v, &u);
		--v, --u;
		g[v].pb(mp(u, i));
		g[u].pb(mp(v, i));
	}
	return true;
}

string ans;
int w[N];
li dist[N];
bool used[N];

void Dijkstra(char c1, char c2){
	forn(i, n) dist[i] = INF64;
	set<pair<li, int>> q;
	forn(i, n) if (ans[i] == c1){
		dist[i] = 0;
		q.insert(mp(0, i));
	}
	while (!q.empty()){
		int v = q.begin()->y;
		q.erase(q.begin());
		for (auto it : g[v]){
			int u = it.x;
			int w = ::w[it.y];
			if (ans[u] == c2 && dist[u] > dist[v] + w){
				if (q.count(mp(dist[u], u)))
					q.erase(mp(dist[u], u));
				dist[u] = dist[v] + w;
				q.insert(mp(dist[u], u));
			}
		}
	}
}

void solve() {
	vector<int> ord(n);
	iota(all(ord), 0);
	sort(all(ord), [](int x, int y){
		return a[x] < a[y];
	});
	ans = string(n, '.');
	
	forn(i, m) w[i] = INF;
	
	memset(used, 0, sizeof(used));
	for (auto v : ord){
		if (used[v]) continue;
		bool fl = false;
		for (auto it : g[v]){
			int u = it.x;
			int i = it.y;
			if (a[u] < a[v]){
				fl = true;
				w[i] = a[v] - a[u];
				ans[v] = ans[u];
				used[v] = true;
				break;
			}
		}
		if (!fl){
			for (auto it : g[v]){
				int u = it.x;
				int i = it.y;
				if (a[u] == a[v]){
					fl = true;
					w[i] = a[v];
					ans[v] = ans[u] == 'W' ? 'B' : 'W';
					ans[u] = ans[v] == 'W' ? 'B' : 'W';
					used[v] = used[u] = true;
					break;
				}
			}
		}
		if (!fl){
			puts("-1");
			return;
		}
	}
	
	Dijkstra('W', 'B');
	forn(i, n) if (ans[i] == 'B' && dist[i] != a[i]){
		puts("-1");
		return;
	}
	
	Dijkstra('B', 'W');
	forn(i, n) if (ans[i] == 'W' && dist[i] != a[i]){
		puts("-1");
		return;
	}
	
	puts(ans.c_str());
	forn(i, m) printf("%d\n", w[i]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 21236
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

int INF=1000000007;


long long int extgcd(long long int a,long long int b,long long int &x,long long int &y) {
    long long int g = a;
    if (b) {
        g = extgcd(b, a % b, y, x);
        y -= x * (a / b);
    } else {
        x = 1;
        y = 0;
    }
    return g;
}

long long int inverse(long long int a,long long int p){
    long long int x,y;
    extgcd(a,p,x,y);
    return(x+p)%p;
}

int MAX_N = 100001;

long long int factorial[100001+1];
//階乗
//factorial をメイン関数内で初期化
void set_fact(int a,int p){
    long long int ans=1;
    factorial[0]=1;
    for(int i=1;i<=a;i++){
        ans=(ans*i%p+p)%p;
        factorial[i]=ans;
    }
}

//nCk mod p
//
long long int combination(int n,int k,int p){
    //set_factを呼んでから
    return factorial[n]*(inverse(factorial[k]*factorial[n-k]%p,p))%p;
}


int main(){
    int n;
    cin>>n;
    int a[n+1];
    bool used[n+1];
    fill_n(used,n+1,false);
    int M,N;
    REP(i,n+1){
        cin>>a[i];
        if(!used[a[i]]){
            used[a[i]]=true;
        }else{
            M=n-i;
            REP(j,i){
                if(a[j]==a[i]){
                    N=j;
                }
            }
        }
    }
    int p=INF;
    fill_n(factorial,MAX_N+1,0);
    set_fact(n+1,p);

    for(int i=1;i<n+2;i++){
        if(i-1<=N+M){
            cout<<(combination(n+1,i,p)-combination(N+M,i-1,p)+p)%p<<endl;
        }else{
            cout<<combination(n+1,i,p)<<endl;
        }

    }


    return 0;
}

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

int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    if(b-a<=2){
         cout<<k+1<<endl;
        return 0;
    }
    ll ans=0;
    if((k-a+1)%2==0){
        ans+=a;
        ll s=(k-a+1)/2;
        s*=b-a;
        ans+=s;
    }else{
        ans+=a+1;
        ll s=(k-a)/2;
        s*=b-a;
        ans+=s;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def solve(nu,mu,du):
    E = []
    vs = [False]*nu
    vs[0] = True

    while True:
        min_dist,ind = float("inf"),float("inf")
        for i in xrange(len(du)):
            if ( ( vs[du[i][0]] and not vs[du[i][1]] ) or ( not vs[du[i][0]] and vs[du[i][1]]) ) and min_dist > du[i][2]:
                min_dist,ind,pf,pt = du[i][2],i,du[i][0],du[i][1]
        E.append(min_dist)
        vs[pf] = vs[pt] = True
        du.pop(ind)
        if all(vs):
            break
        for i in xrange(len(du)):
            try:
                if vs[du[i][0]] and vs[du[i][1]]:
                    du.pop(i)
            except:
                pass

    print sum(E)/100 - len(E)

while True:
    n = input()
    if n == 0:
        exit()
    m = input()
    data = []
    for i in xrange(m):
        data.append( map(int,raw_input().split(",")) )
    solve(n,m,data)

Measured memory_bytes: 4884
#for _ in range(int(input())):
#n=int(input())
#d,t,s=[int(x) for x in input().split()]  

def fun(s,t):
    ans=0
    for i in range(len(t)):
        if s[i]!=t[i]:
           ans+=1
    return ans       


s=input()
t=input()        
m=len(t)
for i in range(0,len(s)-len(t)+1):
   
     m=min(m,fun(s[i:i+len(t)],t))
    
     if m==0:
         break

print(m)         
    
    

Measured memory_bytes: 72648
N,C=map(int,input().split())
IA=[eval(input().replace(" ",","))for _ in range(N)]
MS=[(0,0)]*(N+1)
CS=[0]*(N+1)
RS=0
for i,[a,v] in enumerate(IA):
  CS[i+1]=CS[i]+v
  MS[i+1]=max(CS[i+1]-a,MS[i][0]),max(CS[i+1]-2*a,MS[i][1])
for i in range(N):
  ob=CS[N]-CS[i]
  RS=max(RS,ob+MS[i][0]-2*(C-IA[i][0]),ob+MS[i][1]-(C-IA[i][0]))
print(max(RS,MS[N][0],0))


Measured memory_bytes: 34736
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string

let solve ans w v =
  let (ans, _, xs) = Array.fold_left (fun (ans, j, xs) c -> match xs with
    | [] -> (ans, j + 1, [(c, j)])
    | (ch, _) :: _ ->
      if ch = c then (ans, j + 1, xs)
      else if ch < c then (ans, j + 1, (c, j) :: xs)
      else
        let rec f ans k = function
          | [] -> (ans, j + 1, [(c, k)])
          | (ch, cj) :: tl as ys ->
            if ch >= c then f (if ch * (j - cj) > ans then ch * (j - cj) else ans) cj tl
            else (ans, j + 1, (c, k) :: ys) in
        f ans j xs)
    (ans, 0, [])
    v in
  List.fold_left (fun acc (ch, cj) -> if ch * (w - cj) > acc then ch * (w - cj) else acc) ans xs

let () =
  match read_ns () with
  | [h; w] ->
    let s = Array.make w 0 in
    let t = Array.make w 0 in
    let rec doit i ans =
      if i = h then ans
      else begin
        read_ns () |> List.iteri (fun j e -> t.(j) <- if e = 1 then 0 else s.(j) + 1);
        Array.iteri (fun i e -> s.(i) <- e) t;
        solve ans w t |> doit (i + 1)
      end in
    doit 0 0 |> Printf.printf "%d\n"
  | _ -> assert false

Measured memory_bytes: 5092
#include <bits/stdc++.h> 
#define ll long long int

using namespace std; 

int main() 
{
    string s;
    cin >> s;
    if (s == "SUN"){
    	cout << "7" << endl;
	}
	if (s == "MON"){
    	cout << "6" << endl;
	}
	if (s == "TUE"){
    	cout << "5" << endl;
	}
	if (s == "WED"){
    	cout << "4" << endl;
	}
	if (s == "THU"){
    	cout << "3" << endl;
	}
	if (s == "FRI"){
    	cout << "2" << endl;
	}
	if (s == "SAT"){
    	cout << "1" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int ns = sz(s), nt = sz(t);
    vector<vector<int>> dp(ns+5, vector<int>(nt+5, 0));
    for(int i = 1; i <= ns; i++)
        for(int j = 1; j <= nt; j++)
            dp[i][j] = max({dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + (s[i-1]==t[j-1])});
    int i = ns, j = nt, cnt = dp[ns][nt];
    vector<char> v(cnt);
    while(cnt)
    {
        if(s[i-1] == t[j-1])
            i--, j--, cnt--, v[cnt] = s[i];
        else if(dp[i][j] == dp[i-1][j])
            i--;
        else
            j--;
    }
    for(auto &k: v)
        cout << k;
    cout << endl;
}

Measured memory_bytes: 73956
n=int(input())

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

max=a[0]
min=a[0]
sum=a[0]

for i in range(1,n):
    if max<a[i]:
        max=a[i]
    if min>a[i]:
        min=a[i]
    sum+=a[i]

print(min, max, sum)


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

using namespace std;

int N;

long long f(int x)
{
    return 1LL*x*(x+1)/2;
}

int main()
{
    scanf("%d", &N);
    int S=N;
    for(int i=N; i>=1; i--)
    {
        if(f(i-1)<S)
            printf("%d\n", i), S-=i;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a-b>c)
    cout << 0;

  else
    cout << c - (a - b); 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N,M;
    cin>>N>>M;
    vector<pair<long long,int>> val(N);
    rep(i,N){
        cin>>val[i].first>>val[i].second;
    }
    sort(all(val));
    //安い順にどんどん買っていく
    long long ans=0;
    int buy=0;
    rep(i,N){
        if(buy+val[i].second<=M){
            ans+=val[i].second*val[i].first;
            buy+=val[i].second;
        }else{
            ans+=(M-buy)*val[i].first;
            buy=M;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  rep(i, M) cin >> A[i];

  int sum = 0;
  rep(i, M) sum += A[i];

  if (sum > N) cout << -1 << endl;
  else cout << N-sum << endl;

  return 0;
}


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

int main(){
    int N, M, ans=0, a, b, sum=0, H, W;
    cin >> H >> W;
    string S[H];
    for(int i=0; i<H; i++){
	cin >> S[i];
    }
    
    for(int i=0; i<H; i++){
	cout << S[i]<< endl;
	cout << S[i]<< endl;
    }
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i=0;i<M;i++) {
    cin >> B[i];
  }

  int ans = 0;
  for(int i=0;i<N;i++) {
    int result = 0;
    for(int j=0;j<M;j++) {
      int tmp;
      cin >> tmp;
      result += tmp * B[j];
    }
    if(result+C > 0) {
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

int main(){
    int N;
    string S;
    
    cin >> S;
    
    N = S.length();
    long long A[N] = {};
    long long temp = 0;
    int index = 0;
    for (int i=0;i<N;i++) {
        if (S[N-i-1]=='W') temp += 1;
        else {
            A[index] = temp;
            index+=1;
        }
    }
    
    long long result = 0;
    for (int i=0;i<N;i++) {
        result += A[i];
    }
    cout << result << endl;
    
    
    return 0;
}


Measured memory_bytes: 2180
#include <stdio.h>
#include <stdlib.h>

int main(){
  int A[100];
  int N, i, j, temp, number=0, flag=1;

  scanf("%d", &N);
  if(N < 1 || 100 < N)
    exit(1);

  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
    if(A[i] < 0 || 100 < A[i])
      exit(2);
  }

  while(flag){
    flag = 0;
    for(j = N - 1; 0 < j; j--){
      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	flag = 1;
	number++;
      }
    }
  }

  for(i = 0; i < N-1; i++)
    printf("%d ", A[i]);
  printf("%d\n", A[i]);
  printf("%d\n", number);

  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10000
#define STRLEN 20

int main(void){
    int x;
    scanf("%d", &x);
    if(x > 29)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}


Measured memory_bytes: 1644
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main() {
    double a,b,x; cin >> a >> b >> x;
    double mid = a*a*b/(double)2.0;
    if(x>mid){
        double height = (a*a*b-x)/a/a*2.0;
        printf("%.8f\n",atan2(height,a)/(double)3.1415926535*(double)180.0);
    }else{
        double height = x/a/b*2.0;
        printf("%.8f\n",atan2(b,height)/(double)3.1415926535*(double)180.0);
    }
}


Measured memory_bytes: 256
<?php
  list($n, $k, $q) = explode(" ", trim(fgets(STDIN)));

  $list = array_fill(0, $n, 0);
  for ($i=0; $i<$q; $i++) {
    list($a) = explode(" ", trim(fgets(STDIN)));
    $list[$a-1]++;
  }

  for ($i=0; $i<$n; $i++) {
    $point = $k - ($q-$list[$i]);
    if($point <= 0){
      echo "No";
    }else{
      echo "Yes";
    }
    echo PHP_EOL;
  }

Measured memory_bytes: 9080
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
void max_self(ll &a, ll b){
	a = max(a,b);
	}
int main(){
	int n,w;
	scanf("%d%d",&n,&w);
	vector<ll> dp(w + 1);
	dp[0] = 0;
	for(int i = 0; i < n; ++i){
		int weight , value;
		scanf("%d%d",&weight,&value);
		for(int j = w - weight; j >= 0; --j ){
			max_self(dp[j + weight],dp[j] + value);
			}
		}
		printf("%lld",dp[w]);
		
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	string s;
	char now = 'a';
	bool f = true;

	cin >> s;

	REP(i, 26) {
		REP(j, s.size()) {
			if (s[j] == now) {
				f = false;
				break;
			}
		}

		if (f) {
			cout << now << endl;
			return 0;
		}

		f = true;
		now++;
	}

	cout << "None" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){ll N;cin >> N;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++){ cin >> A[i];}
  vector<ll> S1(N); vector<ll> S2(N); S1[0] = A[0]; // S1[i] = A[0]+A[1]+...+A[i]
  S2[0] = A[0];//S2[i] = A[0]+A[1]+...+A[i]
   ll cnt1 = 0; ll cnt2 = 0;
  for(ll i = 0; i < N; i++){ 
    if(i){S1[i] = S1[i-1] + A[i]; S2[i] = S2[i-1] + A[i];}
    // S1[i]が、1,-1,1,-1,,,,を成しているのかを判定する
    // S2[i]が、-1,1,-1,1,,,を成しているのかを判定する
    
    if( !(i%2)){ //この時、S1はプラスに、S2はマイナスに持っていく
      // == 0 もNG(和は0とはならないため）
      if( S1[i] <= 0){ cnt1 += 1-S1[i]; S1[i] = 1;}
      if( S2[i] >= 0){ cnt2 += S2[i]+1; S2[i] = -1;}}
    else{
      if( S1[i] >= 0){ cnt1 += S1[i]+1; S1[i] = -1;}
      if( S2[i] <= 0){ cnt2 += 1-S2[i]; S2[i] = 1;}}
    
  }
  
  cout << min(cnt1, cnt2)  << endl; return 0;}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<int(n);i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<string> W(n);
    bool flag=true;
    
    for(int i=0;i<n;i++){
        cin >> W[i];
    }
    for(int i=1;i<n;i++){
        if(W[i].front() != W[i-1].back()) flag=false;
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(W[i]==W[j]) flag=false;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, k, a[N], b[N], ans;	

bool check (int x) {
	int res = 0;
	forn (i, 1, n)
		res += max(0ll, -(x) / b[i] + a[i]);

	return res <= k;
}


main () {
	scanf("%lld%lld", &n, &k);
	forn (i, 1, n)
		scanf("%lld", &a[i]);				

	forn (i, 1, n)
		scanf("%lld", &b[i]);
	
	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + n);
	reverse(b + 1, b + 1 + n);

	int l = 0, r = INF + INF + INF;

	while (l <= r) {
		int mid = (l + r) >> 1ll;
		if (check(mid)) {
			ans = mid;
			r = mid - 1;
		} else	
			l = mid + 1;
	}

	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	ll a = 0;
	for(int i = 0; i < 10; i++){
		if(i == 4 || i == 7)continue;
		a += (s[i] - '0')*(int)pow(10, 9-i);
	}
	if(a <= 2019004030)cout << "Heisei" << endl;
	else cout << "TBD" << endl;
	return 0;
}

Measured memory_bytes: 384
d,g = map(int,input().split())
pa = []
ca = []
for i in range(d):
    p,c = map(int,input().split())
    pa.append(p)
    ca.append(c)

def calcBit(n):
    res = []
    for i in range(d):
        res.append(n%2)
        n >>= 1
    return res[::-1]

res = float('inf')
for i in range(2**d):
    tmp = 0
    s = 0
    b = calcBit(i)
    for w,bit in enumerate(b):
        if bit==1:
            tmp += pa[w]
            s += pa[w]*(w+1)*100+ca[w]
    dif = g - s
    if dif>0:
        for j in range(len(pa)-1,-1,-1):
            if b[j]==0:
                t = dif//((j+1)*100)
                dif -= min(t,pa[j])*((j+1)*100)
                tmp += min(t,pa[j])
                if dif<=0:
                    break
    if dif<=0:
        res = min(res,tmp)
print(res)


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

int main(){
  int64_t N;
  cin >> N;

  int64_t ans= 0;
  for(int64_t i=1; i<=N; i++){
    if(i%3!=0 && i%5!=0){
      ans+= i;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    int N;
    cin >> N;
    vector<ll> X(N);
    REP(i,N)cin >> X[i];
    vector<ll> COMP(0);
    COMP.pb(1);
    X[0] = 1;
    REPS(i,N-1){
        if(X[i] != X[i-1] + 1){
            X[i] = X[i-1] + 2;
        }
    }
    ll dou = 1;
    REPS(i,N-1){
        if(X[i] != X[i-1] + 1){
            (*COMP.rbegin())++;
        }else{
            dou++;
            if(dou%2 == 0){
                (*COMP.rbegin())++;
                COMP.pb(0);
            }else{
                (*COMP.rbegin())++;
            }
        }
    }
    ll remain = 0;
    ll ans = 1;
    REP(i,N){
        if(i < COMP.size())remain += COMP[i];
        ans = (ans * remain)%mod;
        remain--;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4636
from fractions import gcd
 
def main():
  k = int(input())
  ans = 0
  for a in range(1, k+1):
    for b in range(a, k+1):
      x = gcd(a,b)
      for c in range(b,k+1):
        if a==b and b==c:
          ans += a
        elif a==b or b==c:
          ans += gcd(x,c) * 3
        else:
          ans += gcd(x,c) * 6
  print(ans)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 10680
from sys import stdin


def main() -> int:
    a = next_int()
    b = next_int()
    c = next_int()
    d = next_int()

    ans = 0
    for i in range(a, b):
        if c <= i < d:
            ans += 1
    print(ans)
    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 10000000000000000
ll n,m;
vector<vector<ll>>v(100010);
vector<ll>dp(100010,-1);
//頂点iのlongest path
ll solve(ll i){
    if(v[i].size()==0)return dp[i]=0;
    ll ans=0;
    rep(j,v.at(i).size()){
        if(dp[v[i][j]]!=-1)ans=max(ans,dp[v[i][j]]+1);
        else ans=max(ans,solve(v[i][j])+1);
    }
    return dp[i]=ans;
}
int main(void){
    ll x,y;cin>>n>>m;
    rep(i,m){cin>>x>>y;x--;y--;v[y].push_back(x);}
    ll ans=0;
    rep(i,n)ans=max(ans,solve(i));
    cout<<ans;
    
}

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

int main () {
    
    int r, g, b, num;
    cin >> r >> g >> b;
    
    num = (100*r+10*g+b);
    
    if(num%4==0){cout<<"YES\n";}
    else{cout<<"NO\n";}
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define RG register
#define il inline
#define N 400010
#define mod 924844033
using namespace std;
struct ed{int nxt,to;}e[N*2];
int head[N],tot,n,m,R[N*2],A[N*2],B[N*2],fac[N*2],_fac[N*2],sz[N];
void link(int u,int v){e[tot].nxt=head[u];e[tot].to=v;head[u]=tot++;}
void lnk(int u,int v){link(u,v),link(v,u);}
void dfs(int u,int faa){
  A[n]++;
  sz[u]=1;
  for(int i=head[u];i!=-1;i=e[i].nxt){
    int v=e[i].to;if(v==faa)continue;
    dfs(v,u);sz[u]+=sz[v];
    A[sz[v]]--;if(A[sz[v]]<0)A[sz[v]]+=mod;
  }
  A[n-sz[u]]--;if(A[n-sz[u]]<0)A[n-sz[u]]+=mod;
  
}
int qp(int a,int b){
  if(!b)return 1;if(a==1)return a;
  int temp=qp(a,(b>>1));
  temp=1ll*temp*temp%mod;
  if(b&1)temp=1ll*temp*a%mod;
  return temp;
}
void NTT(int *a,int f){
  for(int i=0;i<n;++i)if(i<R[i])swap(a[i],a[R[i]]);
  for(int i=1;i<n;i<<=1){
    int gn=qp(5,(mod-1)/(i<<1));
    for(int j=0;j<n;j+=(i<<1)){
      int g=1;
      for(int k=0;k<i;++k,g=1ll*g*gn%mod){
	int x=a[j+k],y=1ll*g*a[j+k+i]%mod;
	a[j+k]=(x+y)%mod;
	a[j+k+i]=(x-y+mod)%mod;
      }
    }
  }
  if(f==-1){
    reverse(a+1,a+n);
    int _n=qp(n,mod-2);
    for(int i=0;i<n;++i)a[i]=1ll*a[i]*_n%mod;
  }
}
int main(){
  memset(head,-1,sizeof(head));
  scanf("%d",&n);for(int i=1;i<n;++i){int u,v;scanf("%d%d",&u,&v),lnk(u,v);}
  dfs(1,1);
  fac[1]=1;fac[0]=1;
  for(int i=2;i<=n;++i)fac[i]=1ll*fac[i-1]*i%mod,A[i]=1ll*A[i]*fac[i]%mod;
  _fac[n]=qp(fac[n],mod-2);for(int i=n;i;--i)_fac[i-1]=1ll*_fac[i]*i%mod;
  for(int i=1;i<=n;++i)B[i]=_fac[n-i];
  m=n;int L=0;
  for(n=1;n<=(m<<1);n<<=1)L++;
  for(int i=0;i<n;++i)R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));
  NTT(A,1),NTT(B,1);
  for(int i=0;i<n;++i)A[i]=1ll*A[i]*B[i]%mod;
  NTT(A,-1);
  for(int i=1;i<=m;++i)printf("%d\n",1ll*A[m+i]*_fac[i]%mod);
  return 0;
}


Measured memory_bytes: 31872
n = int(input())
m = [i for i in range(1,n)]
p = list(map(int,input().split()))
cnt = 0
for i in m:
    if p[i-1] == i:
        p[i-1] = p[i]
        p[i] = i
        cnt += 1

if p[-1] == n:
    cnt += 1
print(cnt)

Measured memory_bytes: 24360
#include<bits/stdc++.h>
using namespace std;
int main(){
/**int x1,x2,x3,x4,x5;
cin>>x1>>x2>>x3>>x4>>x5;
if(x1==0)cout<<1<<endl;
if(x2==0)cout<<2<<endl;
if(x3==0)cout<<3<<endl;
if(x4==0)cout<<4<<endl;
if(x5==0)cout<<5<<endl;
*/
int x,y;
cin>>x>>y;
long long cranes=(4*x -y)/2;
long long turtle=(y-2*x)/2;
if(cranes>=0 && turtle>=0){
    if(cranes * 2 + turtle *4 == y)cout<<"Yes\n";
    else cout<<"No\n";
}
else cout<<"No\n";



return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <cmath>
int main() {
	std::cout << std::fixed << std::setprecision(20);
	float a, b, c;
	std::cin >> a >> b >> c;
	c = c* acos(-1) / 180;
	auto S = a * b / 2 * sin(c);
	auto L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(c));
	auto h = b * sin(c);

	std::cout << S << " " << L << " " << h << std::endl;
	return 0;
}


Measured memory_bytes: 3452
#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#define PB push_back
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using	namespace std;
int n,tmp;
void solve(){
	while(cin >> n  && n!= 0){
		vector <int> data ;
		REP(i,n){
			cin >> tmp;
			data.PB(tmp);
		}
		int sofar = 0 ,end = 0;
		REP(i,n){
			end = max(end+data[i],0);
			sofar = max(end,sofar);
		}
		if(sofar == 0){
			sofar = -10000000;
			REP(i,n)sofar = max(sofar,data[i]);
		}
		cout << sofar <<endl;


	}

}

int main(){
	solve();

}

Measured memory_bytes: 1244
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cinm(char, 4, m);
    for(auto e : m){
        if(e.second != 2){
            Cout("No");
            return 0;
        }
    }
    Cout("Yes");
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] hills = new int[10];
		
		int cnt = 0;
		while(cnt < 10) {
			int hill = Integer.parseInt(scan.next());
			if(hill >= 0 && hill <= 10000) {
				hills[cnt] = hill;
				cnt++;
			} else {
				continue;
			}
		}
		
		for(int i = 0; i < hills.length - 1; i++) {
			for(int j = hills.length - 1; j > i; j--) {
				if(hills[j] > hills[j - 1]) {
					int tmp = hills[j];
					hills[j] = hills[j - 1];
					hills[j - 1] = tmp;
				}
			}
		}
		
		for(int i = 0; i < 3; i++) {
			System.out.println(hills[i]);
		}
		
	}
}

Measured memory_bytes: 26124
#include <bits/stdc++.h>
#include "atcoder/all"

using namespace std;

using i64 = long long;

const i64 MOD = i64(1e9) + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

signed main(){
    using atcoder::dsu;
    int n, q;
    cin >> n >> q;
    dsu uf(n);
    for(int i = 0; i < q; ++i){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0)
            uf.merge(u, v);
        else
            cout << uf.same(u, v) << endl;
    }
}



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

int main()
{
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int curx=sx,cury=sy;
    while(cury!=ty)
    {
        cout<<"U";
        cury++;
    }
    while(curx!=tx)
    {
        cout<<"R";
        curx++;
    }
    while(cury!=sy)
    {
        cout<<"D";
        cury--;
    }
    while(curx!=sx)
    {
        cout<<"L";
        curx--;
    }
    cout<<"L";
    curx--;
    while(cury!=ty)
    {
        cout<<"U";
        cury++;
    }
    cout<<"U";
    cury++;
    while(curx!=tx)
    {
        cout<<"R";
        curx++;
    }
    cout<<"D";
    cury--;
    cout<<"R";
    curx++;
    while(cury!=sy)
    {
        cout<<"D";
        cury--;
    }
    cout<<"D";
    cury--;
    while(curx!=sx)
    {
        cout<<"L";
        curx--;
    }
    cout<<"U";
    cury++;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
const ll mod=1e9+7;
const double eps=1e-6;
int main()
{
    ios::sync_with_stdio(false);
  ll t,a,b,v,w,flag=0;
  cin>>a>>v>>b>>w>>t;
  if(a<b)
  {
      if(a+t*v>=b+t*w)
        flag=1;
  }
  else if(a>b)
  {
      if(b-w*t>=a-v*t)
        flag=1;
  }
  if(flag)
    cout<<"YES";
  else
    cout<<"NO";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n; ll k;
    cin >> n >> k;
    vector<ll> v(n+1);
    rep(i, 1, n+1)
        cin >> v[i];
    vector<bool> a(n+1, false);
    ll i = 1;
    a[i] = true;
    vector<ll> chain;
    chain.push_back(1);
    ll next;
    while(true)
    {
        next = v[i];
        if (a[next] == true)
            break;
        i = next;
        a[next] = true;
        chain.push_back(next);
    }
    vector<ll> chain2;
    bool y = false;
    rep(i, 0, chain.size())
    {
        if (chain[i] == next)
            y = true;
        if (y == true)
            chain2.push_back(chain[i]);
    }
    if (k < (ll)chain.size())
        cout << chain[k];
    else 
    {
        ll rem = chain.size() - chain2.size();
        k = k - (ll)rem;
        ll index = k%(ll)chain2.size();
        cout << chain2[index];
    }
    return 0;
}

Measured memory_bytes: 9096
import java.util.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][][] b = new int[n][3][2];
        
        for (int i = 0; i < n; i++)
            for (int j = 0; j < 3; j++)
                for (int k = 0; k < 2; k++)
                    b[i][j][k] = sc.nextInt() * 60 + sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++) {
                    int res = 0;
                    for (int p = 0; p < n; p++) {
                        if (b[p][0][0] <= b[i][0][0] && b[i][0][0] <= b[p][0][1] &&
                                b[p][1][0] <= b[j][1][0] && b[j][1][0] <= b[p][1][1] &&
                                b[p][2][0] <= b[k][2][0] && b[k][2][0] <= b[p][2][1])
                            res++;
                    }
                    ans = Math.max(ans, res);
                }
        System.out.println(ans);
    }
}


Measured memory_bytes: 30204
#include<stdio.h>

int main(){
    int n,a,b,c,i;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d%d%d", &a, &b, &c);
        if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b) puts("YES");
        else puts("NO");
    }
    return 0;
}

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

minT, maxT = -1, max([A[i] * F[i] for i in range(N)])
while maxT - minT > 1:
    midT = minT + (maxT - minT) // 2
    if sum([max(A[i] - midT // F[i], 0) for i in range(N)]) > K:
        minT = midT
    else:
        maxT = midT

print(maxT)


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

int main() {
	string S;
	cin >> S;
	S.length();
	int ans = 0, cnt = 0;

	for (int i = 0; i < S.length(); i++) {
		char a = S[i];
		if (a == 'A' || a == 'C' || a == 'G' || a == 'T') {
			 cnt++;
		}
		else {
			cnt = 0;
		}
		ans = max(cnt, ans);


	}


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

Measured memory_bytes: 3624
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline 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;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline 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 N;
int A[100002];
int main(){
  int i, r, s=0;
  rd(N);N += (2);
  for(i=(1);i<(N-1);i++){
    rd(A[i]);
  }
  for(i=(1);i<(N);i++){
    s += abs(A[i]-A[i-1]);
  }
  for(i=(1);i<(N-1);i++){
    r = s;
    if(A[i] <min_L(A[i-1], A[i+1])){
      r -= 2* (min_L(A[i-1], A[i+1])- A[i]);
    }
    if(A[i] >max_L(A[i-1], A[i+1])){
      r -= 2* (A[i] -max_L(A[i-1], A[i+1]));
    }
    wt_L(r);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int N, A[100002];
// {
//   int i, s = 0, r;
//   rd(N++++);
//   rep(i,1,N-1) rd(A[i]);
//   rep(i,1,N) s += abs(A[i]-A[i-1]);
//   rep(i,1,N-1){
//     r = s;
//     if(A[i] < min(A[i-1], A[i+1])) r -= 2 (min(A[i-1], A[i+1]) - A[i]);
//     if(A[i] > max(A[i-1], A[i+1])) r -= 2 (A[i] - max(A[i-1], A[i+1]));
//     wt(r);
//   }
// }


Measured memory_bytes: 1664
n = gets.to_i
list = []
n.times do
  list << gets.split(" ").map(&:to_i)
end

list.sort!{|a,b| a[0] <=> b[0]}

prev_t = 0
prev_x = 0
prev_y = 0
list.each do |l|
  t = l[0] - prev_t
  x = l[1] - prev_x
  y = l[2] - prev_y
  if t < (x + y)
    puts "No"
    exit
  elsif (x + y).odd? != t.odd?
    puts "No"
    exit
  else
    prev_t = l[0]
    prev_x = l[1]
    prev_y = l[2]
  end
end

puts "Yes"

Measured memory_bytes: 10480
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  // ここにプログラムを追記
  int l, r, guest = 0;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    guest += r - l + 1;
  }
  cout << guest << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 100001
int PAR[SIZE],RANK[SIZE];
void init_uf(int n){for(int i=0;i<n;i++){PAR[i]=i;RANK[i]=0;}}//initialize
int root(int i){return PAR[i]==i?i:(PAR[i]=root(PAR[i]));}//search group
int same(int x,int y){return root(x)==root(y);}//judge same group
void unite(int x,int y){//add edge
  x=root(x);y=root(y);
  if(x==y)return;
  if(RANK[x]<RANK[y])PAR[x]=y;
  else{PAR[y]=x;if(RANK[x]==RANK[y])RANK[x]++;}
}
int main(){
  int i,n,m,p[SIZE],x,y;
  scanf("%d%d",&n,&m);
  init_uf(n);
  for(i=1;i<=n;i++)scanf("%d",&p[i]);
  for(i=0;i<m;i++){scanf("%d%d",&x,&y);unite(x,y);}
  x=0;for(i=1;i<=n;i++)x+=same(i,p[i]);
  printf("%d",x);
}


Measured memory_bytes: 2808