akhauriyash/Code-Regression huggingface dataset:
#pragma warning (disable:4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;
void solve() {
	map<int, int>L, R;
	int N, X, D; cin >> N >> X >> D;
	int absD = abs(D);
	ll ans = 0;
	if (D == 0) {
		map<int, int>mp2;
		REP(k, N + 1) {
			int now = k * X;
			if (!mp2.count(now)) {
				ans++;
				mp2[now] = 1;
			}
		}
		print(ans);
		return;
	}
	REP(k, N + 1) {
		int r = ((X*k)%D);
		//r = (r + D) % D;
		int rem = X * k - r;
		r = (r + absD) % absD;
		
		int le = k * (k - 1) / 2;
		int ri = N * (N - 1) / 2 - (N - k)*(N - k - 1) / 2;
		if (r < 0) {
			print(0); exit(0);
		}
		le += rem / D; ri += rem / D;
		if (le>ri)swap(le, ri);
		if (!R.count(r) || !L.count(r) || le>R[r] || ri<L[r]) {
			ans += ri - le + 1;
		}
		else {
			if (ri>R[r]) {
				if (le < L[r]) {
					ans+= ri - le + 1 - (R[r] - L[r] + 1);
				}
				else ans += ri - le + 1 - (R[r] - le + 1);
			}
			else if (le<L[r]) {
				if (ri > R[r]) {
					ans += ri - le + 1 - (R[r] - L[r] + 1);
				}
				ans += ri - le + 1 - (ri - L[r] + 1);
			}
		}
		if (!R.count(r) || !L.count(r)) {
			R[r] = ri; L[r] = le;
		}
		else {
			R[r] = max(R[r], ri);
			L[r] = min(L[r], le);
		}
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 25216
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

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

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	int N, A[50], count1 = 1, tmp = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {

		cin >> A[i];
		if (A[i] % 2 == 0)count1 *= 2;

	}
	for (int i = 0; i < N; i++) {

		tmp *= 3;

	}
	cout << tmp - count1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

typedef long long ll;

using namespace std;

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

    if ((int) s.find('B') == -1 || (int) s.find('W') == -1) {
        cout << 0 << endl;
        return 0;
    }

    ll cnt = 0, now = 0;
    bool flag = false;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'B') {
            flag = true;
            continue;
        } else if (flag) {
            cnt += i - now;
            ++now;
        } else {
            ++now;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

using ll = long long;

ll dp[310][310][310] = {};
ll mi[310][310][310] = {};
ll inf = 1e18;

int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> H(N+1,0),L(N+1,0);
    for(int i=1;i<=N;i++){
        cin >> H[i];
        L[i] = H[i];
    }
    sort(L.begin(),L.end());
    L.erase(unique(L.begin(),L.end()),L.end());
    int M = L.size()-1;
    for(int i=0;i<=N;i++) for(int j=0;j<=M;j++) for(int k=0;k<=K;k++){
        dp[i][j][k] = inf;
        mi[i][j][k] = inf;
    }
    dp[0][0][0] = 0;
    mi[0][0][0] = 0;
    for(int i=1;i<=N;i++){
        for(int j=0;j<=M;j++) for(int k=0;k<=K;k++){
            if(H[i]==L[j]){
                for(int pj=0;pj<=M;pj++){
                    ll cost = (pj>=j? 0:L[j]-L[pj]);
                    dp[i][j][k] = min(dp[i][j][k],dp[i-1][pj][k]+cost);
                }
            }else if(k!=K){
                dp[i][j][k+1] = min(dp[i][j][k+1],mi[i-1][j][k]);
                if(j!=0) dp[i][j][k+1] = min(dp[i][j][k+1],dp[i][j-1][k+1]+L[j]-L[j-1]);
            }
        }
        for(int j=M-1;j>=0;j--) for(int k=0;k<=K;k++){
            mi[i][j][k] = min(mi[i][j+1][k],dp[i][j][k]);
        }
    }
    ll ans = inf;
    for(int j=0;j<=M;j++) for(int k=0;k<=K;k++) ans = min(ans,dp[N][j][k]);
    cout << ans << endl;
}

Measured memory_bytes: 454912
n = int(input())

ans = []
while n > 26:
    if n % 26 == 0:
        ans.append(26)
        n = n // 26 - 1
    else:
        ans.append(n % 26)
        n = n // 26
ans.append(n)
ans.reverse()
for i in ans:
    print(chr(i+96), end="")
print("")


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string s0, s1;
    cin >> s0 >> s1;
    string s = "YES";
    REP(i, 3)
    {
        if (s0[i] != s1[2 - i])
            s = "NO";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << "DBG: " << #x << " " << (x) << "\n"

#define inn(x)            int x; in(x);
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)
#define rrep(i, n)        for (int i = (n) - 1; i > -1; --i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair<ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n); inn(m);
    int s[n]; rep(i, n) in(s[i]);
    int t[m]; rep(i, m) in(t[i]);

    int dp[n][m];
    dp[0][0] = 1 + (s[0] == t[0]);
    repr(i, 1, n) dp[i][0] = dp[i - 1][0] + (s[i] == t[0]);
    repr(j, 1, m) dp[0][j] = dp[0][j - 1] + (s[0] == t[j]);

    repr(i, 1, n) repr(j, 1, m) {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%MD;
        if (s[i] != t[j]) (dp[i][j] -= dp[i - 1][j - 1]) %= MD;
        if (dp[i][j] < 0) dp[i][j] += MD;
    }

    out(dp[n - 1][m - 1]);
}

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

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 15872
import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)] #すべてのAi=1 to Mについて報酬0の仕事を追加する
arr.extend(arr2)
arr=sorted(arr,key=lambda x:x[0]) #Aiの小さい順にソート
q=[]
ans=0
pos=0
while 1:
 a,b=arr[pos]
 if a>m: #AiがMより大きければその仕事を請ける意味はない
   break
 if a==arr[pos+1][0]: #Aiの値が等しいとき、その仕事を優先度付きキューに追加する
   heapq.heappush(q,-b)
 else:
   heapq.heappush(q,-b)
   ans-=heapq.heappop(q) #Aiの値が変化したとき、そのAiまででの仕事の報酬の最大値を答えに加える
 pos+=1
