akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

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

using namespace std;

int main(){
  ll n;cin>>n;
  ll a[n-1],b[n-1];
  rep(i,n-1)cin>>a[i]>>b[i];

  vector<ll> graph[n+1];
  rep(i,n-1){
    graph[ a[i] ].push_back( b[i] );
    graph[ b[i] ].push_back( a[i] );
  }

  ll color_count=0;
  rep(i,n)color_count=max(color_count, (ll)graph[i].size());

  map<pair<ll, ll>, ll> color_log;

  ll color_from_parent[n+1];
  
  queue<ll> q;
  q.push(1);
  bool visited[n+1];
  rep(i,n+1)visited[i]=false;
  visited[1]=true;

  while(!q.empty()){
    int from=q.front();
    q.pop();
    ll color=1;
    for(auto to :graph[from]){
      if(visited[to] || from>to)continue;
      if(!visited[to])q.push(to);
      visited[to]=true;
      if(color_from_parent[from]==color)color++;

      color_log[make_pair(from,to)]=color;
      color_from_parent[to]=color;
      color++;
    }
  }

  cout<<color_count<<endl;
  rep(i,n-1)cout<<color_log[make_pair(a[i],b[i])]<<endl;

  return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e1 + 5);

int n;
double v[MAX_N];

double ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lf", &(v[i]));
  }

  sort(v, v + n);

  ans = v[0];

  for (int i = 1; i < n; ++i) {
    ans = (ans + v[i]) / 2.0;
  }

  printf("%lf\n", ans);

  return 0;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
inp = iter(map(int, read().split()))

H, W, D = next(inp), next(inp), next(inp)
addr = [None] * (H*W+1)
for i in range(H):
    for j in range(W):
        v = next(inp)
        addr[v] = (i, j)

cost = []
for m in range(D):
    arr = [0]
    for x in range((H*W-m)//D):
        if m + x * D == 0:
            arr.append(0)
            continue
        r, c = addr[m + x * D]
        nr, nc = addr[m + (x+1) *D]
        arr.append(arr[-1] + abs(nr - r) + abs(nc - c))
    cost.append(arr)

Q = next(inp)
for _ in range(Q):
    s, t = next(inp), next(inp)
    m = s % D
    ans = cost[m][t//D] - cost[m][s//D]
    print(ans)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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 f(ll x){
    return max((ll)0,min((ll)255,x));
}

int main(void){
    ll N,M;
    cin >> N >> M;
    while(N!=0 || M!=0){
        vector<ll> C(M); REP(i,M) cin >> C[i];

        vector<ll> x(N); REP(i,N) cin >> x[i];
        ll dp[2][256]; REP(i,256) dp[0][i] = LL_INF;
        dp[0][128] = 0;

        REP(i,N){
            int a,b;
            if(i%2 == 0){
                a = 1;
                b = 0;
            }
            else{
                a = 0;
                b = 1;
            }
            REP(j,256) dp[a][j] = LL_INF;
            REP(j,256){
                if(dp[b][j] == LL_INF) continue;
                REP(k,M){
                    ll t = f(j + C[k]);
                    chmin(dp[a][t], dp[b][j] + (t-x[i])*(t-x[i]));
                }
            }
        }

        ll ans = LL_INF;
        int a; if(N%2 == 0) a = 0; else a = 1;
        REP(i,256) chmin(ans, dp[a][i]);
        cout << ans << en;
        cin >> N >> M;
    }
    return 0;
}


Measured memory_bytes: 3264
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long W  = keyboard.nextInt();
		long H  = keyboard.nextInt();
		long x  = keyboard.nextInt();
		long y  = keyboard.nextInt();
		
		double men = (W*H)/2.0;
		double a = x*H;
		double b = (W*H)-a;
		double c = y*W;
		double d = (W*H)-c;
		
		double xx = Math.min(a, b);
		double yy = Math.min(c, d);
		
		int hou = 0;
		
		if(xx == men) {
			hou ++;
		}
		if(yy == men) {
			hou ++;
		}
		
		if(hou <= 1) {
			hou = 0;
		}else {
			hou = 1;
		}

		System.out.print(men + " " + hou);
		keyboard.close();	
	}
}


