akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int mod = 1000000007;

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

    vector<int> dp(k+1);
    dp[k] = 1;
    rep(i,n){
        vector<int> nx(k+1);

        int x = 0;
        for(int j=k; j>=k-a[i]; --j){
            (x += dp[j]) %= mod;
            nx[j] = x;
        }
        for(int j=k-a[i]-1; j>=0; --j){
            (x += dp[j]) %= mod;
            (x += mod-dp[j+a[i]+1]) %= mod;
            nx[j] = x;
        }

        dp = nx;
    }
    cout << dp[0] << "\n";
    return 0;
}


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

const long long MOD = 998244353;

int A, B, C, D;

long long memo[3005][3005][2];

/*
long long dp(int i, int j){
    if(i < A || j < B){
        return 0;
    }else if(i == A && j == B){
        return 1;
    }else if(i == A){
        return memo[i][j] = A*dp(i, j-1)%MOD;
    }else if(j == B){
        return memo[i][j] = B*dp(i-1, j)%MOD;
    }else if(memo[i][j] != -1){
        return memo[i][j];
    }else{
        long long res = ((j)*dp(i-1, j)%MOD + (i)*dp(i, j-1)%MOD)%MOD;
        printf("dp(%d, %d)=%lld\n", i, j, res);
        return memo[i][j] = res;
    }
}
*/

long long dp(int i, int j, int mode){
    if(i > C || j > D){
        return 0;
    }else if(i == C && j == D){
        return 1;
    }else if(memo[i][j][mode] != -1){
        return memo[i][j][mode];
    }

    long long res = 0;
    if(mode == 0){
        res += i*dp(i, j+1, 0); // lazily turn right
        res += j*dp(i+1, j, 1); // forced to push up
    }else{
        res += dp(i, j+1, 0);
        res += j*dp(i+1, j, 1);
    }

    res %= MOD;
    //printf("dp(%d, %d, %d)=%lld\n", i, j, mode, res);
    return memo[i][j][mode] = res;
}

int main(){
    scanf("%d%d%d%d", &A, &B, &C, &D);

    memset(memo, -1, sizeof(memo));
    printf("%lld", dp(A, B, 0));
    return 0;
}


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

int main() {
	string s; cin >> s;
	int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
	int nums[4] = {a, b, c, d};

	for (int bit = 0; bit < (1 << 3); ++bit) {
		string ans = to_string(a);
		int sum = a;

		for (int i = 0; i < 3; ++i) {
			int num = nums[i + 1];
			// bit = 1 -> +
			if (bit & (1 << i)) {
				sum += num;
				ans += "+" + to_string(num);
			}

			// bit = 0 -> -
			else {
				sum -= num;
				ans += "-" + to_string(num);
			}
		}

		if (sum == 7) {
			ans += "=7";
			cout << ans << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                emplace_back
#define mp              make_pair
#define sz(a)           a.size()
#define mods(a, m)          ((a % m + m) % m)   
#define md(a)               mods(a, MOD)
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)     for (int i = b; i < e; i++)
#define forr(i, b, e)     for (int  i = b; i < e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;
typedef long double       ld;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e7 + 7);
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1);
#define tam 1230456
ll go(ll n)
{
    if (n==1)
        return 1;
    return go(n/2)*2+1;
}
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    ll n;
    cin>>n;
    cout<<go(n);

}
// PLUS ULTRA!


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


int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
template<class T> inline bool chmax(T& a, T b) { if(a<b) { a = b; return 1;} return 0;}

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

    vector<int> left(N+1,0),right(N+1,0);
    for(int i=0;i<N;i++) left[i+1]=GCD(left[i],a[i]);
    for(int i=N-1;i>=0;i--) right[i]=GCD(right[i+1],a[i]);

    int res=0;
    for (int i = 0; i < N; i++) {
      int l=left[i];
      int r=right[i+1];
      chmax(res,GCD(l,r));
    }
    cout<<res<<endl;
   
}


