akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
    int H, W;
    while(cin >> H >>W)
    {
        if (!H && !W)
            break;
        
        int i = 0;
        while (i++ < H)
        {
            int j = 0;
            while (j++ < W)
            {
                if (i == 1 || i == H)
                    cout << '#';
                else if (j == 1 || j == W)
                    cout << '#';
                else
                    cout << '.';
                    
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3056
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            String S = in.next();
            int start = 0, end = S.length() - 1;
            int exchange = 0;
            while (start < end)
            {
                if (S.charAt(start) == 'W' && S.charAt(end) == 'R')
                {
                    exchange++;
                    start++;
                    end--;
                } else if (S.charAt(start) == 'R')
                    start++;
                else if (S.charAt(end) == 'W')
                    end--;
            }
            out.print(exchange);
        }

    }
}



Measured memory_bytes: 31980
#include<bits/stdc++.h>
using namespace std;
bool f(int x){
  int keta =0;
  while(x){
    keta++;
    x/=10;
  }
  return keta%2==1;
}
int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    if(f(i)){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    int a, b;
    int n; scanf("%d", &n);

    a = 0, b = 0;

    while(n--) {
        int res;
        char s1[101];
        char s2[101];
        scanf(" %s", s1);
        scanf(" %s", s2);

        res = strcmp(s1, s2);
        if(res > 0) a += 3;
        else if(res < 0) b += 3;
        else a++, b++;
    }

    printf("%d %d\n", a, b);

    return EXIT_SUCCESS;
}


Measured memory_bytes: 2052
#include <stdio.h>