Measured memory_bytes: 21844
import heapq


n, m, s = map(int, input().split())
if s >= 2500:
    s = 2499

edges = [[] for _ in range(n)]
for _ in range(m):
    from_, to, cost, time = map(int, input().split())
    edges[from_-1].append((to-1, cost, time))
    edges[to-1].append((from_-1, cost, time))

banks = [(0, 0) for _ in range(n)]
for i in range(n):
    coin, time = map(int, input().split())
    banks[i] = (coin, time)

INF = float('INF')
DP = [INF] * (n * 2500)
ans = [INF] * n


def to_one_dimension(node, coin):
    return node * 2500 + coin


def push_todo(node, coin, time):
    if coin < 0:
        return
    if time >= DP[to_one_dimension(node, coin)]:
        return
    heapq.heappush(todo, (time, node, coin))


def charge(node, current_coin, current_time):
    coin, time = banks[node]
    new_coin = current_coin + coin
    if new_coin >= 2500:
        new_coin = 2499
    push_todo(node, new_coin, current_time+time)


todo = [(0, 0, s)]
while todo:
    current_time, node, current_coin = heapq.heappop(todo)
    if current_time < ans[node]:
        ans[node] = current_time

    one_d_idx = to_one_dimension(node, current_coin)
    if current_time >= DP[one_d_idx]:
        continue

    DP[one_d_idx] = current_time
    charge(node, current_coin, current_time)

    for to, cost, time in edges[node]:
        push_todo(to, current_coin-cost, current_time+time)

for a in ans[1:]:
    print(a)


Measured memory_bytes: 35868
#include<bits/stdc++.h>
#define INF 1073741824
#define ll long long
#define PI (2*acos(0.0))
#define Hare printf("here\n")
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define on(val,pos) val|(1<<pos)
#define off(val,pos) val&(~(1<<pos))
#define check(val,pos) (val&(1<<pos))

//first four adjacent,second four corner
//int row[8]={0,-1,0,1,1,-1,-1,1};
//int col[8]={-1,0,1,0,-1,-1,1,1};
using namespace std;
vector<int> net[100005];
stack<int> st;
bool visit[100005];
void topsort(int n){
    visit[n]=true;
    for(int i=0;i<net[n].size();i++){
        if(!visit[net[n][i]])topsort(net[n][i]);
    }

    st.push(n);
    return;
}
int BFS(int len){
    int arr[len+5]={0},mx=0;
    while(!st.empty()){
        int n=st.top();
        st.pop();

        for(int i=0;i<net[n].size();i++){
            int k=net[n][i];
            arr[k]=max(arr[k],arr[n]+1);
            mx=max(mx,arr[k]);
        }
    }
    return mx;
}

int main(){
    int i,j,k,n,m,val,t=0,cnt,test;
    //freopen("000input.txt","r",stdin);
    cin>>n>>m;
    for(i=0;i<m;i++){
        scanf("%d %d",&k,&val);
        net[k].pb(val);
    }

    for(i=1;i<=n;i++)if(!visit[i]) topsort(i);
    printf("%d\n",BFS(n));

    //free();   //if pointer array
    return 0;
}


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

#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void input(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

void solveTest(){
	
}