Measured memory_bytes: 1408
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto X = readln.split.map!(to!int).array;
    auto L = readln.chomp.to!int;

    auto dp = new int[][](N, 30); // 頂点iから2^j回の移動で辿りつける最遠頂点
    int left = 0;
    int right = 0;
    while (right < N) {
        if (X[right] - X[left] <= L) {
            right++;
            continue;
        }
        else {
            dp[left][0] = right-1;
            left++;
        }
    }
    while (left < N) dp[left][0] = N-1, left++;

    foreach (j; 0..29) {
        foreach (i; 0..N) {
            dp[i][j+1] = dp[dp[i][j]][j];
        }
    }

    auto Q = readln.chomp.to!int;
    while (Q--) {
        auto s = readln.split.map!(to!int);
        auto a = s[0]-1;
        auto b = s[1]-1;
        if (b < a) swap(a, b);
        auto ans = 0;
        while (dp[a][0] < b) {
            auto k = 0;
            while (dp[a][k+1] < b) k++;
            ans += 2^^k;
            a = dp[a][k];
        }
        writeln(ans+1);
    }
}


Measured memory_bytes: 32152
import math

a,b,C = map(float, input().split())

if C == 90:
    L = a + b + math.sqrt(a**2 + b**2)
    h = b
    S = (a*b) / 2
else:
    L = a + b + math.sqrt(a**2 + b**2 -2 * a * b * math.cos(math.radians(C)))

    h = b * math.sin(math.radians(C))

    S = 0.5 * a * b * math.sin(math.radians(C))

print(S,L,h)


Measured memory_bytes: 5672
# 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>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int main() {
	string s;
	cin >> s;
	int ans = 700;
	if (s[0] == 'o')ans += 100;
	if (s[1] == 'o')ans += 100;
	if (s[2] == 'o')ans += 100;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>

#define INF pow(2, 30)

using namespace std;

int dp[1024][1024];

int main(void){
	int n, m;
	scanf("%d %d", &n, &m);
	int D[1024];
	int C[1024];

	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;

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

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

	for(int i = 0;i < n;++i){
		for(int j = 0;j < m;++j){
			dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
			dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + D[i]*C[j]);
		}
	}

	int t = INF;
	for(int i = 1;i <= m;++i){
		t = min(t, dp[n][i]);
	}

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

	return 0;
}


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

int main () {
    int N,K;
    map<int, int> A;
    cin >> N >> K;
    for(int i = 1; i<=N; i++) A[i] = 0;
    for(int i = 0; i<K; i++) {
        int d;
        cin >> d;
        for(int i = 0; i<d; i++) {
            int A_tmp;
            cin >> A_tmp;
            A[A_tmp]++;
        } 
    }
    int res = 0;
    for(auto x: A) {
        if(x.second == 0) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[200007];
ll brr[200007];
ll m = 1e9+7;
int main()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;++i)
    {
        cin>>arr[i];
        brr[i] = ((arr[i]%m)+(brr[i-1]%m))%m;
    }
    ll sum = 0;
    for(ll i=2;i<=n;++i)
    {
        ll val  = ((arr[i]%m)*(brr[i-1]%m))%m;
        sum = ((sum%m)+(val%m))%m;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 6720
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int ans = 0;
  REP(i, N){
    int tmp; cin >> tmp;
    ans += tmp - 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    int n;
    cin >> n;
    vector<int> Graph[n];
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        Graph[a].push_back(b);
        Graph[b].push_back(a);
    }
    vector<int> dist(n, -1);
    dist[0] = 0;
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()) {
        int now = Q.front();
        Q.pop();
        for(auto x : Graph[now]) {
            if(dist[x] != -1) continue;
            dist[x] = dist[now] + 1;
            Q.push(x);
        }
    }
    int count0 = 0;
    rep(i, n) {
        if(dist[i] % 2 == 0) count0++;
    }
    int count1 = n - count0;
    int now1 = 1, now2 = 2, now3 = 3;
    vector<int> Ans(n, -1);
    if(count0 < (n+2) / 3) {
        rep(i, n) {
            if(dist[i] % 2 == 1) {
                if(now1 <= n) {
                    Ans[i] = now1;
                    now1 += 3;
                } else {
                    Ans[i] = now2;
                    now2 += 3;
                }
                if(now1 > n && now2 > n) break;
            }
        }
    }
    if(count1 < (n+2) / 3) {
        rep(i, n) {
            if(dist[i] % 2 == 0) {
                if(now1 <= n) {
                    Ans[i] = now1;
                    now1 += 3;
                } else {
                    Ans[i] = now2;
                    now2 += 3;
                }
                if(now1 > n && now2 > n) break;
            }
        }
    }
    if(count0 >= (n+2) / 3 && count1 >= (n+2) / 3) {
        rep(i, n) {
            if(dist[i] % 2 == 0) {
                if(now1 <= n) {
                    Ans[i] = now1;
                    now1 += 3;
                }
            } else {
                if(now2 <= n) {
                    Ans[i] = now2;
                    now2 += 3;
                }
            }
        }
    }
    rep(i, n) {
        if(Ans[i] == -1) {
            cout << now3 << ' ';
            now3 += 3;
        } else {
            cout << Ans[i] << ' ';
        }
    }
}


