akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int count = 1;
	int value;
	for( int i=0; i<N; i++ )
	{
		int a;
		cin>>a;
		if( i == 0 )
		{
			value = a;
		}
		else
		{
			if( a<=value )
			{
				value = a;
				count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
vector<int> price;
int main(){
cin.tie(0);
 int k,n,result=0;
  cin >> n >> k;
  for(int i=1;i<=n;i++){
   int t;
    cin >>t;
    price.push_back(t);
  }
sort(price.begin(),price.end());

for(int i=0;i<k;i++){
 result+=price[i]; 
}
  
cout << result;
return 0;
}






ll gcd(ll a, ll b){

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }

}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    while (1) {
        int n, m;
        cin >> n >> m;
        if (n==0 && m==0) break;
        vector<vi> tr(3);
        rep(i, 3) {
            int n2;
            cin >> n2;
            rep(i2, n2) {
                int t;
                cin >> t;
                --t;
                tr[i].pb(t);
            }
        }
        auto ip3 = [] (int e) {
            int res = 1;
            rep(i, e) res *= 3;
            return res;
        };
        int ans1 = 0, ans2 = 0;
        rep(i, n) ans2 += 2 * ip3(i);
        int ans = INF;
        vector<bool> d(ip3(n));
        queue<pair<vector<vi>, int>> q;
        auto ps = [&] (vector<vi> tr, int cnt) {
            int res = 0;
            rep(i, 3) {
                for (int j : tr[i]) res += i * ip3(j);
            }
            if (cnt>m || d[res] || ans!=INF) return;
            if (res==ans1 || res==ans2) ans = cnt;
            d[res] = true;
            q.push({tr, cnt});
        };
        const int from[] = {0, 1, 1, 2}, to[] = {1, 0, 2, 1};
        ps(tr, 0);
        while (!q.empty()) {
            auto p = q.front(); q.pop();
            rep(i, 4) {
                if (p.first[from[i]].empty()) continue;
                int f = p.first[from[i]].back();
                int t = -1;
                if (!p.first[to[i]].empty()) t = p.first[to[i]].back();
                if (t > f) continue;
                p.first[from[i]].pop_back();
                p.first[to[i]].pb(f);
                ps(p.first, p.second+1);
                p.first[to[i]].pop_back();
                p.first[from[i]].pb(f);
            }
        }
        cout << (ans!=INF?ans:-1) << endl;
    }
    return 0;
}



Measured memory_bytes: 4708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
	int n,t;
	cin >> n >> t;
	int ans = 10000000;
	for(int i=0;i<n;i++){
		int c,temp;
		cin >> c >> temp;
		if(temp<=t&&ans>=c)
			ans = c;
	}
	if(ans != 10000000)
		cout<<ans<<endl;
	else
		cout<<"TLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int n,m,minn,ans;
int a[10000000],b[10000000],c[10000000],d[10000000];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>c[i]>>d[i];
	}
	for(int i=1;i<=n;i++)
	{
		minn=1e9;
		for(int j=1;j<=m;j++)
		{
			if(abs(c[j]-a[i])+abs(d[j]-b[i])<minn)
			{
				minn=abs(c[j]-a[i])+abs(d[j]-b[i]);
				ans=j;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 6400
n=int(input())
a=[int(i) for i in input().split()]
ans=0
kai=0
ok=True
for i in range(n-1):
    if a[i]!=i+1:
        kai+=1
        if a[a[i]-1]!=i+1 or kai==3:
            ok=False
if ok:
    print("YES")
else:
    print("NO")

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++) 
#define reps(i, A, n) for(int (i)=(A); (i)<(n); (i)++)
#define pb emplace_back
using LL = long long;

const LL MOD = 1e9+7;
 
int N;
int K;
vector<int> S[114514];

int main() {
  scanf("%d", &N);
  reps(k, 1, N+11) {
    if (k*(k-1) > 2*N) {
      puts("No");
      return 0;
    }
    
    if (k*(k-1) == 2*N) {
      K = k;
      break;
    }
  }
  
  int cnt = 0;
  rep(i, K) {
    reps(j, i+1, K) {
      ++cnt;
      S[i].pb(cnt);
      S[j].pb(cnt);
    }
  }
  assert(cnt == N);
  
  printf("Yes\n%d\n", K);
  rep(i, K) {
    printf("%d", (int)S[i].size());
    for (int v : S[i]) {
      printf(" %d", v);
    }
    puts("");
  }
}
      
    
    


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  int n,m,s[10],c[10];
  cin >> n >> m;
  for(int i = 0; i < m; i++)
    cin >> s[i] >> c[i];
  
  int st = pow(10, n-1);
  if(st == 1) st = 0;
  int end = pow(10, n);
  
  
  for(int i = st; i < end; i++) {
    bool flag = 1;
    string str = to_string(i);
    for(int j = 0; j < m; j++) {
      if(str[s[j]-1] != c[j]+'0') 
        flag = 0; 
    }
    if(flag) {
      cout << str << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

int n, k;
vector<int> p, c;
v2<int> cycles;
vector<bool> v;

const ll INF = 1e18;

void dfs(int node){
    v[node] = true;
    cycles.back().push_back(node);
    if(!v[p[node]]) dfs(p[node]);
}

void solve(){
    cin >> n >> k;
    p = vector<int>(n), c = vector<int>(n);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
        --p[i];
    }
    for(int i = 0; i < n; ++i) cin >> c[i];

    v = vector<bool>(n, false);
    for(int i = 0; i < n; ++i){
        if(!v[i]){
            cycles.push_back({});
            dfs(i);
        }
    }

    ll ans = -INF;
    for(auto& a : cycles){
        // for(int i : a) cout << i << " ";
        // cout << '\n';
        int l = a.size();
        a.insert(a.end(), a.begin(), a.end());
        vector<ll> pref(2*l, 0), best(2*l, -INF);
        pref[0] = c[a[0]];
        for(int i = 1; i < 2*l; ++i) pref[i] = pref[i-1] + c[a[i]];
        for(int i = 0; i < 2*l; ++i){
            for(int j = i; j < 2*l; ++j){
                ll seg = pref[j] - (i-1 >= 0 ? pref[i-1] : 0);
                best[j-i] = max(best[j-i], seg);
            }
        }
        // for(ll i : best) cout << i << ' ';
        // cout << '\n';

        if(k-1 < 2*l){
            for(int i = 0; i <= k-1; ++i) ans = max(ans, best[i]);
        }
        else{
            for(int i = 0; i < 2*l; ++i) ans = max(ans, best[i]);
            for(int i = 0; i <= (k-1)%l; ++i){
                ll score = pref[l-1]*((k-1)/l) + best[i];
                ans = max(ans, score);
            }
        }
    }

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

vector<int> C(26, 0); // C[i]
vector<vector<int> > S(365, vector<int>(26, 0)); // S[d][i]
int D;
int N;

int score(vector<int> V) {
	vector<int> c = C;
	int s = 0;
	for (int d = 0; d < D; d++) {
		c[V[d]] = 0;
		s += S[d][V[d]];
		s -= accumulate(c.begin(), c.end(), 0);
		for (int i = 0; i < N; i++) {
			c[i] += C[i];
		}
		cout << s << endl;
	}
	return s;
}

int main() {
	cin >> D;
	N = 26;
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	for (int d = 0; d < D; d++) {
		for (int i = 0; i < N; i++) {
			cin >> S[d][i];
		}
	}
	vector<int> V(D, 0);
	for (int d = 0; d < D; d++) {
		cin >> V[d];
		V[d]--;
/*
		int i = 0;
		for (int j = 1; j < N; j++) {
			if (S[d][i] < S[d][j]) i = j;
		}
		V[d] = i;
		*/
	}
/*
	random_device seed_gen;
	mt19937 engine(seed_gen());
	uniform_real_distribution<> dist1(0.0, 1.0);

	vector<int> newV = V;
//	cout << "cur " << score(V);
//	for (int d = 0; d < D; d++) { cout << " " << V[d]+1; }
//	cout << endl;
	int ms = score(V);
	for (int j = 0; j < 10000; j++) {
		newV = V;
		for (int k = 0; k < 1; k++) {
			newV[int(dist1(engine) * D)] = int(dist1(engine) * N);
		}
		int ns = score(newV);
//		cout << "new " << ns;
//		for (int d = 0; d < D; d++) { cout << " " << newV[d]+1; }
//		cout << endl;
		if (ms < ns) V = newV;
	}

	for (int d = 0; d < D; d++) {
		cout << V[d] + 1 << endl;
	}
	*/
	score(V);
	return(0);
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> S(N);
  int total = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &S[i]);
    total += S[i];
  }
  int ans = 0;
  if (total % 10 != 0) { ans = total; }
  else {
    sort(S.begin(), S.end());
    for (int i = 0; i < N; ++i) {
      if (S[i] % 10 != 0) {
        ans = total - S[i];
        break;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int a,b,c,d,e,k,i;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
scanf("%d",&e);
scanf("%d",&k);
if(e-a>k){
printf(":(");
}
else{
printf("Yay!");
}
return 0;
}

Measured memory_bytes: 128
s = input()

k = 0
for i,a in enumerate(s):
    j = i+1
    if j%2 == 0 and a == "R":
        k += 1
        break
    elif j%2 == 1 and a == "L":
        k += 1
        break

if k > 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 2940
N = int(input())
A = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for value in A:
    C[value - 1] += 1
ways_all = 0
for i in range(N):
    ways_all += (C[i] * (C[i] - 1)) // 2
for value in A:
    print(ways_all - C[value - 1] + 1)

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

int main(void){
  int a,b,c,i,j;
  j = 0;
  cin >> a >> b >> c;
  for(i=a;i<=b;i++){
    if(c % i == 0){
      j++;
    }
  }
  cout << j<< endl;
}

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

const int MOD = 1000000007;
const int MAXN = 3005;

void add(int &a, int b) { a += b; if(MOD <= a) a -= MOD; }
void div(int &a) { a = ((a&1) ? a+MOD : a) >> 1; }

int D[MAXN][MAXN], E[MAXN][MAXN];

int A[MAXN];

int N, Q, Ans;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> Q;
	for(int i = 1; i <= N; i++) cin >> A[i];

	for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++)
		D[i][j] = A[i] > A[j];
	for(int qi = Q, a, b; qi--;) {
		cin >> a >> b;
		for(int i = 1, t; i <= N; i++) {
			t = D[a][i];
			add(t, D[b][i]);
			div(t);
			E[a][i] = E[b][i] = t;

			t = D[i][a];
			add(t, D[i][b]);
			div(t);
			E[i][a] = E[i][b] = t;
		}
		{
			int t = D[a][b];
			add(t, D[b][a]);
			div(t);
			E[a][b] = E[b][a] = t;
		}
		for(int i = 1; i <= N; i++) {
			D[i][a] = E[i][a];
			D[i][b] = E[i][b];
			D[a][i] = E[a][i];
			D[b][i] = E[b][i];
			D[i][i] = 0;
		}
	}

	for(int i = 1; i < N; i++) for(int j = i+1; j <= N; j++)
		add(Ans, D[i][j]);
	for(; Q--;) {
		Ans <<= 1;
		if(MOD <= Ans) Ans -= MOD;
	}
	cout << Ans << endl;
	return 0;
}

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


// Driver program to test methods of graph class 
int main() 
{
    int n,m;
    cin >> n >> m;
    priority_queue<int> a;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        a.push(tmp);
    }
    
    for(int i=0; i < m;i++){
        a.push(a.top() / 2);
        a.pop();
    }

    
    long long answer = 0;
    
    for(int i = 0; i < n; i++){
        answer += a.top();
        a.pop();
    }
    
    cout << answer << endl;
}


Measured memory_bytes: 892
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CRemainderGame {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    vector<int> a, b;
    int d[51][51];

    bool ok(int s) {
        FOR(i, 0, 50) {
            FOR(j, 0, 50) {
                if (i == j) {
                    d[i][j] = 1;
                } else {
                    d[i][j] = INF;
                }
            }
        }

        FOR(i, 1, 50) {
            if (s >> i & 1) {
                FOR(j, 0, 50) {
                    d[j][j % i] = 1;
                }
            }
        }

        FOR(k, 0, 50) FOR(i, 0, 50) FOR(j, 0, 50) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

        bool ok = true;
        REP(i, a.size()) {
            if (d[a[i]][b[i]] >= INF) {
                ok = false;
                break;
            }
        }

        return ok;
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        a.resize(N), b.resize(N);
        REP(i, N) cin >> a[i];
        REP(i, N) cin >> b[i];

        int s = 0;
        FOR(i, 1, 50) s |= 1LL << i;

        if (!ok(s)) {
            cout << -1 << endl;
            return;
        }

        REV(i, 50, 1) {
            s ^= 1LL << i;
            if (!ok(s)) {
                s |= 1LL << i;
            }
        }

        int res = 0;
        FOR(i, 1, 50) {
            if (s >> i & 1) {
                res += 1LL << i;
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CRemainderGame solver;
    solver.solve(in, out);
    return 0;
}


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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

bool ok(int A, int B, string s)
{
    string a = "", b = "";
    for(int i = 0; i < A; i++)
        a += s[i];

    for(int i = A+1; i < s.size(); i++)
        b += s[i];

    if(s[A] != '-') return 0;

    for(char c: a) {
        int x = c - '0';
        if(x < 0 or x > 9) return 0;
    }

    for(char c: b) {
        int x = c - '0';
        if(x < 0 or x > 9) return 0;
    }

    return 1;
}

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

    int a, b;
    string s;
    cin>>a>>b>>s;

    cout<<(ok(a,b,s) ? "Yes" : "No")<<"\n";

    return 0;
}


Measured memory_bytes: 256
a=0
b=0
c=0

for i in range(10):
    x = int(input())
    if x > c:
        a = b
        b = c
        c = x

    elif x > b:
        a = b
        b = x
        
    elif x > a:
        a = x

print(c)
print(b)
print(a)


Measured memory_bytes: 5592
n = input().split()

total = 0

min = 0
x = 0
y = 0
x_total = 0
y_total = 0


while(x < int(n[0])):
    #if(x <= int(n[0])):

    x += int(n[1])
    x_total += int(n[2])
    #print(x_total)
    #if(y <= int(n[0])):
while(y < int(n[0])):
    y += int(n[3])
    y_total += int(n[4])
    #print(y_total)

if(x_total < y_total):
    print(x_total)
else:
    print(y_total)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define N 1000000007;

using namespace std;

int main()
{
 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 int n;
 cin>>n;
 if (n%1000==0)
    cout<<0;
 else
 cout<<1000-n%1000;

 return(0);

}


Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const BIG_COST = 3000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)
	costs := make([][]int, nNodes)

	for r := 0; r < nNodes; r++ {
		costs[r] = make([]int, nNodes)
		for c := 0; c < nNodes; c++ {
			costs[r][c] = scanInt(sc)
		}
	}

	states := make([]int, nNodes)
	minCosts := make([]int, nNodes)

	for i := 1; i < nNodes; i++ {
		minCosts[i] = BIG_COST
	}

	for {
		var u int
		minCost := BIG_COST

		for i := 0; i < nNodes; i++ {
			if states[i] != ST_JOINED && minCosts[i] < minCost {
				minCost = minCosts[i]
				u = i
			}
		}

		// 全てのノードが MST に JOIN できたので終了。
		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for v := 0; v < nNodes; v++ {
			cost := costs[u][v]

			// MST内の u と MST外の v との辺の重みをそれぞれ minCosts[v] として
			// 保存しておく。このうち辺の重みが最小となる v が次のループで MST に JOIN する。
			if states[v] != ST_JOINED && cost != -1 && cost < minCosts[v] {
				minCosts[v] = cost
			}
		}
	}

	sum := 0
	for _, cost := range minCosts {
		sum += cost
	}
	fmt.Println(sum)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}



Measured memory_bytes: 1220
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)3e5 + 5;
const int mod = (int)1e9 + 7;

ll diff(ll a, ll b) {
    return abs(a - b);
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int a, b, c;
    cin >> a >> b >> c;
    ll mini = infl;
    for (int i = a / 2; i <= a / 2 + a % 2; i++)
        mini = min(mini, diff(1ll * i * b * c, 1ll * (a - i) * b * c));
    for (int i = b / 2; i <= b / 2 + b % 2; i++)
        mini = min(mini, diff(1ll * i * a * c, 1ll * (b - i) * a * c));
    for (int i = c / 2; i <= c / 2 + c % 2; i++)
        mini = min(mini, diff(1ll * i * a * b, 1ll * (c - i) * a * b));
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n;
  string s;
  cin >> s;
  bool f=true;
  if (s.size()%2==1) {
     cout << "No" << endl;
     return 0;
  }
  else{
   for (int i=0;i < s.size();i=i+2){
      if (s[i]=='h' && s[i+1] =='i'){
         f=true;
      }
      else {
         f=false;
         break;
      }
   }
  }
  if (f) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0; 
}


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

int main() {
	int n;
	vector<int> r;
	while (true)
	{
		scanf("%d", &n);
		if (n==0)break;
		int max=-2147483648,now=0,in=0;
		for (int i=0; i<n; i++)
		{
			cin >> in;
			now += in;
			if (now > max) max=now;
			if (now < 0) now=0;
		}
		r.push_back(max);
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.append(0)
C.append(0)

D = sum(B)

for i in range(N):
  if A[i+1]-A[i]==1:
    D = D + C[A[i]-1]
  else:
    D = D

print(D)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9 + 7;

int main(){
	int m1, m2, d1, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1 != m2){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
taka = [a,b]
ao = [c,d]
flag = True

while a > 0 or c > 0:
    c -= b
    if c <= 0:
        break
    a -= d
    if a <= 0:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9088
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	bool a[1001];
	int x;

	memset(a, 0, sizeof(a));

	a[1] = 1;

	for (int i = 2; i < 32; i++) {
		int k = i * i;
		while (k <= 1000) {
			a[k] = 1;
			k *= i;
		}
	}

	cin >> x;

	while (!a[x])
		x--;

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  string s,t;
  cin >> s >> t;
  ll ans = 0;
  REP(i,SZ(s)){
    if(s[i]==t[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
Arr.forEach(function(v){
var arr=v.split(",").map(Number);
var b=arr.pop();
var a=arr.pop();
var sum=arr.reduce(function(a,b){return a+b});
var time=sum/(a+b);
var d=a*time;
var D=0;
for(var i=0;i<arr.length;i++){
  D+=arr[i];
  if(D>=d)break;
}
console.log(i+1);
});

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
#define IREP(i,n) for(ll i=1;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG(x) cerr << x << "\n"

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x,a,b;
    cin >> x >> a >> b;
    
    // b-aが賞味期限から経った日数
    if (b-a <= 0) cout << "delicious\n";
    else if(b-a <= x) cout << "safe\n";
    else cout << "dangerous\n";

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    for(;;){
        int cycle;
        cin >> cycle;
        if(cycle == 0)
            return 0;

        vector<int> t(cycle);
        for(int i=0; i<cycle; ++i)
            cin >> t[i];

        int n;
        cin >> n;
        vector<int> interview(101, 24);
        for(int i=0; i<n; ++i){
            int d, m;
            cin >> d >> m;
            interview[d] = min(interview[d], m);
        }

        vector<vector<int> > dp(101, vector<int>(cycle, INF));
        dp[0][cycle-1] = 0;
        for(int d=1; d<=100; ++d){
            for(int prev=0; prev<cycle; ++prev){
                int curr = (prev + 1) % cycle;
                if(t[curr] <= interview[d])
                    dp[d][curr] = min(dp[d][curr], dp[d-1][prev]);
                dp[d][0] = min(dp[d][0], dp[d-1][prev] + 1);
            }
        }

        cout << *min_element(dp[100].begin(), dp[100].end()) << endl;
    }
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
using namespace std;
using LL = long long;
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

int d, t, s;

int main(){
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3608
import itertools

n = int(input())

l = len(str(n))
P = [3,5,7]
count = 0

for l_i in range(3, l+1):
  comb = list(itertools.product(P, repeat = l_i))
  for comb_i in comb:
    check_num = int(''.join(map(str, comb_i)))
    if check_num <= n and len(set(comb_i)) == 3:
      count += 1
      
print(count)

Measured memory_bytes: 6756
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;

int main(){
    int n;cin>>n;
    P a[100010];
    for(int i=0;i<n;i++){
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        cout<<a[i].second<<' ';
    }
    cout<<endl;
    return 0;
}

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

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

    int counter = 0;
    for (int i = A; i <= B; ++i) {
        string s = to_string(i);
        bool kaibun = true;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] != s[s.size() - j - 1]) {
                kaibun = false;
                break;
            }
        }
        if (kaibun) ++counter;
    }

    cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,M;
  cin >>A>>B>>M;
  vector<int> ref(A),mic(B),sum(M+1);
  vector<vector<int>> dis(M, vector<int>(3));
  for (int i=0;i<A;i++){
    cin >> ref.at(i);
  }
  for (int i=0;i<B;i++){
    cin >> mic.at(i);
  }
  for (int i=0;i<M;i++){
    for (int j=0;j<3;j++){
      cin >> dis.at(i).at(j);
    }
  }
  for (int i=0;i<M;i++){
    sum.at(i)=ref.at(dis.at(i).at(0)-1)+mic.at(dis.at(i).at(1)-1)-dis.at(i).at(2);
  }
  std::sort(ref.begin(),ref.end());
  std::sort(mic.begin(),mic.end());
  sum.at(M)=ref.at(0)+mic.at(0);
  std::sort(sum.begin(),sum.end());
  cout <<sum.at(0);
}

Measured memory_bytes: 9804
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
const int mxN = 15;
bool switches[mxN];
// bulb -> switches
vector<int> adj[mxN];
int p[mxN];
int summ[mxN], n, m;

int check(){
	memset(summ,0,sizeof(summ));
	FOR(i,m){
		for(auto neigh : adj[i]){
			summ[i] += switches[neigh];
		}
		//debuga(switches,m);
		//debuga(summ,m);
		if(summ[i]%2 != p[i]) return 0;
	}
	return 1;
}

// enumerate thru all possible combinations 2^n
void solve(){
	cin >> n >> m;
	
	FOR(i,m){
		int cnt; cin >> cnt;
		FOR(_,cnt){
			int y; cin >> y;
			--y;
			adj[i].pb(y);
		}
	}
	// everything is 10-indexed
	FOR(m) cin >> p[i];
	int ans = 0;
	FOR(i,pow(2,n)){
		FOR(j,n){
			// if in bin ith index is 1 then switch i is on
			switches[j] = (i >> j) & 1;
		}
		ans += check();
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


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

using namespace std;

const int INF = 1 << 30;


template< typename T >
struct SegmentTree
{
  vector< T > seg;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, INF);
  }

  T merge(T a, T b)
  {
    return (min(a, b));
  }

  void set(int k, int x)
  {
    seg[k + sz - 1] = x;
  }

  void build()
  {
    for(int k = sz - 2; k >= 0; k--) {
      seg[k] = merge(seg[2 * k + 1], seg[2 * k + 2]);
    }
  }

  T rmq(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (INF);
    if(a <= l && r <= b) return (seg[k]);
    return (merge(rmq(a, b, 2 * k + 1, l, (l + r) >> 1),
                  rmq(a, b, 2 * k + 2, (l + r) >> 1, r)));
  }

  T rmq(int a, int b)
  {
    return (rmq(a, b, 0, 0, sz));
  }

  void update(int k, T x)
  {
    k += sz - 1;
    seg[k] = x;
    while(k > 0) {
      k = (k - 1) >> 1;
      seg[k] = merge(seg[2 * k + 1], seg[2 * k + 2]);
    }
  }
};

int rev[200000];
SegmentTree< int > seg1(200000), seg2(200000);
vector< int > g[200000];
pair< int, int > ans[200000];
int ptr;

void rec(int l, int r, int par = 0)
{
  if(l >= r) return;

  g[par].push_back(++ptr);
  int curr = ptr;

  if(l % 2 == 0) {
    auto p = seg1.rmq(l, r);
    auto q = seg2.rmq(rev[p], r);
    seg1.update(rev[p], INF);
    seg2.update(rev[q], INF);
    ans[curr] = {p, q};
    rec(l, rev[p], par);
    rec(rev[p] + 1, rev[q], curr);
    rec(rev[q] + 1, r, par);
  } else {
    auto p = seg2.rmq(l, r);
    auto q = seg1.rmq(rev[p], r);
    seg2.update(rev[p], INF);
    seg1.update(rev[q], INF);
    ans[curr] = {p, q};
    rec(l, rev[p], par);
    rec(rev[p] + 1, rev[q], curr);
    rec(rev[q] + 1, r, par);
  }
}

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


  for(int i = 0; i < N; i += 2) {
    seg1.set(i, P[i]);
    seg2.set(i + 1, P[i + 1]);
  }
  seg1.build();
  seg2.build();
  for(int i = 0; i < N; i++) rev[P[i]] = i;
  rec(0, N);

  typedef pair< int, int > Pi;
  priority_queue< Pi, vector< Pi >, greater< >> que;
  for(auto &to : g[0]) que.emplace(ans[to].first, to);

  bool first = false;
  while(!que.empty()) {
    auto p = que.top();
    que.pop();
    if(first++) cout << " ";
    cout << ans[p.second].first + 1 << " " << ans[p.second].second + 1;
    for(auto &to : g[p.second]) que.emplace(ans[to].first, to);
  }
  cout << endl;
}

Measured memory_bytes: 26752
# include <bits/stdc++.h>
using namespace std;
# define ll long long
const ll N = 2e5 + 10, MOD = 998244353;
ll ans;
ll fac[N] = {1}, ifac[N] = {1}, ps[N] = {1};
ll C(ll m, ll n){
	return fac[n] * ifac[m] % MOD * ifac[n - m] % MOD; 
}
ll binPow(ll x, ll y){
	ll ans = 1;
	while(y){
		if(y & 1){
			ans = ans * x % MOD;
		}
		x = x * x % MOD;
		y >>= 1;
	}
	return ans;
}
void solve(){
	ll n, m, k, ans = 0;
	cin >> n >> m >> k; 
	for(int i = 0; i <= k; ++i){
		ans = (ans + C(i, n - 1) * m % MOD * binPow(m - 1, n - i - 1) % MOD) % MOD; 
	}
	cout << ans << '\n';
}
int main(){
	for(int i = 1; i < N; ++i){
		fac[i] = fac[i - 1] * i % MOD;
		ifac[i] = binPow(fac[i], MOD - 2);
	}
	int t = 1;
	while(t--){
		solve();
	}
}

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


int main(){
  int N,Y;
  cin >> N >> Y;
  int A = 0,B= 0,C = 0;
  int ans = -1;
  int k;
  for(int i = 0;i <= N;i++){
    for(int j = 0;j <= N-i;j++){
      k = N - i -j;
      if(k >=0){
      if(10000*i + 5000*j + 1000*k == Y){
        A = i;
        B = j;
        C = k;
        ans = 1;
        break;
      }
      }
    }
  }
  if(ans == -1){
	A = -1;
    B = -1; 
    C = -1;
  }
  cout << A << " " << B << " " << C << endl;
}
  
		

Measured memory_bytes: 3604
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;

vector<int> par;

int root(int x){
  if (par[x] == x){// 根
    return x;
  }
  else {
    return par[x] = root(par[x]); // 経路圧縮
  }
}

void unite(int x, int y){
  x = root(x);
  y = root(y);
  if (x == y){}
  else{
    par[x] = y;     //xの親をyの親にする
  }
}

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

signed main(){
	int h,w;
	cin>>h>>w;
	int n=h*w;
	par.assign(n,0);
	for(int i=0;i<n;i++){
		par[i]=i;
	}
	string x;
	vector<int> a(n,0);
	for(int i=0;i<h;i++){
		cin>>x;
		for(int j=0;j<w;j++){
			if(x[j]=='#') a[i*w+j]=1;
		}
	}

	for(int i=0;i<h-1;i++){
		for(int j=0;j<w-1;j++){
			if(a[i*w+j]!=a[(i+1)*w+j]){
				unite(i*w+j,(i+1)*w+j);
			}
			if(a[i*w+j]!=a[i*w+j+1]){
				unite(i*w+j,i*w+j+1);
			}
		}
		int j=w-1;
		if(a[i*w+j]!=a[(i+1)*w+j]){
			unite(i*w+j,(i+1)*w+j);
		}
	}
	for(int j=0;j<w-1;j++){
		int i=h-1;
		if(a[i*w+j]!=a[i*w+j+1]){
			unite(i*w+j,i*w+j+1);
		}
	}
	ll ans=0;
	vector<int>bk(n,0);
	vector<int>wh(n,0);
	for(int i=0;i<n;i++){
		if(a[i]==1)bk[root(i)]++;
		else wh[root(i)]++;
	}
	for(int i=0;i<n;i++){
		ans+=(ll)bk[i]*wh[i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 998244353
#define all(vec) vec.begin(), vec.end()

const int MAX = 310000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(long n, long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<long> pom(210000);

void POMInit(long m){
  pom.at(1) = m;
  for(long i=2;i<=200020;i++){
    pom.at(i) = pom.at(i-1)*(m-1);
    pom.at(i) %= MOD;
  }
}

long POM(long m, long n){
  if(m < n) return 0;
  else return pom.at(n);
}

int main() {
    // 前処理
    COMinit();
    
    //cout << COM(100000, 50000) << endl;
    long n,m,k;
    cin >> n >> m >> k;
    POMInit(m);
    long ans = 0;
    for(long i=k; i>=0; i--){
      long p =  pom.at(n-i);
      long tmp = COM(n-1,i) * p % MOD;
      ans += tmp;
      ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12080
#include <bits/stdc++.h>
using namespace std;
 
int read() {
    int f = 1, x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f; return x;
}
 
/*============ Header Template ============*/

const int N = 200005;
int a[N], f[N][20], idx[N];
int MIN(int x,int y) {
	return a[x] < a[y] ? x : y;
}
int findmin(int x, int y) {
	int z = idx[y - x + 1];
	return MIN(f[x][z], f[y - (1 << z) + 1][z]);
}
struct sav {
	int l, r, x, y;
	sav (const int a = 0, const int b = 0) : l(a), r(b), x(findmin(a, b)), y(findmin(x + 1, b + 1)){}
};
bool operator < (sav x, sav y) {
	return a[x.x] > a[y.x];
}
priority_queue<sav> q;
int main(){
	int n = read();
	a[0] = n + 1; idx[0] = -1;
	for (int i = 1; i <= n; i ++) idx[i] = idx[i >> 1] + 1, f[i][0] = f[i][1] = i;
	for (int i = 1; i <= n; i ++) a[i] = read();
	for (int i = n; i; i --)
		for (int j = 2; i + (1 << j) - 1 <= n + 1; j ++)
			f[i][j] = MIN(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
	q.push(sav(1, n));
	for (; !q.empty();){
		sav now = q.top(); q.pop();
		printf("%d %d ", a[now.x], a[now.y]);
		if (now.l < now.x) q.push(sav(now.l, now.x - 1));
		if (now.x + 1 < now.y) q.push(sav(now.x + 1, now.y - 1));
		if (now.y < now.r) q.push(sav(now.y + 1, now.r));
	}
	return 0;
}

Measured memory_bytes: 19444
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = 1e9;
const ll MOD = 998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,N;cin>>H>>W>>N;
  int sr,sc;cin>>sr>>sc;
  string S,T;
  cin>>S>>T;
  int l=1,r=W,u=1,d=H;
  bool remain=true;
  for(int i=N-1;i>=0;i--){
    switch(T[i]){
      case 'U':
        d = min(d+1,H);
        break;
      case 'D':
        u = max(u-1,1);
        break;
      case 'L':
        r = min(r+1,W);
        break;
      case 'R':
        l = max(l-1,1);
        break;
    }
    switch(S[i]){
      case 'U':
        u++;
        break;
      case 'D':
        d--;
        break;
      case 'L':
        l++;
        break;
      case 'R':
        r--;
        break;
    }
    remain &= l<=r&&u<=d;
    //debug(remain);
  }
  remain &= l<=sc&&sc<=r&&u<=sr&&sr<=d;
  cout<<(remain? "YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 920
import math
N = int(input())
K = int(input())
# keta → 10 なら 2
S = str(N)
keta = len(S)


dp1 = [ [ 0 ]* (keta + 1)  for _ in range(100) ] #超えないことが確定した方
dp2 = [  [ 0 ]* (keta + 1)  for _ in range(100) ] # 超える可能性がある方
# dp[以下確定済みフラグ][0でないの個数 k ][上からn桁目か] の条件を満たしたものの個数

i = int(S[0])
dp2[0][0] = 1 #超える可能性はある

for n in  range(0,keta):
    # for i in range(0,10): #次の桁に来る候補  #ここを省略して 1～9 と 0で場合分け
    for k in range(0, K + 1):
        num = int(S[n])  #実際の数字
        num_to_9  = 9 - num  # 5 だったら 6,7,8,9
        num_hiku1_to_1 = max(0,num - 1) #未満が確定する 0 以外の数
        # 確定から確定
        #確定済みには何をつけても良い

        if num == 0:
            dp1[k + 1][n + 1] += dp1[k][n] * 9 # 1~ 9
            dp1[k][n + 1] += dp1[k][n] # 0を足して確定
            # dp1[k][n + 1] += dp2[k][n]
            dp2[k][n + 1] += dp2[k][n] #0を足して未定パターン

        else:
            dp1[k + 1][n + 1] += dp1[k][n] * 9 # 1~ 9 を 超えないことが確定したやつに足したパターン
            dp1[k + 1][n + 1] += dp2[k][n] * (num - 1)  # 超えないやつを未定に足したパターン
            dp2[k + 1][n + 1] += dp2[k][n] #未定に引き続き未定になるやつを足したパターン

            # 0 を足すパターンがまだ
            dp1[k][n + 1] += dp1[k][n] # 超えないが確定したやつに0を足すパターン
            #  当然dp1に遷移

            dp1[k][n + 1] += dp2[k][n] # 超えるかもなやつに0を足すパターン
            # num > 0なのでdp2 からdp1に遷移
        # 未確定から未確定


print(dp1[K][keta] + dp2[K][keta])




Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main() {
    int n;
    cin >> n;
    pair<int, int> sorta[200001];
    for(int i = 0; i < n; i++){
    	int a;
    	cin >> a;
    	sorta[i] = make_pair(a, i);
    }
    sort(sorta, sorta + n);
    int ans[200001];
    for(int i = 0; i < n; i++){
    	if(i < n / 2) ans[sorta[i].second] = sorta[(n - 1) / 2 + 1].first;
    	else ans[sorta[i].second] = sorta[(n - 1) / 2].first;
    }
    for(int i = 0; i < n; i++){
    	cout << ans[i];
    	if(i == n - 1) cout << endl;
    	else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 4480
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

// 辺を表す構造体
struct edge{
    int from, to;
    long long cost;
};


// v:=頂点数 es:=辺の集合 cost:=始点からの最短経路のコストを格納する配列
// s:=始点(指定しなければ頂点0) g:=終点(指定しなければ頂点v-1)
// 始点から到達可能で、かつ終点へ到達可能な負閉路が検出された場合falseを、それ以外の場合trueを返す
bool bellman_ford(int v, const vector<edge>& es, vector<long long>& cost, int s = 0, int g = -1){
    if(g == -1){
        g = v - 1;
    }

    constexpr long long INF = 1LL << 61;

    cost.assign(v, INF);
    cost[s] = 0;

    for(int i = 0 ; i < v * 2 ; ++i){
        for(auto& e : es){
            if(cost[e.from] < INF && cost[e.from] + e.cost < cost[e.to]){
                if(i >= v - 1 && e.to == g){
                    return false;
                }else if(i >= v - 1){
                    cost[e.to] = -INF;
                }else{
                    cost[e.to] = cost[e.from] + e.cost;
                }
            }
        }
    }

    return true;
}

int main(){
    ll N,M;
    cin>>N>>M;
    vector<edge> G;
    vector<ll> cost(N);
    int a,b;
    ll c;
    REP(i,M){
        cin>>a>>b>>c;
        a--;
        b--;
        c=-c;
        G.push_back({a,b,c});
    }

    if(!bellman_ford(N,G,cost,0,N-1)){
        cout<<"inf"<<endl;
    }else{
        cout<<-cost[N-1]<<endl;
    }
}

Measured memory_bytes: 3708
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a,-1,-1):
  if x - 500*i < 0: continue
  for j in range(b,-1,-1):
    if x - 500*i - 100*j < 0: continue
    for k in range(c,-1,-1):
      if x - 500*i - 100*j - 50*k == 0: ans += 1
print(ans)

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

int main() {

    int N, W;
    cin >> N >> W;

    vector<long long> dp(W+1, 0);
    // dp[i] = max value that can be taken with the total weight of exactly i

    for (int i=0; i<N; i++) {
        
        int w, v;
        cin >> w >> v;

        for (int weight_already = W - w; weight_already >= 0; weight_already--) {
            dp[weight_already + w] = max(dp[weight_already + w], dp[weight_already] + v);
        }
    }
    
    long long ans = 0;
    for (auto& x: dp)
        ans = max(ans, x);

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N,i,count,sum;
    cin>>N;
    long long A[N];
    for(i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A,A+N);
    count=1;sum=0;
    for(i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            count++;
        }else{
            sum+=count%2;
            count=1;
        }
    }
    sum+=count%2;
    cout<<sum<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc090() {
	ll n, m;
	ll ans = 0;

	cin >> n >> m;

	// 隣接数が奇数であれば表、偶数であれば裏
	if (n == 1) {
		if (m == 1) {
			ans = 1;
		}
		else {
			ans = m - 2;
		}
	}
	else if (m == 1) {
		if (n == 1) {
			ans = 1;
		}
		else {
			ans = n - 2;
		}
	}
	else {
		ans = (n - 2) * (m - 2);
	}

	cout << ans << "\n";
}

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

	solve_abc090();

	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    cout<<"Christmas";
    rep(i,25-D)cout<<" Eve";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256