int main(){
	fastio();
	//input();

	/*int t;
	cin>>t;
	while(t--){
		solveTest();
	}*/

	int a[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	int n;
	cin>>n;
	vector<vector<bool>> flag(3,vector<bool>(3,false));
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(a[j][k]==x){
					flag[j][k]=true;
				}
			}
		}
	}
	cout << ((flag[0][0] && flag[0][1] && flag[0][2]) ||\
          (flag[1][0] && flag[1][1] && flag[1][2]) ||\
          (flag[2][0] && flag[2][1] && flag[2][2]) ||\
          (flag[0][0] && flag[1][0] && flag[2][0]) ||\
          (flag[0][1] && flag[1][1] && flag[2][1]) ||\
          (flag[0][2] && flag[1][2] && flag[2][2]) ||\
          (flag[0][0] && flag[1][1] && flag[2][2]) ||\
          (flag[2][0] && flag[1][1] && flag[0][2]) ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  V<ll> a(7);
  for(int i=0;i<7;i++)cin>>a[i];
  ll ans=a[1];
  if(a[0]&&a[3]&&a[4]){
    ll d=min({a[0],a[3],a[4]});
    if((a[3]-d)%2==0&&(a[4]-d)%2==0){
      a[0]-=d;
      a[3]-=d;
      a[4]-=d;
      ans+=3*d;
    }else if((a[3]-d)%2==1&&(a[4]-d)%2==1){
      a[0]-=d-1;
      a[3]-=d-1;
      a[4]-=d-1;
      ans+=(d-1)*3;
    }else if((a[0]-d)%2==1){
      a[0]-=d-1;
      a[3]-=d-1;
      a[4]-=d-1;
      ans+=(d-1)*3;
    }else{
      a[0]-=d;
      a[3]-=d;
      a[4]-=d;
      ans+=3*d;
    }
  }
   ans+=a[0]/2*2;
  ans+=a[3]/2*2+a[4]/2*2;
  cout<<ans<<"\n";
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int w = sc.nextInt();
		// スペース区切りの整数の入力
		int h = sc.nextInt();
		int n = sc.nextInt();
		// 文字列の入力
		int x[] = new int[n];
		int y[] = new int[n];
		int a[] = new int[n];
		int maxx = w;
		int maxy = h;
		int minx = 0;
		int miny = 0;
		for(int i=0; i<n; i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			a[i] = sc.nextInt();
			switch (a[i]){
				case 1:
					if(minx < x[i]){
						minx = x[i];
					}
					break;
				case 2:
				if(maxx > x[i]){
					maxx = x[i];
				}
				break;
				case 3:
				if(miny < y[i]){
					miny = y[i];
				}
				break;
				case 4:
				if(maxy > y[i]){
					maxy = y[i];
				}
				break;
		}
	}
	int answer = (maxx - minx) * (maxy - miny);
	if(maxx - minx < 0|| maxy - miny < 0){
		answer = 0;
	}
		System.out.println(answer);
}
}

Measured memory_bytes: 10320
def nC2(num):
  if num <= 1:
    return 0
  else:
    return int(num * (num-1) / 2)

n = int(input())
text_dict = {}
for _ in range(n):
  sorted_text = ''.join(sorted(list(input())))
  if sorted_text in text_dict.keys():
    text_dict[sorted_text] = text_dict[sorted_text] + 1
  else:
    text_dict[sorted_text] = 1

count = 0
for text, c in text_dict.items():
  count += nC2(c)
  
print(count)

Measured memory_bytes: 17808
#include <bits/stdc++.h>
using namespace std;
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
 
#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
 
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  int N;
  cin >> N;
  vector<PII> cnt(N);
  REP(i,N) cnt[i].SS = i;
  REP(i,N*(N-1)/2){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	--a;
	--b;
	if(c > d) cnt[a].FF += 3;
	else if(c < d) cnt[b].FF += 3;
	else{
	  cnt[a].FF++;
	  cnt[b].FF++;
	}
  }
  RSORT(cnt);
 
  VI ord(N);
  REP(i,N)
	if(i>0 && cnt[i].FF == cnt[i-1].FF)
	  ord[cnt[i].SS] = ord[cnt[i-1].SS];
	else
	  ord[cnt[i].SS] = i+1;
 
  REP(i,N) cout << ord[i] << endl;
 
  return 0;
}

Measured memory_bytes: 3132
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#define LL long long


using namespace std;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front())
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }


	return 0;
}


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

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
const int MAX_VAL = 55555;
bool is_prime[MAX_VAL + 1];
vector<int> primes;
void sieve()
{
    for (int i = 0; i < MAX_VAL + 1; i++)
    {
        is_prime[i] = true;
    }
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= MAX_VAL; i++)
    {
        if (is_prime[i])
        {
            primes.push_back(i);
            for (int j = 2 * i; j <= MAX_VAL; j += i)
            {
                is_prime[j] = false;
            }
        }
    }
}

