akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(){
    int N;
    long long ans;
    cin >> N;
    for(int i = 0; i <= N; i++){
        if(i * i <= N) ans = i*i;
        else break;
    }
    cout << ans <<endl;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;
 
 
int main(void){
  int n,t;
  cin>>n;
 
  vector<int> a;
  int maxa=0;
  for(int i=0;i<n;i++){
    cin>>t;
    a.pb(t);
    maxa=max(maxa,t);
  }
 
  int tmp;
  if(maxa==a[0]) tmp=a[1];
  else tmp=a[0];
 
  for(int i=0;i<n;i++){
    if(fabs(maxa/2 - tmp) > fabs(maxa/2 - a[i])) tmp=a[i];
  }
  cout<<maxa<<" "<<tmp<<endl;
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='1')a[i]='9';
        else if(a[i]=='9')a[i]='1';
    }
    cout<<a;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
A, B = [], []
R = 2*10**4 + 1
for i in range(N):
    A.append(1+R*i)
    B.append(10**9-R*i)
for i, p in enumerate(P):
    p -= 1
    A[p] += i
print(*A)
print(*B)

Measured memory_bytes: 75572
#include <iostream>
#include <cmath>
using namespace std;
//とりまイントとダブルが入り乱れるときは
//とりまどちらかに統一しよう。

int max(int x,int y){
  if(x>y) return x;
  return y;
}

int min(int x,int y){
  if(x<y) return x;
  return y;
}

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; // 合計金額
        if (total == X) ++res; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

string tar[4]{"dream", "dreamer", "erase", "eraser"};

int main(int argc, char **argv)
{
	string s; cin >> s;
	reverse(s.begin(), s.end());
	for (ll i = 0; i < 4; ++i)reverse(tar[i].begin(), tar[i].end());

	ll j{0};
	while (true)
	{
		bool ok{false};
		for (ll i = 0; i < 4; ++i)
		{
			auto pos = s.find(tar[i], j);
			if (pos == j)
			{
				// std::cout << tar[i] << std::endl;
				j = pos + tar[i].size();
				ok = true;
			}
		}

		if (!ok) break;
		if (j == (ll)s.size()) break;
	}

	std::cout << (j == (ll)s.size() ? "YES" : "NO")<< std::endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
	
	char a= '#';
	int i,j;
	int H,W;
	
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0){
			break;
		}
		else{
			for( i =0; i<H; i++){
				for( j=0; j<W; j++){
					if((i+j)%2 != 0){
						printf(".");
					}
					else{
						printf("%c",a);
					}
				}
				printf("\n");
				j=0;
			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2588
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <stdio.h>
using namespace std;

int main() {
	int n,x,y,a,b;
	int R= 0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>y>>a>>b;
		if(a>=5&&b>=2)R=(x*a*4/5)+(y*b*4/5);
		else if(a>=5 && b<2 &&(x*a+y*b)>(x*4/5*a)+((b+2-b)*y*4/5)){
			R=x*a*4/5+(b+2-b)*y*4/5;
		}
		else if(a<5 && b>=2 && (x*a+y*b)>(a+5-a)*x*4/5+(y*b*4/5)){
			R=(a+5-a)*x*4/5+y*4/5*b;
		}
		else R=x*a+y*b;
		cout<<R<<endl;
	}




	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, c, k;
	cin >> n >> c >> k;
	ll t[n];
	for(int i=0; i<n; i++) cin >> t[i];
	sort(t, t+n);

	int ans=0, x=-1, p=0;
	for(int i=0; i<n; i++){
		if(p==0){
			x=t[i];
			p++;
		}else if(p==c){
			ans++;
			x=t[i];
			p=1;
		}else if(t[i]<=x+k) p++;
		else if(t[i]>x+k){
			ans++;
			x=t[i];
			p=1;
		}
	}
	ans++;
	cout << ans << endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	int A[n], B[n], T[10001], minw = 10000;
	r(i, n){
		cin >> A[i];
		minw = min(minw, A[i]);
	}

	int ans = 0;
	bool V[n];
	r(i, n){
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B+n);
	r(i, n) T[B[i]] = i;
	r(i, n){
		if(V[i]) continue;
		int cur = i, S = 0, m = 10000, an = 0;
		while(true){
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if(V[cur])break;
		}
		ans += min(S + (an-2)*m, m + S + (an+1)*minw);
	}
	cout << ans << endl;
	return 0;
}


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

int *dp;
int *s;
int size;

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

int main()
{

	int i;

	scanf("%d", &size);
	dp = (int *) malloc(sizeof(int)*size);
	s = (int *) malloc(sizeof(int)*size);

	for(i=0;i<size;i++)
		scanf("%d", &s[i]);

	dp[0] = 0;
	dp[1] = abs(s[1] - s[0]);

	for(i=2;i<size;i++)
	{
		dp[i] = min(dp[i-1] + abs(s[i]-s[i-1]), dp[i-2] + abs(s[i-2] - s[i]));
	}
	
	printf("%d", dp[size-1]);
}

Measured memory_bytes: 896
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", max(0, a - b * 2));

	return 0;
}


