akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <map>
#define MAX_N 100
#define MAX_M 100
using namespace std;

int main() {
    int n, m;
    int ans = 0;
    map<string, int> dict;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        dict[s]++;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        string s;
        cin >> s;
        dict[s]--;
    }

    for(auto x: dict) {
       if (ans < x.second) {
            ans = x.second;
       }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int C[3][3];
    rep(i, 3) {
        rep(j, 3) {
            cin >> C[i][j];
        }
    }

    bool flag = true;
    rep(i, 2) {
        int c1 = C[i][0] - C[i + 1][0];
        int c2 = C[i][1] - C[i + 1][1];
        int c3 = C[i][2] - C[i + 1][2];
        if (c1 != c2 || c2 != c3) flag = false;
        c1 = C[0][i] - C[0][i + 1];
        c2 = C[1][i] - C[1][i + 1];
        c3 = C[2][i] - C[2][i + 1];
        if (c1 != c2 || c2 != c3) flag = false;
    }

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

Measured memory_bytes: 256
#python3

def main():
    n = int(input())
    g = [[-1 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = map(int, input().split())
            g[i][x-1] = y 


    ans = -1
    for i in range(1<<n):
        h = [0 for _ in range(n)]
        for k in range(n):
            if (i>>k) & 1: 
                h[k] = 1

        flag = True
        for j in range(n):
            if h[j] == 1:
                for k in range(n):
                    if g[j][k] == -1:
                        continue
                    if g[j][k] != h[k]:
                        flag = False
        if flag:
            ans = max(sum(h), ans)
    print(ans)
main()

Measured memory_bytes: 3064
#include <fstream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <bitset>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <set>
#include <complex>

using namespace std;

const int SIZE = 1 << 10;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int a, b, c, answer = 0;
    scanf("%d%d%d", &a, &b, &c);
    while (a + 2 <= b || a + 2 <= c) {
        a += 2;
        answer++;
    }
    while (b + 2 <= a || b + 2 <= c) {
        b += 2;
        answer++;
    }
    while (c + 2 <= a || c + 2 <= b) {
        c += 2;
        answer++;
    }
    if (a > b)
        swap(a, b);
    if (a > c)
        swap(a, c);
    if (b > c)
        swap(b, c);
    if (a == b && a != c)
        answer++;
    if (b == c && a != b)
        answer += 2;
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 128
<?php
while ($line = fgets(STDIN)) {
    $inputs[] = trim($line);
};
$x = (int)$inputs[0];

$money = 100;

$year = 0;
while(1) {
    $money = floor($money * 1.01);
    $year++;
    if ($money >= $x) {
        break;
    }
}
echo "$year\n";


Measured memory_bytes: 16172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll fac[500005],inv[500005];
const int N=500000;
ll power(ll base,ll n)
{
    ll r=1;
    while(n)
    {
        if(n&1) r=(r*base)%mod;
        base=(base*base)%mod;
        n/=2;
    }
    return r%mod;
}

void pre()
{
    fac[0]=1;
    for(int i=1;i<=N;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
    inv[N]=power(fac[N],mod-2);
    for(int i=N-1;i>=0;i--)
    {
        inv[i]=inv[i+1]*(i+1)%mod;
    }
}
ll C(ll m,ll n)
{
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
   cin>>n>>k;
   pre();
   k=min(k,n-1);
   ll ans=0;
   for(int i=0;i<=k;i++)
   {
       ans+=C(i,n)*C(n-i-1,n-1)%mod;
   }
   ans%=mod;
   cout<<ans<<'\n';









}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, x, n) for(ll i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N; cin >> N;
    pli p[N];
    rep(i, N){
        cin >> p[i].first;
        p[i].second = i;
    }
    sort(p, p+N, greater<pli>());
    //dp[i][j]:=[0,i)と[j,N)まで決まっているときの最大値
    ll dp[N+1][N+1];
    fill(dp[0], dp[N+1], 0);
    rep(i, N){
        ll A = p[i].first, id = p[i].second;
        //すでにi個並べている
        //[0,j)と[N+j-i,N)が埋まっているとき
        rep(j, i+1){
            dp[j+1][N+j-i] = max(dp[j+1][N+j-i], dp[j][N+j-i] + A*abs(j-id));
            dp[j][N+j-i-1] = max(dp[j][N+j-i-1], dp[j][N+j-i] + A*abs(N+j-i-1-id));
        }
    }
    ll ans = 0;
    rep(i, N+1){
        ans = max(ans, dp[i][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 34912
//  Mohib Manva.//  
#include<bits/stdc++.h>
using namespace std;
 
 
int main() {
    int t = 1;
    //  scanf("%d",&t);
    while (t--) {
        int n;
        scanf("%d",&n);
        for(int i=0;i*4 <=n && i<=100;i++){
            int x = 4 * i;
            if ((n - x)%7==0) {
                puts("Yes");
                return 0;
            }
        }     
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int n,k;
    cin >> n >> k;

    int x[n];
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    
    int ans = 0;
    for(int i=0;i<n;i++){
        ans = ans + min(2 * abs(k-x[i]), 2 * abs(x[i]));
    }
    cout << ans << endl;
    return 0;
       
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1000000007;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<pair<int,int>> P;
    for (int i=0;i<N;++i){
        int x,y; cin >> x >> y;
        P.emplace_back(x+y,x-y);
    }

    sort(ALL(P));
    int ans=0;
    int mx=P[0].first,Mx=P[0].first,my=P[0].second,My=P[0].second;
    for (int i=1;i<N;++i){
        int x=P[i].first,y=P[i].second;
        chmax(ans,abs(x-mx)); chmax(ans,abs(x-Mx));
        chmax(ans,abs(y-my)); chmax(ans,abs(y-My));
        chmin(mx,x); chmax(Mx,x); chmin(my,y); chmax(My,y);
    }

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

Measured memory_bytes: 5328
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
int p[110000];
int q[110000];
int cnt[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		scanf("%d%d",p+i,q+i);
		p[i]--;q[i]--;
		cnt[p[i]]++;
		cnt[q[i]]++;
		
	}
	for(int i=0;i<a;i++){
		if(cnt[i]%2){
			printf("NO\n");return 0;
		}
	}
	printf("YES\n");
}

Measured memory_bytes: 1280
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
using namespace std;

const int MAX_N = 4e5 + 15;
int n, m;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	cout << n - m + 1 << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void no() {cout << "No" << endl;}
void yes() {cout << "Yes" << endl;}

void solve() {
	ll a, b, c;
	cin >> a >> b >> c;
	ll x = c - (a + b);
	if (x <= 0) no();
	else {
		if (4 * a * b < x * x) yes();
		else no(); 
	}
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3596
//
//  main.cpp
//  ABC174C
#include <iostream>
using namespace std;
using ll = long long;
bool flag[1000006]={}; // 一回辿ったノード
int main(int argc, const char * argv[]) {
    ll k;
    cin >>k;
    ll s=7%k; // スタートノード　ここからノード０に行くのに何回辿るかを数える
    ll ans=1;
    while(flag[s]!=true){
        if(s==0){
            cout <<ans<<endl;
            return 0;
        }
        flag[s]=true;
        s=(s*10+7)%k; // 7,77,777,7777
        ans++;
    }
    // 同じノードにたどり着くとき、ノード０に行くことができない
    cout<<-1<<endl;
    return 0;
}


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

long long keta(long long x)
{
	long long cnt = 0;
	while (x)
	{
		cnt++;
		x /= 10;
	}
	return cnt;
}

long long f(long long a, long long b)
{
	return max(keta(a), keta(b));
}

signed main(void)
{
	long long n, a, b, ans;

	cin >> n;
	ans = 1e9;
	rep(i, sqrt(n))
	{
		if (n % i != 0) continue;
		a = i;
		b = n / i;
		ans = min(f(a, b), ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e5+5;
int n,ans;
int a[maxn],b[maxn],q1[maxn],q2[maxn];
map<int,int>occur,vis;
map<int,vector<int> >e;
void dfs(int x){
	vis[x]=1;
	rep2(i,0,SZ(e[x]))if(!vis[e[x][i]])dfs(e[x][i]);
}
int main(){
	read(n);
	rep(i,1,n)read(a[i]),a[n+1]^=a[i];
	rep(i,1,n)read(b[i]),b[n+1]^=b[i];
	rep(i,1,n+1)q1[i]=a[i];sort(q1+1,q1+n+1+1);
	rep(i,1,n+1)q2[i]=b[i];sort(q2+1,q2+n+1+1);
	rep(i,1,n+1)if(q1[i]!=q2[i])return puts("-1"),0;
	rep(i,1,n)if(a[i]!=b[i])occur[a[i]]=occur[b[i]]=1,e[a[i]].pb(b[i]),ans++;
	occur[a[n+1]]=occur[b[n+1]]=1;
	if(!vis[b[n+1]])dfs(b[n+1]),ans++;
	rep(i,1,n)if(a[i]!=b[i]&&!vis[a[i]])dfs(a[i]),ans++;
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 29952
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}
struct Hen{
	int a;
	int b;
	int c;
};

int main() {
	int l = ri();
	int n = 0;
	int ll = l;
	while (ll) ll /= 2, n++;
	std::vector<Hen> a;
	for (int i = 0; i + 1 < n; i++) {
		a.push_back({i, i + 1, 0});
		a.push_back({i, i + 1, 1 << i});
	}
	int base = 1 << (n - 1);
	for (int i = 0; i + 1 < n; i++) {
		if (l >> i & 1) {
			a.push_back({i, n - 1, base});
			base += 1 << i;
		}
	}
	assert(n <= 20);
	assert(a.size() <= 60);
	std::cout << n << " " << a.size() << std::endl;
	for (auto &i : a) std::cout << i.a + 1 << " " << i.b + 1 << " " << i.c << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;


int main()
{
    int n, m;
    long long k;

    cin >> n >> m >> k;

    vector<long long> a(n);

    vector<long long> b(m);

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

    for (int i = 0; i < m; i++)   cin >> b[i];
    

    //aとbの先頭を比較して、小さいほうを引いていく。
    //Kから引いて行って、残っている最小よりもKが小さくなったらカウント終了
    //上の考え方はよくなかった
    //abの組み合わせを求める問題と読み換えるのが正解
    
    int count = 0;
   
    vector<long long> suma(n + 1);
    vector<long long> sumb(m + 1);
    
    suma[0] = 0;
    sumb[0] = 0;

    for (int i = 1; i <= n; i++) suma[i] = a[i-1]+suma[i - 1];
    for (int i = 1; i <= m; i++) sumb[i] = b[i-1]+sumb[i - 1];
    /*
    int i = 0;
    int begin = m;
    int count1 = 0;
    while (i <= n) {
        
        for (int j = begin; j >= 0; j--) {
            if (k >= suma[i] + sumb[j]) {
                count1 = i + j;
                begin = j;
                break;
            }
        }

        if (count < count1) count = count1;
        i++;
    }
    */
    
    int begin = m;
    for (int i = 0; i < n + 1; i++) {

        int count1 = 0;

        for (int j = begin; j >= 0;j--) {
            if (k>=suma[i]+sumb[j]) {
                count1 = i + j;
                begin = j;
                break;
            }
        }
        if (count<count1) count = count1;

    }

    std::cout << count << endl;   

    return 0;
}

Measured memory_bytes: 9576
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,t;
  cin>>n>>t;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll ans=1e18;
  rep(i,1<<n)if(__builtin_popcount(i)>=t){
    ll mx=0;
    ll re=0;
    rep(j,n){
      if(i>>j&1 && mx>=a[j]){
	re+=mx+1-a[j];
	++mx;
      }
      MX(mx,a[j]);
    }
    MN(ans,re);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))


signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans=1e15;
    rep(i,2*max(x,y)+1){
        ll res=max(0,(x-i/2))*a+max(0,(y-i/2))*b+c*i;
        chmin(ans,res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)


int main(){
    ll n, m;
    cin >> n >> m;

    if(n == 1){
        cout << m << endl;
        return 0;
    }
    vector<ll> d;
    for(int i = 1; i < sqrt(m)+1; i++){
        if(m%i == 0){
            d.push_back(i);
            d.push_back(m/i);
        }
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    for(int i = 0; i < d.size(); i++){
        if(m - d[i]*(n-1) > 0 && (m - d[i]*(n-1))%d[i] == 0){
            cout << d[i] << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
h, w = [int(i) for i in input().split(" ")]

a = []
for i in range(h):
    a.append(input())
    
for _ in range(w + 2):
    print("#", end = "")
print()
for i in range(h):
    print("#", end = "")
    print(a[i], end = "")
    print("#")
for _ in range(w + 2):
        print("#", end = "")   


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  int x,y;
  x=a>b?a:b;
  int sum=0;
  sum+=x;
   if(x==a)
   {
     a--;
     y=a>b?a:b;
   }
  else
  {
    b--;
    y=a>b?a:b;
  }
  sum+=y;
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
struct SCC { int stamp, scc_num;
  struct Node : vector<int> {
    int dfn, low, scc; bool inS;
    Node() { dfn = low = scc = -1; inS = false; }
  };
  vector<Node> N; vector<int> stk;
  void init(int n) {
    N.clear(); N.resize(n); stk.clear();
  }
  void addEdge(int u, int v) { N[u].push_back(v); }
  void Tarjan(int u) { N[u].low = N[u].dfn = stamp++;
    stk.push_back(u); N[u].inS = true;
    for (auto &v : N[u]) if (!~N[v].dfn) Tarjan(v),
      N[u].low = min(N[u].low, N[v].low);
    else if (N[v].inS)
      N[u].low = min(N[u].low, N[v].dfn);
    if (N[u].dfn == N[u].low) {
      int v; do { v = stk.back(); stk.pop_back();
        N[v].scc = scc_num; N[v].inS = false;
      } while (v != u); scc_num++;
    }
  }
  void run() { stamp = scc_num = 0;
    for (int i = 0 ; i < N.size() ; i++)
      if (!~N[i].dfn) Tarjan(i);
  }
};
// LatexBegin
struct _2Sat : SCC {
  void init(int n) { SCC::init(2 * n); }
  /* addCond(0, 0, 1, 1) -> v0 or !v1*/
  void addCond(int o1, int v1, int o2, int v2) {
    addEdge((v1 << 1) | (o1 ^ 1), (v2 << 1) | o2);
    addEdge((v2 << 1) | (o2 ^ 1), (v1 << 1) | o1);
  }
  bool check() {
    for (int i = 0 ; i < N.size() ; i += 2)
      if (N[i].scc == N[i ^ 1].scc) return false;
    return true;
  }
  vector<int> construct() { vector<int> ret;
    for (int i = 0 ; i < N.size() ; i += 2)
      ret.push_back(N[i].scc < N[i ^ 1].scc);
    return assert(check()), ret;
  }
} solver;
// LatexEnd
typedef long long LL;
typedef pair<LL, LL> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; LL d; cin >> n >> d;
    vector<pii> arr(n);
    vector<int> pts;
    for (auto &p : arr) {
        cin >> p.F >> p.S;
        pts.push_back(p.F);
        pts.push_back(p.S);
    }
    solver.init(2 * n);
    for (int i = 0 ; i < 2 * n ; i++) {
        for (int j = 0 ; j < i ; j++) {
            if (abs(pts[i] - pts[j]) >= d)
                continue;
            solver.addEdge(i * 2 + 1, j * 2 + 0);
            solver.addEdge(j * 2 + 1, i * 2 + 0);
        }
    }
    for (int i = 0 ; i < 2 * n ; i += 2) {
        solver.addEdge(i * 2 + 0, (i + 1) * 2 + 1);
        solver.addEdge((i + 1) * 2 + 0, i * 2 + 1);
    }
    solver.run();
    if (solver.check()) {
        cout << "Yes\n";
        auto ans = solver.construct();
        for (int i = 0 ; i < 2 * n ; i += 2) {
            if (ans[i])
                cout << arr[i / 2].S << '\n';
            else
                cout << arr[i / 2].F << '\n';
        }
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N; cin>>N;
    ll sum=0;
    for(int i=1;i<=N;i++){
    	if(i%3!=0&&i%5!=0) sum+=i;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3640
import Control.Monad

ret [] l       = foldl (\acc x -> if x == 0 then acc + 1 else acc) 0 l
ret (x : xs) l =
  let 
    l' = foldl (\l y -> take (y-1) l ++ [(head $ drop (y - 1) l) - 1] ++ drop y l) l (tail x)
  in 
    ret xs l'

 
  






main = do
      [n, m] <- (map read . words) <$> getLine
      inputlist <- replicateM n ((map read . words) <$> getLine)
      putStrLn $ show $ ret inputlist $ replicate m n


Measured memory_bytes: 1532
#include <stdio.h>

int main() 
{
   int a,b,c,cont1;
    
    scanf("%i %i %i",&a,&b,&c);

     for(a;a<=b;a++)
     {
         if(c%a==0)
         {
             cont1++;
         }
     }

     printf("%i\n",cont1);

}




Measured memory_bytes: 2100
using System;
class _0110 {
    static int Parse(string s) {
        int res = 0, b = 1;
        for(int i = s.Length-1; i >= 0; i--) {
            res += (s[i] - '0') * b;
            b *= 10;
        }
        return res;
    }
    public static void Main() {
        string str;
        char c;

        while ((str = Console.ReadLine()) != null) {
            for (c = '0'; c <= '9'; c++) {
                string cExpr = str.Replace('X', c);
                string[] strs = cExpr.Split('+', '=');
                if (c == '0' && ((strs[0].Length > 1 && strs[0][0] == '0') || (strs[1].Length > 1 && strs[1][0] == '0') || (strs[2].Length > 1 && strs[2][0] == '0'))) continue;
                if (Parse(strs[0]) + Parse(strs[1]) == Parse(strs[2])) {
                    Console.WriteLine(c);
                    break;
                }
            }
            if (c == ('9' + 1)) Console.WriteLine("NA");
        }
    }
}

Measured memory_bytes: 8808
/*input
4
75 26 45 72 81 47 97 97 2 2 25 82 84 17 56 32
*/
#include <bits/stdc++.h>
using namespace std;

const int M = 18, Mod = 1000000007;

struct Poly {
	pair<int, int> a[1 << M];
	Poly() {
		memset(a, 0, sizeof a);
	}

	void Up() {
		for(int i = 0; i < M; ++i)
			for(int j = 0; j < (1 << M); ++j)
				if(j & (1 << i)) {
					if(a[j ^ (1 << i)].first > a[j].first) 
						swap(a[j].first, a[j].second), a[j].first = a[j ^ (1 << i)].first;
					else if(a[j ^ (1 << i)].first > a[j].second)
						a[j].second = a[j ^ (1 << i)].first;
				}
	}

	Poly operator* (Poly x) {
		Poly res = Poly();

		Up(), x.Up();
		for(int i = 0; i < (1 << M); ++i) {
			pair<int, int> &tmp = res.a[i];
			if(a[i].first == x.a[i].first)
				tmp.first = max(a[i].first + x.a[i].second, a[i].second + x.a[i].first);
			else tmp.first = a[i].first + x.a[i].first;
		}
		return res;
	}
} k;

int main(){
	int n; scanf("%d", &n);
	for(int i = 0; i < (1 << n); ++ i)
		scanf("%d", &k.a[i].first);

	k = k * k;
	for(int i = 1; i < (1 << n); ++ i) {
		k.a[i].first = max(k.a[i].first, k.a[i - 1].first);
		printf("%d\n", k.a[i].first);
	}
}

Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int n, m, mx, s, a[105];
vector<int> g;
int main()
{
	int i, j, k, z;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		scanf ("%d", &a[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = n; j >= i; j--) {
			z = i + n - j;
			if (z > m) break;
			if (z == 0) continue;
			s = 0;
			g.clear();
			for (k = 0; k < i; k++) {
				g.push_back(a[k]);
				s += a[k];
			}
			for (k = n - 1; k >= j; k--) {
				g.push_back(a[k]);
				s += a[k];
			}
			sort(g.begin(), g.end());
			for (k = 0; k < m - z && k < g.size(); k++) {
				if (g[k] >= 0) break;
				s -= g[k];
			}
			mx = max(mx, s);
		}
	}
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, n) for(int i = n-1; i >= 0; i--)
#define rep4(i, x, n) for(int i = x; i > n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    int N;
    cin >> N;
    int C[N];
    rep(i, N) cin >> C[i];
    ll dp[N];
    map<int, int> mp;
    vector<int> vec[N];
    dp[0] = 1;
    mp[C[0]] = 0;
    vec[0].push_back(0);
    rep2(i, 1, N){
        if(C[i] == C[i-1]) dp[i] = dp[i-1];
        elif(!mp.count(C[i])){
            dp[i] = dp[i-1];
            mp[C[i]] = i;
            vec[i].push_back(i);
        }
        else{
            dp[i] = dp[i-1];
            int j = mp[C[i]];
            int k = vec[j].size()-1;
            dp[i] += dp[vec[j][k]];
            dp[i] %= MOD;
            vec[j].push_back(i);
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 23040
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
    A[i]=A[i]-(i+1)
A.sort()
tmp=0
if N%2==1:
    tmp=A[N//2]
else:
    tmp=A[N//2-1]
ans=0
for i in range(N):
    ans+=abs(A[i]-tmp)
print(ans)

Measured memory_bytes: 26708
from heapq import *
from collections import defaultdict

def Dijkstra(s, N, E):
    # https://ja.wikipedia.org/wiki/%E3%83%80%E3%82%A4%E3%82%AF%E3%82%B9%E3%83%88%E3%83%A9%E6%B3%95
    d = [10**30] * (N + 1)
    d[s] = 0
    Q = []
    for v in range(1, N + 1):
        heappush(Q, (d[v], v))
    while Q:
        x, u = heappop(Q)
        for v, y in E[u].items():
            alt = d[u] + y
            if d[v] > alt:
                d[v] = alt
                heappush(Q, (alt, v))
    return d

N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for i in range(M)]

Ea = defaultdict(dict)
Eb = defaultdict(dict)

for u, v, a, b in UVAB:
    Ea[u][v] = a
    Ea[v][u] = a
    Eb[u][v] = b
    Eb[v][u] = b
    
Da = Dijkstra(S, N, Ea)
Db = Dijkstra(T, N, Eb)

T = [None] * (N + 1)
t = 10**30

for i in range(N, 0, -1):
    r = Da[i] + Db[i]
    t = min(t, r)
    T[i] = t

ST = 10**15

for i in range(1, N + 1):
    print(ST-T[i])


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

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

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

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

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

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

int find(char str[]){
	long long key, i, h;
	key = getKey(str);
	for( i = 0; ; i++ ){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h], str) == 0 ){
			return 1;
		}else if( strlen(H[h]) == 0 ){
			return 0;
		}
	}
	return 0;
    /* your task */

}

int insert(char str[]){
	long long key, i, h;
	key = getKey(str);
	for( i = 0; ; i++ ){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h], str) == 0 ){
			return 1;
		}else if( strlen(H[h]) == 0 ){
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
	
    /* your task */

}

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

    return 0;
}


Measured memory_bytes: 16052
// https://atcoder.jp/contests/abc055/tasks/abc055_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << n * 800 - (n / 15) * 200 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define S_MAX 100

int main(){
  string s;

  cin >> s;
  bool ok = true;
  for(int i=0; i<s.size(); i++) {
    char c = s[i];
    if(i%2==1) {
      if(c=='L' || c=='U' || c=='D') {
      } else {
	ok = false;
      }
    } else {
      if(c=='R' || c=='U' || c=='D') {
      } else {
	ok = false;
      }
    }
  }
  if(ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 10**10
for i in range(0, n-k+1):
    mid = (x[i] + x[i+k-1]) // 2
    if x[i + k-1] <= 0:
        ans = min(ans, abs(x[i]))
    elif x[i] >= 0:
        ans = min(ans, abs(x[i+k-1]))
    elif mid < 0:
        ans = min(ans, abs(x[i]) + abs(x[i+k-1]) * 2)
    else:
        ans = min(ans, abs(x[i]) * 2 + abs(x[i+k-1]))

print(ans)


Measured memory_bytes: 14480
#include <cstdio>
#include <cstring>
using namespace std;

#define L 3194304
bool HA[L];
char T[256];

int main() {
    int n, sum, t;
    char c;
    T['A'] = 0x01, T['C'] = 0x02, T['G'] = 0x03, T['T'] = 0x04;
    scanf("%d", &n);
    while ( getchar() != '\n' );
    for ( register int i = 0; i++ < n; ) {
        sum = 0;
        t = 1;
        bool flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            sum += c * t;
            t *= 4;
        }
        if ( flag ) {
            HA[sum] = true;
        } else {
            puts( HA[sum] ? "yes" : "no" );
        }
    }
    return 0;
}

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int A, B;
  cin >> A >> B;
  A = (A - 2 + 13) % 13;
  B = (B - 2 + 13) % 13;
  if(A > B) {
    cout << "Alice" << endl;
  }else if(A < B) {
    cout << "Bob" << endl;
  }else {
    cout << "Draw" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[7] = { 1,3,5,7,8,10,12 }, b[4] = { 4,6,9,11 }, c = 2;
	int x, y, i;

	scanf("%d %d", &x, &y);

	for (i = 0; i < 7; i++) {
		if (a[i] == x) {
			while (i < 7) {
				i++;
				if (a[i] == y) {
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	for (i = 0; i < 4; i++) {
		if (b[i] == x) {
			while (i < 4) {
				i++;
				if (b[i] == y) {
					printf("Yes\n");
					return 0;
				}
			}
		}
	}

	printf("No");
	return 0;
}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N+2];


void solve()
{
      int a,b,c ;
      cin >> a >> b >> c;
      swap(a,b);
      swap(a,c);
      cout << a << " "  << b << " " << c;
      
}

int32_t main()
{
      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

      int test = 1;
      // cin >> test;

      // cout << setprecision(9) << fixed;
      // clock_t z = clock();
      while(test--)solve();
      // cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const double INF = 1e18;
const int MAX = 10004;

int N,M;
int a[10][10];
int a1[10][10];
int a2[10][10];
int b[MAX][MAX];

int main()
{
    cin>>N>>M;
    for(int i = 0;i<10;i++)
        for(int j = 0;j<10;j++)
            cin>>a[i][j];
    for(int k = 0;k<10;k++)
    for(int i = 0;i<10;i++)
    for(int j = 0;j<10;j++)
    {
        if(a[i][j] > a[i][k] + a[k][j])
            a[i][j] = a[i][k] + a[k][j];
    }
    LL sum = 0;
    for(int i = 1;i<=N;i++)
        for(int j = 1;j<=M;j++)
    {
        int temp;
        cin>>temp;
        if(temp != -1)
        {
            sum +=a[temp][1];
        }
    }
    cout<<sum<<endl;

    return 0;
}


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

int main(void)
{
	double x1,y1,x2,y2;
	double a;
	
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	
	a = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	a = sqrt(a);
	
	printf("%f",a);
	
	return 0;
}

Measured memory_bytes: 652
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(A);
		int cnt = 0;
		long cur = A[0];
		for (int i = 1; i < N; i++) {
			if (cur * 2 < A[i]) {
				cnt = i;
			}
			cur += A[i];
		}
		System.out.println(N - cnt);
	}
}


Measured memory_bytes: 62904
#include <iostream>

using namespace std;

int main()
{
char a;

cin>>a;

if((a=='a')||(a=='e')||(a=='i')||(a=='o')||(a=='u')||(a=='A')||(a=='E')||(a=='I')||(a=='O')||(a=='U')){cout<<"vowel";}

else{cout<<"consonant";}


    return 0;
}


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

using namespace std;
const int N = 1e5 + 5;
const int inf = 0x3f3f3f3f;
map<int, int>mp[N];
int num, cnt, head[12*N], d[12*N], vis[12*N];
struct node
{
    int nxt, ed, len;
}e[12*N];
void add(int x, int y, int z)
{
    e[cnt].nxt = head[x];
    e[cnt].ed = y;
    e[cnt].len = z;
    head[x] = cnt++;
}
int get_id(int x,int y)
{
    if(mp[x].count(y)) return mp[x][y];
    else return mp[x][y] = ++num;
}
priority_queue<pair<int, int> ,vector<pair<int, int> >, greater<pair<int, int> > >Q;
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    num = n;
    memset(head, -1, sizeof(head));
    for(int i = 0; i < m; i++){
        int x,y,z;
        scanf("%d %d %d", &x, &y, &z);
        int nx = get_id(x, z), ny = get_id(y, z);
        add(nx, ny, 0), add(ny, nx, 0);
        add(x, nx, 1), add(nx, x, 1);
        add(y, ny, 1), add(ny, y, 1);
    }
    for(int i = 1; i <= num; i++){
        d[i] = inf;
    }
    d[1] = 0;
    Q.push(make_pair(0, 1));
    while(!Q.empty()){
        int t = Q.top().second;
        Q.pop();
        if(vis[t]) continue;
        vis[t] = 1;
        for(int i = head[t]; ~i; i = e[i].nxt){
            int v = e[i].ed, len = e[i].len;
            if(d[v] > d[t] + len){
                d[v] = d[t] +len;
                Q.push(make_pair(d[v], v));
            }
        }
    }
    printf("%d\n", d[n]==inf ? -1: d[n]/2);
    return 0;
}


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

int main() {
    int N, L;
    string S[110];
    cin >> N >> L;
    rep(i, N) { cin >> S[i]; }
    sort(S, S + N);
    rep(i, N) { cout << S[i]; }
    cout << endl;
}

Measured memory_bytes: 3656
n = int(input())
b = [int(i) for i in input().split()]
a = []
for i in range(n-1):
  if i == 0:
    a.append(b[0])
    
  else:
    a.append(min(b[i-1], b[i]))
a.append(b[-1])
print(sum(a))

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<stack>
#include<sstream>
#include<string>
#include<cassert>
#include<ctime>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int kase = 0;
ll n, m;

const int maxn = 55;
int a[maxn];
int cnt[4];

ll pow_mod(ll a, ll p)
{
	if (p == 0)  return 1;
	ll ans = pow_mod(a, p / 2);
	ans = ans * ans;
	if (p % 2 == 1)   ans = ans * a;
	return ans;
}

int main()
{
	int p;
	while (cin >> n >> p)
	{
		memset(cnt, 0, sizeof(cnt));
		for (int i = 1; i <= n; i++)
		{
			int tmp;
			scanf("%d", &tmp);
			tmp %= 2;
			a[i] = tmp;
			cnt[tmp]++;
		}
		if (n == 1)
		{
			if (a[1] == 0 && p == 0)
				cout << 2 << endl;
			else if (a[1] == 1 && p == 0)
				cout << 1 << endl;
			else if (a[1] == 1 && p == 1)
				cout << 1 << endl;
			else if (a[1] == 0 && p == 1)
				cout << 0 << endl;
			continue;
		}
		if (cnt[1] == 0)
		{
			if (p == 0)
				printf("%lld\n", pow_mod(2, n));
			else
				printf("0\n");
			continue;
		}
		ll aa = 2;
		ll ans = pow_mod(aa, cnt[0] + cnt[1] - 1);
		if (p == 0)
			cout << ans << endl;
		else
			printf("%lld\n", pow_mod(aa , n) - ans);
	}
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import math

A, B = map(int, input().split())
num = 0

for i in range(1251):
    num += 1
    if math.floor(num * 0.08) == A:
        if math.floor(num * 0.1) == B:
            print(num)
            exit()
else:
    print(-1)

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

int main(){
	int N,K;
	cin >> N >> K;
	vector<long long> a(N);
	for(auto &i:a)cin >> i;
	vector<long long> sum(N+1,0);
	vector<long long> psum(N+1,0);
	for(int i=0;i<N;i++){
		sum[i+1]=sum[i]+a[i];
		psum[i+1]=psum[i]+max(0LL,a[i]);
	}
	
	long long ans=-999999999999999LL;
	for(int i=0;i+K-1<N;i++){
		long long tmp=max(0LL,sum[i+K]-sum[i]);
		tmp+=psum[i];
		tmp+=psum[N]-psum[i+K];
		ans=max(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

typedef tuple<ll, ll, ll> tl;

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

    ll n;
    cin>>n;
    vector<LP> xs(n);
    vector<LP> ys(n);
    rep(i, n) {
        ll x, y;
        cin>>x>>y;
        xs[i].fi = x; xs[i].se = i;
        ys[i].fi = y; ys[i].se = i;
    }
    sort(rng(xs));
    sort(rng(ys));

    priority_queue<tl, vector<tl>, greater<tl>> q;
    rep(i, n - 1) {
        q.emplace(xs[i + 1].fi - xs[i].fi, xs[i].se, xs[i + 1].se);
        q.emplace(ys[i + 1].fi - ys[i].fi, ys[i].se, ys[i + 1].se);
    }
    UnionFind ds(n);
    ll ans = 0;
    while (!q.empty()) {
        tl t = q.top(); q.pop();
        ll w = get<0>(t);
        ll v1 = get<1>(t);
        ll v2 = get<2>(t);
        if (ds.issame(v1, v2)) continue;
        ds.merge(v1, v2);
        ans += w;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11632
#include <iostream>
using namespace std;
/*
x?????????????????????????????????calc(x)
calc(0) = 1
calc(i) = calc(i - 1) * calc(i - 2) + calc(i - 3)
*/
int answer[30] = {};

int calc(int n) {
	for (int i = 0; i <= n; i++) {
		if (i == 0) answer[i] = 1;
		else if (i == 1) answer[i] = 1;
		else if (i == 2) answer[i] = 2;
		else answer[i] = answer[i - 1] + answer[i - 2] + answer[i - 3];
	}
	return (answer[n] / 3650) + ((answer[n] % 3650 > 0) ? 1 : 0);
}

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0) return 0;
		cout << calc(n) << endl; 
	}
}

Measured memory_bytes: 3092
from collections import Counter

N,M = map(int,input().split())
A = list(map(int,input().split()))

cums = [0]
for a in A:
    cums.append((cums[-1] + a) % M)

ctr = Counter(cums)

ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)


Measured memory_bytes: 16556
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    for (int i = 0; i < n; ++i) {
        if(v[i]%2 == 0){
            if(v[i]%3 == 0 || v[i]%5 == 0) continue;
            else {
                puts("DENIED");
                return 0;
            }
        }
    }
    puts("APPROVED");
    return 0;
}

Measured memory_bytes: 764
/* B - Trick or Treat */

#include <stdio.h>

int main(void){
  int N, K, i, A[100] = {0}, d[100], j, given, ans = 0;
  scanf("%d %d", &N, &K);
  for(i = 0; i < K; i++){
    scanf("%d", &d[i]);
    for(j = 0; j < d[i]; j++){
      scanf("%d", &given);
      A[given - 1]++;
    }
  }
  for(i = 0; i < N; i++){
    if(A[i] == 0){
      ans++;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 1732