bool is_prime_func(int val)
{
    for (int i = 2; i * i <= val; i++)
    {
        if (val % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    sieve();
    cin >> N;
    int pos = 2;
    int cnt = 0;
    while (cnt < N)
    {

        if (is_prime[pos] and pos % 5 ==1)
        {
            cnt++;
            cout << pos << " ";
        }
        pos++;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  int mx = 0;
  rep(i, n-1) {
    if ((abs(x[i])+abs(y[i]))%2 != (abs(x[i+1])+abs(y[i+1]))%2) {
      cout << -1 << endl;
      return 0;
    }
    chmax(mx, int((abs(x[i])+abs(y[i]))));
  }
  vector<int> arms;
  ll p = 1;
  while (p <= mx) {
    arms.push_back(p);
    p <<= 1;
  }
  reverse(arms.begin(), arms.end());
  if (!((abs(x[0])+abs(y[0]))%2))
    arms.push_back(1);
  cout << arms.size() << endl;
  rep(i, arms.size())
    cout << arms[i] << (i+1<arms.size()?' ':'\n');
  rep(i, n) {
    ll cx = 0, cy = 0;
    rep(j, arms.size()) {
      ll mn = 1e18, d;
      rep(k, 4) { //(0, 1, 2, 3) == (U, R, D, L)
        ll nx = cx, ny = cy;
        switch (k) {
          case 0 : ny += arms[j]; break;
          case 1 : nx += arms[j]; break;
          case 2 : ny -= arms[j]; break;
          case 3 : nx -= arms[j]; break;
        }
        ll dist = abs(x[i]-nx)+abs(y[i]-ny);
        if (chmin(mn, dist))
          d = k;
      }
      switch (d) {
        case 0 : cy += arms[j]; cout << 'U'; break;
        case 1 : cx += arms[j]; cout << 'R'; break;
        case 2 : cy -= arms[j]; cout << 'D'; break;
        case 3 : cx -= arms[j]; cout << 'L'; break;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <ctime>
#include <cmath>

using namespace std;

int main() {

    int a,b;
    cin>>a;
    cin>>b;
    int c = a+b;
    if(c>=10)
        cout<<"error"<<endl;
    else
        cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i,j,n,m,a,b,c;
	int matrixA[101][101];
	int matrixB[101];
	
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a);
			matrixA[i][j] = a;
		}
	}
	
	for(j=0;j<m;j++){
		scanf("%d",&b);
		matrixB[j] = b;
	}
	c=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			c += matrixA[i][j] * matrixB[j];
		}
		printf("%d\n",c);
		c=0;
	}
}

Measured memory_bytes: 1068
import copy
h,w,k=map(int,input().split())
v=[]
for _ in range(h):
    array=list(input())
    v.append(array)
ans=0
for a in range(2**h):
    c=copy.deepcopy(v)
    for b in range(h):
        if a>>b & 1:
            for d in range(w):
                c[b][d]=0
    for e in range(2**w):
      z=copy.deepcopy(c)
      temp=0
      for f in range(w):
        if e>>f & 1:
          for g in range(h):
            z[g][f]=0
      for p in range(h):
        temp+=z[p].count("#")
      if temp==k:
        ans+=1
print(ans)

Measured memory_bytes: 9340
# Σ(i ^ j = k) ai * bj = ckという形で式が表されるとき
# fwht(a)*fwht(b)=fwht(c)が成り立ち高速化できる
# すごく必死に考えると
# a = [p0 p1 p2 ... p2^N-1]
# b = [x0 x1 x2 ... x2^N-1]
# c = [2^N-1 -1 -1 -1 .... -1]
# とするとうまいことaとcに変数が入らない形になるのでfwht(c)/fwht(a)を計算し
# fwht(b)がわかるのでこれを逆変換すればbが求められる
# なお逆変換は b = fwht(fwht(b)) / 要素数で求められる、なぜかは知らない
# またまたなぜかは知らないがこうして求めた答えは各要素に定数が足されたものになるらしい
# 今回はx0 = 0と分かっているのbを[0 x1-x0 ... x2^N-1-x0]と補正してやればよい

N = int(input())
A = [int(i) for i in input().split()]
MOD = 998244353

NN = 1 << N

def fwht(a) :
    i = 1
    while i < NN :
        j = 0
        while j < NN :
            for k in range(i) :
                x, y = a[j+k], a[i+j+k]
                a[j+k], a[i+j+k] = (x + y) % MOD, (x - y) % MOD
            j += i << 1
        i <<= 1

def inv(x) :
    return pow(x, MOD - 2, MOD)

s = inv(sum(A) % MOD)
for i in range(NN) :
    A[i] = (A[i] * s) % MOD
A[0] = (A[0] - 1) % MOD
fwht(A)

B = [- 1] * (NN)
B[0] = (NN-1) % MOD
fwht(B)

C = [(inv(A[i]) * B[i]) % MOD for i in range(NN)]
fwht(C)

for i in range(NN) :
    C[i] = (C[i] * inv(NN)) % MOD

for i in range(NN) :
    print((C[i] - C[0]) % MOD)

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    int ans=1001001001001001001ll;
    if(A&1)chmin(ans,B*C);
    else chmin(ans,0ll);

    if(B&1)chmin(ans,A*C);
    else chmin(ans,0ll);

    if(C&1)chmin(ans,A*B);
    else chmin(ans,0ll);

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


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

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 rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
const double PI = 3.1415926535;

int main() {
    double a,b,x;
    cin >> a >> b >> x;
    if(2*x>a*a*b)cout << fixed << setprecision(10) << (long double)(atan(2*(a*a*b-x)/(a*a*a))*180/PI) << endl; 
    else cout << fixed << setprecision(10) << (long double)(atan(a*b*b/(2*x))*180/PI) << endl; 
}

Measured memory_bytes: 512
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0007&lang=jp

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

//テ」ツδ榲」ツつッテ」ツδュテ・ツョツ堙ァツセツゥ
#define ALL(v) (v).begin(),(v).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define SORT(x) sort(begin(x),end(x))
#define SELECT_SORT(x, n) sort(begin(x),begin(x)+n)
#define SWAP(type, a, b) do {type tmp = a; a = b; b = tmp;} while (0)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

//テ・ツョツ堙ヲツ閉ー
#define INF 2000000000000
#define MAX 10

//DEBUGテァツ板ィ
#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


int yami_kin(int money)
{
	int risoku = money*0.05;
	money = money + risoku;
	
	if(money % 1000 == 0){
		return money;
	}else{
		return (money - (money%1000)) + 1000;
	}
}

int main()
{
	int money= 100000; //10テ、ツクツ?・ツ??
	int n=0;
	cin >> n;
	for(int i=0; i<n; i++){
		money = yami_kin(money);
		//cout << money << endl;
	}
	cout << money << endl;
	
}

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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

using ll = long long;

typedef long long lint;

int main(){
    int r;cin >> r;
    cout<<2 * r * 3.141592653589793238462643383279<<endl;;
}

Measured memory_bytes: 3788
import numpy as np

def search_arctan(tan):
    low = 0
    high = np.radians(90)
    while (high-low>=10**(-12)):
        mid = (low+high)/2 
        if np.tan(mid)<=tan:
            low = mid
        else:
            high = mid
    return np.rad2deg(mid)

a,b,x = list(map(int,input().split()))

l = x/(a*a)

if l<=b/2.0:
    ans = search_arctan(b**2.0/(2.0*a*l))
else:
    ans = search_arctan(2.0*(b-l)/a)

print(ans)

Measured memory_bytes: 12500
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}


fn main() {
    let (s, _) : (String, String) = read_tuple2();
    let (a, b) : (i32, i32) = read_tuple2();
    let u : String = read();
    let (a, b) = if u == s {(a-1, b)} else {(a, b - 1)};
    println!("{} {}", a, b)
}


Measured memory_bytes: 2052
def solve(n, m, s, t):
    dp = [[0 for i in range(m + 1)] for _ in range(n + 1)]
    for i in range(n):
        for j in range(m):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

    ans = ''
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            ans = s[n - 1] + ans
            n -= 1
            m -= 1
    print(ans)
    return

s = input()
t = input()

solve(len(s), len(t), s, t)

Measured memory_bytes: 120028
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/intrusive/rbtree.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<0>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"");if(i>INF/2)cout<<"INF";else cout<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto j:v)output(j);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define LINF 9223372036854775807
#define MOD 1000000007
#define endl "\n"
template<typename T=lint>T in(){return *istream_iterator<T>(cin);}
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};