Measured memory_bytes: 888
def power(a, n, M):
    if n == 0: return 1
    tmp = power(a*a%M, n/2, M)
    if n % 2 == 1:
        tmp = tmp * a % M
    return tmp
m, n = map(int, raw_input().split())
print power(m, n, 1000000007)

Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,end) for(int i = 0; i < end; i += 1)
#define repb(i,st) for(int i = st; i >= 0; i -= 1) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	auto start = high_resolution_clock::now(); 

	int n, k;
	cin >> n >> k;
	vector<ll int> a(n);
	repf(i,n) cin >> a[i];

	vector<ll int> dp(n , 2e9);
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i = 2; i < n; i++){
		for(int j = i-1 ; j >= max(i-k, 0); j--){
			dp[i] = min(dp[j] + abs(a[i] - a[j]), dp[i]);
			// trace1(dp[i])
		}
	}
	cout << dp[n-1];
	
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 1792
N,W = map(int,input().split())

dp = [0]*(W+1) # dp[i][w]はi個までの品物を使い、w以下の重さ分詰めたときの価値の最大値

for i in range(N):
    w,v = map(int,input().split())
    for j in range(W+1)[::-1]:
        if j>=w:
            dp[j] = max(dp[j],dp[j-w]+v)
        else:
            dp[j] = dp[j]

print(dp[-1])

Measured memory_bytes: 42840
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll nax=1e6+5, inf=1e18;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
void solve(){
	ll n;string s;
	cin>>n>>s;
	if(sz(s)<=n){
		cout<<s;
	}else{
		cout<<s.substr(0,n)<<"...";
	}
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


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


/**
 * Created by Reopard on 2014/07/03.
 */
public class Main{

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        char[] c = new char[100];
        char tmp;
        boolean flag=true;
        int p = 0;
        String text;
        while(true){
            text = br.readLine();
            p = 0;
            flag=true;
            if(text.equals(".")) break;

            for(int i = 0; i < text.length(); i++){
                tmp = text.charAt(i);

                if(tmp == '('){
                    c[p] = '(';
                    p++;
                }else if(tmp == '['){
                    c[p] = '[';
                    p++;
                }else if(tmp == ')'){
                    if(p > 0 && c[p - 1] == '('){
                        p--;
                    }else{
                        flag=false;
                    }
                }else if(tmp == ']'){
                    if(p > 0 && c[p - 1] == '['){
                        p--;
                    }else{
                        flag=false;
                    }
                }else if(tmp == '.'){
                    if(p == 0 && flag){
                        System.out.println("yes");
                        break;
                    }else{
                        System.out.println("no");
                        break;
                    }
                }
                if(i == text.length() - 1){
                    i = -1;
                    text = br.readLine();
                }
            }

        }
    }
}

Measured memory_bytes: 22708
import math


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, M = map(int, input().split())
if M < 2 and N < 2:
    Count = 0
elif M < 2:
    Count = comb(N, 2)
elif N < 2:
    Count = comb(M, 2)
else:
    Count = comb(N, 2) + comb(M, 2)
print(Count)



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

int main() {
    int n,ans=0;
    cin>>n;
    vector<int> del(n);
    rep(i,n)cin>>del[i];
    rep(j,n){
        rep(k,n){
            if(j<k)ans+=del[k]*del[j];
        }
    }
    cout<<ans;
	return 0;
}

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