print(ans)

Measured memory_bytes: 43664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int A = 5e5 + 2;
const int mod = 1e9 + 7;
int a[A];
struct seg_tree {
    bool in[26] = {};
}tree[4 * A];
seg_tree merge(seg_tree x, seg_tree y) {
    seg_tree ret;
    for (int i = 0; i < 26; i++)
        ret.in[i] = x.in[i] | y.in[i];
    return ret;
}
void build(int node, int l, int r) {
	if (l == r) {
		tree[node].in[a[l]] = 1;
	}
	else {
		ll mid = (l + r) >> 1;
		build(node << 1, l, mid);
		build(node << 1 | 1 , mid + 1, r);
		tree[node] = merge(tree[node << 1], tree[node << 1 | 1]);
	}
}
void update(int node, int l, int r, int ind, int val) {
	if (ind < l || r < ind)
		return;
	if (l == r) {
		tree[node].in[a[l]] = 0;
		a[l] = val;
		tree[node].in[a[l]] = 1;
	}
	else {
		ll mid = (l + r) >> 1;
		update(node << 1, l, mid, ind, val);
		update(node << 1 | 1, mid + 1, r, ind, val);
		tree[node] = merge(tree[node << 1], tree[node << 1 | 1]);
	}
}
seg_tree search(int node, int l, int r, int low, int high) {
	if (high < l || r < low)
		return seg_tree();
	if (low <= l && r <= high)
		return tree[node];
	ll mid = (l + r) >> 1;
	return merge(search(node << 1, l, mid, low, high), search(node << 1 | 1, mid + 1, r, low, high));
}
int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, q;
    string s;
    cin >> n >> s >> q;
    for (int i = 1; i <= n; i++) {
        a[i] = (s[i - 1] - 'a');
    }
    build(1, 1, n);
    while(q--) {
        int op;
        cin >> op;
        if (op == 1) {
            int ind;
            char ch;
            cin >> ind >> ch;
            update(1, 1, n, ind, ch - 'a');
        }
        else {
            int l, r;
            cin >> l >> r;
            seg_tree tmp = search(1, 1, n, l, r);
            int cnt = 0;
            for (int i = 0; i < 26; i++)
                cnt += tmp.in[i];
            cout << cnt << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 32484
#include<cstdio>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

int main(){
	int n,m;
	int dist[100][100];
	int ans = 0;
	int a[1000],b[1000],c[1000];
	scanf("%d %d",&n,&m);
	fill(dist[0],dist[0]+10000,INF);
	for(int i=0;i<m;i++){
		scanf("%d %d %d",a+i,b+i,c+i);
		a[i]--;
		b[i]--;
		dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
	}
	for(int i=0;i<n;i++) dist[i][i] = 0;
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(dist[i][k]!=INF&&dist[k][j]!=INF) dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	for(int i=0;i<m;i++){
		bool flag = true;
		for(int s=0;s<n;s++){
			if(dist[s][a[i]]+c[i]==dist[s][b[i]]) flag = false;
		}
		if(flag) ans++;
	}
	printf("%d\n",ans);
}


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

namespace cs
{
    public class Program
    {
        public static void Main(string[] args)
        {


            
            var input = long.Parse(Console.ReadLine());

            Console.WriteLine(Math.Pow(input, 2 ) * 3);

            // 忘れずに消すやつ
            Console.ReadKey();
           
        }


        public static long modder(){
            return (long)Math.Pow(10,9) + 7;
        }

        public static long GCD(long n, long m){
            
            if(m % n == 0) return n;
            else return GCD(m%n, n);

        }

        public static long LCD(long n, long m){

            return m * n / GCD(n,m);
        }
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private enum COLOR{WHITE,GRAY,BLACK}
	private static final int INFINITY = 1<<30;
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[][] m = new int[n][n];
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			for (int j = 0; j < n; j++) {
				m[i][j] = Integer.parseInt(st.nextToken());
			}
		}
		reader.close();
		
		System.out.println(prim(n, m));
	}

	private int prim(int n, int[][] m) {
		
		COLOR[] colors = new COLOR[n];
		int[] d = new int[n];
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			colors[i] = COLOR.WHITE;
			d[i] = INFINITY;
			p[i] = -1;
		}
		
		d[0] = 0;
		while (true) {
			int minv = INFINITY;
			int u = -1;
			for (int i = 0; i < n; i++) {
				if (colors[i] == COLOR.BLACK) continue;
				if (minv > d[i]) {
					minv = d[i];
					u = i;
				}
			}
			if (u == -1) break;
			colors[u] = COLOR.BLACK;
			for (int v = 0; v < n; v++) {
				if (colors[v] == COLOR.BLACK) continue;
				if (m[u][v] == -1) continue;
				if (d[v] > m[u][v]) {
					d[v] = m[u][v];
					p[v] = u;
				}
			}
		}
		
		int cost = 0;
		for (int i = 0; i < n; i++) {
			if (p[i] != -1) cost += m[i][p[i]];
		}
		return cost;
	}
}