int main(){
    lint n;
    cin>>n;
    cout<<(lint)pow(n,3);
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main()
{
  int n; cin >> n;
  vs s(n); rep(i,n) cin >> s[i];

  int ans = 0;
  rep(k,n){
    bool f = true;
    rep(i,n) rep(j,n){
      if(s[i][(j+k)%n] != s[j][(i+k)%n]) f = false;
    }
    if(f) ans += n;
  }

  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
      cin>>n;
      n*=n;
      cout<<n;
    }
    return 0ll;
}


Measured memory_bytes: 3532
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    if(A * B < N || N + 1 < A + B) {cout << -1 << endl; return 0;}
    vector<int> v[B];
    int cnt = 0;
    rep(i, A) v[0].push_back(i + 1);
    REP(i, A + 1, N) {v[cnt % (B - 1) + 1].push_back(i); cnt++;}
    cnt = 0;
    RREP(i, B - 1, 0) {
        rep(j, v[i].size()) {
            if (cnt != 0) cout << " ";
            cout << v[i][j];
            cnt++;
        }
    }
    cout << endl;


    return 0;
}
// 7
// 6
// 1 2 3 4 5

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define ld                 long double
#define ff                 first
#define ss                 second
#define P                 pair<int,int>
#define pb                 push_back
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
const int N = 100005;//change it when needed
int n, k;
int a[N][3];
int go() {
    for (int i = 1; i < n; i++) {
        a[i][0] += max(a[i - 1][1], a[i - 1][2]);
        a[i][1] += max(a[i - 1][0], a[i - 1][2]);
        a[i][2] += max(a[i - 1][1], a[i - 1][0]);
    }
    return max({a[n - 1][0], a[n - 1][1], a[n - 1][2]});
}
void solve() {
    int  m, ans = 0, cnt = 0, sum = 0;
    cin >> n ;
    k = 3;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < k; j++) {
            cin >> a[i][j];
        }
    }
    cout << go() << endl;
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t; cin >> t; while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <limits>