typedef long long ll;

const int mxN = 2e5 + 5;
int N;
ll h[mxN], C, dp[mxN];

struct line {
    ll m, c;

    line(ll _m, ll _c) {
        m = _m;
        c = _c;
    }
    ll value(ll x) {
        return (m * x + c);
    }
};

deque<line> lines;

inline ll square(ll x) {
    return (x * x);
}

bool chk(line& l1, line& l2, line& l3) {
    return (l3.c - l2.c) * (l2.m - l1.m) >= (l2.c - l1.c) * (l3.m - l2.m);
}

void add_line(ll _m, ll _c) {
    line new_line = line(_m, _c);
    while (lines.size() >= 2 && chk(lines[(int) lines.size() - 2], lines[(int) lines.size() - 1], new_line)) {
        lines.pop_back();
    }
    lines.emplace_back(new_line);
}

ll query(ll x) {
    while (lines.size() > 1 && lines[0].value(x) > lines[1].value(x)) {
        lines.pop_front();
    }
    return lines[0].value(x);
}

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

    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    add_line(-2 * h[0], square(h[0]) + dp[0]);
    for (int i = 1; i < N; i++) {
        ll val = query(h[i]);
        dp[i] = val + square(h[i]) + C;
        add_line(-2 * h[i], square(h[i]) + dp[i]);
    }
    cout << dp[N - 1];

    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int l, r;
	cin >> l >> r;
	int M = min(r,l+2020);
	ll ans = 3000;
	for(int L = l; L <= M; L++){
		for(int R = L + 1; R <= M; R++){
			chmin(ans,(ll)L * R % 2019);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3608
#include <stdio.h>

int c(char a[])
{for(int i=0;i<100;i++)
    if(i%2==0)
    {if(a[i]=='L'){return 0;}}
    else if(a[i]=='R'){return 0;}
    return 1;
}

int main(void){
char a[100];
scanf("%s",a);

if (c(a)==0){printf("No");}
else printf("Yes");




return 0;    

}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

long long GCD(long long x, long long y){
  if(y == 0)
    return x;
  else
    return GCD(y, x%y);
}

int main(void) {
  long long a, b;
  scanf("%lld%lld", &a, &b);
  long long g = GCD(a, b);
  int count = 1;
  
  for(long long i = 2; i*i < g; i++){
    if(g%i == 0){
      count++;
      while(g%i == 0){
        g = g/i;
      }
    }
  }

  if(g > 1)
   count++;
  printf("%d\n", count);
  return 0;
}

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

using namespace std;

int n;
vector<string> v;

int main() {
	ios::sync_with_stdio(0);
	cin>>n;
	v.resize(n);
	for(int i=0; i<n; ++i) cin>>v[i];
	sort(v.begin(),v.end());	
	cout<<unique(v.begin(),v.end())-v.begin()<<endl;
	return 0;
}

Measured memory_bytes: 7532
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] count = new int[100000];
		int max = 0;
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			count[a]++;
		}
		for(int i = 0; i < 100000-2; i++) {
			int now=count[i]+count[i+1]+count[i+2];
			max = Math.max(now, max);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 59520
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<vector<P>> graph(100010, vector<P>());
vector<int> dis(100010);
vector<bool> vis(100010);
vector<bool> vis2(100010);
bool ans = true;

void dfs(int n, int p, int d, int &mi) {
	dis[n] = d; vis[n] = true; chmin(mi, d);
	for (P i : graph[n]) {
		if (vis[i.first]) {
			if (d + i.second != dis[i.first]) ans = false;
		}
		else dfs(i.first, n, d + i.second, mi);
	}
}

void dfs2(int n, int s) {
	dis[n] -= s; vis2[n] = true;
	for (P i : graph[n]) {
		if (vis2[i.first]) continue;
		dfs2(i.first, s);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int h, w, n;
	cin >> h >> w >> n;
	vector<PP> p(n);
	rep(i, n) cin >> p[i].first.second >> p[i].first.first >> p[i].second;
	sort(all(p));
	vector<int> x(n), y(n), a(n);
	rep(i, n) {
		x[i] = p[i].first.second;
		y[i] = p[i].first.first;
		a[i] = p[i].second;
		x[i]--; y[i]--;
	}
	rep(i, n - 1) {
		if (y[i] == y[i + 1]) {
			graph[x[i]].pb(P(x[i + 1], a[i + 1] - a[i]));
			graph[x[i + 1]].pb(P(x[i], a[i] - a[i + 1]));
		}
	}
	rep(i, h) {
		if (!vis[i]) {
			int s = 0;
			dfs(i, -1, 0, s);
			dfs2(i, s);
		}
	}
	rep(i, n) if (dis[x[i]] > a[i]) ans = false;
	cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll x,y; cin>>x>>y;
	ll g = 4*x - y;
	if(g<0 || g&1 ) cout<<"No";
	else if( g/2 > x ) cout<<"No"; 
	else cout<<"Yes";
	return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>

int main(){
	int N,D;
	scanf("%d %d",&N,&D);
	if(N%(2*D+1)==0){
		printf("%d\n",N/(2*D+1));
	}else{
		printf("%d\n",N/(2*D+1)+1);
	}
	return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    //マップはキーの順番を保持している連想配列
    map<string, int> mp;
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        mp[S]++;
    }
    int ma = 0;
    for(auto & p:mp)ma = max(ma, p.second);
    for(auto & p:mp)if(ma==p.second) cout << p.first << endl;
}

Measured memory_bytes: 23808
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	// your code goes here
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	
    ll n;
	cin>>n;
	n--;
    vector<char>v;
	
	while(n>=(ll)0){
	    ll z = 0;
	    z = n%26;
	    char c = 'a' + z;
	    v.push_back(c);
	    n = n/(ll)26;
	    n--;
	}
	
	for(int i=v.size()-1;i>=0;i--){
	    cout<<v[i];
	}   
	cout<<"\n";
	
	return 0;
}


Measured memory_bytes: 3556
n = int(input())
s = input()
#入力

WE =[]
if s[0] == 'W':
    WE.append([1,0])
else:
    WE.append([0,1])
for i in range(1,n):
    if s[i] == 'W':
        WE.append([WE[i-1][0]+1,WE[i-1][1]])
    else:
        WE.append([WE[i-1][0],WE[i-1][1]+1])

ans = n
for i in range(n):
    if i == 0:
        a = WE[n-1][1]-WE[0][1]
    elif i == n-1:
        a = WE[n-2][0]
    else:
        a = WE[i-1][0] + WE[n-1][1]-WE[i][1]
    ans = min(a,ans)

print(ans)

Measured memory_bytes: 77856
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int n, q;

struct SegmentTree {
private:
	int n;
	vector<int> node;
public:
	SegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1, 0);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2];
	}

	void add(int k, int val) {
		k += (n - 1);
		node[k] += val;

		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = node[2 * k + 1] + node[2 * k + 2];
		}
	}

	int getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return node[k];

		int vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
		return vl + vr;
	}
};