int main()
{
	int i, j;
	
	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= 9; j++) {
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define ve vector<int>
using namespace std;


int main(){
  int n,x,A=1,l=0;
  cin>>n>>x;
  ve L(n);
  for(int i=0;i<n;i++) cin>>L[i];
  for(int i=0;i<n;i++){
    l+=L[i];
    if(l>x) break;
    A++;
  }
  cout<<A<<endl;
}
    


Measured memory_bytes: 256
# 1と素因数の個数の和が答え
# つまりAの素因数を求めて、その中でBの約数となっているものを数えればよい。

def p_factors(x): # prime_factors
    ret = [1]
    check = 2
    while (True):
        if x % check == 0:
            ret.append(check)
            while x % check == 0:
                x = x // check
        check += 1
        if x == 1 or check > int(x**0.5)+1:
            break
    if x != 1:
        ret.append(x)
    return ret

def main():
    A, B = map(int, input().split())
    factors = p_factors(A)
    cnt = 0
    for f in factors:
        if B % f == 0:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 38640
#include <stdio.h>
#include <algorithm>
#include <functional>

#define NDEBUG
#ifdef NDEBUG
#define debug(...) ((void)0)
#else
#define debug(...) {printf("%s(%d):", __func__, __LINE__); printf(__VA_ARGS__);}
#endif

int N, H;
int a[100000];
int b[100000];

int max(int a, int b){return(a>b)?a:b;}
int min(int a, int b){return(a<b)?a:b;}
int main(){
        scanf("%d %d",&N,&H);
        for(int i = 0; i < N; i++) scanf("%d %d",a+i,b+i);

        int maxa_ind = 0;
        for(int i = 0; i < N; i++)
                if(a[maxa_ind] < a[i]) maxa_ind = i;
        int b_of_maxa_ind=b[maxa_ind];

        std::sort(b,b+N,std::greater<int>());
        int cnt=0;
        int bind = 0;
        while(H > 0 && b[bind] > a[maxa_ind]){
                cnt++; H -= b[bind++];
        }
        if(H > 0){
                cnt += H/a[maxa_ind];
                cnt += (H%a[maxa_ind]==0)?0:1;
        }

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

}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;

int ans;
signed main(){
	
    char s[4];
    int f=0;
    rep(i,4)cin>>s[i];
    rep(i,3){
        if(s[i]==s[i+1])f=1;
    }
    if(f)cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
    
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = max(0, c - (a- b));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	int a,b,c;
  	cin>>a>>b>>c;
  	if(a<=c&&c<=b) cout<<"Yes\n";
  	else if(b<=c&&c<=a) cout<<"Yes\n";
 	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________
template <typename T = long long, const int sz = 5 * 10000000> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO<int> io;
int n, m, k;
constexpr int MAX = 1e9 + 1;
constexpr int N = 200010;
int a[N], b[N];
int nn;
main() {
    n = io.read(), m = io.read(), k = io.read();
    nn = n;
    rep(i, n) {
        a[i + 1] = io.read() + a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while(*io.now && *io.now <= 32) io.now++;
                while('0' <= *io.now and *io.now <= '9') io.now++;
            }
            break;
        }
    }
    rep(i, m) {
        b[i + 1] = io.read() + b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    int now = nn;
    int ans = now;
    for(int i = 1; i <= m; i++) {
        while(b[i] + a[now] > k) now--;
        ans = max(ans, i + now);
    }
    io.write(ans);
}


Measured memory_bytes: 7728
#include<iostream>
#include<map>
using namespace std;
int main(){
  for(;;){
    int n, m;
    map<char, char> mpa;
    cin >> n;
    if(n == 0) break;
    for(int i = 1; i <= n; i++){
      char a, b;
      cin >> a >> b;
      mpa[a] = b;
    }
    cin >> m;
    for(int i = 1; i <= m; i++){
      char c;
      cin >> c;
      if(mpa.count(c)){
	cout << mpa[c];
      }else{
	cout << c;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
N,A,B=map(int, input().split())
S=input()
count=0
astu=0
for s in S:
    if s=="a":
        if count<A+B:
            print("Yes")
            count+=1
        else:
            print("No")
    elif s=="b":
        if count<A+B and astu<B:
            print("Yes")
            astu+=1
            count+=1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 76212
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
#define INF 10000000000
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    vector<bool> ans(8,false);
    int n,count=0;
    cin>>n;
    rep(i,n){
        int a=0,j=0;  
        cin>>a;
        if(a>399) j=1;
        if(a>799) j=2;
        if(a>1199) j=3;
        if(a>1599) j=4;
        if(a>1999) j=5;
        if(a>2399) j=6;
        if(a>2799) j=7;
        if(a>3199) j=8;
        if(j==8){
            count+=1;
        }
        else{
            ans.at(j)=true;
        }
    }
    int num=0;
    rep(i,8){
        if(ans.at(i)==true){
            num+=1;
        }
    }
    int y=num+count;
    if(num==0&&count!=0){
        num+=1;
    }
    cout<<num<<" "<<y<<endl;
    
}

Measured memory_bytes: 256
S = input()
N = len(S)
flag = False
if S == S[::-1]:
    if S[:(N-1)//2] == S[:(N-1)//2][::-1]:
        if S[((N+3)//2) - 1:] == S[((N+3)//2) - 1:][::-1]:
            flag = True
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <queue>
#include <stdio.h>
using namespace std;
const int N=1e5+10;
int main(){
    int n,m,t;
    queue<int> q[N];
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&n,&t);
        if(n==0){
            scanf("%d",&n);
            q[t].push(n);
        }
        else if(n==1){
            if(!q[t].empty())printf("%d\n",q[t].front());
        }
        else if(!q[t].empty())q[t].pop();
    }
    
}


Measured memory_bytes: 70324
#include <bits/stdc++.h>
#define ll long long
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
ll h,n;
ll a[2000],b[2000];
ll dp[1001][10001];
ll run(ll i,ll l)
{
	if(l<=0)
	{
		return 0;
	}	
	if(i==n)
	{
		if(l==0)
		{
			return 0;
		}	
		return 1e18;
	}
	if(dp[i][l]!=-1)
	{
		return dp[i][l];
	}	
	return dp[i][l]=min({run(i+1,l),b[i]+run(i,l-a[i]),b[i]+run(i+1,l-a[i])});
}
int main()
{
    cin>>h>>n;
    REP(i,n)
    {
		cin>>a[i]>>b[i];
	}	
    memset(dp,-1,sizeof(dp));
    cout<<run(0,h);
}

Measured memory_bytes: 79360
#include <iostream>
using namespace std;
int main(void){
    int n, a[100000], sum; //sumはn人の平均値の合計
    int num;  //numは平均値以下の所得者数
    
    while(true){
        cin >> n;
        if(n == 0) break;
        
        sum = 0;
        num = 0;

        for(int i = 0; i < n; i++){  
            cin >> a[i];
            sum += a[i];
        }
        int mean = sum / n;
        for(int i = 0; i < n; i++){
            if(a[i] <= mean) num++;
        }
        cout << num << endl;
    }
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








int main(){
   ll n;
   cin >> n;
   map <ll,ll> cnt;
   set <ll> st;
   ll a[n+1];
   for (ll i = 0;i < n;i++){
     cin >> a[i];
     cnt[a[i]]++;
    st.insert(a[i]);
   }

  ll ans = 0;
  
  for (auto x : st){
      if (x == cnt[x]) continue;
      if (x < cnt[x]) ans += cnt[x]-x;
      else ans += cnt[x];
  //   ans += min(abs(cnt[x]-x),cnt[x]);
    }


  // for (auto p : cnt) {
  //       if (p.first == p.second) continue;
  //       if (p.first < p.second) ans += p.second - p.first;
  //       else ans += p.second;
  //   }
  cout << ans << endl;
    
}

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

int main() {
        long long x;
        cin >> x;
        long long a = x/11;
        long long b = x%11;
        if (b==0) cout << 2*a << endl;
        else if (b>6) cout << 2*a+2 << endl;
        else cout << 2*a+1 << endl;
        return 0;
}


Measured memory_bytes: 256
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    string S;
    ll K =0;
    cin >> S;
    cin >> K;

    //vll X(N);
    //REP(i,N) cin >> X[i];


    //本文
        REP(i,K){
            if(S[i]!='1'){cout << S[i];return 0;}
        }
    
    //出力
    cout << 1;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

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

int main() {
	int A,B;
  	char op;
  	cin>> A >> op >> B;
  
  	int result;
  	if(op=='+'){
    	result=A+B;
    }
  	else{
     	result=A-B; 
    }
  
  	cout<<result<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	vector<int> v(n);
	rep(i, n) {
		cin >> v[i];
	}

	ll dp[105][105];
	memset(dp, 0, sizeof(dp));

	dp[0][v[0]] = 1;

	REP(i, 1, n-1) {
		rep(j, 21) {
			if(j + v[i] <= 20) {
				dp[i][j + v[i]] += dp[i-1][j];
			}

			if(j - v[i] >= 0) {
				dp[i][j - v[i]] += dp[i-1][j];
			}
		}
	}

	cout << dp[n-2][v[n-1]] << endl;

	return 0;
}

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

typedef long long ll;

const int N = 2e5+5;
bool vis[N];
int a[N];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++ i ) cin >> a[i];
    
    int ans = 0;
    vis[0] = 1;
    for (int i = 1; i <= n; ++ i ) 
    {
        if (vis[a[i]-1] == 1) 
        {
            ans = max(ans, a[i]);
            vis[a[i]] = 1;
        }
    }
    
    if (ans == 0) cout << -1 << endl;
    else cout << n-ans << endl;
    
    return 0;
}

Measured memory_bytes: 1280
/*	Don’t Quit
	
	When things go wrong as they sometimes will;
		When the road you’re trudging seems all uphill;
			When the funds are low, and the debts are high;
				And you want to smile, but you have to sigh;
					When care is pressing you down a bit
						Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+10;
int dp[N],vis[N];
vector<int>v[N],v1[N];

int dfs(int n)
{
	if(dp[n]!=-1)
		return dp[n];
	int ans=0;
	for(int i=0;i<v[n].size();i++)
	{
		ans=max(ans,dfs(v[n][i])+1);
	}
	dp[n]=ans;
	return ans;
}
int32_t main()
{
	int n,m;
	cin>>n>>m;
	int x,y;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		v[x].pb(y);
		v1[y].pb(x);
	}
	for(int i=1;i<=n;i++)
	{
		dp[i]=-1;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		
			ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 20864
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
    ll n;
    cin>>n;
    V<P> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].fi;
        a[i].se=i;
    }
    sort(all(a));
    set<ll> s;
    s.insert(-1);
    s.insert(n);
    ll ans=0;
    for(int i=0;i<n;i++){
        s.insert(a[i].se);
        auto ite=s.find(a[i].se);
        ll l,r;
        ite--;
        l=a[i].se-(*ite);
        ite++;
        ite++;
        r=(*ite)-a[i].se;
        ans+=a[i].fi*l*r;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 15832
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    *nh, = map(int, read().split())
    n, h = nh[0], nh[1:]
    o = "Yes"
    for i in range(1, n):
        if h[i-1]<h[i]:
            h[i] -= 1
        if h[i-1]>h[i]:
            o = "No"
            break
    print(o)

if __name__ == "__main__":
    main()


Measured memory_bytes: 12528
time_list = [ int(i) for i in input().split()]

a = time_list[0]
b = time_list[1]
c = time_list[2]
d = time_list[3]

output = 0
if b < c or d < a:
    output = 0
else:
    output = min(b,d) - max(a,c)

print(output)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
 int S =N%10;
  if(S==3){
  	cout<<"bon";
  }
  else if(S==1 ||S==6 || S==8 || S==0){
  cout<<"pon";
  }
  else{
  cout<<"hon";
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
struct node {
    int to,next;
}E[MAXN * 2];
int head[MAXN],sumE;
int dp[MAXN],A,lim,res;
int val[MAXN],tot;
bool vis[MAXN];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void Init() {
    read(N);
    int a,b;
    for(int i = 1 ; i < N ; ++i) {read(a);read(b);add(a,b);add(b,a);}
    
}
void dfs(int u,int fa) {
    int son = 0;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    dfs(v,u);
	    ++son;
	    dp[u] += dp[v];
	}
    }
    dp[u] -= son / 2;
    if(son % 2 == 0 && fa) dp[u]++;
}
struct BIT {
    int tr[MAXN],s;
    void clear() {
	for(int i = 1 ; i <= s ; ++i) tr[i] = 0;
    }
    int lowbit(int x) {return x & -x;}
    int query(int x) {
	int res = 0;
	while(x > 0) {
	    res += tr[x];
	    x -= lowbit(x);
	}
	return res;
    }
    void insert(int x,int v) {
	while(x <= s) {
	    tr[x] += v;
	    x += lowbit(x);
	}
    }
    int find_max() {
	int L = 1,R = s;
	int x = query(s);
	if(x == 0) return 0;
	while(L < R) {
	    int m = (L + R + 1) >> 1;
	    if(query(m - 1) != x) L = m;
	    else R = m - 1;
	}
	return L;
    }
}BST;
void calc(int u,int fa) {
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    calc(v,u);
	}
    }
    tot = 0;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    val[++tot] = dp[v];
	}
    }
    if(!tot) {dp[u] = 1;++res;return;}
    BST.clear();
    sort(val + 1,val + tot + 1);
    for(int i = 1 ; i <= tot ; ++i) vis[i] = 1;
    BST.s = tot;int p = 0;
    for(int i = tot ; i >= 1 ; --i) {
	if(!vis[i]) continue;
	while(p < i && val[p + 1] + val[i] <= lim) {
	    ++p;BST.insert(p,1);
	}
	if(p >= i) BST.insert(i,-1);
	int t = BST.find_max();
	if(t) {vis[t] = 0;vis[i] = 0;BST.insert(t,-1);--res;}
    }
    if(fa) {
	dp[u] = 1;++res;
	for(int i = 1 ; i <= tot ; ++i) {
	    if(vis[i]) {
		if(val[i] + 1 > lim) break;
		dp[u] += val[i];--res;
		break;
	    }
	}
    }
}
bool check(int m) {
    lim = m;res = 0;
    calc(1,0);
    return res <= A;
}
void Solve() {
    dfs(1,0);
    out(dp[1]);space;
    A = dp[1];
    int L = 1,R = N - 1;
    while(L < R) {
	int mid = (L + R) >> 1;
	if(check(mid)) R = mid;
	else L = mid + 1;
    }
    out(R);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}


Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	
	class Node
	{
		public List<int> Vectors {get;set;}
		public Node()
		{
			Vectors = new List<int>();
		}
	}
	public static void Main(string[] args)
	{
		int[] p = Input().ToInt();
		int n = p[0];
		int m = p[1];
		Node[] nodes = new Node[n];
		dp = new long[n+1];
		
		for(int i = 0; i < n; i++)
		{
			nodes[i] = new Node();
			dp[i]=-1;
		}
		for(int i = 0; i < m; i++)
		{
			p = Input().ToInt();
			nodes[p[1]-1].Vectors.Add(p[0]-1);
		}
		long r = 0;
		for(int i = 0; i < n; i++)
		{
			r = Math.Max(r, Update(nodes, i, 0));
		}
		
		Console.WriteLine(r);
	}
	private static long[] dp;
	
	private static long Update(Node[] nodes, int index, long distance)
	{
		if(dp[index]!=-1)
		{
			return dp[index];
		}
		//dp[index] = distance;
		long dr = distance;
		foreach(int p in nodes[index].Vectors)
		{
			dr = Math.Max(dr, Update(nodes, p, distance)+1);
		}
		dp[index] = dr;
		return dr;
	}
	
	public static long GCD(long a, long b)
	{
		if(b == 1) return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 40192
#include <iostream>
#include <map>

using namespace std;

int main() {
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  string S;
  cin >> S;
  map<char,int>freq;

  for (int i = 0; i < S.size(); i++) {
    if (freq.count(S[i]) == 0) {
      freq[S[i]] = 0;
    }
    freq[S[i]]++;
  }

  //cout << "nisdf" << endl;
  char min_alphabet;
  bool has_min_alphabet = false;
  for (int i = 0; i < alphabet.size(); i++) {
    //cout << freq.count(alphabet[i]) << endl;
    if (freq.count(alphabet[i]) == 0) {
      //cout << "====" << endl;
      //cout << alphabet[i] << endl;
      min_alphabet = alphabet[i];
      has_min_alphabet = true;
      break;
    }
  }
  if (has_min_alphabet) {
    cout << min_alphabet << endl;
  } else {
    cout << "None" << endl;
  }
}


Measured memory_bytes: 888
N=int(input())
answer=0

xylist=[]
pxylist=[]
mxylist=[]
for _ in range(N):
  x,y=map(int,input().split())
  xylist.append((x,y))
  pxylist.append(x+y)
  mxylist.append(x-y)
pxylist.sort()
mxylist.sort()

answer=max(pxylist[-1]-pxylist[0],mxylist[-1]-mxylist[0])
print(answer)

Measured memory_bytes: 52828
n = int(input())
total = 0
problems_to_solve = []
for i in range(1,n+1):
    total += i
    problems_to_solve.append(i)
    if total >= n:
        diff =  total - n
        for problem in problems_to_solve:
            if problem != diff:
                print(problem)
        break
    


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
using namespace std;

int main(void)
{
    int N, M;
    long k;
    cin >> N >> M >> k;    

    for (int y = 0; y <= N; y++)
    {
        for (int x = 0; x <= M; x++)
        {
            long black = y * M + x * N - x * y * 2;
            
            if (black == k)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
#define P pair<ll,ll>
#define fs first
#define sc second
using namespace std;


#define N_MAX 200000
int main(){
  ll n,k;
  cin >> n >> k;
  vector<P> vec;

  ll a[n];
  rep(i,0,n){
    cin >> a[i];
  }

  sort(a,a+n);

  ll temp = 1;
  rep(i,0,n-1){
    if(a[i] != a[i+1]){
      vec.push_back(P(temp,a[i]));
      temp = 1;
    }
    else temp++;
  }
  vec.push_back(P(temp,a[n-1]));

  sort(vec.begin(),vec.end());

  ll ans = 0;temp = max(0LL,(ll)vec.size() - k);
  rep(i,0,temp){
    ans += vec[i].fs;
  }

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

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

using namespace std;

int main(){
  int d,g;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  for(int i=0;i<d;i++){
      cin >> p[i] >> c[i];
  }
  int m=1005; //解く問題の最小数
  for(int i=0;i<(1<<d);i++){
    int sum=0; //合計点
    int cnt=0; //解いた問題の数
    for(int j=0;j<d;j++){
      if(i>>j & 1){
        sum+=c[j]+100*(j+1)*p[j];
        cnt+=p[j];
      }
    }
    if(g>sum){
        for(int j=d-1;j>=0;j--){
            if(i>>j & 1){
                continue;
                
            }
            if(g>sum+100*(j+1)*p[j]){
                goto end;
                
            }
            else{
                cnt+=(g-sum-1)/(100*(j+1))+1;
                break;
            }
            
        }
    }
    m=min(m,cnt);
end:
    ;
  }
  cout << m << endl;        
}


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

int main()
{
	int N;
	int B[200010];

	cin >> N;

	for (int i = 0; i <= N; i++)
		B[i] = 0;

	for (int i = 2; i <= N; i++)
	{
		int a;
		cin >> a;

		B[a]++;
	}

	for (int i = 1; i <= N; i++)
		cout << B[i] << endl;

	return 0;
}



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

using namespace std;


int maxhappinessinvacations(int **arr,int n){

   
   int DP[n][3];

 for(int i=0;i<3;i++)
 	DP[0][i]=arr[0][i];
  

for(int i=1;i<n;i++){

  DP[i][0]=arr[i][0]+max(DP[i-1][1],DP[i-1][2]);
  DP[i][1]=arr[i][1]+ max(DP[i-1][0],DP[i-1][2]);
  
  DP[i][2]=arr[i][2]+ max(DP[i-1][0],DP[i-1][1]);


}

return max(max(DP[n-1][0],DP[n-1][1]),DP[n-1][2]);


}

int main(){

 

  int n;

   cin>>n;

   int **arr=new int*[n];


   for(int i=0;i<n;i++){
      arr[i]=new int[3];
     for(int j=0;j<3;j++)
       cin>>arr[i][j];

   }

    cout<<maxhappinessinvacations(arr,n)<<endl;


  
  



	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i < 51; i++) {
        for (int j = 0; j < 26; j++) {
            if (i + j == X) {
                if (i * 2 + j * 4 == Y) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
S = {1}

def f(L, S):
    last = L[-1]-1
    if A[last] not in S:
        L.append(A[last])
        S |= {A[last]}
        return f(L, S)
    else:
        return L
P = f(L, S)
a = A[P[-1]-1]
j = P.index(a)
r = len(P)
l = r - j

if k+1 <= j:
    print(P[k])
else:
    print(P[j+(k-j)%l])

Measured memory_bytes: 189356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define REP(i,a,b) \
for(int i=int(a);i<=int(b);i++)
#define DEP(i,a,b) \
for(int i=int(a);i>=int(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)
	map<ll,ll> mp;
void primeFactors(ll n)  
{   
    while (n % 2 == 0)  
    {  
        if(mp.find(2)!=mp.end()){
        	mp.find(2)->second++;
        }  
        else{
        	mp.insert({2,1});
        }
        n = n/2;  
    }  
  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {   
        while (n % i == 0)  
        {  
            if(mp.find(i)!=mp.end()){
        	mp.find(i)->second++;
        }  
        else{
        	mp.insert({i,1});
        } 
            n = n/i;  
        }  
    }  
    if (n > 2)  
        {
        	if(mp.find(n)!=mp.end()){
        	mp.find(n)->second++;
        }  
        else{
        	mp.insert({n,1});
        }
        }  
}  
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,i,j,k,l;
	cin>>n;
	primeFactors(n);
	ll ans=0;
	TR(mp,it){
		ll x=it->second;
		ans+=(ll(sqrt(8*x+1))-1)/2;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3700
a,b,k=map(int,input().split())
for i in range(k):
    if i%2==0:
        if a%2==1:
            a-=1
        a//=2
        b+=a
    else:
        if b%2==1:
            b-=1
        b//=2
        a+=b
print(a,b)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>

using namespace std;

int binary_Serch(vector<int> A, int key) {
	int left = 0;
	int right = A.size();
	
	while (left < right) {
		int mid = (left + right) / 2;
		if (A[mid] == key) {
			return true;
		}
		else if (key < A[mid]) {
			right = mid;
		}
		else if (A[mid] < key) {
			left = mid + 1;
		}
	}
	return false;
}

int main() {
	int n, q;
	cin >> n;
	vector<int> s(n);
	for (int i = 0; i < n; ++i)cin >> s[i];
	cin >> q;
	vector<int> t(n);
	for (int i = 0; i < q; ++i)cin >> t[i];

	int ans = 0;
	for (int i = 0; i < q; ++i) {
		if(binary_Serch(s, t[i])) ++ans;
	}

	cout << ans << endl;

	return 0;
}


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

// --- DEBUG begin --- cut here ---
template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

template <typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}
// --- DEBUG end --- cut here ---


ll fact(ll i) {
  if (i == 0) return 1;
  return i * fact(i-1);
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> P(N), Q(N);
  for (ll i = 0; i < N; i++) {
    int x; cin >> x; x--;
    P.at(i) = x;
  }
  for (ll i = 0; i < N; i++) {
    int x; cin >> x; x--;
    Q.at(i) = x;
  }

  auto ord = [&](auto vec) -> ll {
    vector<bool> seen(N);
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
      ll scnt = vec.at(i);
      for (ll j = 0; j < vec.at(i); j++) {
	if (seen.at(j)) scnt--;
      }
      DLOG("scnt", scnt);
      DLOG("fact(N-i-1)", i, fact(N-i-1));
      ans += scnt * fact(N-i-1);
      seen.at(vec.at(i)) = true;
    }
    return ans;
  };

  
  ll xp = ord(P);
  DLOG("xp", xp);
  ll xq = ord(Q);
  DLOG("xq", xq);
  cout << abs(xp - xq) << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    static long dp[][] = new long[51][51];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        int a[] = new int[n];
        int odd = 0;
        int even = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] % 2 == 0) {
                even++;
            } else {
                odd++;
            }
        }
        long count = 0;
        long sumo = 0;
        long sume = 0;
        if (p == 0) {
            for (int i = 0; i <= odd; i += 2) {
                sumo += combination(odd, i);
            }
            for (int i = 0; i <= even; i++) {
                sume += combination(even, i);
            }
            count = sumo * sume;
            System.out.println(count);
        } else {
            for (int i = 1; i <= odd; i += 2) {
                sumo += combination(odd, i);
            }
            for (int i = 0; i <= even; i++) {
                sume += combination(even, i);
            }
            count = sumo * sume;
            System.out.println(count);
        }
    }
    static long combination(int n, int k) {
        if (n == k || k == 0) {
            return 1;
        } else if (dp[n][k] != 0) {
            return dp[n][k];
        }
        return dp[n][k] = combination(n - 1, k) + combination(n - 1, k - 1);
    }
}

Measured memory_bytes: 24020
A, B = map(int, input().split())

array = []
bin_B = bin(B)[2:]
digit_B = len(bin_B)

if (A-1) % 4 == 1 or (A-1) % 4 == 2:
    if B % 4 == 1 or B % 4 == 2:
        array.append('0')
    else:
        array.append('1')
else:
    if B % 4 == 1 or B % 4 == 2:
        array.append('1')
    else:
        array.append('0')

for i in range(2, digit_B+1):
    num = 2 ** i
    if (A-1) % num < (num // 2) or ((A-1) % num) % 2 == 1:
        if B % num < (num // 2) or (B % num) % 2 == 1:
            array.append('0')
        else:
            array.append('1')
    else:
        if B % num < (num // 2) or (B % num) % 2 == 1:
            array.append('1')
        else:
            array.append('0')

array.reverse()
result = ''
for i in array:
    result += i

print(int(result, 2))

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

const ll mod = 1000000007 ;

bool isInteger(double n)
{
	if(floor(n)==ceil(n))
		return true ;
	return false ;
}

using namespace std ;

int main()
{
	int n;
	cin>>n;
	cout<<(n/500)*1000+((n%500)/5)*5;
}


Measured memory_bytes: 3620
var x={};
  x["1to2"]=300;
  x["1to3"]=500;
  x["1to4"]=600;
  x["1to5"]=700;
  x["1to6"]=1350;
  x["1to7"]=1650;
  x["2to1"]=6;
  x["2to3"]=350;
  x["2to4"]=450;
  x["2to5"]=600;
  x["2to6"]=1150;  
  x["2to7"]=1500;
  x["3to1"]=13;
  x["3to2"]=7;
  x["3to4"]=250;
  x["3to5"]=400;
  x["3to6"]=1000;
  x["3to7"]=1350;
  x["4to1"]=18;
  x["4to2"]=12;
  x["4to3"]=5;
  x["4to5"]=250;
  x["4to6"]=850;
  x["4to7"]=1300;
  x["5to1"]=23;
  x["5to2"]=17;
  x["5to3"]=10;
  x["5to4"]=5;
  x["5to6"]=600;
  x["5to7"]=1150;
  x["6to1"]=43;
  x["6to2"]=37;
  x["6to3"]=30;
  x["6to4"]=25;
  x["6to5"]=20;
  x["6to7"]=500;
  x["7to1"]=58;
  x["7to2"]=52;
  x["7to3"]=45;
  x["7to4"]=40;
  x["7to5"]=35;
  x["7to6"]=15;
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
while(true){
   var s=Arr.shift()-0;
   if(s==0)break;
   var hm1=(Arr.shift()).split(" ").map(Number);
   var g=Arr.shift()-0;
   var hm2=(Arr.shift()).split(" ").map(Number);
   var S=(parseInt(hm1[0],10)*60)+parseInt(hm1[1],10);
   var G=(parseInt(hm2[0],10)*60)+parseInt(hm2[1],10);
   var cnt=0;
   if((S>=1050 && S<=1170) || G>=1050 && G<=1170)cnt++;
   if(x[g+"to"+s]<=40)cnt++;
   var money=x[s+"to"+g];
   if(cnt==2){
      money=Math.floor(money/2);
      while(money%50!=0)money++;
   }
   console.log(money);
}

Measured memory_bytes: 7904
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main(){
    int n;
    cin >> n;
    long long int x;
    long long int answer = 0LL;
    long long int sum = 0LL;
    for(int i = 0; i < n; i++){
        cin >> x;
        answer += sum*x;
        sum += x;
        sum %= MOD;
        answer %= MOD;
    }
    cout << answer << "\n";
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fs first
#define se second
 
struct trap{
	ll l=-1,r=-1,d=-1;
};
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll ans=0;
	vector<pair<ll,ll>>arr[n+1];
	for(ll i=1;i<=n;i++)
	{
		ll m;
		cin>>m;
		for(ll j=0;j<m;j++)
		{
			ll a,b;
			cin>>a>>b;
			arr[i].pb({a,b});
		}
	}
	for(ll i=1;i<(1<<n);i++)
	{
		vector<ll>mark(n+1,1);
		ll f=0;
		for(ll j=1;j<=n;j++)
		{

			if(i&(1<<(j-1)))
			for(ll k=0;k<arr[j].size();k++)
			{
				auto h=arr[j][k];
				if(h.se==0)
				{
					ll p=h.fs;
					if(!((~i)&1<<(p-1)))
						f++;
				}
				else if(h.se==1)
				{
					ll p=h.fs;
					if(!(i&1<<(p-1)))
						f++;
				}

			}
		}
		if(f==0)
		{
			ll c=0;
			ll h=i;
			while(h)
			{
				if(h&1)
					c++;
				h=h>>1;
			}
			ans=max(ans,c);
		}
		// ll c=0,f=0;
		// for(ll j=1;j<=n;j++)
		// 	{
		// 		if(mark1[j]>=0 && mark2[j]==0)
		// 			c++;
		// 		else if(mark1[j]==0 && mark2[j]<0)
		// 		{

		// 		}
		// 		else
		// 			f++;
		// 	}
		// 	cout<<c<<" "<<f<<endl;
		// if(f==0)
		// ans=max(ans,c);
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 256
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 200009
#define INF (ll)1e15
#define mod ((ll)1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n,m;

struct edge{
	int y,nxt;
	edge(){}
	edge(int yy,int nn){
		y=yy,nxt=nn;
	}
}e[inf*2];
int head[inf],ecnt;

void addedge(int x,int y){
	ecnt++;
	e[ecnt]=edge(y,head[x]);
	head[x]=ecnt;
	return;
}

int fa[inf],val[inf],p[inf],vis[inf],num;

bool dfs(int u){
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].y;
		if (!p[v]){
			dfs(v);
		}
	}
	num++;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].y;
		if (!p[v]){
			vis[val[v]]=num;
		}
	}
	val[u]=0;
	while (vis[val[u]]==num){
		val[u]++;
	}
	return p;
}

int main(){
	rd(n)
	int x,y;
	for (int i=1;i<=n;i++){
		rd(fa[i])
		addedge(fa[i],i);
	}
	int now=1,cnt=0;
	while (!p[now]){
		p[now]=1;
		now=fa[now];
	}
	memset(p,0,sizeof(p));
	while (!p[now]){
		p[now]=1;
		cnt++;
		now=fa[now];
	}
	int minv=n+1,maxv=0;
	for (int i=1;i<=n;i++){
		if (p[i]){
			dfs(i);
			maxv=max(maxv,val[i]);
			minv=min(minv,val[i]);
		}
	}
	if (maxv!=minv || !(cnt&1)){
		puts("POSSIBLE");
	}
	else{
		puts("IMPOSSIBLE");
	}
	return 0;
}

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

int main(){
    ll n;
    cin >> n;
    
    ll ans = 0;
    for(ll i = 1; i < n; i++){
        ans += i;
    }
    cout << ans << endl;

    return 0;

}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B, C;
  IN(A,B,C);
  set<ll> st;
  st.emplace(A);
  st.emplace(B);
  st.emplace(C);

  if(st.size()==2){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)x.size()
//#define int ll

const int MOD = 1e9 + 7;

void add(int &a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

inline int mult(int a, int b) {
	return (a * 1ll * b) % MOD;
}

int b_pow(int a, int b) {
	if (!b) {
		return 1;
	}
	if (b & 1) {
		return mult(a, b_pow(a, b - 1));
	}
	return b_pow(mult(a, a), b >> 1);
}

const int MX = 4e6 + 10;
int f[MX], rf[MX];

int C(int n, int k) {
	if (n < 0 || k < 0 || n < k) {
		return 0;
	}
	return mult(f[n], mult(rf[k], rf[n - k]));
}

const int N = 2010;
int dp[N][N];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	f[0] = 1;
	for (int i = 1; i <= 4e6; i++) {
		f[i] = mult(f[i - 1], i);
	}
	rf[4000000] = b_pow(f[4000000], MOD - 2);
	for (int i = 4e6 - 1; i >= 0; i--) {
		rf[i] = mult(rf[i + 1], i + 1);
	}
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 1 << '\n';
		exit(0);
	}
	for (int i = 0; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			if (!j) {
				dp[i][j] = 1;
				continue;
			}
			if (i > 0) {
				add(dp[i][j], dp[i - 1][j]);
			}
			if (j > 0) {
				add(dp[i][j], mult(dp[i][j - 1], C(i + j * (k - 1) - 1, k - 2)));
			}
		}
	}
	int ans = dp[n][n];
	for (int i = 2; i <= n; i++) {
		ans = mult(ans, i);
	}
	cout << ans << '\n';
}	

Measured memory_bytes: 47232