using namespace std;

int main()
{
    int n;

    cin >> n;

    vector <vector <int> > m(n + 1, vector <int> (3)), summ(n + 1, vector <int>(3, -1));

    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 3; j++)
            cin >> m[i][j];

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

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int ii = 0; ii < 3; ii++)
            {
                if (ii != j)
                {
                    summ[i][j] = max(summ[i - 1][ii] + m[i][j], summ[i][j]);
                }
            }
        }
    }
    int answ = 0;
    for (int i = 0; i < 3; i++)
        answ = max(answ, summ[n][i]);
    cout << answ;

    return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M, C;
  cin>>N>>M>>C;
  int ans = 0;
  int sum;
  int tmp;
  int B[M];
  for(int i=0;i<M;++i) cin>>B[i];
  for(int i=0;i<N;++i) {
    sum = C;
    for(int j=0;j<M;++j) {
      cin>>tmp;
      sum += B[j]*tmp;
    }
    if(sum>0) ans++;
  }
  cout<<ans<<endl;
}



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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,sz[N];

char s[N];

int main(){
	ll a,b;
	int c,d;
	scanf("%lld%lld%d%d",&a,&b,&c,&d);
	ll mcm=(ll)c*d / __gcd(c,d);
	ll div= (b/c + b/d - b/mcm) - ( (a-1)/c + (a-1)/d - (a-1) / mcm );
	printf("%lld\n",b-a-div+1); 
}



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

dp = [float("inf") for _ in range(N)]
dp[0] = 0

for i in range(N):
    if i + 1 < N:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
    if i + 2 < N:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))

print(dp[N - 1])


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