int main() {
	cin >> n >> q;
	SegmentTree seg(vector<int>(n, 0));
	for (int i = 0; i < q; i++) {
		int c, x, y;
		cin >> c >> x >> y;
		if (c == 0)seg.add(x-1, y);
		else cout << seg.getsum(x-1, y) << endl;
	}
}


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

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

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int n;
  cin >> n;
  vector<bool> v(n, false);
  v[0] = true;
  //vector<int> v(n);
  //map<pair<int, int>, int> mp;
  map<int, int> mp;
  REP(i, n) {
    int a;
    cin >> a;
    mp[i+1] = a;
  }
  
  int current = 1;
  vector<bool> used(n, false);
  used[0] = true;
  int count = 0;
  while(1) {
    eprintf("count,cur,nex:%d,%d,%d\n", count,current, mp[current]);
    current = mp[current];
    count++;
    if(current == 2) {
      cout << count << endl;
      return 0;
    }
    else if(count > n) {
      cout << "-1" << endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 4992
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int times = sc.nextInt();
			Map<String, Long> map = new HashMap<>();
			for (int i = 0; i<times; i++){
				int query = sc.nextInt();
				String key = sc.next();
				switch (query) {
				case 0:
					long x = sc.nextLong();
					map.put(key,x);
					break;
				case 1:
					System.out.println(map.get(key));
					break;
				}
			}
		}
	}
}


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