Measured memory_bytes: 18280
n = gets.to_i

a = (1..100).to_a

result = Array.new(70000, 0)

a.repeated_combination(3).each{ |x|
	f = x[0] ** 2 + x[1] ** 2 + x[2] ** 2 + x[0] * x[1] + x[1] * x[2] + x[2] * x[0]
	size = x.uniq.size
	if size == 1 then
		result[f] += 1
	elsif size == 2 then
		result[f] += 3
	else
		result[f] += 6
	end
}

(1..n).each{|x|
	puts result[x]
}


Measured memory_bytes: 14908
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int N = 2e5+100;
struct node{ int x,v; };
bool operator < (node a,node b){ return a.v<b.v; }

int a[N],b[N],n; ll ans;
bool check(){
    priority_queue<node> Q;
    for(int i=1;i<=n;++i) Q.push((node){i,b[i]});
    while(!Q.empty()){
        node cur=Q.top(); Q.pop();
        if(a[cur.x]<b[cur.x]){
            int l=cur.x-1; if(l<=0) l+=n;
            int r=cur.x+1; if(r>n) r-=n;
            int up=b[l]+b[r];
            //if(up>=b[cur.x]) return false;
            ans+=(b[cur.x]-a[cur.x])/up;
            if(b[cur.x]-a[cur.x]<up) return false;
            b[cur.x]-=(b[cur.x]-a[cur.x])/up*up;
        }
        if(a[cur.x]<b[cur.x]) Q.push((node){cur.x,b[cur.x]});
    }
    for(int i=1;i<=n;++i) if(b[i]!=a[i]) return false;
    return true;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    for(int i=1;i<=n;++i) scanf("%d",&b[i]);
    if(check()) printf("%lld\n",ans);
    else printf("-1\n");
    return 0;
}

Measured memory_bytes: 3956
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let s = buf.trim().chars().collect::<Vec<char>>();
    let mut c = 0 as u64;
    for i in s {
        c += (i as u8 - 48_u8) as u64;
        c = c%9;
    }
    if c == 0 {
        println!("Yes");
    }else{
        println!("No");
    }
}