int main() {
	string s;
	cin >> s;
	string out = "";
	if (s.length() == 3) {
		out.push_back(s[2]);
		out.push_back(s[1]);
		out.push_back(s[0]);
	} else {
		out = s;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long a[200100],b[200100],n,m,ans;
bool flag;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
    	b[i]=i-a[i];
    	if(a[i]>=i||a[i]>a[i-1]+1){
    		flag=true;
		}
	} 
	if(flag){
		cout<<"-1";
		return 0;
	}
	for(int i=n;i>0;i--){
      if(i!=n&&b[i]==b[i+1])continue;
      ans+=a[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int a,b,c,d; cin>>a>>b>>c>>d;
  if(abs(c-a)<=d||abs(b-a)<=d&&abs(c-b)<=d){
    cout << "Yes"<<endl;
  }
  else cout<<"No"<<endl;
  
}


Measured memory_bytes: 3664
//挿入アルゴリズム
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int>A(n);
    
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    //とりあえず表示
    for(int i = 0; i < n; i++){
        cout << A[i];
        if(i!=n-1){
                cout << " ";
            }else{
                cout << "\n";
            }
    }

    //ソート開始
    for(int i = 1; i < n; i++){
        int j = i;
        while(j >= 1){
            if(A[j]<=A[j-1]){
                int tmp;
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                j--;
            }else{
                j--;
            } 
        }
        for(int k = 0; k < n; k++){
            cout << A[k];
            if(k!=n-1){
                cout << " ";
            }else{
                cout << "\n";
            }
        }
    }
}


Measured memory_bytes: 3088
def check(a, b):
    for _ in range(4):
        if a == b:
           return True
        b = list(map(lambda x: [-x[1], x[0]], b))
    return False
def main(n):
    lines = [None] * n
    for i in range(n):
        m = int(input())
        xy = [None] * m
        for j in range(m):
            xy[j] = list(map(int, input().split()))
        lines[i] = xy
    x, y = lines[0][0]
    ans = list(map(lambda z: [z[0] - x, z[1] - y], lines[0]))
    for num, line in enumerate(lines[1:]):
        x, y = line[0]
        fline = list(map(lambda z: [z[0] - x, z[1] - y], line))
        x, y = line[-1]
        eline = list(map(lambda z: [z[0] - x, z[1] - y], line[::-1]))
        if check(ans, fline) or check(ans, eline):
            print(num+1)
    print("+" * 5)



while 1:
    n = int(input())
    if n == 0:
        break
    main(n + 1)


Measured memory_bytes: 5620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc097/tasks/abc097_b

int main() {
    int X; cin >> X;
    vector<int> expo(X+5);

    expo[1] = 1;
    for (int b = 2; b <= X; b++) {
        int v = b * b;
        while(v <= X) {
            expo[v] = 1;
            v *= b;
        }
    }

    for (int i = X; i > 0; i--) if (expo[i]){
            cout << i << "\n";
            return 0;
    }

    return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

from itertools import permutations
n = int(input())
list_XY = []
list_CO = []
for i in range(n):
    x, y = map(int, input().split())
    list_XY.append([x, y, i])

list_XY.sort(key=lambda x:x[0])
for i in range(n-1):
    list_CO.append([list_XY[i][2], list_XY[i+1][2], abs(list_XY[i][0]-list_XY[i+1][0])])

list_XY.sort(key=lambda x:x[1])
for i in range(n-1):
    list_CO.append([list_XY[i][2], list_XY[i+1][2], abs(list_XY[i][1]-list_XY[i+1][1])])

list_CO.sort(key=lambda x:x[2])
uf = UnionFind(n)
ans = 0

for i, j, cost in list_CO:
    if not uf.same(i, j):
        uf.union(i, j)
        ans += cost
    if uf.size(0) == n:
        break

print(ans)

Measured memory_bytes: 53548
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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 dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,q;
  cin>>n>>q;
  vector<pair<ll,pll>> p(n);
  rep(i,n){
    ll s,t,x;
    cin>>s>>t>>x;
    p[i].F=x;
    p[i].S=mp(s-x,t-x);
  }
  sort(all(p));
  set<ll> d;
  map<ll,ll> pp;
  rep(i,q){
    ll dd;
    cin>>dd;
    d.insert(dd);
    pp[dd]=INF;
  }
  rep(i,n){
    auto itr=d.upper_bound(p[i].S.S);
    auto itre=d.lower_bound(p[i].S.F);
    while(itr!=itre&&*itre<p[i].S.S){
      pp[*itre]=p[i].F;
      ll g=*itre;
      itre++;
      d.erase(g);
    }
  }
  for(auto hh:pp){
    if(hh.S==INF)COUT(-1);
    else COUT(hh.S);
  }
}


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

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

using namespace std;

int main(){
	int n,k;
	string s; cin>>n>>k>>s;

	vector<int> B,W;
	if(s[ 0 ]=='0') B.emplace_back(0);
	int pre=0;
	rep(i,n){
		if(i==n-1 || s[i]!=s[i+1]){
			if(s[pre]=='1') B.emplace_back(i-pre+1);
			else            W.emplace_back(i-pre+1);
			pre=i+1;
		}
	}
	if(s[n-1]=='0') B.emplace_back(0);

	if(k>=W.size()){ cout<<n<<endl; return 0; }

	int ans=0,sum=0;
	rep(i,k) sum+=B[i]+W[i];
	for(int i=k;i<=W.size();i++){
		sum+=B[i];
		ans=max(ans,sum);
		if(i<W.size()){
			sum-=B[i-k];
			sum+=W[i];
			sum-=W[i-k];
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    if(n<1200) print("ABC");
    else if(n<2800) print("ARC");
    else print("AGC");
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

    char a[n];

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }


    for(int i=0;i<n;i++)
    {
        if(a[i] == a[i+1])
            a[i]='1';
    }


    int count=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>='a' && a[i]<='z')
            count++;

    }

    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int a,b,c,n,x,z;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b) {
		n=b;
	}
	else {
		n=a;
	}
	if(n<c) {
		x=c;
	}
	else {
		x=n;
	}
	z=(a+b+c)-x;
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 128
n,m = map(int, input().split())
x= list(map(int,input().split()))

