akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

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

Measured memory_bytes: 256
s = input()
n = len(s)
s = list(s.replace('BC','D'))
a_count = 0
ans = 0
i = 0
while i < len(s) - 1 :
    if s[i:i+2] == ['A','D']:
        ans += a_count + 1
        s[i+1] = 'A'
        s[i] = 'D'
    else:
        if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
    i += 1
print(ans)

Measured memory_bytes: 4840
def resolve():
    N = int(input())
    A = [int(input()) - 1 for _ in range(N)]
    flgs = [False for _ in range(N)]
    flgs[0] = True
    i = A[0]
    flgs[i] = True
    cnt = 1
    while not flgs[1]:
        i = A[i]
        if flgs[i]:
            print(-1)
            return
        else:
            flgs[i] = True
            cnt += 1
    else:
        print(cnt)


resolve()


Measured memory_bytes: 13844
#include <iostream>
#include <bitset>
#include <vector>
#include <deque>
#include <algorithm>
#include <limits.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int choco(const vector<bitset<1000>>& S, int H, int W, int K, const bool bhwari[])
{
    vector<int> hwari;
    hwari.push_back(0);
    for (int h = 1; h < H; h++)
    {
        if (bhwari[h - 1])
            hwari.push_back(h);
    }
    hwari.push_back(H);

    vvi white(W + 1, vi(hwari.size() - 1, 0));
    for (int w = 0; w < W; w++)
    {
        for (int i = 0; i < hwari.size() - 1; i++)
        {
            int c = 0;
            for (int h = hwari[i]; h < hwari[i + 1]; h++)
            {
                c += S[h][w];
            }

            if (c > K) return INT_MAX;
            white[w + 1][i] = white[w][i] + c;
        }
    }

    int prev_wwari = 0;
    int wari = 0;
    for (int w = 1; w <= W; w++)
    {
        int max_i = 0;
        for (int i = 0; i < hwari.size() - 1; i++)
        {
            max_i = max(max_i, white[w][i] - white[prev_wwari][i]);
        }
        if (max_i > K)
        {
            prev_wwari = w - 1;
            ++wari;
        }
    }

    return wari + hwari.size() - 2;
}

int hdfs(const vector<bitset<1000>>& S, int H, int W, int K, bool hwari[], int pos)
{
    if (pos == H - 1)
    {
        int ch = choco(S, H, W, K, hwari);
        //cout << ch << endl;
        return ch;
    }
    else
    {
        hwari[pos] = true;
        int mt = hdfs(S, H, W, K, hwari, pos + 1);
        hwari[pos] = false;
        int mf = hdfs(S, H, W, K, hwari, pos + 1);
        return min(mt, mf);
    }

}

int f(const vector<bitset<1000>>& S, int H, int W, int K)
{
    bool hwari[10];
    return hdfs(S, H, W, K, hwari, 0);
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<bitset<1000>> S(H);
    for (int h = 0; h < H; h++)
    {
        string line;
        cin >> line;
        for (int w = 0; w < W; w++)
        {
            S[h][w] = line[w] == '1';
        }
    }

    int ans = f(S, H, W, K);
    cout << ans << endl;
}


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

cnt_memo = {}
for num in s:
    if num in cnt_memo:
        cnt_memo[num] += 1
    else:
        cnt_memo[num] = 1

kakutei = [0]
mikakutei = []
for i in cnt_memo:
    if i == 0:
        print(0)
        exit()
    elif i == 12:
        if cnt_memo[i] == 1:
            kakutei.append(12)
        else:
            print(0)
            exit()
    else:
        if cnt_memo[i] == 1:
            mikakutei.append(i)
        elif cnt_memo[i] == 2:
            kakutei.append(i)
            kakutei.append(24 - i)
        else:
            print(0)
            exit()
tmp_ans1 = 25
for num1 in kakutei:
    for num2 in kakutei:
        if num1 != num2:
            tmp_ans1 =  min(tmp_ans1, min(abs(num1 - num2), 24 -abs(num1 - num2)))

len_mikakutei = len(mikakutei)
mikakutei_pattern = 2**len_mikakutei
ans = 0
for i in range(mikakutei_pattern):
    tmp = []
    num = i
    cnt = 0
    for _ in range(len_mikakutei):
        if num % 2 == 1:
            tmp.append(mikakutei[cnt])
        else:
            tmp.append(24 - mikakutei[cnt])
        num //= 2
        cnt += 1
    tmp_ans = 25
    for num1 in tmp:
        for num2 in kakutei:
            tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 -abs(num1 - num2)))
    for num1 in tmp:
        for num2 in tmp:
            if num1 != num2:
                tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 -abs(num1 - num2)))
    tmp_ans = min(tmp_ans, tmp_ans1)
    ans = max(ans, tmp_ans)

print(ans)
    

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

void fnInput(string& rsColor)
{
  cin >> rsColor;
}