Measured memory_bytes: 2960
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 10000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[300001];
ll res[100001];
ll res2[100001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n*3;i++){
		scanf("%lld",&a[i]);
	}
	priority_queue<ll,vector<ll>,greater<ll> > que;
	ll sum=0;
	for(int i=0;i<n;i++){
		que.push(a[i]);
		sum+=a[i];
	}
	res[0]=sum;
	for(int i=n;i<2*n;i++){
		que.push(a[i]);
		sum+=a[i];
		ll v=que.top();
		que.pop();
		sum-=v;
		res[i-n+1]=sum;
	}
	priority_queue<ll> que2;
	sum=0;
	for(int i=2*n;i<3*n;i++){
		que2.push(a[i]);
		sum+=a[i];
	}
	res2[n]=sum;
	for(int i=2*n-1;i>=n;i--){
		que2.push(a[i]);
		sum+=a[i];
		ll v=que2.top();
		que2.pop();
		sum-=v;
		res2[i-n]=sum;
	}
	ll ans=res[0]-res2[0];
	for(int i=1;i<=n;i++){
		ans=max(ans,res[i]-res2[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int n,m;
    cin>>n>>m;
    cout<<(n*(n-1))/2+(m*(m-1))/2<<endl;
}

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

int main() {
    vector<int> nums(10, 0);
    rep(i, 3) {
        int a;
        cin >> a;
        nums[a]++;
    }
    for (int i = 0; i < 10; i++) {
        if (nums[i] == 2) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
def together(xs)
  xs.sort!
  ans = [[xs[0]]]
  j = 0
  for i in 1..(xs.length - 1)
    if xs[i] == xs[i - 1]
      ans[j] << xs[i]
    else
      ans << [xs[i]]
      j += 1
    end
  end
  ans
end

def count2(xs)
  xs = together(xs)
  ans = []
  for x in xs
    ans << [x[0], x.length]
  end
  ans
end

n = gets.to_i
as = gets.split.map(&:to_i)
as = count2(as)
ans = 0
for a in as
  diff = a[1] - a[0]
  ans += diff if diff > 0
  ans += a[1] if diff < 0
end
puts ans

Measured memory_bytes: 18068
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n[3]; rep(i, 3) cin >> n[i];
    sort(n, n+3);
    cout << n[2]*10+n[1]+n[0] << ln;
}



Measured memory_bytes: 256
dict={}
n=int(input())
for i in range(n):
    s=input()
    if s in dict:
        dict[s]+=1
    else:
        dict.setdefault(s,0)
itemMaxValue = max(dict.items(), key=lambda x: x[1])
listOfKeys = []

for key, value in dict.items():
    if value == itemMaxValue[1]:
        listOfKeys.append(key)
        
listOfKeys.sort()
for x in listOfKeys:
    print(x)

Measured memory_bytes: 32096
N, M = map(int, input().split())

AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

# print(N, M)
# print(AB)

AB.sort(key=lambda x: x[0])
# print(AB)

count = 0
cost = 0
for a, b in AB:
    if count + b <= M:
        count += b
        cost += a * b
    else:
        diff = M - count
        count += diff
        cost += a * diff

    if count == M:
        break

print(cost)


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

char s[3333];
char t[3333];

enum {
	DROP_S,
	DROP_T,
	USE
};

int slen, tlen;
int data[3333][3333];

int mamegu[3333][3333];

int main(void) {
	int i, j;
	if (scanf("%3332s", s) != 1) return 1;
	if (scanf("%3332s", t) != 1) return 1;
	slen = (int)strlen(s);
	tlen = (int)strlen(t);

	for (i = slen - 1; i >= 0; i--) {
		for (j = tlen - 1; j >= 0; j--) {
			int action = DROP_S;
			int score = data[i + 1][j];
			if (data[i][j + 1] > score) {
				action = DROP_T;
				score = data[i][j + 1];
			}
			if (s[i] == t[j] && data[i + 1][j + 1] + 1 > score) {
				action = USE;
				score = data[i + 1][j + 1] + 1;
			}
			data[i][j] = score;
			mamegu[i][j] = action;
		}
	}

	for (i = j = 0; i < slen && j < tlen; ) {
		switch (mamegu[i][j]) {
			case DROP_S:
				i++;
				break;
			case DROP_T:
				j++;
				break;
			case USE:
				putchar(s[i]);
				i++;
				j++;
				break;
		}
	}
	putchar('\n');

	return 0;
}


Measured memory_bytes: 79736
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)

Int N;
Int res[900];


Int solve(int x){
	res[x] = res[x-1] + res[x-2];
	x+=1;
	if (x-1==N) return res[x-1];
    else return solve(x);
}

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

	cin >> N;
	res[0]=2;
	res[1]=1;
	for (Int i=2;i<=N;i++)res[i]=res[i-1]+res[i-2];
	cout<<res[N]<<endl;
	return 0;
}

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

int main() {
    int k, n;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(),a.end());
    int ans = 0;
    rep(i, k) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 3628
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int A[] = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = scanner.nextInt();
        }
 
        System.out.println(Arrays.toString(A).replaceAll("[,\\[\\]]", ""));
        for (int j = 1; j < A.length; j++) {
            int key = A[j];
            int i = j - 1;
            while (i >= 0 && A[i] > key) {
                A[i + 1] = A[i];
                i--;
            }
            A[i + 1] = key;
            System.out.println(Arrays.toString(A).replaceAll("[,\\[\\]]", ""));
        }
    }
}

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

bool v[30005];
int n,a[20005],t;