if n>=m:
    print('0')
    exit()

x.sort()

y=[0]*(m-1)
for i in range(m-1):
    y[i]=x[i+1]-x[i]
if n==1:
    print(sum(y))
    exit()
y.sort(reverse=True)
for i in range(n-1):
    y[i]=0
print(sum(y))

Measured memory_bytes: 13968
#include<stdio.h>
long long mod=998244353;
long long fac[1000005];
long long inv(long long b){
	if(b==1)
		return 1;
	return (mod-mod/b)*inv(mod%b)%mod;
}
int main(){
	long long N,A,B;long long K;long long ans=0;
	scanf("%lld%lld%lld%lld",&N,&A,&B,&K);
	fac[0] = 1;
	fac[1] = 1;
	for(int i=2;i <= 3e5+5;i++)
		fac[i] = (fac[i-1]*i)%mod;
	for(int i=0;i<=N;i++){
		if((K-i*A)>=0&&(K-i*A)%B==0&&(K-i*A)/B<=N){
			long long  b=(K-i*A)/B;
			long long tmp1=(fac[N-i]*fac[i])%mod;
			long long tmp2=(fac[N-b]*fac[b])%mod;
			ans=(ans+((fac[N]*inv(tmp1))%mod)*((fac[N]*inv(tmp2))%mod))%mod;
		}
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 4224
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n, t, a := nextInt(), float64(nextInt()), float64(nextInt())
	h := make([]float64, n)

	for i := 0; i < n; i++ {
		h[i] = float64(nextInt())
	}

	nearest := 0
	div := 10000.0
	for i := 0; i < n; i++ {
		temp := t - h[i]*0.006
		if math.Abs(a-temp) < div {
			div = math.Abs(a - temp)
			nearest = i
		}
	}
	fmt.Println(nearest + 1)
}


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

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 3e5 + 5;
ll sum = 0, ans;
int a[N];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    ans = 1e9 * 1ll * 1e9;
    scanf("%d",&n);
    for ( int i = 1; i <= n; i++ ){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    ll csum = 0;
    for ( int i = 1; i <= n - 1; i++ ){
        csum += a[i];
        ans = min( ans, abs( sum - csum - csum ) );
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024