akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	int N;
	cin >> N;

	int ans = N / 2;

	if (N % 2 == 0) {
		ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  string t;
  cin >> s;
  cin >> t;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) != t.at(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr,0,sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        char a, b;
        cin >> a >> b;
        string s1;
        for(int i = 0; i < a - '0'; i++){
            s1 += b;
        }
        string s2;
        for(int i = 0; i < b - '0'; i++){
            s2 += a;
        }
        cout << min(s1, s2) << '\n';
    } 
}

Measured memory_bytes: 31488
#include <stdio.h>
#define N 101
#define INF 1000000

int prim(void);
int n, d[N], pi[N], color[N], G[N][N];

int main(){
  int i, j;

  scanf("%d", &n);

  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      scanf("%d", &G[i][j]);
    }
  }

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

  return 0;
}
 
 int prim(){
   int i, u, v, mincost, sum = 0;

   for(u = 1; u <= n; u++){
     d[u] = INF;
     pi[u] = -1;
     color[u] = 0;
   }

   d[1] = 0;
   
   while(1){
     mincost = INF;
     for(i = 1; i <= n; i++){
       if(color[i] != 1 && d[i] < mincost){
	 mincost = d[i];
	 u = i;
       }
     }

     if(mincost == INF) break;
     
     color[u] = 1;
     for(v = 1; v <= n; v++){
       if(G[u][v] != -1){
	 if(color[v] != 1 && G[u][v] < d[v]){
	   pi[v] = u;
	   d[v] = G[u][v];
	 }
       }
     }
     
   }
   for(i = 1; i <= n; i++) sum += d[i];
   
   return sum;
 }

Measured memory_bytes: 640
import sys
#input = sys.stdin.buffer.readline

def main():
    H,W,K = map(int,input().split())
    s = [list(map(str,input())) for _ in range(H)]
    ans = [[0 for _ in range(W)] for _ in range(H)]
    up,down = 0,1
    count = 1
    for i in range(H):
        if "#" not in s[i]:
            if down != H:
                down += 1
            else:
                for x in range(up,down):
                    for y in range(W):
                        ans[x][y] = ans[up-1][y]
        else:
            now = 0
            for j in range(W):
                if s[i][j] == "#":
                    for x in range(up,down):
                        for y in range(now,j+1):
                            ans[x][y] = count
                    now = j+1
                    count += 1
            if s[i][-1] == ".":
                for x in range(up,down):
                    for y in range(now,W):
                        ans[x][y] = count-1
            up = down
            down += 1
    
    for i in range(H):
        print(*ans[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 8272
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

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

    ll N, _N; cin >> N;
    _N = N;
    ll i, j = 0;

    while(N != 0) {
        i = N % 10;
        N = (N - i) / 10;
        j ++;
    }

    ll k = 1; rep(l, j - 1) k *= 10; k = k * (i + 1) - 1;

    if (k == _N ) cout << i + (j - 1) * 9 << endl;
    else cout << i - 1 + 9 * (j - 1) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fint register int
#define h 5010
#define p h 
#define int long long
using namespace std;
struct node
{
	int to;
	int nxt;
	int val;
	int from;
}
e[p];
int cnt;
int head[p];
int a[p],pt[p];
int st[p];
int f[h][h];
bool vis[p];
int n,k;
int tot;
int maxxs=-1e18;
inline int read();
inline void dfs(int x,int step);
inline void adds(int u,int v,int w);
signed main()
{
	n=read(),k=read();
	for(fint i=1;i<=n;i++)
	a[i]=read();
	for(fint i=1;i<=n;i++)
	pt[i]=read();
//	for(fint i=1;i<=n;i++)
//	adds(i,a[i],pt[a[i]]),f[i][a[i]]=pt[a[i]];//建图
//	for(fint i=1;i<=n;i++)
//	for(fint j=1;j<=n;j++)
//	cout<<f[i][j]<<" ";
	/*for(fint i=1;i<=n;i++)
	tot=0,dfs(i,0);
	cout<<maxxs;暴力做法，思路显然，复杂度O(k*n^2)*/ 
	int stp=0;
	for(fint i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		int hea=a[i];
		while(!vis[hea])
		vis[hea]=1,stp++,f[i][stp]=f[i][stp-1]+pt[hea],hea=a[hea];//记录每一步从i开始每一步推进的路径 
		st[i]=stp,stp=0;
	} 
//	for(fint i=1;i<=n;i++)	
//	for(fint j=1;j<=n;j++)	
//	cout<<f[i][j]<<" ";
	for(fint i=1;i<=n;i++)
	for(fint j=1;j<=st[i];j++)
	{
		if(j>k)
		break;//到哪个点停 
		int ans=f[i][j];
		if(f[i][st[i]]>=0)
		ans+=(k-j)/st[i]*f[i][st[i]];//更新答案，此时剩余可走步数/环步数*到环所需步数 
		maxxs=max(maxxs,ans);
	}
	cout<<maxxs;
	return 0;
}

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
		f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}

inline void adds(int u,int v,int w)
{
	e[++cnt].to=v;
	e[cnt].from=u;
	e[cnt].nxt=head[u];
	e[cnt].val=w;
	head[u]=cnt;
	return ;
}
/*
inline void dfs(int x,int step)
{
	if(step==k)
	return ;
	for(fint i=head[x];i;i=e[i].nxt)
	{
		tot+=e[i].val;
		maxxs=max(tot,maxxs);
		dfs(e[i].to,step+1);
	}
	return ;
}暴力搜索求出最大权值 */

Measured memory_bytes: 199484
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");
    // String nyu=sc.nextLine();

//int[] num=new int[6];

int H=Integer.parseInt(nyu[0]);
int W=Integer.parseInt(nyu[1]);

      nyu=sc.nextLine().split(" ");

int h=Integer.parseInt(nyu[0]);
int w=Integer.parseInt(nyu[1]);


//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);

System.out.println((H-h)*(W-w));

	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[3],dp[1<<17][3];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[j];
			for(int k=0;k<3;k++)if(j!=k)dp[i+1][j]=max(dp[i+1][j],dp[i][k]+a[j]);
		}
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
}