Measured memory_bytes: 27308
import java.io.BufferedReader;
import java.io.InputStreamReader;
//}ü\[g
//while¶Ì18Ítry-catchðüêÈ©Á½çA^CG[ªo½Ó¡s
//public class Problem0019_Factorial {
public class Main {
	public static void main(String[] args) {
		try {
		//	Problem0019_Factorial test = new Problem0019_Factorial();
			Main test = new Main();
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			
			String line;
			while((line = reader.readLine()) != null) {
				try {
					int n = Integer.parseInt(line);
					test.showAnswer(n);
				} catch(Exception e) {
					break;
				}
			}
		
		/*	for(int i = 1; i < 21; i++) {
				System.out.print(i + ":\t");
				test.showAnswer(i);
			}
		*/
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	void showAnswer(int max) {
		long answer = 1;
		for(int i = max; i > 0; i--) {
			answer = answer * i;
		}
		
		System.out.println(answer);
	}

}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair <int, int> pLL;
typedef double DB;
const LL MOD = 1e9+7;
const LL NMAX = 1e6+7;
const string NAME = "test";

int n, m;
pLL a[NMAX], b[NMAX];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        int v; cin >> v;
        m = max(m, v);
        if(i % 2) a[v].fi++;
        else b[v].fi++;
    }
    for(int i = 1; i <= m; ++i) a[i].se = b[i].se = i;
    sort(a + 1, a + m + 1);
    sort(b + 1, b + m + 1);
    if(a[m].se == b[m].se)
        cout << n - max(a[m-1].fi + b[m].fi, a[m].fi + b[m-1].fi);
    else
        cout << n - a[m].fi - b[m].fi;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=505;
int n,m;
vector <int> v;
int a[N][N];
int main(){
	n=read();
	if (n==1)
		return puts("1\n1"),0;
	For(i,1,n)
		v.pb(i);
	int t=n;
	while (v.size()%4!=0)
		v.pb(t--);
	sort(v.begin(),v.end());
	n=v.size();
	m=n/2;
	For(i,0,m-1)
		For(j,0,m-1)
			a[j][(i+j)%m]=j&1?v[i<<1]:v[i<<1|1];
	printf("%d\n",m);
	For(i,0,m-1){
		For(j,0,m-1)
			printf("%d ",a[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2176
MOD = 10**9 + 7
H, W = map(int, input().split())
maze = []
for _ in range(H):
  maze.append(input())

dp = [[0]*W for _ in range(H)]
dp[0][0] = 1

for i in range(H):
  for j in range(W):
    if i-1 >= 0 and maze[i][j] == ".":
      dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD
    if j-1 >= 0 and maze[i][j] == ".":
      dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD
print(dp[H-1][W-1])

Measured memory_bytes: 49424
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int s,w;
	cin>>s>>w;
	if(s>w){
		cout<<"safe"<<"\n";
	}
	else{
		cout<<"unsafe"<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3612
/********************/
                    /*user -> tushar284*/
                    /******************/
#include<bits/stdc++.h>
                                                    /*********/            
using namespace std;                             /*   __   __   */
#define  f              first                    /*   @ ) ( @   */
#define  s              second                   /*     / \     */            
#define  mp             make_pair                /*  __  -  __  */
#define  loop(i,s,e)    for(int i=s;i<e;i++)     /*    ..^..    */
#define  rev(i,s,e)     for(int i=s;i>=e;i--)     /*     |     */
#define  mod            1000000007                  /*   |   */
#define  pb             push_back                      /***/
#define  start	        int main()                     
#define  fast           ios_base::sync_with_stdio(false);cin.tie(0);
#define  test           int t; cin>>t;while(t--)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;


start
{   
   string se;
   cin>>se;
   if(se=="ABC")cout<<"ARC";
   else cout<<"ABC";
    
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	ll n, x, a[100];
	cin >> n >> x;
	ll sum = 0;
	REP(i, n){
		cin >> a[i];
		sum += a[i];
	}
	ll ans;
	if(x > sum) ans = n-1;
	else if(x == sum) ans = n;
	else{
		ll diff = sum - x;
		sort(a, a+n, greater<int>());
		ans = n;
		REP(i, n){
			if(diff > a[i]){
				diff -= a[i];
				ans--;
			}
			else if(diff == a[i]){
				diff -= a[i];
				ans--;
				break;
			}
			else{
				ans--;
				break;
			}
		}
	}

	cout << ans << endl;
	rtn 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define me(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=500005;
int main()
{
	int n;
	cin>>n;
	cout<<n/2+n%2;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
from collections import defaultdict
import math

def solve(n):
    q = deque()
    q.append(n)#n追加
    #dict[m] = mからNにするまで必要な費用
    dist = defaultdict(lambda: float('inf'))#無限個を無限で埋める
    dist[n] = 0#nにする費用は0
    while len(q):
        m = q.popleft()

        if m == 0:#0ならやめる
            continue
        if m == 1:#1のとき多分おかしくなるのでやっとく
            if dist[0] > dist[1] + d:
                dist[0] = dist[1] + d
                continue
        
        #5,3,2で割る
        for x,cost in ([5,c],[3,b],[2,a]):

            y = m%x #余り
            e = 1 if y else 0 #余りあるとき1
            #割り切れる数まで減らすor割り切れるなら普通に割る
            hiyou = min((n-(m//x))*d,dist[m]+cost+(e*d*y),dist[m]+ (m-(m//x))*d)#今の値から遷移するか+1し続けたときの安い方
            if dist[m//x] > hiyou:
                q.append(m//x)
                dist[m//x] = hiyou

            #割り切れる数まで増やす
            hiyou = min((n-(m//x)+1)*d,dist[m]+cost+((x-y)*d),dist[m]+ (m-(m//x-1))*d)
            if e and dist[m//x+1]> hiyou:
                q.append(m//x+1)
                dist[m//x+1] = hiyou
    

    return dist[0]


t = int(input())
for i in range(t):
    n,a,b,c,d, = list(map(int,input().split()))
    print(solve(n))


Measured memory_bytes: 11300
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	if(a%111==0)
	cout<<a;
	else if(a<=100&&a<111)
	cout<<"111";
	else if(a>111&&a<222)
	cout<<"222";
	else if(a>222&a<333)
	cout<<"333";
	else if(a>333&&a<444)
	cout<<"444";
	else if(a>444&&a<555)
	cout<<"555";
	else if(a>555&&a<666)
	cout<<"666";
	else if(a>666&&a<777)
	cout<<"777";
	else if(a>777&&a<888)
	cout<<888;
	else
	cout<<"999";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
	int N;
	cin >> N;
	if (N < 30) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	}




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

typedef long long ll;

typedef pair<int, int> p;

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

    string S;
    cin >> S;

    int ans;

    for(int i = S.length() - 2; i >= 0; i -= 2) {
        bool checker = false;
        for(int j = 0; j < i / 2; j++) {
            if(S[j] != S[i / 2 + j]) {
                checker = true;
                break;
            }
        }
        if(checker) continue;
        ans = i;
        break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
'use strict';
function main(input) {
  const args = input.split(' '),
        N = parseInt(args[0]),
        K = parseInt(args[1]);
  let P = 0;
  for (let i = 1; i <= N; ++i) {
    let cnt = 0;
    while (i * Math.pow(2, cnt) < K) {
      ++cnt;
    }
    P += 1/N * Math.pow(2, -cnt);
  }
  console.log(P);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <stdio.h>
 
int main( void )
{
    double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
    double x = 0;
    double y = 0;
 
    while( scanf( "%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f ) != EOF )
    {
 
        y = ( c * d - a * f ) / ( b * d - e * a ); 
                                                    
        x = ( c - ( b * y ) ) / a;
 
        printf( "%.3lf %.3lf\n", x, y );
    }
 
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    if((b * (n - 1) + a) - (a * (n - 1) + b) + 1 < 0) cout << 0 << '\n';
    else cout << (b * (n - 1) + a) - (a * (n - 1) + b) + 1<< '\n';
    return 0;
}


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

int main()
{
    long N, K;
    cin >> N >> K;

    // long N_log2 = (long)log2(N);
    // long K_long2 = (long)log2(K);
    double prob = 0;
    for (long val = 1; val < N+1; val++)
    {
        // cout << val << "   ";
        double prob_temp = 1/(double)N;
        //prob_temp = 1/N;

        long val_temp = val;
        while (val_temp < K)
        {
            val_temp  *= 2;
            prob_temp /= 2.0;
        }
        prob += prob_temp;
        // cout << prob << endl;
    }
    
    cout << std::setprecision(12) << prob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define Rep(i, n, a) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, n, 0)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;

signed main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    ll ans = 0, cnt = 0;
    rep(i, s.size())
    {
        if (s[i] == 'W')
        {
            ans += i - cnt;
            cnt++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int main(){
    int n;
    cin >>n;
    cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int a, b;
	cin >> a >> b;
	cout << (a <= 8 && b <= 8 ? "Yay!" : ":(") << endl;
	return 0;
}
 

Measured memory_bytes: 256
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_b

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())

    for i in range(1, n+1):
        price = int(i * 1.08)
        if price == n:
            print(i)
            return

    print(':(')

if __name__ == '__main__':
    main()


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


int main() {
    long long N, R = 0, G = 0, B = 0;
    long long count = 0;
    string S;
    cin >> N >> S;
    REP(i,N){
        if(S[i] == 'R'){
            R++;
        } else if(S[i] == 'G'){
            G++;
        } else {
            B++;
        }
    }

    int M = round(N / 2.0 - 1);

    REP(i, M) { //iは等差の間隔
        REP(j, N - 2){ //jは一番小さいやつ（左のやつ）
            if(j + 2 * i + 2 > N-1){
                break;
            }

            if(S[j] != S[j + i + 1] && S[j + i + 1] != S[j + 2 * i + 2] && S[j + 2 * i + 2] != S[j]) {
                count++;
            }
        }
    }

    cout << R * G * B - count << endl;
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,l,result=0,tmp=0;
  int a[LIMIT2]={0};
  char s[LIMIT1][100];
  int visited[100][100]={0};
  std::queue<ll> que;
  
  scanf("%lld %lld",&n,&m);
  rep(i,n) scanf("%s",s[i]);
  
  rep(i,n){
    rep(j,m){
      rep(l,n) rep(k,m) visited[l][k]=0;
      tmp=0;
      if(s[i][j]=='#'||visited[i][j]==1) continue;
      que.push(i*1000+j);
      while(!que.empty()){
        k = que.front();
        tmp = k/1000000;
        k %= 1000000;
        que.pop();
        if(visited[k/1000][k%1000]==1) continue;
        visited[k/1000][k%1000]=1;
        tmp++;
        for(l=0;l<4;l++){
          if(k/1000+dy[l]<0||k%1000+dx[l]<0) continue;
          if(k/1000+dy[l]>=n||k%1000+dx[l]>=m) continue;
          if(s[k/1000+dy[l]][k%1000+dx[l]]!='#') que.push(tmp*1000000+(k/1000+dy[l])*1000+k%1000+dx[l]);
        }
        result=max(result,tmp-1);
      }
    }
  }
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s, t;
    cin >> s >> t;
    vector<string> ans;
    int l = s.size() - t.size() + 1;
    rep(i, l){
        string sub = s.substr(i, (int)t.size());
        bool invalid = false;
        rep(j, (int)t.size()){
            if(t[j] != sub[j] && sub[j] != '?') invalid = true;
        }
        if(invalid) continue;
        rep(j, (int)t.size()) {
            if(sub[j] == '?') sub[j] = t[j];
        }
        string res = "";
        rep(j, (int)s.size()){
            if(j < i && s[j] == '?') res += 'a';
            else if(j < i) res += s[j];
            else if(j < i + t.size()) res += sub[j - i];
            else if(s[j] == '?') res += 'a';
            else res += s[j];
        }
        ans.push_back(res);
    }
    sort(ans.begin(), ans.end());
    if(ans.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << ans[0] << endl;
    
}

Measured memory_bytes: 256
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

N = int(input())
total = 0

for n in range(1, N + 1, 2):
    if len(divisor(n)) == 8:
        total += 1

print(total)

Measured memory_bytes: 9184
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;

string tobin(ll a){
    string ret = "";
    while(a>0){
        if(a%2 == 0) ret += "0";
        else ret += "1";
        a /= 2;
    }
    reverse(all(ret));
    return ret;
}

ll add(ll n,ll a){
    //cout<<"in :"<<tobin(n)<<" "<<tobin(a)<<endl;
    ll i = 1;
    while(i<=a){
        if(a&i){
            if(!(n&i)){
                n += i;
            }
            else{
                if(n&(i<<1)){
                    n -= i;
                    n -= (i<<1);
                }
                else{
                    n -= i;
                    n = add(n,i<<1);
                    n = add(n,i<<2);
                }
            }
        }
        i <<= 1;
    }
    //cout<<"out :"<<n<<endl;
    return n;
}

int main(void) {
    ll d,g;
    cin>>d>>g;
    vl p(d),c(d);
    ll mondaisu = 0;
    rep(i,d){
        cin>>p[i]>>c[i];
        mondaisu += p[i];
    }
    rep1(i,mondaisu+1){
        rep(j,pow(2,d)){
            ll sum = 0;
            ll maxi = 0;
            ll tensu = 0;
            rep(k,d){
                if(j&(1<<k)){
                    sum += p[k];
                    tensu += 100*(k+1)*p[k]+c[k];
                }
                else maxi = k+1;
            }
            ll nokori = i-sum;
            if(nokori < 0) continue;
            for(ll k = d-1;k>=0 && nokori > 0;k--){
                //cout<<j<<" "<<k<<" "<<(1<<k)<<" "<<(j&(1<<k))<<endl;
                if((j&(1<<k)) == 0){
                    //cout<<k<<endl;
                    if(nokori < p[k]){
                        tensu += 100*(k+1)*nokori;
                        nokori = 0;
                    }
                    else{
                        nokori -= p[k]-1;
                        tensu += (100)*(k+1)*(p[k]-1);
                    }
                }
            }
            if(tensu >= g){
                cout<<i<<endl;
                return 0;
            }
        }
    }
	return 0;
}


Measured memory_bytes: 4084
s = list(str(input()))
for p in range(int(len(s))):
    del s[-1]
    t = int(len(s))
    if t % 2 == 0:
        for i in range(t//2):
            if s[i] != s[i+t//2]:
                break
        else:
            print(t)
            break


Measured memory_bytes: 2940
#include "bits/stdc++.h"
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <random>
#include <stdio.h>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef string ST;


#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl


#
void func() {
  LL N;
  cin >> N;
  vector<LL> A(N);
  vector<LL> B(N);
  vector<LL> C(N);
  REP(i, N) {
    cin >> A[i];
    cin >> B[i];
    cin >> C[i];
  }

  for (LL i = 1; i < N; ++i) {
    A[i] += max(B[i - 1], C[i - 1]);
    B[i] += max(A[i - 1], C[i - 1]);
    C[i] += max(A[i - 1], B[i - 1]);
  }
  cout << max(max(A[N - 1], B[N - 1]), C[N - 1]);
}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 2560
s=list(input())
k=int(input())

while k>0:
    for i in range(len(s)):
        ss=ord(s[i])
        check=122-ss+1
        if check <= k and s[i]!='a':
            k-=check
            s[i]='a'
        else:
            continue
    if s.count('a')==len(s) and k>0:
        k=k%26
        s[-1]=chr(ord(s[-1])+k)
        ans=''.join(s)
        break
    else:
        s[-1]=chr(ord(s[-1])+k)
        ans=''.join(s)
        break
print(ans)
            

Measured memory_bytes: 4152
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
     int min;
     int max;
     long sum = 0;
     Scanner scanner = new Scanner(System.in);
     int n = scanner.nextInt();
     int a = scanner.nextInt();
     min = a;
     max = a;
     sum = sum + a;
     for(int i=0;i<n-1;i++){
       int b = scanner.nextInt();
       sum = sum + b;
       if(min > b){
         min = b;
       }
       if(max < b){
         max = b;
       }
     }

     System.out.println(min + " " + max + " " + sum);

  }
}


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

using namespace std;
int main(){
  int N;
  cin >> N;

  vector<int> X(N);
  for(int i = 0; i < N; i++){
    cin >> X[i];
  }
  long long int ans = 0;
  long long int min = 1000000000;
  for(int i = 1; i <= 100; i++){
    ans = 0;
    for(int j = 0; j < N; j++){
      ans += (X[j] - i) * (X[j] - i);

    }
    if(ans < min) min = ans;
  }

  cout << min << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  int ans = 0;
  for(int i = 0; i < N; i++) {
    vector<int> A(M);
    int sum = 0;
    for(int j = 0; j < M; j++) {
      cin >> A.at(j);
      sum += A.at(j) * B.at(j);
    }
    sum += C;
    if(sum > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans = 1;
    ll ansbefore = 1;
    for(ll j=0;j<n;j++){
        if(a[j]==0){
                    ans = 0;
                    break;
        }
    }
    if(ans!=0){
        for(ll i=0;i<n;i++){
            ans *= a[i];
            if(ans>1000000000000000000||ans/a[i]!=ansbefore || ans<=0){
                ans = -1;
                break;
            }
            ansbefore = ans;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
int modpow(int a,int b){
    if(!b)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int fac(int a){
    int Ans=1;
    for(int i=1;i<=a;i++){
        Ans*=i;
        Ans%=MOD;
    }
    return Ans;
}//kaijo
int comb(int a,int b){
    return fac(a)*modpow(fac(a-b),MOD-2)%MOD*modpow(fac(b),MOD-2)%MOD;
}
int n;
vector<int> v;
int two[334];
int A;
int ans=0;
int main(){
    cin>>n;
    rep(i,n){
        cin>>A;
        v.push_back(A);
    }
    sort(v.begin(),v.end());
    two[0]=1;
    for(int i=1;i<=30;i++)two[i]=two[i-1]*2;
    for(int i=n-1;i>=1;i--){
        for(int j=0;j<=30;j++){
            if(two[j]>v[i]){
                if(binary_search(v.begin(),v.begin()+i,two[j]-v[i])){
                    ans++;
                    auto Itr=upper_bound(v.begin(),v.begin()+i,two[j]-v[i])-1;
                    v.erase(v.begin()+(Itr-v.begin()));
                    i--;
                }
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 1400
import sys
input=sys.stdin.readline
h,w,n=map(int,input().split())
l=[tuple(map(int,input().split())) for i in range(n)]
l.sort()
res=0
ans=h
for x,y in l:
    if x>y+res:
        ans=min(ans,x-1)
    if x==y+res:
        res+=1
print(ans)

Measured memory_bytes: 30892
import math
def main():
    a,b,h,m = map(int, input().split())
 
    ar = h * 360 / 12 + m * 30 / 60
    br = m * 360 / 60
    kakudo = x if (x := abs(ar-br)) < 180 else 360-x
    ans = a**2+b**2-2*a*b*math.cos(kakudo*math.pi/180)
    print(ans**0.5)
    
    # print(math.sqrt(ans))
if __name__ == "__main__":
    main()

Measured memory_bytes: 9516
#include "bits/stdc++.h"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define mod (int)1e9 + 7
#define For(i,a,n) for(i=a;i<n;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int a,i,n;
    string st;
    cin>>a>>st;
    n = st.size();
    For(i,0,n){
    	if(i<a) cout<<st[i];
    	else{
    		cout<<"...";
    		break;
    	}
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main()
{
    int antena[5],i,j;
    int k;
    for(i=0; i<5; i++){ cin >> antena[i]; }
    cin >> k;
    for(i=0; i<4;i++) {
        for(j=i+1; j<5; j++){
            if(antena[j]-antena[i]>k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

//solve

int solve( int i , int m, int n, int A[]){

    if( m == 0 ) return 1;
    if( i >= n ) return 0;

    int res = solve( i + 1 , m , n, A ) || solve( i + 1, m - A[i] , n , A );

    return res;

}


int main(){

    int n, q, i, j;

    scanf("%d", &n);

    int A[n];

    for( i = 0; i < n; i++){

        scanf("%d", &A[i]);

    }

    scanf("%d", &q );

    int m;

    for( i = 0; i < q ; i++ ){

        scanf("%d", &m );

        if( solve( 0 , m , n , A ) ) printf("yes\n");
        else printf("no\n");

    }

    return 0;

}

Measured memory_bytes: 2692
import sys
sys.setrecursionlimit(10000)
def search(x,y,m):
    if not(0<=x<len(m[0]) and 0<=y<len(m)) or m[y][x]=='0': return
    m[y][x] = '0'
    for dx,dy in [[-1,-1],[0,-1],[1,-1],[-1,0],[1,0],[-1,1],[0,1],[1,1]]:
        search(x+dx,y+dy,m)
while True:
    w,h = map(int,input().split())
    if w==h==0: break
    m = [input().split() for _ in range(h)]
    c = 0
    for y in range(h):
        for x in range(w):
            if m[y][x]=='1':
                c += 1
                search(x,y,m)
    print(c)

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

vector<ll> lay;
vector<ll> p;

//level n ,layer x

ll fun(ll n, ll x)
{
	if (x == 0)
		return 0;
	if (n == 0)
		return 1;
	if (x <= lay[n - 1] + 1)
		return fun(n - 1, x - 1);
	if (x == lay[n - 1] + 2)
		return fun(n - 1, x - 1) + 1;
	if (x < lay[n])
		return p[n - 1] + 1 + fun(n - 1, x - 1 - (lay[n - 1] + 1));
	return p[n];
}

int main()
{
	ll n, k;
	cin >> n >> k;
	lay.push_back(1);
	p.push_back(1);
	for (int i = 1; i <= n; i++)
	{
		ll l = lay[i - 1] * 2 + 3;
		ll pp = p[i - 1] * 2 + 1;
		lay.push_back(l);
		p.push_back(pp);
	}
	cout << fun(n, k) << endl;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int a[N] , n , m;
ll w[N + N] , t[N + N];

int main(){
    scanf("%d%d",&n,&m);
    rep(i,0,n) scanf("%d",a + i) , --a[i];
    ll full = 0;
    rep(i,1,n) {
        int l = a[i-1] , r = a[i];
        if(r < l) r += m;
        full += r - l;
        t[l + 1]++;
        t[r + 1]--;
        w[l + 1]+=l+1;
        w[r + 1]-=l+1;
    }
    ll Mx=0;
    rep(i,1,m+m) {
        t[i] += t[i-1];
        w[i] += w[i-1];
    }
    rep(i,0,m) Mx=max(Mx,t[i]*i+t[i+m]*(i+m)-w[i]-w[i+m]);
    printf("%lld\n",full-Mx);
    return 0;
}


Measured memory_bytes: 3712
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int a, b;
    cin >> a >> b;
    if (a + b < 10) {
        cout << a + b << endl;
    } else {
        cout << "error" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = map(int, input().split())
h = list(map(int, input().split()))

dp = [0 for _ in range(len(h))]
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, len(h)):
    dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))

print(dp[-1])


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n1, n2, n3, n4;

  cin >> n1 >> n2 >> n3 >> n4;

  map<int, int> m;

  m[n1]++;
  m[n2]++;
  m[n3]++;
  m[n4]++;

  if (m[1] > 0 and m[9] > 0 and m[7] > 0 and m[4] > 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
ans = 0
for i in range(N):
  B[i] = A[i]-(i+1)

B.sort()
b = B[N//2]

for j in range(N):
  ans += abs(B[j]-b)

print(ans)

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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(9)<<fixed;
	
	int x,y;
	cin>>x>>y;
	
	if(y%2==0)
	{
		int a2=y/2-x;
		int a1=x-a2;
		if(a1>=0 && a2>=0)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3652