int main(){
	scanf("%d",&n);
	if(n==3){ puts("2 5 63"); return 0;}
	for(int i=2;i<n;i+=2) if((n-i)<=15000&&i<=5000&&(n-i)%3!=1){
        for(int j=2,c=1;j<=30000&&c+i<=n;j+=2,c++) printf("%d ",j);
		for(int j=3,c=1;j<=30000&&c<=i;j+=3) if(j&1) printf("%d ",j),c++;
		break;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  int a,b;cin>>a>>b;
  int n = b - a;
  int ans = n*(n+1)/2 - b;
  cout << ans << endl;
}


Measured memory_bytes: 256
a = int(input())
b = input()
def my_count(l):
  p = 0
  for i in range(10):
    i = str(i)
    if i in l:
      p = p + 1
  return p
s = []
ans = 0
for i in range(10):
  k = str(i)  
  s.append(b.find(k))
  if s[i] >= 0:
    for j in range(10):
      h = str(j)  
      y = b[s[i]+1:len(b)]
      t = y.find(h)
      if t >= 0:
        c = y[t+1:len(b)]
        ans = ans + my_count(c)
print(ans)

Measured memory_bytes: 3188
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	static int ans = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		
		//方針
		//数字とindexをpairとかで持っておき、数字ソート
		//loop
		//大きい順に、自分より大きい数字を一つ含む時の左と右の候補を計算
		//Treesetに自分のindexを入れる
		//loop
		String tt = sc.next();
		String ss = sc.next();
		int ans = 0;
		for(int i = 0;i < 3;i++){
			if(tt.charAt(i) == ss.charAt(i)){
				ans++;
			}
		}
		System.out.println(ans);




	}


	static void sieve(ArrayList<Long> list){
		int n = 50000000;
		boolean[] is_prime = new boolean[n+1];
		int[] prime = new int[n];
		for(int i= 0;i <=n;i++){
			is_prime[i] = true;
		}
		list.add((long) 1);
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				list.add((long)i);
				for(int j = 2*i;j <= n;j+=i){
					is_prime[j] = false;
				}
			}
		}



	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}

class Town{
	int index;
	int x ;
	int y;
	public Town(int index,int x,int y) {
		this.index = index;
		this.x = x;
		this.y = y;
		// TODO 自動生成されたコンストラクター・スタブ
	}


}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}

class Pair implements Comparable{
	int from;
	int end;
	public Pair(int from,int end) {
		this.from = from;
		this.end = end;
		// TODO 自動生成されたコンストラクター・スタブ
	}

	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   otherpair.from - from;
	}








}