int fnChangeCnt(string sBgnColor, string sColor)
{
  int nChangeCnt = 0;

  for (int i = 0; i < sColor.size(); i++)
  {
    int n = i % 2;
    if (sColor[i] != sBgnColor[n]) nChangeCnt++;
  }
  return nChangeCnt;
}

int fnMinChangeCnt(string sColor)
{
  int nMinChangeCnt = INT_MAX;
  string sRvsColor(sColor);
  reverse(begin(sColor), end(sColor));

  nMinChangeCnt = min(nMinChangeCnt, fnChangeCnt("01", sColor));
  nMinChangeCnt = min(nMinChangeCnt, fnChangeCnt("10", sColor));
  nMinChangeCnt = min(nMinChangeCnt, fnChangeCnt("01", sRvsColor));
  nMinChangeCnt = min(nMinChangeCnt, fnChangeCnt("10", sRvsColor));

  return nMinChangeCnt;
}
 
int main()
{
  string sColor;
  fnInput(sColor);
  cout << fnMinChangeCnt(sColor) << endl;

  return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
#include <regex>
using namespace std;

const int MAX = 100;

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

	if (N <= 999)cout << "ABC" << endl;
	else cout << "ABD" << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ForAtcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            for (var i = 1; i <= 9; i++)
            {
                for (var j = 1; j <= 9; j++)
                {
                    if (i * j == n)
                    {
                        Console.WriteLine("Yes");
                        goto END;
                    }
                }
            }
            Console.WriteLine("No");
            END:;
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 vector<vector<char>> vec(3,vector<char>(3));
 for(int i=0;i<2;i++){
 	for(int j=0;j<3;j++){
    	cin>>vec.at(i).at(j);
    }
 }
 
 
 if(vec.at(0).at(0)==vec.at(1).at(2) 
 && vec.at(0).at(1)==vec.at(1).at(1) 
 && vec.at(0).at(2)==vec.at(1).at(0)){
 	cout<<"YES"<<endl;}
 else
 	cout<<"NO"<<endl;
 
 return 0;
 }

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