Measured memory_bytes: 1408
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	string s;
	cin>>s;
	int w;
	cin>>w;
	for(int i=0; i<s.size(); i += w){
		cout<<s[i];
	}
	cout<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(){
  int a,b;
  cin >> a >> b;
  if(a<=2*b){
    cout << 0 << endl;
  }
  else{
    cout << a-2*b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)
n = int(input())

if n < 357:
    print(0)
    exit()

def dfs(start):
    if int(start) > n:
        return 0
    if not ("3" in start and "5" in start and "7" in start):
        count=0
    else:
        count=1
    count += dfs(start + "3")
    count += dfs(start + "5")
    count += dfs(start + "7")
    return count
print(dfs("3")+dfs("5")+dfs("7"))

Measured memory_bytes: 3064
let rec for_fold a b f v = if a >= b then v else for_fold (a+1) b f (f v a)
let _ = Scanf.scanf "%d %d" @@ fun n x ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  for_fold 0 (n+1) (fun s i ->
    let s' = Array.fold_left (+) 0 a in
    let a0 = min a.(0) a.(n-1) in
    for i = n-1 downto 1 do
      a.(i mod n) <- min a.(i mod n) a.((i-1) mod n)
    done; a.(0) <- a0;
    min s (s' + i*x)) 10101010101010
  |> Printf.printf "%d\n"

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  
  for(int i=n-2; i>=0; i--){
    if(a[i]>a[i+1]) a[i]--;
  }
  rep(i,n-1){
    if(a[i]>a[i+1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int x,n;char o;long long a,b=-1e18,c=-1e18;
int main()
{
	scanf("%d%lld",&n,&a);
	for(int i=1;i<n;i++){scanf(" %c%d",&o,&x);if(o=='-') a=b=max(a-x,(c=b+x));else a+=x,b=max(b-x,c+=x);}
	printf("%lld\n",a);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        string s;
        cin >> s;
        int n = s.size();
        ll white = 0ll;
        ll ans = 0ll;
        for (int i = n - 1; i >= 0; --i) {
            if (s[i] == 'W') {
                white++;
            } else {
                ans += white;
            }
        }

        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1336
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;

int main() {
	ll x;
	cin >> x;
	int ans = ceil((-1 + sqrt(1 + 8 * x)) / 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
vector<int> g[440000];
const int INF = 1e18;
signed main(){
	int n,m;cin >> n >> m;
	auto toid = [&](int x,int t){
		return x + t*n;
	};
	rep(_,m){
		int a,b;cin >> a >> b;
		a--;b--;
		rep(i,3)g[toid(a,i%3)].push_back(toid(b,(i+1)%3));
	}
	vector<int> dist(n*3+10,INF),vis(n*3+10);
	int start,goal;cin >>  start >> goal;
	start--;goal--;
	dist[toid(start,0)] = 0;
	queue<int> q;
	q.push(toid(start,0));
	while(q.size()){
		auto now = q.front();q.pop();
		for(auto next:g[now]){
			if(vis[next])continue;
			vis[next] = 1;
			dist[next] = dist[now]+1;
			q.push(next);
		}
	}
	int ret = dist[toid(goal,0)];
	if(ret == INF)cout << -1 << endl;
	else cout << ret/3 << endl;


	return 0;
}

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

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int w, h;
int field[50][50];
const int dx[8] = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[8] = {1, -1, 0, 0, -1, 1, -1, 1};

void dfs(const int x, const int y, const int label) {
	field[y][x] = label;
	for(int i = 0; i < 8; ++i) {
		const int nx = x + dx[i], ny = y + dy[i];
		if(nx < 0 || ny < 0 || nx >= w || ny >= h)
			continue;

		if(field[ny][nx] == 1)
			dfs(nx, ny, label);
	}
}

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

	while(cin >> w >> h, w) {
		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				cin >> field[i][j];

		int label = 2;
		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				if(field[i][j] == 1)
					dfs(j, i, label++);

		cout << label - 2 << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1308
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int A[114514];
    vector<int> R;
    map<int,int> M;
    cin >> N;
    REP(i,N){
        cin >> A[i];
        M[A[i]]++;
    }
    sort(A,A+N);
    R.push_back(A[0]);
    REP(i,N-1){
        if(A[i]!=A[i+1]){
            R.push_back(A[i+1]);
        }
    }
    sort(R.begin(),R.end());
    int K=R.size();
    if(K>3){
        cout << "No" << endl;
    }else if(K==3){
        if(N%3==0 && ((R[0]^R[1])==R[2])&& M[R[0]]==M[R[1]] && M[R[0]]==M[R[2]]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(K==2){
        if(R[0]==0 && 2*M[R[0]]==M[R[1]]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(K==1){
        if(R[0]==0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 6776
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

double dp[3030][3030];

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

  int n; cin >> n;
  double p[n];
  rep(i, n) cin >> p[i];

  dp[0][0] = 1.0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (j == 0) {
        dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
      } else {
        dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1 - p[i - 1]);
      }
    }
  }

  double ans = 0;

  for (int i = 0; i <= n; ++i) {
    if (i > n - i) {
      ans += dp[n][i];
    }
  }

  cout << setprecision(15) << ans << '\n';

  return 0;
}

Measured memory_bytes: 72064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n;
	vector<vector<Pi>> g(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		g[a].push_back(Pi(b,i));
		g[b].push_back(Pi(a,i));
	}
	ll ret;
	auto dfs=[&](auto &dfs,int v,int pre,int go)->bool{
		if(v==go) return true;
		for(auto to:g[v]){
			if(to.fi==pre) continue;
			if(dfs(dfs,to.fi,v,go)){
				ret|=(1ll<<to.se);
				return true;
			}
		}
		return false;
	};
	cin>>m;
	vector<ll> num(m);
	rep(i,m){
		int u,v;
		cin>>u>>v;
		u--,v--;
		ret=0;
		dfs(dfs,u,-1,v);
		num[i]=ret;
	}
	ll ans=0;
	rep(i,1<<m){
		ll pari=__builtin_popcountll(i);
		ll now=0;
		rep(j,m){
			if(1ll<<j & i){
				now|=num[j];
			}
		}
		ll x=n-1-__builtin_popcountll(now);
		x=1ll<<x;
		if(pari%2==0) ans+=x;
		else ans-=x;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,K,i,x,y,z;
 cin >> N >> K;
  x = 1;
  
  for (i = 0; i < N; i++) {
   if (x * 2 < x + K) {
     x *= 2;
   }
    else {
      x += K;
    }
  }
    cout << x << endl;
}
    

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int N; ll M, A[100005], S[100005];
ll getCount(ll val) {
  ll cnt = 0LL;
  for(int i = 1; i <= N; ++i) {
    ll l = 0, r = N+1;
    while(r-l > 1) {
      ll m = (l+r)/2;
      if(A[i]+A[m] >= val) r = m;
      else l = m;
    }
    if(r < N+1) cnt += N-r+1;
  }
  return cnt;
}
int main() {
  scanf("%d %ld", &N, &M);
  for(int i = 1; i <= N; ++i) scanf("%ld", &A[i]);
  sort(A+1, A+N+1);
  for(int i = 1; i <= N; ++i) S[i] += S[i-1]+A[i];
  ll l = 0, r = 2e5+1;
  while(r-l > 1) {
    ll m = (l+r)/2;
    if(getCount(m) < M) r = m;
    else l = m;
  }
  ll val = r, cnt = 0LL, ans = 0LL;
  for(int i = 1; i <= N; ++i) {
    ll al = 0, ar = N+1;
    while(ar-al > 1) {
      ll am = (al+ar)/2;
      if(A[am]+A[i] >= val) ar = am;
      else al = am;
    }
    ans += S[N]-S[al]+A[i]*(N-al);
    cnt += N-al;
  }
  ans += (M-cnt)*l;
  printf("%ld\n", ans);
}

Measured memory_bytes: 1664
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
using namespace std;

int main() {
	int N;
	string S;
	cin >> N;
	cin >> S;
	vector<pair<int, int>> Sum;
	Sum.push_back({ 0,0 });
	for (int i = 1; i <= N; i++) {
		if (S[i-1] == 'E')Sum.push_back({ Sum[i-1].first, Sum[i-1].second + 1 });
		else Sum.push_back({ Sum[i - 1].first+1, Sum[i - 1].second});
	}
	int mi = 3000000;
	int v;
	for (int i = 1; i <= N; i++) {
			v = Sum[i - 1].first + (Sum[N].second - Sum[i].second);
			mi = min(v, mi);
		
	}
	cout << mi << endl;

}



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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

vector<int> v;

int main()
{
	int n;
	cin>>n;
	rep(i, 0, n)
	{
		int x;
		cin>>x;
		v.pb(x);
	}
	sort(all(v));
	ll ans = v[n/2] - v[n/2 -1];
	cout<<ans<<endl;
}


Measured memory_bytes: 892
n,q = gets.split.map(&:to_i)
ss = gets.split('')
lrs = q.times.map{ gets.split.map(&:to_i) }

counts = []
ss.each.with_index do |str, i|
  if i == 0
    counts[i] = 0
  elsif ss[i-1]=='A' && ss[i]=='C'
    counts[i] = counts[i-1] + 1
  else
    counts[i] = counts[i-1]
  end
end

lrs.each do |lr|
  l, r = lr
  puts counts[r-1] - counts[l-1]
end


Measured memory_bytes: 25544
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 0;
		
		for(int i = 1; i <= n; i++) {
			if((i % 3 != 0) && (i % 5 != 0)) {
				ans += i;
			}
		}

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

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

int main(){
	long long int n;
	cin >> n;
	long long int a,b;
	cin >> a >> b;
	long long int ans = n;
	if(a%2 == b%2){
		ans = (b-a)/2;
	}
	else{
		long long int to_1 = (a-1)+(b-a+1)/2;
		long long int to_n = (n-b)+(b-a+1)/2;
		ans = min(to_1,to_n);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N,i,j,G=0;
    scanf("%d",&N);
    int x[N+2];
    
    x[0] = 0;
    x[N+1] = 0;
    
    for(i=1;i<=N;i++){
        scanf("%d",&x[i]);
    }
    
    G = 0;
    for(i=1;i<N+1;i++){ //一旦抜かずに全行程での旅費計算
        G += abs(x[i] - x[i-1]); 
    }
    G += abs(x[N]);
    
    //それぞれ抜いた場合の旅費を計算
    int G_;
    G_ = G;
    for(i=1;i<N+1;i++){
        G_ -= abs(x[i] - x[i-1]);
        G_ -= abs(x[i+1] - x[i]);
        G_ += abs(x[i+1] - x[i-1]);
        printf("%d\n",G_);
        G_ = G;
    }
}

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

using namespace std;

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int C = A - B;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  sort(H.begin(), H.end());

  int l = 0, r = 1e9 + 10;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    auto iter = upper_bound(H.begin(), H.end(), m * B);
    long long cnt = 0;
    while (iter != H.end()) {
      int h = *iter - m * B;
      cnt += (h + C - 1) / C;
      iter++;
    }
    if (cnt <= m) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

int main() {
    int n , x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i  = 0;i < n; i++) cin >> a.at(i);
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0;i < n; i++) {
        if (x >= a.at(i)) {
            x -= a.at(i);
            ans ++;
        }
    }
    if (x > 0 && ans == n) ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import Data.List
totalTime :: Int -> [Int] -> Int
totalTime _ [] = 0
totalTime t ts = snd $ foldl' f (head ts, t) (tail ts) where
  f (last, accum) next = (next, accum + min t (next - last))

main = do
  [ws1, ws2] <- (map words . lines) <$> getContents
  let t = read (ws1 !! 1)
  let ts = map read ws2
  print (totalTime t ts)


Measured memory_bytes: 130428
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int r;
	cin >> r;
	cout << 3*r*r << endl;
	return 0;
}


Measured memory_bytes: 764
import collections
h,w,k = map(int, input().split())
a = [[c for c in input()] for i in range(h)]

min_dis  = w*h
s = False
for i in range(h):
    for j in range(w):
        if a[i][j] == 'S':
            s = (i, j)
            break
    if s:
        break

dq = collections.deque()
dq.append((0, s[0], s[1]))

moved = [[False for j in range(w)] for i in range(h)]
while dq:
    m, y, x = dq.popleft()
    if moved[y][x]:
        continue
    else:
        moved[y][x] = True
    if m > k:
        continue
    if y == 0 or y == h-1 or x == 0 or x == w-1:
        print(1)
        exit()
    min_dis = min(min_dis, y, h-1-y, x, w-1-x)
    for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        if 0<=y+dy<h and 0<=x+dx<w and a[y+dy][x+dx] == '.' and not moved[y+dy][x+dx]:
            dq.append((m+1, y+dy, x+dx))
print(1+(min_dis+k-1)//k)


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

typedef long long ll;
// typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;


int main() {
  string S;
  cin >> S;

  bitset<3>ans;
  for(int i = 0; i < (1 << 3); i++) {
    bitset<3>bit(i);

    int sum = stoi(S.substr(0, 1));
    for(int j = 0; j < 3; j++) {
      if(bit.test(j)){
        sum -= stoi(S.substr(j+1, 1));
      } else {
        sum += stoi(S.substr(j+1, 1));
      }
    }
    if(sum == 7) {
      ans = bit;
      break;
    }
  }

  for(int i = 0; i < 4; i++) {
    cout << S.substr(i, 1);
    if(i == 3) break;

    if(ans.test(i)){
      cout << "-";
    } else {
      cout << "+";
    }
  }
  cout << "=7" << endl;
}


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

int main(void){
  ll N,K;
  cin >> N >> K;
  vector<ll> Array(100000);
  
  for(ll i=0;i<N;i++){
    ll a,b;
    cin >> a >> b;
    Array.at(a-1)+=b;
  }
  for(ll i=0;i<100000;i++){
    K-=Array.at(i);
    if(K>0) continue;
    else{
      cout << i+1 << endl;
      return 0;
    }
  }
}
    

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10,inf=1e9;
int dp[maxn][3],n,m;
bool vis[maxn][3];
vector<int> a[maxn];
struct pa{
    int val,nod,l;
}p;
int main(){
    int u,v;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<3;j++)
        dp[i][j]=inf;
    scanf("%d%d",&u,&v);
    dp[u][0]=0;
    queue<pa> q;
    q.push({0,u,0});
    while(!q.empty()){
        p=q.front();q.pop();
        if(vis[p.nod][p.l])continue;
        vis[p.nod][p.l]=true;
        for(int i:a[p.nod]){
            if(!vis[i][(p.l+1)%3]){
                dp[i][(p.l+1)%3]=p.val+1;
                q.push({p.val+1,i,(p.l+1)%3});
            }
        }
    }
    printf("%d\n",dp[v][0]==inf?-1:dp[v][0]/3);
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll W[110];
    rep(i,0,N) cin >> W[i];
    ll ans = INF;
    rep(T,1,N){
        ll v1 = 0, v2 = 0;
        rep(i,0,N){
            if(i+1 <= T){
                v1 += W[i];
            }else{
                v2 += W[i];
            }
        }
        ans = min(ans, abs(v1 - v2));
    }
    print(ans);
    
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef struct {
  char name[100];
  int t;
}Queue;

Queue Q[100000];
int n, head = 0, tail = 0;

void enqueue(Queue);
Queue dequeue(void);  

int main(){
  int i, q, count = 0, time = 0;
  Queue cell;
  
  scanf("%d %d",&n,&q);
  
  for (i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  
  while(count != n){
    cell = dequeue();
    if(cell.t - q <= 0){
      time += cell.t;
      cell.t = 0;
      count++;
      
      printf("%s %d",cell.name ,time);
      printf("\n");   
      
    } else if (cell.t > 0){
      time += q;    
      cell.t -= q;
      enqueue(cell);
    }
    
  }
  
  return 0;
 
}
  

void enqueue(Queue x){ 

  if(tail == n)    tail = 1;
   else {
    tail++;
  }
  
  Q[tail] = x;
}
  

Queue dequeue(){
  if(head == n)    head = 1;
  
  else {
    head++;
  }
  return Q[head];
}
 

Measured memory_bytes: 6744
def main():
  n = int(input())
  ans = 0
  for k in divisors(n):
    if k == 1:
      continue
    if check(n, k):
      ans += 1
  ans += len([None for k in divisors(n-1) if k != 1])
  print(ans)

def check(original_n, k):
  n = original_n
  while n % k == 0:
    n = n // k
  n = n % k
  return n == 1

def divisors(n):
  result = []
  for i in range(1, n+1):
    if i*i > n:
      break
    if n%i == 0:
      result.append(i)
      d = n // i
      if d != i:
        result.append(d)
  return result


main()

Measured memory_bytes: 9312
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1


template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}
 
template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

const int MAX = 200200;
const ll mod = 1000000007;
ll A[MAX];

int main() {
	int N; scanf("%d", &N);
	REP(i, N) scanf("%lld", A + i);
	ll inv2 = (mod + 1)/2;
	ll ans = 0;
	REP(i, N) ans += A[i];
	ans %= mod;
	ans = (ans * ans)%mod;
	REP(i, N) {
		ans = (ans - (A[i]*A[i])%mod + mod)%mod;
	}
	ans = (ans * inv2)%mod;
	printf("%lld\n", ans);
}

Measured memory_bytes: 5316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g;}
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

int main()
{
	int n, m;
	cin >> n >> m;
	vvb graph(n, vb(n, false));
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a][b] = true;
		graph[b][a] = true;
	}
	vi perm;
	rep(i, n)perm.push_back(i);
	int ans = 0;
	do
	{
		if (perm[0] != 0)break;
		bool val = true;
		rep(i, n - 1)
		{
			if (!graph[perm[i]][perm[i + 1]])
			{
				val = false;
				break;
			}
		}
		if (val)ans++;
	} while (next_permutation(all(perm)));
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int max, second, index, n, i, tmp;
	while(scanf("%d", &n)>0){
		max=0;
		second=0;
		for(i=0;i<n;i++){
			scanf("%d",&tmp);
			if(tmp>max){
				second=max;
				max=tmp;
				index=i;
			}
			else{
				if(tmp>second){
					second=tmp;
				}
			}
		}
		for(i=0;i<n;i++){
			if(i==index){
				printf("%d\n",second);
			}
			else{
				printf("%d\n",max);
			}
		}
	//	printf("\n");
	}
	return 0;
 } 

Measured memory_bytes: 1536
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int n,k;
    int ans=1;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        ans=fmin(ans*2,ans+k);
    printf("%d",ans);
    return 0;
}

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

int main()
{
    int64_t H, W;
    int64_t ans;
    cin >> H >> W;

    if (H == 1 || W == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    if (H * W % 2 == 1)
    {
        ans = (H * W + 1) / 2;
        cout << ans << endl;
    }
    else
    {
        ans = (H * W) / 2;
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
typedef long long ll;
using namespace std;

int h, w, a[500][500];
vector<pair<pair<int,int>,pair<int,int>>> v;
bool flag;
int main() {
	cin >> h >> w;
	lp(h)
		LP(w, j)
			cin >> a[i][j];
	flag = true;
	lp(h) {
		if (flag) {
			LP(w, j) {
				if (a[i][j] % 2) {
					if (j != w - 1) {
						v.push_back(mkp(mkp(i, j), mkp(i, j + 1)));
						a[i][j + 1]++;
					}
					else if (i != h - 1) {
						v.push_back(mkp(mkp(i, j), mkp(i + 1, j)));
						a[i + 1][j]++;
					}
				}
			}
		}
		else{
			for (int j = w - 1; j >= 0; j--) {
				if (a[i][j] % 2) {
					if (j != 0) {
						v.push_back(mkp(mkp(i, j), mkp(i, j - 1)));
						a[i][j - 1]++;
					}
					else if (i != h - 1) {
						v.push_back(mkp(mkp(i, j), mkp(i + 1, j)));
						a[i + 1][j]++;
					}
				}
			}
		}
		flag = !flag;
	}
	cout << v.size() << endl;
	lp(v.size())
		cout << v[i].first.first + 1 << sp << v[i].first.second + 1 << sp << v[i].second.first + 1 << sp << v[i].second.second + 1 << endl;
	return 0;
}


Measured memory_bytes: 5104
package main

import "fmt"

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var Q, H, S, D, N int
	fmt.Scan(&Q, &H, &S, &D, &N)
	L := min(4*Q, min(2*H, S)) //  Q,H,Sを使った場合の1Lあたりの最低料金
	ans := 0
	if 2*L > D { // Lの方が割高なので、出来るだけDで買い、残りをLで買う
		ans = (N/2)*D + (N%2)*L
	} else { // 全部Lで買う
		ans = N * L
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

string f(char c) {
  if (c == ' ') return "101";
  if (c == '\'') return "000000";
  if (c == ',') return "000011";
  if (c == '-') return "10010001";
  if (c == '.') return "010001";
  if (c == '?') return "000001";
  if (c == 'A') return "100101";
  if (c == 'B') return "10011010";
  if (c == 'C') return "0101";
  if (c == 'D') return "0001";
  if (c == 'E') return "110";
  if (c == 'F') return "01001";
  if (c == 'G') return "10011011";
  if (c == 'H') return "010000";
  if (c == 'I') return "0111";
  if (c == 'J') return "10011000";
  if (c == 'K') return "0110";
  if (c == 'L') return "00100";
  if (c == 'M') return "10011001";
  if (c == 'N') return "10011110";
  if (c == 'O') return "00101";
  if (c == 'P') return "111";
  if (c == 'Q') return "10011111";
  if (c == 'R') return "1000";
  if (c == 'S') return "00110";
  if (c == 'T') return "00111";
  if (c == 'U') return "10011100";
  if (c == 'V') return "10011101";
  if (c == 'W') return "000010";
  if (c == 'X') return "10010010";
  if (c == 'Y') return "10010011";
  if (c == 'Z') return "10010000";
}

char g(int x) {
  static string v = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
  return v[x];
}

main {
  string s;
  while (getline(cin, s)) {
    string x;
    for (auto &c : s) x += f(c);
    x += string((5 - x.size() % 5) % 5, '0');
    assert(x.size() % 5 == 0);
    string r;
    rep(i, x.size() / 5) r += g(stoi(x.substr(i * 5, 5), nullptr, 2));
    cout << r << endl;
  }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class UnionFind{
	vector<ll> rank;
	vector<ll> diff_weight;
	vector<ll> num;
public:
	vector<ll> par;

	UnionFind(ll N):par(N),num(N),rank(N),diff_weight(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
			rank[i]=0;
			diff_weight[i]=0;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		ll r = root(par[x]);
		diff_weight[x]+=diff_weight[par[x]];
		return par[x]=r;
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]) swap(rx,ry);
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		num[rx] += num[ry];
	}

	void relate(ll x,ll y,ll w){
		w+=weight(x),w-=weight(y);
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]){
			swap(rx,ry);
			w = -w;
		}
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		diff_weight[ry] = w;
		num[rx] += num[ry];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}

	ll weight(ll x){
		root(x);
		return diff_weight[x];
	}

	ll diff(ll x,ll y){
		return weight(y)-weight(x);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),M=in(),K=in();
	UnionFind uf(N);
	vector<int> S(N,0);
	map<int,vector<int>> follow,block;
	REP(i,M){
		int A=in()-1,B=in()-1;
		if(B>A) swap(A,B);
		S[A]--;
		S[B]--;
		uf.unite(A,B);
	}

	REP(i,K){
		int A=in()-1,B=in()-1;
		if(B>A) swap(A,B);
		if(uf.same(A,B)){
			S[A]--;
			S[B]--;
		}
	}
	REP(i,N){
		S[i] = max(uf.getsize(uf.root(i))-1+S[i],0LL);
	}
	PRINTALL(S);
	return 0;
}


Measured memory_bytes: 4352