void fastInputOutput(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

ll GCD(ll a, ll b){ll gcd, g;g = __gcd(a, b);return g;}
ll gcd(ll a, ll b){if(b == 0){return a;}else{return gcd(b, a%b);}}
ll extended_gcd(ll a, ll b, ll *x, ll *y){if(a == 0){*x = 0;*y = 1;return b;}ll x1, y1;ll d = extended_gcd(b%a, a, &x1, &y1);*x = y1-(b/a)*x1;*y = x1;return d;}
ll LCM(ll a, ll b){ll gcd, g;g = __gcd(a, b);return (a/g)*b;}
ll PowFun(ll base, ll power){ll ans = 1;for(int i = 1; i <= power; i++){ans *= base;}return ans;}
/*This is better power function here used binary exponentiation*/
ll MadeFun(ll b, ll p){if(p == 0){return 1;}else if(p%2 == 0){return MadeFun(b*b, p/2);}else{return b*MadeFun(b*b, (p-1)/2);}}


const ll INF_LONG = 1LL<<61;
const unsigned int inf_int = 1<<31;
const ll mod = 1e9+7;
double phi = acos(-1);
void Solve()
{
    ll a, b; cin >> a >> b;
    a = a*b;
    cout << a << endl;
}
int main()
{
    fastInputOutput();
    Solve();
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

int N,M;
int** dp;

void func(){
	int codeTable[M];

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

	int num;
	dp[0][128] = 0;

	for(int count = 1; count <= N; count++){
		scanf("%d",&num);

		for(int i = 0; i <= 255; i++){
			if(dp[count-1][i] != BIG_NUM){
				for(int k = 0; k < M; k++){
					if(i+codeTable[k] > 255){
						dp[count][255] = min(dp[count][255],dp[count-1][i]+(num-255)*(num-255));
					}else if(i+codeTable[k] < 0){
						dp[count][0]  = min(dp[count][0],dp[count-1][i]+(num)*(num));
					}else{
						dp[count][i+codeTable[k]] = min(dp[count][i+codeTable[k]],dp[count-1][i] + (num-(i+codeTable[k]))*(num-(i+codeTable[k])));
					}
				}
			}
		}
	}

	int minimum = BIG_NUM;

	for(int i = 0; i <= 255; i++){
		minimum = min(minimum,dp[N][i]);
	}

	printf("%d\n",minimum);

}

int main(){

	dp = new int*[20001];
	for(int i = 0; i <= 20000; i++){
		dp[i] = new int[256];
	}

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		for(int i = 0; i <= N; i++){
			for(int k = 0; k <= 255; k++)dp[i][k] = BIG_NUM;
		}

		func();
	}

	return 0;
}

Measured memory_bytes: 23056
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const int N = 1005;
const ll inf = 1e18;
int parent[N];

int main() {
    int n, m;
    cin >> n >> m;
    vector< ll> dist(n + 1, -inf);

    vector< tuple< int, int, int> > V;
    while (m--) {
        int a, b, c;
        cin >> a >> b >> c;
        V.push_back(make_tuple(a, b, c));
    }

    dist[1] = 0;
    for (int i = 0; i < n; ++i) {
        for (auto& it : V) {
            int a, b, c;
            tie(a, b, c) = it;
            if (dist[a] + c > dist[b]) {
                dist[b] = dist[a] + c;
                parent[b] = a; 
            }
        }
    }

    vector< bool> inpath(n + 1, 0);
    parent[1] = -1;

    int x = n;
    while(x != -1) {
        if(inpath[x]) break;
        inpath[x] = 1;
        x = parent[x];
    }

    bool ok = true;
    for (auto& it : V) {
        int a, b, c;
        tie(a, b, c) = it;
        if (dist[a] + c > dist[b]) {
            if(inpath[b]) ok = false;
        }
    }

    if(ok) printf("%lld\n", dist[n]);
    else puts("inf");
}

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

int main()
{
    int l,r;
    cin >> l >> r;
    int i, j;
    int tmp = 2018;
    for(int k=l;k<min(r,l+2019);k++){
        for(int m=k+1;m<=min(r,k+2019);m++){
            if(((k%2019)*(m%2019))%2019 < tmp){
                tmp = ((k%2019) * (m%2019)) % 2019;
                i = k;
                j = m;
            }
        }
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 384
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M, K = MI()
    uf = UnionFind(N)
    fri_list = [[]for _ in range(N)]
    blo_list = [[]for _ in range(N)]
    cnt_list = [0] * N
    for i in range(M):
        a, b = MI()
        a, b = a - 1, b - 1
        uf.union(a, b)
        fri_list[a].append(b)
        fri_list[b].append(a)
    for i in range(K):
        c, d = MI()
        c, d = c - 1, d - 1
        blo_list[c].append(d)
        blo_list[d].append(c)
    for i in range(N):
        cnt = uf.size(i)
        cnt -= len(fri_list[i]) + 1
        for b in blo_list[i]:
            if uf.same(i, b) == True:
                cnt -= 1
        cnt_list[i] = cnt
    print(' '.join(map(str, cnt_list)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 112652
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int N=26;

int main(){
  int D;
  cin>>D;
  int c[N];
  REP(i,N)cin>>c[i];
  int s[D][N];
  REP(d,D)REP(n,N)cin>>s[d][n];
  int t[D];
  REP(i,D){
    cin>>t[i];
    t[i]--;
  }
  lint ans=0;
  int last[N];
  REP(n,N)last[n]=-1;
  REP(d,D){
    ans+=s[d][t[d]];
    last[t[d]]=d;
    REP(n,N)ans-=c[n]*(d-last[n]);
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int N,T,A,i,dif,ANS;
  cin>>N>>T>>A;
  
  int ans = 1e9;
  A=1000*A;
  vector<int> H(N);
  for(i=0;i<N;i++){
    cin>>H[i];
    H[i] = T*1000-H[i]*6;
    dif = abs(A-H[i]);
    if (dif < ans){
      ans = dif;
      ANS = i+1;
    }
  }
  cout << ANS;

}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(){
    int x[1000]={0};
    int N=0;
    int i=0;
    int K=0;
    int a=0;
    int b=0;
    int ans=0;
    cin>>N>>K;
    for(i=0;i<N;i++){
        cin>>x[i];
        if(x[i]>=K){
            b=x[i]-K;
        }else{
            b=K-x[i];
        }
        if(x[i]>=b){
            ans=ans+b*2;
        }else{
            ans=ans+x[i]*2;
        }
    }
    
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
int32_t main()
{
fastio;
int n;in n;
string s;in s;
bool f=false;
int c=0;
for(int i=1;i<=s.size();i++){
    if(s[i]==s[i-1]){
        if(f==true) continue;
        else {
            f=true;
            //out i<<" ";
        }
    }
    else {
    c++;
    }
}
out c;
    return 0;
}


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

class UF{
  vi p,r;

public:
  UF(int n):p(n,-1),r(n,0){ }

  int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }

  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }

  bool same(int x,int y){return find(x)==find(y);}
};

const int INF= 1e9;

struct edge{
  int from, to, cost;
  edge(int x,int y, int z):from(x),to(y),cost(z){}
  bool operator<(const edge &x)const{ return cost>x.cost; }
  //逆！！！ (for priority_queue)
};

class Kruskal{
  int n;
  vector< vector<edge> > g;
public:
  Kruskal(int a=0):n(a){ g.resize(n); }

  void AddEdge(int a, int b, int cost){
    g[a].push_back(edge(a,b,cost));
    g[b].push_back(edge(b,a,cost));
  }

  int MinSpanningTree(){
    UF connect(n);
    priority_queue<edge> q;
    for(int v=0;v<n;v++){
      for(int i=0;i<(int)g[v].size();i++)q.push(g[v][i]);
    }
    
    int res = 0;
    while(q.size()){
      edge e = q.top(); q.pop();
      if(!connect.same(e.from,e.to)){
	res += e.cost;
	connect.unite(e.from,e.to);
      }
    }
    return res;
  }
};

int main(){
  int n,m;
  while(scanf("%d",&n),n){
    Kruskal p(n);
    cin >> m;
    for(int i=0;i<m;i++){
      int a,b,c;
      scanf("%d,%d,%d",&a,&b,&c);
      p.AddEdge(a,b,c/100-1);
    }
    cout << p.MinSpanningTree() << endl;
  }
}

Measured memory_bytes: 1636
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	char a, b;
  cin>>a>>b;
  cout<<(a==b?'H':'D')<<endl;
	return 0;
}


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

x,y=[int(i) for i in input().rstrip().split()]

g1={1,3,5,7,8,10,12}
g2={4,6,9,11}
g3={2}

for G in [g1,g2,g3] :
  if all( n in G for n in [x,y] ):
    print("Yes")
    break
else:
  print("No")

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

int main()
{
	int A, B, C, D, ans = 0;

	cin >> A >> B >> C >> D;

	if (C < B) ans = max(0,D - C - max(D - B,0)- max(A-C,0));
	
	cout << ans;

	return 0;
}

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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999
#define P(x)           printf("%d\n", (x));

typedef long long ll;

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

	switch(D){
	case 22: cout << "Christmas Eve Eve Eve" << endl; break;
	case 23: cout << "Christmas Eve Eve" << endl; break;
	case 24: cout << "Christmas Eve" << endl; break;
	case 25: cout << "Christmas" << endl; break;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<int> e(n,0), w(n,0);
  rep(i,n){
    if(s[i]=='W') e[i]++;
    if(i==n-1) break;
    e[i+1] = e[i];
  }
  rrep(i,n-1){
    if(s[i]=='E') w[i]++;
    if(i==0) break;
    w[i-1] = w[i];
  }
  int ans=INF;
  reps(i,1,n-1) chmin(ans, e[i-1] + w[i+1]);
  chmin(ans, w[1]);
  chmin(ans, e[n-2]);
  //rep(i,n) cout << e[i] << " " << w[i] << endl;
  cout << ans;

return 0;
}


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

int main() {

  int X, A, B; cin >> X >> A >> B;
  if (B - A <= 0) {
    cout << "delicious" << endl;
  }
  else if (B - A > X) {
    cout << "dangerous" << endl;
  }
  else {
    cout << "safe" << endl;
  }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll dp[2010][2010]={0},in[2020],n,o;
queue<pii>q;
int main(){
	cin>>n;rep(i,n)cin>>in[i];
	rep(i,n)dp[i][1]=in[i],q.push(pii(i,1));
	while(!q.empty()){
		pii r=q.front();q.pop();
		int a=r.first,b=r.second,s=a-1,t=(s+1+b)%n;
		if(s==-1)s=n-1;
		rep(i,2){
			if(b%2&&in[s]<in[t])s=a;
			if(dp[s][b+1]<dp[a][b]+(b%2?0:in[(i?t:s)])){
				dp[s][b+1]=dp[a][b]+(b%2?0:in[(i?t:s)]);
				if(b+1!=n)q.push(pii(s,b+1));
			}
			if(b%2==0)s=a;
		}
	}
	rep(i,n)o=max(o,dp[i][n]);
	cout<<o<<endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int count[110];
int dp[110][110];

int rec(int i, int c){
    if(i == 100){
        return c == 75;
    }

    if(dp[i][c] != -1){
        return dp[i][c];
    }

    int res = 0;
    for(int j=0;j<=count[i];++j){
        int nc = c * (j + 1);
        if(nc <= 75){
            res += rec(i + 1, nc);
        }
    }

    return res;
}

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

    int N;
    std::cin >> N;

    for(int i=2;i<=N;++i){
        int x = i;
        for(int j=2;j<=x;++j){
            while(x % j == 0){
                x /= j;
                count[j] += 1;
            }
        }
    }

    memset(dp, -1, sizeof(dp));
    
    int res = rec(1, 1);
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
N = int(input())
n = len(str(N))

cnt = 0
for i in range(3,n+1):
    l = []
    x = ""
    def fa(x,l,i):
        if len(x) == i:
            if int(x) <= N:
                if x.count("3") >= 1 and x.count("5") >= 1 and x.count("7"):
                    l.append(x)
            return 
        else:
            x += "3"
            fa(x,l,i)
            fb(x,l,i)
            fc(x,l,i)
    def fb(x,l,i):
        if len(x) == i:
            if int(x) <= N:
                if x.count("3") >= 1 and x.count("5") >= 1 and x.count("7"):
                    l.append(x)
            return 
        else:
            x += "5"
            fa(x,l,i)
            fb(x,l,i)
            fc(x,l,i)
    def fc(x,l,i):
        if len(x) == i:
            if int(x) <= N:
                if x.count("3") >= 1 and x.count("5") >= 1 and x.count("7"):
                    l.append(x)
            return 
        else:
            x += "7"
            fa(x,l,i)
            fb(x,l,i)
            fc(x,l,i)
    fa(x,l,i)
    fb(x,l,i)
    fc(x,l,i)
    k = sorted(set(l))
    cnt += len(k)

print(cnt)

Measured memory_bytes: 5716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define VEC vector<int>
typedef pair<int, int>pii;
typedef pair<int, bool>pib;
// vector<VEC> v (n, VEC(n))
//loop(i,n)loop(j,n)dp[i][j]=-1;
//printf("%d\n", n);
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	string s;
	cin >> s;
	bool ans = false;
	loop(i, s.length() - 1)
	{
		if (s[i] == 'A'&&s[i + 1] == 'C')
		{
			ans = true;
			break;
		}
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <time.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <math.h>
#define ll long long
#define int64 long long
#define ull unsigned long long
#define pb push_back
#define INF 0x3f3f3f3f
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define pi 3.141592653589793238462

using namespace std;

const int maxn = 305;
const int maxm = 2e6 + 5;
const int mod = 1e9 + 7;
const int seed = 10007;
const double eps = 1e-5;
int n, m;
int a[maxn][maxn];
bool vis[maxn];
int num[maxn];
int ans;

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    memset(vis, true, sizeof(vis));
    ans = INF;
    for (int i = 0; i < m; i++) {
        memset(num, 0, sizeof(num));
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= m; k++) {
                int tar = a[j][k];
                if (vis[tar]) {
                    num[tar]++;
                    break;
                }
            }
        }
        int x, y = 0;
        for (int j = 1; j <= m; j++) {
            if (num[j] > y) {
                y = num[j], x = j;
            }
        }
        ans = min(y, ans);
        vis[x] = false;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main=do
    [n,c,k]<-map read.words<$>getLine
    ts<-sort <$> replicateM n (fst.fromJust.B.readInt<$>B.getLine)
    let ks = map (+k) ts
    print $ sol 0 0 c ts ks

sol n w c [] _ = n+(w+c-1)`div`c
sol n 0 c (t:ts) (k:ks) = sol n 1 c ts (k:ks) 
sol n w c (t:ts) (k:ks)
    | w == c = sol (n+1) 0 c (t:ts) $ drop c (k:ks)
    | k >= t = sol n (w+1) c ts (k:ks)
    | otherwise = sol (n+1) 0 c (t:ts) $ drop w (k:ks)

Measured memory_bytes: 30972
#include <iostream>
using namespace std;
const int maxm = 1e4 + 10;
int a[maxm];
int main()
{
	int n, m, sum = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	if (n - sum < 0)
		cout << -1 << endl;
	else
		cout << n - sum << endl;
	return 0;
}

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

struct UnionFind{
    vector<int> parent;
    vector<int> rank;
    UnionFind(int n):rank(n+1,0),parent(n+1){
        rep(i,n+1) parent[i]=i;
    }

    int find(int x){
        if (parent[x] == x) return x;
        else return find(parent[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x==y) return;
        else if(rank[x]<rank[y]) parent[x]=y;
        else{
            parent[y]=x;
            if (rank[x]==rank[y]){
                rank[x]+=1;
            }
        }
    }
};

/*abc157-d*/
int main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vector<int> friends(n+1);
    vector<int> bad(n+1);
    rep(i,n+1){
        friends[i]=0;
        bad[i]=0;
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        friends[a]++;
        friends[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int c,d;
        cin >> c >> d;
        if (uf.find(c)==uf.find(d)){
            bad[c]++;
            bad[d]++;
        }
    }
    vector<int> group(n+1);
    rep(i,n)group[i]=0;
    rep(i,n){
        int par;
        par = uf.find(i+1);
        group[par]++;
    }
    rep(i,n){
        int par;
        par = uf.find(i+1);
        cout << group[par] - friends[i+1]-bad[i+1]-1;
        cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2816