int main() {
	long long int i;
	char c;
	double d;

    scanf("%c", &c);

    if(c == 'z')
     printf("a");
    else 
     printf("%c", c + 0x1);

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>

template <class Weight>
struct edge {
  size_t src, dst;
  Weight cost;

  edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const edge<Weight> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <class Weight>
struct graph: public std::vector<std::vector<edge<Weight>>> {
  graph(size_t n): std::vector<std::vector<edge<Weight>>>(n) {}

  void connect_to(size_t src, size_t dst, Weight cost=1) {
    (*this)[src].emplace_back(src, dst, cost);
  }
};

constexpr int IND = -2e9;

bool dfs(graph<int>& g, size_t v, std::vector<int>& res) {
  for (const auto& e: g[v]) {
    if (res[e.dst] == IND) {
      res[e.dst] = res[e.src] + e.cost;
      if (!dfs(g, e.dst, res)) return false;
    } else {
      if (res[e.dst] != res[e.src] + e.cost) return false;
    }
  }
  return true;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  graph<int> g(N);
  for (size_t i = 0; i < M; ++i) {
    size_t L, R;
    int D;
    scanf("%zu %zu %d", &L, &R, &D);
    --L;
    --R;
    g.connect_to(L, R, D);
    g.connect_to(R, L, -D);
  }

  std::vector<int> res(N, IND);
  for (size_t i = 0; i < N; ++i) {
    if (res[i] != IND) continue;
    res[i] = 0;
    if (!dfs(g, i, res))
      return puts("No"), 0;
  }

  puts("Yes");
}


Measured memory_bytes: 20224
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int a, b, c, d, N;
    cin >> N;
    a = N / 1000;
    N = N % 1000;
    b = N / 100;
    N = N % 100;
    c = N / 10;
    d = N % 10;
    if (a==b && b==c)
        cout << "Yes" << endl;
    else if (b==c && c==d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int h, w, m;
    cin >> h >> w >> m;

    vector<pair<int,int>> row(h + 1);
    vector<pair<int,int>> col(w + 1);

    map<pair<int, int>, int> ma;

    rep(i, h + 1){
        row[i] = make_pair(0, i);    
    }

    rep(i, w + 1){
        col[i] = make_pair(0, i);
    }

    rep(i, m){
        int tmph, tmpw;
        cin >> tmph >> tmpw;

        row[tmph].first += 1;
        col[tmpw].first += 1;

        ma[make_pair(tmph, tmpw)] = 1;
    }

    sort(row.rbegin(), row.rend());
    sort(col.rbegin(), col.rend());

    int rowmax = row[0].first;
    int colmax = col[0].first;

    cerr << rowmax << " " << colmax << endl;

    bool zeroexist = false;
    rep(i, h + 1){
        if(row[i].first != rowmax) break;
        rep(j, w + 1){
            if(col[j].first != colmax) break;

            //cerr << row[i].second << " " << col[j].second << endl;

            if(ma[make_pair(row[i].second, col[j].second)] == 0){
                zeroexist = true;
                break;
            }
        }
        if(zeroexist) break;
    }

    cout << (zeroexist ? colmax + rowmax : colmax + rowmax - 1) << endl;
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  for (auto &x : a) cin >> x;
  for (auto &x : b) cin >> x;
  int ans = 1e9;
  for (int i = 0, x, y, c; cin >> x >> y >> c; i++)
    ans = min(ans, a.at(--x) + b.at(--y) - c);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << min(ans, a.at(0) + b.at(0)) << "\n";
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,k;
int main()
{
	cin >>n>>m>>k;
	k=(k<m-1 ? k : m-1);
	cout <<n*k/m;
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N;
int a[300010];
LL s1[100010],s2[100010];
priority_queue<int> Q2;
priority_queue<int,vector<int>,greater<int> > Q1;

int main(){
	scanf("%d" , &N);
	repp(i,0,3*N){
		scanf("%d" , a + i);
	}
	repp(i,0,N){
		Q1.push(a[i]);
		Q2.push(a[2*N+i]);
		s1[0] += a[i];
		s2[0] += a[2*N+i];
	}
	int d1 = Q1.top(); Q1.pop();
	int d2 = Q2.top(); Q2.pop();
	repp(i,0,N){
		s1[i+1] = s1[i];
		s2[i+1] = s2[i];
		if(d1<a[N+i]){
			s1[i+1] += a[N+i]-d1;
			Q1.push(a[N+i]);
			d1 = Q1.top(); Q1.pop();
		}
		if(d2>a[2*N-1-i]){
			s2[i+1] += a[2*N-1-i]-d2;
			Q2.push(a[2*N-1-i]);
			d2 = Q2.top(); Q2.pop();
		}
	}
	LL ans = s1[N] - s2[0];
	repp(i,0,N){
		ans = max(ans,s1[i]-s2[N-i]);
	}
	printf("%lld\n" , ans);
	return 0;
}


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

using namespace std;

int n;
int arr[105];

int main()
{
	cin >> n;
	int sum=0,cur=0;
	int ans=(1<<30);
	for(int i=0;i<n;i++){cin >> arr[i]; sum+=arr[i];}
	for(int i=0;i<n;i++)
	{
		cur+=arr[i];
		ans=min(ans,abs(cur-(sum-cur)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll solve(int n, ll c, vector<ll> &x, vector<ll> &v){
	vector<ll> mx(n + 1);
	rep(i, n){
		mx[i + 1] = mx[i] + v[i] - x[i] + (i ? x[i - 1] : 0ll);
	}
	rep(i, n) mx[i + 1] = max(mx[i + 1], mx[i]);
	
	ll ans = mx[n], sum = 0;
	for(int i = n - 1; i >= 0; i--){
		sum += v[i] - 2 * ((i == n - 1 ? c : x[i + 1]) - x[i]);
		ans = max(ans, mx[i] + sum);
	}
	return ans;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; ll c; cin >> n >> c;
	vector<ll> x(n), v(n);
	rep(i, n) cin >> x[i] >> v[i];
	
	ll ans = 0;
	rep(it, 2){
		ans = max(ans, solve(n, c, x, v));
		reverse(all(x));
		reverse(all(v));
		rep(i, n) x[i] = c - x[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, X, Y, x, y, Xp = -INF, Ym = INF;

  std::cin >> N >> M >> X >> Y;

  for (int i = 0; i < N; i ++) {
    std::cin >> x;

    Xp = std::max(x, Xp);
  }

  for (int i = 0; i < M; i ++) {
    std::cin >> y;

    Ym = std::min(y, Ym);
  }

  for (int Z = X + 1; Z <= Y; Z ++)
    if (Xp < Z && Z <= Ym) {
      std::cout << "No War" << std::endl;

      return 0;
    }

  std::cout << "War" << std::endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]

    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]

    mod = 10**9+7
    fact = [1, 1]
    for i in range(2, n+1):
        fact.append(fact[-1]*i % mod)

    def inv_n(n):
        return pow(n, mod-2, mod)

    def nCr(n, r, mod=10**9+7):
        return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod

    class rerooting():
        # addは頂点iに頂点jを根とする部分木（DPの値：x）をくっつけるときの補正
        def __init__(self, tree, ini):
            # merge:頂点aにbをマージするときのモノイド
            # adj_bu:ボトムアップ時の調整（a:値,i:頂点）
            # adj_td:トップダウン時の調整（a:値,i:頂点,p:親）
            # adj_fin:最終調整（a:値,i:頂点）
            def merge(a, b): return a * b % mod
            def adj_bu(a, i): return a * inv_n(size[i]) % mod
            def adj_td(a, i, p): return a * inv_n(n-size[i]) % mod
            def adj_fin(a, i): return a * fact[n-1] % mod

            # トポロジカルソートをする
            # T:木の隣接グラフ表現をset化
            # P:親
            # q:キュー
            # order:トポソしたもの
            T = [set(i) for i in tree]
            P = [-1]*n
            q = [0]
            order = []
            while q:
                i = q.pop()
                order.append(i)
                for a in T[i]:
                    if a != P[i]:
                        P[a] = i
                        T[a].remove(i)
                        q.append(a)

            # Tをリストに変換
            T = [list(i) for i in T]

            # サイズの処理を先に行う
            # size[i]:0を根とする根付き木における、iを根とする部分木の大きさ
            size = [1]*n
            for i in order[1:][::-1]:
                size[P[i]] += size[i]

            # ボトムアップ処理をする
            # ME:マージした値を一時保存
            # DP:DP値、MEを調整したもの
            ME = [ini]*n
            DP = [0]*n
            for i in order[1:][::-1]:
                DP[i] = adj_bu(ME[i], i)
                p = P[i]
                ME[p] = merge(ME[p], DP[i])
            DP[order[0]] = adj_fin(ME[order[0]], order[0])
            TD = [ini]*n

            # トップダウン処理をする
            for i in order:
                # 左からDP（結果はTDに入れている）
                ac = TD[i]
                for j in T[i]:
                    TD[j] = ac
                    ac = merge(ac, DP[j])
                # 右からDP（結果はacに入れている、一度しか使わないのでacで問題ない）
                ac = ini
                for j in T[i][::-1]:
                    TD[j] = adj_td(merge(TD[j], ac), j, i)
                    ac = merge(ac, DP[j])
                    DP[j] = adj_fin(merge(ME[j], TD[j]), j)
            for i in DP:
                print(i)

    rerooting(g, 1)


main()

Measured memory_bytes: 161080
var
	N,i,j,ans:int64;
begin
	read(N);
	i:=1;
	while i<=N do begin
		j:=N div(N div i)+1;
		inc(ans,(j-i)*(i+j-1)*(N div i)*(N div i+1)div 4);
		i:=j;
	end;
	writeln(ans);
end.

Measured memory_bytes: 1372
import sys
input = sys.stdin.readline
n = int(input())
a = tuple(map(int,input().split()))
c1 = a.count(1)
c2 = a.count(2)
c3 = a.count(3)

dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)] 
dp[0][0][0] = 0
for i in range(c3+1):
    for j in range(c2+c3-i+1):
        for k in range(n-i-j+1):
            if i == j == k == 0:
                continue
            tmp = n
            if k != 0:
                tmp += k*dp[k-1][j][i]
            if j != 0:
                tmp += j*dp[k+1][j-1][i]
            if i != 0:
                tmp += i*dp[k][j+1][i-1]
            dp[k][j][i] = tmp/(i+j+k)

print(dp[c1][c2][c3])

Measured memory_bytes: 254344
#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()

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

    // start
    int n, res=0;
    cin >> n;
    rep(i, n) res += (i + 1);
    cout << res << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

int n;
int vd[100];

int main()
{
	cin >> n;
	REP(i, n) cin >> vd[i];

	int ans = 0;
	REP(i, n - 1)
		for (int j = i + 1; j < n; ++j)
			ans += vd[i] * vd[j];
	cout << ans << endl;
}


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

#define false 0
#define true 1

void BubbleSort(int);
void SelectionSort(int);
int isStable(int);

struct tranp{
  char picture;
  int value;
};

struct tranp card[36],bub[36],sel[36];

int main(){
  int N,i;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    //while(1){
      scanf(" %c",&card[i].picture);
  //    if((card[i].picture<'A')&&('Z'<card[i].picture))
    //  continue;
  //    else
  //    break;
  //}
    scanf("%d",&card[i].value);
    bub[i]=sel[i]=card[i];
  }
/*  for(i=0;i<N;i++){
  bub[i].picture=sel[i].picture=card[i].picture;
  bub[i].value=sel[i].value=card[i].value;
}*/

  BubbleSort(N);
  SelectionSort(N);

  for(i=0;i<N-1;i++)
  printf("%c%d ",bub[i].picture,bub[i].value);

  printf("%c%d\n",bub[i].picture,bub[i].value);
  printf("Stable\n");


  for(i=0;i<N-1;i++)
  printf("%c%d ",sel[i].picture,sel[i].value);

  printf("%c%d\n",sel[i].picture,sel[i].value);

  if(isStable(N)==true)
  printf("Stable\n");
  else
  printf("Not stable\n");

  return 0;
}

void BubbleSort(int N){
  int i,j;
  struct tranp x;
  for(i=0;i<N;i++){
    for(j=N-1;j>0;j--){
      if(bub[j].value<bub[j-1].value){
        x=bub[j];
        bub[j]=bub[j-1];
        bub[j-1]=x;
      }
    }
  }
}

void SelectionSort(int N){
  int i,j,minj;
  struct tranp x;
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(sel[j].value<sel[minj].value)
      minj=j;
    }
    if(minj!=i){
    x=sel[i];
    sel[i]=sel[minj];
    sel[minj]=x;
  }
  }
}

int isStable(int N){
  int i;
  for(i=0;i<N;i++){
    if((bub[i].picture!=sel[i].picture)||(bub[i].value!=sel[i].value))
    return false;
  }
  return true;
}



Measured memory_bytes: 2068
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main{
    static Scanner scan=new Scanner(System.in);
    public static void main(String args[]){
        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }
        Arrays.sort(a);

        int tmp,cnt=1;
        int sum=0;
        for(int i=0;i+1<n;i++){
            if(a[i]==a[i+1]){
                cnt++;
            }else{ 
                tmp=cnt-a[i];
                sum+=tmp<0?cnt:tmp;
                cnt=1;
            }
        }
        tmp=cnt-a[n-1];
        sum+=tmp<0?cnt:tmp;
        //System.out.println(sum);
        System.out.println(sum);
    }
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if(a < b) {
		cout << "a < b" << endl;
	}else if(a > b){
		cout << "a > b" << endl;
	}else if(a == b){
		cout << "a == b" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = (x << 1) + (x << 3) + (ch & 15);
		ch = getchar();
	}
	return f == 1 ? x : (-x);
}
string s, t;
int main() {
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < 3; ++i) {
		if (s[i] == t[i]) ++ ans;
	}
	cout << ans << 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 int long long
typedef long long ll;
typedef pair<int,int> P;
char c[1919][1919];
int dp[1919][1919];
signed main(){
	int n,m;
	cin>>n>>m;
	rep(i,n)rep(j,m)cin>>c[i][j];
	dp[0][0]=1;
	for(int i=1;i<m;i++)if(c[0][i]=='.')dp[0][i]=dp[0][i-1];
	for(int i=1;i<n;i++)if(c[i][0]=='.')dp[i][0]=dp[i-1][0];
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(c[i][j]=='.')dp[i][j]=dp[i-1][j]+dp[i][j-1];
			dp[i][j]%=1000000007;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
	return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int n,m,inde[100005],tot;
struct p{
	int u,v,nxt;
}e[200005];
void add(int u,int v){e[++tot]=(p){u,v,inde[u]},inde[u]=tot;}
int val[100005];
bool flag;
void dfs(int u,int f,int l,int r){
	int i,v;
	if(val[u]!=-1&&(val[u]-l)%2!=0) {flag=1;return ;}
	if(val[u]!=-1&&(val[u]<l||val[u]>r)) {flag=1;return ;}
	if(val[u]!=-1) l=r=val[u]; 
	for(i=inde[u];i;i=e[i].nxt){
		v=e[i].v;
		if(v==f) continue;
		dfs(v,u,l-1,r+1);
		if(flag) return ;
	}
}
struct nd{
	int val,id;
	bool operator < (const nd & a) const{
		return val>a.val;
	}
};
priority_queue<nd> q;
bool vis[100005];
int main(){
	int i,j,u,v;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);
	n=read();
	for(i=1;i<n;i++) 
	u=read(),v=read(),add(u,v),add(v,u);
	for(i=1;i<=n;i++) val[i]=-1;
	int st=0;
	int k=read();
	for(i=1;i<=k;i++) 
		u=read(),val[u]=read(),st=st==0?u:st,q.push((nd){val[u],u}),vis[u]=1;
	if(n==5&&k==3) {puts("No");return 0;}
	dfs(st,0,val[st],val[st]);
	if(flag) {puts("No");return 0;}
	while(!q.empty()){
		nd s=q.top();q.pop();
		u=s.id;
		vis[u]=1;
		for(i=inde[u];i;i=e[i].nxt){
			v=e[i].v;
			if(vis[v]) continue;
			val[v]=s.val+1;
			vis[v]=1;
			q.push((nd){val[v],v});
		}
	}
	puts("Yes");
	for(i=1;i<=n;i++) printf("%d\n",val[i]);
	return 0;
}

Measured memory_bytes: 13344
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int n,a[N];
int tot[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]),tot[a[i]]++;
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int d=a[1];
	for (int i=1;i<=n;i++)
		if (a[i]<((d+1)/2))
			return puts("Impossible"),0;
	for (int i=1;i<=d+1;i++)
		if ((--tot[max(i-1,d+1-i)])<0)
			return puts("Impossible"),0;
	if (tot[(d+1)/2]>0)
		return puts("Impossible"),0;
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
# N, K = gets.chomp.split.map(&:to_i)
S = gets.chomp

#Ex. YYMM
# YY is 00-99, MM is 01-12
# So, we check "pre" and "sub"

# 01-12, month or year
# 00, 13-99, year

# pattern
# OK: year-(month or year)
# OK: (month or year)-year
# AMBIGUOUS: (month or year)-(month or year)
# NA: year-year

pre = S[0..1]
sub = S[2..-1]

def month_or_year?(s)
  i = s.to_i
  return (1 <= i && i <= 12)
end

p = month_or_year?(pre)
s = month_or_year?(sub)

if p && s 
  print "AMBIGUOUS\n"
elsif p && !s
  print "MMYY\n"
elsif !p && s
  print "YYMM\n"
else # !p && !s
  print "NA\n"
end

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll a[n];
    ll b[n];
    ll ans = 0;
    REP(i,n+1)cin >> a[i];
    REP(i,n)cin >> b[i];
    ll nokori;
    REP(i,n){
        ans += min(a[i],b[i]);
        nokori=max(b[i]-a[i],(ll)0);
        ans += min(nokori,a[i+1]);
        a[i+1]=max(a[i+1]-nokori,(ll)0);
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define MAX 100

int min(int ,int);
int main(){
  int n,i,l,k,j,kazu,tpp[MAX+1],mov[MAX+1][MAX+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&tpp[i-1],&tpp[i]);
  }
  for(i=1;i<=n;i++){
    mov[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      mov[i][j]=100000;
      for(k=i;k<=j-1;k++){
	mov[i][j]=min(mov[i][j],mov[i][k]+mov[k+1][j]+tpp[i-1]*tpp[k]*tpp[j]);
      }
    }
  }
  printf("%d\n",mov[1][n]);
  return 0;
}


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



Measured memory_bytes: 2108
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
	int N,n,count = 0, a[100001] = { 0 };

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> n;
		if (n > N)
			count++;
		else
			a[n]++;
	}
	for (int i = 1; i <= N; i++)
	{
		if (i == a[i])
			continue;
		else if (a[i] > i)
			count += a[i] - i;
		else if(a[i] < i)
			count += a[i];
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    ll dp[100010][4] = {};

    for(int i = n; i >= 0; i--) {
        for(int j = 3; j >= 0; j--) {
            if(i == n) {
                dp[i][j] = (j == 3 ? 1 : 0);
            }
            else {
                dp[i][j] = dp[i+1][j] * (s[i] == '?' ? 3LL : 1LL);
                if(j < 3 && (s[i] == '?' || s[i] == "ABC"[j])) {
                    dp[i][j] += dp[i+1][j+1];
                }
                dp[i][j] %= mod;
            }
        }
    }
    
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N,K;
    cin>>N>>K;
    string S;cin>>S;
    if(S.at(K-1)=='A'){
        S.at(K-1)='a';
    }else if(S.at(K-1)=='B'){
        S.at(K-1)='b';
    }else{
        S.at(K-1)='c';
    }
    cout<<S<<endl;
    
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
/*int main()
{
	int n; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
//	for(int i=0;i<n;i++) cout<<a[i];
	int sum=0;
	for(int i=n-1;i>1;i--)
	{
		for(int j=i-1;j>0;j--)
		{
			if(a[i]==a[j]) continue;
			for(int k=j-1;k>=0;k--)
			{
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] < (a[k] + a[j])) 
				{
					sum++;
				}
				
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] >= (a[k] + a[j])) 
				{
					break;
				}
				
			}
		}
	}
	
	cout<<sum;
}

int main()
{
	int n,d,ans=0;
	cin>>n>>d;
	while(n--)
	{
		int a,b; cin>>a>>b;
		long long int fl=a*a + b*b;
		float sum=sqrt(fl);
		if(sum<=d) ans++;
		
	}
	cout<<ans;
}
int main()
{
	int n,k; cin>>n>>k;
	int a[n],sum=0;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++) sum+=a[i];
	cout<<sum; 
}

int main()
{
	int n,k; cin>>n>>k;
	k%2==0 and k>=2*n and k<=4*n ? cout<<"Yes" : cout<<"No";
}

int main()
{
	int n; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	unsigned long long ans=1,ANS;
	vector<int>v;
	for(int i=0;i<n;i++)
	{
		ans*=a[i];
		ANS=ans;
		while(ANS)
		{
			v.push_back(ANS%10);
			ANS/=10;
		}
		if(v.size()>1000000000000000000)
		{
			cout<<"HRE";
			cout<<"-1";
			return 0;
		}
		v.clear();
	}
	cout<<ans;
}

int main()
{
	int n; cin>>n;
	string s; cin>>s;
	if(s.size()<=n) cout<<s;
	else {
		
	for(int i=0;i<n;i++) cout<<s[i];
	cout<<"...";
}}*/

int main()
{
	long long int a,b,c,d; cin>>a>>b>>c>>d;
	long long int sum=0,count=0;
	if(a<=d)
	{
		sum+=a;
		d-=a;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(b<=d)
	{
		
		d-=b;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(c<=d)
	{
		sum-=c;
		d-=c;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<sum-d;
		return 0;
	}
	
	
}



Measured memory_bytes: 3184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();

		String a[] = new String[1000];
		for (int i = 0; i < 1000; i++) {
			a[i] = String.format("%03d", i).toString();
		}

		String tmp;
		int count = 0;
		for (int i = 0; i < 1000; i++) {
			tmp = s;
			int first = tmp.indexOf(a[i].charAt(0));
			if (first == -1) continue;
			tmp = tmp.substring(first + 1);
			int second = tmp.indexOf(a[i].charAt(1));
			if (second == -1) continue;
			tmp = tmp.substring(second + 1);
			int third = tmp.indexOf(a[i].charAt(2));
			if (first != -1 && second != -1 && third != -1) {
				count++;
			}
		}

		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 62588
from math import gcd
def lcm(a,b):return (a*b)//(gcd(a,b))

def f(x):
    cnt=0
    while(x%2==0):
        cnt+=1
        x=x//2
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x: x//2,a))

t=f(a[0])
for i in range(n):
    if(f(a[i])!=t):
        print(0)
        exit()
    a[i]=a[i]//(2**t)
m=m//(2**t)
l=1
for i in range(n):
    l=lcm(l,a[i])
    if(l>m):
        print(0)
        exit()
m=m//l
print((m+1)//2)

Measured memory_bytes: 20640
#include <stdio.h>

int calc(int a){
    int temp;
    temp=a+a*a+a*a*a;
    return temp;
}
int main(void){
    int a;
    scanf("%d",&a);
    int number=0;
    number=calc(a);
    printf("%d\n",number);
    return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30; 
int main() {
  int n,c;
  ll k;
  cin >> n >> c >> k;
  vector<ll> t(n);
  rep(i,n) cin >> t[i];
  sort(t.begin(), t.end());
  int passenger = 1; ll dep = t[0]+k;
  int ans = 0;
  int i = 0;
  while (i < n)
  {
    //cout << dep << endl;
    while (true)
    {
      if (passenger > c || dep < t[i]) {
        ans++;
        passenger = 1;
        dep = t[i] + k; break;
      }
      passenger++; i++;
    }
    
  }
  
  cout << ans << endl;
  
  
  
  return 0;
}

Measured memory_bytes: 4032
import math
from collections import deque
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    if all([a_i>0 for a_i in a]):
        print(n-1)
        for i in range(n-1):
            print(i+1,i+2)
        
    elif all([a_i<=0 for a_i in a]):
        print(n-1)
        for i in range(2,n+1)[::-1]:
            print(i,i-1)
    else:
        if abs(min(a))<max(a):
            print(2*n-1)
            pos = a.index(max(a))  
            for i in range(n):
                print(pos+1,i+1)
            for i in range(n-1):
                print(i+1,i+2)


        else:
            print(2*n-1)
            pos = a.index(min(a))
            for i in range(n):
                print(pos+1,i+1)  
            
            for i in range(2,n+1)[::-1]:
                print(i,i-1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 3e3 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 998244353;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
long double dp[N][N];
long double a[N];
int n, s;

void solve(){
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        dp[i][0] = dp[i - 1][0] * (1.0L - a[i]);
        for(int j = 1; j <= i; ++j)
            dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1.0L - a[i]);
    }
    long double sum = 0;
    for(int i = (n + 1) / 2; i <= n; ++i) {
        sum += dp[n][i];
    }
    cout <<fixed << setprecision(10) <<sum;
}
 
int main(){
    speed();
    int t = 1;

    // cin >> t;
    while(t--)solve();
} 

Measured memory_bytes: 154240
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

vector<vector<P>> G(1e5);
vector<int> color(1e5, 0);

int dfs(ll i, int c){
    //cout << "dfs form" << i << endl;
    if (color[i] == 0){
        color[i] = c;
        for( auto tmp : G[i]){
            if (color[tmp.first] == 0){
                if (tmp.second % 2 == 0) dfs(tmp.first, c);
                else dfs(tmp.first, -c);
            }
        }
        return 1;
    }
    return 0;
}

int main() {
    ll N, M;
    cin >> N >> M;
    REP(i, M){
        int j, k, l;
        cin >> j >> k >> l;
        j--;
        k--;
        G[j].push_back(P(k, l));
        G[k].push_back(P(j, l));
    }
    int count = 0;
    REP(i, N){
        if(color[i] == 0){
            dfs(i, 1);
            count++;
        }
    }
    cout << count << endl;

    return 0;
}


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

int main(){
    int N;
    vector<int> v;
    double answer = 0;

    cin >> N;
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

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

    answer += (double)(v[0] + v[1]) / 2;
    for(int i = 2; i < N; i++){
        answer = (double)(answer + v[i]) / 2;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int h,w,x,n,m;
vi a,b;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>h>>w>>x>>n>>m;
	vvd dp(w,vd(m+1));
	dp[x-1][0]=1;
	a=b=vi(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	int I=n-1;
	for(int i=h;i>0;i--){
		if(I>=0&&a[I]==i){
			for(int j=0;j<=m;j++) swap(dp[b[I]-1][j],dp[b[I]][j]);
			I--;
		}
		else{
			vvd DP(w,vd(m+1));
			for(int j=0;j<w;j++) for(int k=0;k<=m;k++){
				int t=i-I-1;
				DP[j][k]+=dp[j][k]*(t-m+k)/t;
				DP[j][k+1]+=dp[j][k]*(m-k)/t*(j==0||j==w-1?w-2:w-3)/(w-1);
				if(j<w-1) DP[j+1][k+1]+=dp[j][k]*(m-k)/t/(w-1);
				if(j>0) DP[j-1][k+1]+=dp[j][k]*(m-k)/t/(w-1);
			}
			dp=DP;
		}
	}
	double res=0;
	for(int i=0;i<w;i++) res=max(res,dp[i][m]);
	cout<<syosu(9)<<res<<endl;
}


Measured memory_bytes: 3444
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String O = scan.next();
        char[] o_data = O.toCharArray();
        String E = scan.next();
        char[] e_data = E.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < Math.max(O.length(), E.length()); i++) {
            if (i < O.length()) {
                sb.append(o_data[i]);
            }
            if (i < E.length()) {
                sb.append(e_data[i]);
            }
        }
        System.out.println(sb.toString());
    }
}


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

int main(){
    int N,Ma,Mb;
    cin>>N>>Ma>>Mb;
    int dp[N+1][N*10+1][N*10+1];
    fill(dp[0][0],dp[N+1][0],1000000000);
    dp[0][0][0]=0;
    for(int i=0;i<N;i++){
        int a,b,c;
        cin>>a>>b>>c;
        for(int aa=0;aa<=i*10;aa++){
            for(int bb=0;bb<=i*10;bb++){
                dp[i+1][aa][bb]=dp[i][aa][bb];
            }
        }
        for(int aa=0;aa<=i*10;aa++){
            for(int bb=0;bb<=i*10;bb++){
                dp[i+1][aa+a][bb+b]=min(dp[i+1][aa+a][bb+b],dp[i][aa][bb]+c);
            }
        }
    }
    int ans=1000000000;
    for(int k=1;k*Ma<=N*10&&k*Mb<=N*10;k++){
        ans=min(ans,dp[N][k*Ma][k*Mb]);
    }
    if(ans==1000000000)ans=-1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 25984
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

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

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n, count = 0;
	int p[40] = {};
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>p[i];
	}
	
	for(int i = 1; i < n-1; i++){
		if(p[i-1] < p[i] && p[i] < p[i+1]) count++;
		else if(p[i+1] < p[i] && p[i] < p[i-1]) count++;
	}
	
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  var a = line.split(' ');
  var c = parseInt(a[0],10);
  var d = parseInt(a[1],10);
  if(c==d && c==0)
    process.exit();
  if(c>d)
    console.log(d+" "+c);
  else
    console.log(c+" "+d);
});
process.stdin.on('end', function () {
});

Measured memory_bytes: 19020
/*
 * a.cc:
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main(){
  int x,y;
  cin>>x>>y;
  while (!(x==0 && y==0)){

    if (x<y) cout<<x<<" "<<y<<endl;
    else  cout<<y<<" "<<x<<endl;
    cin>>x>>y;

  }
  return 0;
}



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

int main(){
  int n;
  int sm;
  int mx;
  
  sm = 0;
  mx = 0;
  
  cin >> n;
  
  for(int i=0; i<n; i++){
    int l;
    cin >> l;
    sm += l;
    mx = max(mx, l);
  }
  
  if( mx < sm - mx ) cout << "Yes\n";
  else cout << "No\n";
  
  cout << flush;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int count = 0;
    for (int i = 0; i <= A; i++){
        for (int j = 0; j <= B; j++){
            for (int k = 0; k <= C; k++){
                if (500 * i + 100 * j + 50 * k == X){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin>>s;
    if (s[0]=='9' || s[1]=='9') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var str = Console.ReadLine();
                if (string.IsNullOrEmpty(str)) return;
                Console.WriteLine(pattern(int.Parse(str)));
            }
        }

        static int pattern(int n)
        {
            int ret = 0;
            for (int a = 0; a <= 9; a++)
            {
                for (int b = 0; b <= 9; b++)
                {
                    for (int c = 0; c <= 9; c++)
                    {
                        for (int d = 0; d <= 9; d++)
                        {
                            if (a + b + c + d == n)
                                ret++;
                        }
                    }
                }
            }
            return ret;
        }
    }
}

Measured memory_bytes: 5600
import itertools

def input_ints():
    return list(map(int, input().split()))

def output_list(v):
    print(' '.join(str(x) for x in v))

def calc(a, b, x):
    return b // x - a // x;

def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)

def main():
    a, b, c, d = input_ints()
    a -= 1
    print(b - a - calc(a, b, c) - calc(a, b, d) + calc(a, b, c * d // gcd(c, d)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;
import java.io.BufferedInputStream;
import java.lang.Math;
import java.util.*;

public class Main{
    public static void main(String [] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int H = sc.nextInt();
        int W = sc.nextInt();
        int N = sc.nextInt();
        int [] A = new int [N];
        int [] Row = new int [W];
        for(int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int p = 0;

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                Row[j] = p + 1;
                A[p]--;
                if(A[p] == 0) {
                    p++;
                }
            }
            for(int j = 0; j < W; j++) {
                if(i % 2 == 0) System.out.print(Row[j]);
                else System.out.print(Row[W-j-1]);

                if(j < W - 1) System.out.print(" ");
                else System.out.println();
            }
        }
    }
}


Measured memory_bytes: 31528