Measured memory_bytes: 21844
function main (s) {
    s=s.split(" ");
	console.log((s[0][s[0].length-1]==s[1][0]&&s[1][s[1].length-1]==s[2][0])?"YES\n":"NO\n");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>
int main(void){

int N, m;
scanf("%d", &N);
int a[N];
m = 0;

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

for(int i = 0;i<N;i++){
    for(int j = 0;j<i;j++){
        m += a[i]*a[j];
    }
}

printf("%d\n", m);
    return 0;
}

Measured memory_bytes: 128
while True:
  a,op,b = input().split()
  a = int(a)
  b = int(b)
  if op== "?" : break
    
  if op == "+":
      print(int(a+b))
  elif op == "-":
      print(int(a-b))
  elif op == "*":
      print(int(a*b))
  elif op == "/":
      print(int(a/b))
  else:break


Measured memory_bytes: 5596
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
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; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int N,X,Y;
    cin >> N >> X >> Y;
    ll ans[2005] = {};
    ll dist;
    for(int i=1; i<=N; ++i)
    {
        for(int j=i; j<=N; ++j)
        {
            dist = min(abs(j-i),min(abs(X-i)+1+abs(Y-j),abs(X-j)+abs(Y-i)+1));
            ++ans[dist];
        }
    }

    for(int i=1; i<N; ++i)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' ||s[2] == '7'  ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e6+3)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


ll power(ll x,ll k){
  ll ret=1;
  while(k>0){
    if(k&1) (ret*=x) %= M;
    (x*=x) %= M;
    k >>= 1;
  }
  return ret;
}

int fact[M+10];
int ifact[M+10];

main(){
  fact[0]=1;
  FOR(i,1,M+1){
    fact[i]=(1LL*fact[i-1]*i)%M;
    ifact[i]=power(fact[i],M-2);
  }

  int q;
  cin>>q;
  while(q--){
    int x,d,n;
    cin>>x>>d>>n;
    if(d==0){
      cout<<power(x,n)<<endl;
    }else{
      int t=(1LL*x*power(d,M-2))%M;
      
      if(t<=M&&M<=t+n-1){
        cout<<0<<endl;
      }else{
        cout<<(((1LL*fact[t+n-1]*ifact[t-1])%M)*power(d,n)%M)<<endl;
      }
    }
  }
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int S;
  cin >> S;

  int p = pow(10, 9);

  cout << 0 << " " << 0 << " ";
  cout << p << " " << 1 << " ";
  cout << (p - 1) - (S - 1) % p << " " << (S - 1) / p + 1 << endl;

  cerr << abs(p * ((S - 1) / p + 1) - ((p - 1) - (S - 1) % p));
}

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


int main() {
  int A,B;
  cin >> A >> B;

  if (A > 2*B){
  cout << A-2*B << endl;
  }else{
    cout << 0 <<endl;
  }
}

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

int a[55];

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	sort(a, a + n, greater<int>());
	int ans = 0;
	for(int i = 0; i < k; i++)
		ans += a[i];
	printf("%d\n", ans);
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    set<int> values;
    values.insert(a[0]);
    values.insert(a[1]);
    values.insert(a[2]);
    
    cout << values.size() << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
typedef long long ll;
typedef pair<int,int> pii;

int main() {
    #ifndef LOCAL
        fastIO;
    #endif
    int n,k,temp,entradas,rta=0;
    cin >> n >> k;
    int snukes[n+1];
    memset(snukes,0,sizeof(snukes));
    for(int i=0;i<k;i++){
        cin >> temp;
        for(int j=0;j<temp;j++){
            cin >> entradas;
            snukes[entradas]++;
        }
    }
    for(int i=1;i<n+1;i++){
        if(snukes[i]==0) rta++;
    }
    cout << rta << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const int INF = 1001001001;
vector<vector<int>> graph;
vector<int> counter;
vector<int> ans;
vector<bool> reached;


int main(){
    int N,Q;
    cin >> N >> Q;
    graph = vector<vector<int>>(N);
    counter = vector<int>(N,0);
    reached = vector<bool>(N,false);
    ans = vector<int>(N,0);
    int x,y;
    for(int i=0;i<N-1;i++){
        cin >> x >> y;
        x--;y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    for(int i=0;i<Q;i++){
        cin >> x >> y;
        x--;
        counter[x] += y;
    }

    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        ans[v] += counter[v];
        reached[v] = true;
        for(auto x : graph[v]){
            if(reached[x]) continue;
            ans[x] += ans[v];
            que.push(x);
        }
    }
    for(int i=0;i<N;i++) cout << ans[i] << ' ';
    cout << endl;
}


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

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

ll gcd(ll x, ll y){
    if(y == 0) return x;
    else return gcd(y, x%y);
}

//gcd(A, B)の約数（＝A, Bの公約数）を求める関数
//求めた公約数は、vector<pair<ll, int>>型配列に入れられる。(firstが公約数の値、secondが出現回数)
vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> p;
    //Nの約数を求める時は、約数の候補は、1~sqrt(N)までを見ればよいことから、このようにする
    //今回は1はmain関数内のarray.size()+1の+1で補っている
    for(ll i = 2; i*i < n; i++){
        if(n % i != 0) continue;
        p.emplace_back(i, 0);
        //iで何回割れるかを求める
        while(n % i == 0){
            n /= i;
            p.back().second++;
        }
    }
    if(n != 1) p.emplace_back(n, 1);
    return p;
}

int main(){
    ll A, B;
    cin >> A >> B;
    ll g = gcd(A, B);
    auto array = factorize(g);
    ll ans = array.size() + 1;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

const double pi = 3.14159265358979323846;

// #define fio() cin.tie(0); ios::sync_with_stdio(false);
// template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
// template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos
// 1e18

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

  ll A, B;
  cin >> A >> B;

  ll r = A * B;
  r -= A + B - 1;

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, K; cin >> N >> K;
    vec x(N); readvec(x);
    SORT(x);
    
    int ans = INF, tmp;
    REP(i, N - K + 1){
        if(x[i] * x[i + K - 1] < 0){
            tmp = x[i + K - 1] - x[i] + min(llabs(x[i]), llabs(x[i + K - 1]));
        }else{
            tmp = max(llabs(x[i]), llabs(x[i + K - 1]));
        }
        ans = min(tmp, ans);
    }

    cout << ans;

    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 1024
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

x, n = MAP()
p = LIST()
i = 0
while True:
    if x-i not in p:
        print(x-i)
        sys.exit()
    if x+i not in p:
        print(x+i)
        sys.exit()
    i += 1

Measured memory_bytes: 72548
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    long long N;
    cin >> N;
    if (N % 2 == 0) cout << N << endl;
    else cout << N * 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#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 XOX
    ~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__) << ", "

#define F first
#define S second
#define endl '\n'
#define pb emplace_back
#define mp make_pair
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define all(v) (v).begin(), (v).end()
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie();                    \
    cout.tie()
#define min3(x, y, z) (x < y ? (x < z ? x : z) : (y < z ? y : z))
#define max3(x, y, z) (x > y ? (x > z ? x : z) : (y > z ? y : z))
#define MAX_N int(1e6 + 7)
#define MAX_M int(1e6 + 7)
#define MAX_V int(1e6 + 7)
#define oo int(1e9 + 217)
#define MOD int(1e9 + 7)
using ll = long long;
using vi = vector< int >;
using vl = vector< ll >;
using vpii = vector< pair< int, int > >;
using pii = pair< int, int >;

typedef tree<
    int,
    null_type,
    less< int >,
    rb_tree_tag,
    tree_order_statistics_node_update >
    oset;

void solve()
{
}

int main()
{
    fast;
    string s, t;
    int ans = oo;
    cin >> s >> t;
    for (int i = 0; i <= s.size() - t.size(); i++)
    {
        int cnt = 0;
        int poz = i;
        for (int j = 0; j < t.size(); j++)
        {
            if (s[ poz ] != t[ j ])
                cnt++;
            poz++;
        }
        ans = min(ans, cnt);
    }
    cout << ans;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

int main(void)
{
    string a, b;
    int i, o;

    cin >> a >> b;
    for(i = o = 0; i < (signed)a.size(); i ++)
        o += a[i] == b[i];
    cout << o << endl;

    return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  string s; std::cin >> s;
  vi w(n), e(n);
  rep(i, n) {
    w[i] = (s[i] == 'W');
    e[i] = (s[i] == 'E');
  }
  rrep(i, n-1) w[i] += w[i-1];
  drep(i, n-1) e[i] += e[i+1];
  int ans = inf;
  rep(i, n) {
    int tmp = 0;
    if (i > 0) tmp += w[i-1];
    if (i+1 < n) tmp += e[i+1];
    chmin(ans, tmp);
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 2964
import math
A, B = map(int, input().strip().split())

Amin=math.ceil(A*100/8)
Amax=(A+1)*100//8
if Amax*8/100 == Amax*8//100:
    Amax-=1

Bmin=B*10
Bmax=(B+1)*10
if Bmax/10 == Bmax//10:
    Bmax-=1

ans=-1
flag=False
for a in range(Amin,Amax+1):
    for b in range(Bmin,Bmax+1):
        if a==b:
            ans=a
            flag=True
            break
    if flag:
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stdio.h>
#include <map>

using namespace std;
int main(void)
{
	string w;
	
	cin >> w;
	
	for (char i = 'a'; i != 'z'; i++) {
		int count = 0;
		for (int j = 0; j < w.size(); j++) {
			if (w[j] == i) {
				count++;
			}
		}
		
		if (count % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  ll k, a, b;
  cin >> k >> a >> b;

  ll ans = 1 + k;

  if (a < b && k >= a - 1) {
    ll t = (k - (a - 1)) / 2;
    ans = max(ans, 1 + (k - t * 2) + (b - a) * t);
  }

  cout << ans << "\n";

}



Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
from collections import deque, Counter

def main():

    h, w = MII()
    h += 2; w += 2
    grid = '#' * w
    for _ in range(h-2):
        grid += '#' + IS() + '#'
    grid += '#' * w

    if grid[1+w] == '#' or grid[(h-1)*w-2] == '#': print(-1); exit(0)

    c = Counter(grid)
    dot = c['.']

    def bfs(start, goal):
        INF = 10**9
        dist = [INF] * (h*w)
        dist[start] = 1
        q = deque([start])
        while q:
            v = q.popleft()
            if v == goal: return dist[v]
            dv = dist[v]
            for mv in (-1,1,w,-w):
                x = v + mv
                if grid[x] == '#': continue
                dw = dv + 1
                if dw >= dist[x]: continue
                dist[x] = dw
                q.append(x)
        return -1
    res = bfs(1+w, (h-1)*w-2)
    if res == -1: print(-1); exit(0)
    print(dot-res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



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


map<string, int> mp;
#define ll long long



int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i <= b; i++) {
        if ((a*i + c) % b==0) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    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++)

int main() {
  int d, t, s;
  cin >> d >> t >> s;

  if (t * s >= d) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



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

int main(void){
    int n, k, ans=0;
    cin >> n >> k;
    vector<int>L(n);
    rep(i,n) cin >> L[i];
    sort(L.begin(), L.end());
    for(int i=1; i<=k; i++){
        ans+=L[L.size()-i];
    }
    cout <<ans << endl;
}

Measured memory_bytes: 256
import math
import collections
import numpy as np


class Edge:
    def __init__(self, dst, color):
        self.dst = dst
        self.color = color

    def __repr__(self):
        return str(self.dst) + ' ' + str(self.color)


def main():
    N = int(input())
    adj_list = [[] for _ in range(N+1)]
    edge_order = []
    for _ in range(N-1):
        a, b = list(map(int, input().split()))
        edge_order.append((a, len(adj_list[a])))
        adj_list[a].append(Edge(b, None))
        adj_list[b].append(Edge(a, None))

    max_deg = 0
    for i in range(1, N+1):
        max_deg = max(max_deg, len(adj_list[i]))
    K = max_deg
    print(K)

    queue = collections.deque()
    queue.append((1, None))
    while queue:
        cur_node, used_color = queue.popleft()
        # print(' ')
        # print('cur_node: ', cur_node)
        # print('used_color: ', used_color)
        # print('adj_list: ', adj_list)

        # color is [0, K-1]
        if used_color is None:
            color = 0
        else:
            color = (used_color + 1) % K
        for edge in adj_list[cur_node]:
            if edge.color is not None:
                pass
            else:
                edge.color = color
                for inv_edge in adj_list[edge.dst]:
                    if inv_edge.dst == cur_node:
                        inv_edge.color = color
                adj_list[edge.dst]
                queue.append((edge.dst, color))
                color = (color + 1) % K
        # print('queue: ', queue)

    for i, j in edge_order:
        print(adj_list[i][j].color + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73916
#include <cstdio>
#include <cstring>
#include <algorithm>

int n;
int M,D,h,m,id;
int cnt[1001];
int t[1001];
char io;
bool flag[1001];
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(cnt,0,sizeof(cnt));
		memset(t,0,sizeof(t));
		memset(flag,0,sizeof(flag));
		for(int i=0;i<n;i++){
			scanf("%2d/%2d %2d:%2d %c %3d",&M,&D,&h,&m,&io,&id);
			if(io=='I'){
				t[id]=h*60+m;
				flag[id]=true;
			}else{
				if(id==0){
					for(int i=1;i<=999;i++){
						if(flag[i])cnt[i]+=h*60+m-std::max(t[i],t[0]);
					}
					flag[0]=false;
				}else{
					if(flag[0]){
						cnt[id]+=h*60+m-std::max(t[id],t[0]);
					}
					t[id]=h*60+m;
					flag[id]=false;
				}
			}
		}
		int res=0;
		for(int i=1;i<=999;i++){
			res=std::max(res,cnt[i]);
		}
		printf("%d\n",res);
	}
	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t,i,n,b,flag=1,a;
	cin>>n>>a>>b;
	//cin.ignore();
	int res=min(b,n*a);
	cout<<res<<endl;
	//int arr[t];
	//f(i,0,t)
	//	cin>>arr[i];
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示
#include <map>
#include<set>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define PI 3.1415926535
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

#define MAX_N 50005//ここにNの最大値を入れる
#define MAX_K 100005



int main() {
    string s;
    cin >> s;
    int p1, p2;
    for (int i = 0; i < s.length(); i++) {
        if (s.at(i) == 'A') {
            p1 = i;
            break;
        }
    }
    for (int i = s.length() - 1; i >= 0; i--) {
        if (s.at(i) == 'Z') {
            p2 = i;
            break;
        }
    }
    int ans = p2 - p1 + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664