akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
  int val;
  struct Node *prev;
  struct Node *next;
};

struct Node *root = NULL;
struct Node *tail = NULL;

void insert(struct Node **head, int val) {
  struct Node *new = malloc(sizeof(struct Node));

  new->val = val;
  new->next = *head;
  new->prev = NULL;

  if (*head != NULL)
    (*head)->prev = new;
  else {
    root = new;
    tail = new;
  }

  *head = new;
}

void delete(struct Node **head, struct Node *node) {
  if (*head == NULL || node == NULL)
    return;

  if (*head == node)
    *head = node->next;

  if (node->next != NULL)
    node->next->prev = node->prev;
  else
    tail = node->prev;

  if (node->prev != NULL)
    node->prev->next = node->next;

  free(node);

  return;
}

struct Node *find(struct Node **head, int val) {
  if (*head == NULL)
    return NULL;

  struct Node *cur = *head;

  while (cur != NULL) {
    if (cur->val == val)
      return cur;
    cur = cur->next;
  }

  return NULL;
}

void deleteFirst(struct Node **head) {
  if (*head == NULL)
    return;

  delete(head, find(head, (*head)->val));
}

void deleteLast() {
  if (root == NULL || tail == NULL)
    return;

  struct Node *node = tail;

  if (node->prev != NULL) {
    node->prev->next = NULL;
    tail = node->prev;
  } else {
    root = NULL;
  }

  free(node);
}

void printList() {
  if (root == NULL)
    return;

  struct Node *cur = root;

  // print everything in list
  while (cur->next != NULL) {
    printf("%d ", cur->val);
    cur = cur->next;
  }

  if (cur != NULL)
    printf("%d\n", cur->val);
}

int main() {
  int n, i, element;
  char command[15];

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s", &command);

    if (!strcmp(command, "insert")) {
      scanf("%d", &element);
      insert(&root, element);
    } else if (!strcmp(command, "deleteFirst")) {
      deleteFirst(&root);
    } else if (!strcmp(command, "deleteLast")) {
      deleteLast(&root);
    } else if (!strcmp(command, "delete")) {
      scanf("%d", &element);
      delete(&root, find(&root, element));
    }
  }

  printList();
}



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

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	vector<int>x(n);
	for (int i = 0; i < n; i++)cin >> x.at(i);
	ll ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ll dis = x.at(i + 1) - x.at(i);
		ans += min(b, dis * a);
	}
	cout << ans << endl;
	/*
	町を順番に訪れるのが必ず最適かどうか？

	*/


}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	ll N, W;
	cin >> N >> W;
	vector<ll> w(N+1), v(N+1);
	for (int i = 0; i < N; i++)cin >> w[i+1] >> v[i+1];
	vector<vector<ll> > dp(N+1, vector<ll>(100001, INF_LL/4)); //iまでの荷物を入れて価値jになったナップザックの重さ
	dp[0][0] = 0;
	for (int i = 0; i < N; i++)for (int j = 0; j <= 100000; j++) {
		if (dp[i][j] == INF_LL / 4)continue; //ありえない場合は飛ばす
		dp[i + 1][j + v[i + 1]] = min(dp[i][j] + w[i + 1], dp[i + 1][j + v[i + 1]]);
		dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
	}
	int ans = 0;
	for (int j = 0; j <= 100000; j++) {
		if (dp[N][j] <= W)ans = max(ans, j);
	}

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

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

int main(){
  int n,v,p;
  ll m; //n=problem,m=judge,v=voting,p=select
  cin>>n>>m>>v>>p;
  ll vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  ll z;
  sort(vec,vec+n);
  reverse(vec,vec+n);
  if(vec[n-1]+m>=vec[p-1]){
    if(v<=p){
      cout<<n<<endl;
      return 0;
    }
    if(v>p){
      z=0;
      for(int i=p-1;i<n-1;i++){
        z+=vec[n-1]+m-vec[i];
      }
      if(z>=(v-p)*m){
        cout<<n<<endl;
        return 0;
      }
    }
  }
  int ok=p-1,ng=n-1,search;
  for(int query=0;query<20;query++){
    search=(ok+ng)/2;
    if(vec[search]+m<vec[p-1]){
      ng=search;
      continue;
    }
    if(v<=p){
      ok=search;
      continue;
    }
    z=0;
    for(int i=p-1;i<n;i++){
      if(i!=search){
        z+=min(m,vec[search]+m-vec[i]);
      }
    }
    if(z>=(v-p)*m){
      ok=search;
    }
    else{
      ng=search;
    }
  }
  cout<<ok+1<<endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String[] line = br.readLine().split(" ");
        int[] like = new int[N+1];
        like[0] = -1;
        for(int i=1;i<=N;i++) like[i] = Integer.parseInt(line[i-1]);
        int count = 0;
        for(int i=1;i<=N;i++){
        	if(like[like[i]]==i) count++;
        }
        int answer = count/2;
        System.out.println(answer);
    }
}

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

int main(){
  char ch[9];

  for(int i=0; i<3; i++){
    string s;
    cin >> s;
    ch[i*3] = s[0];
    ch[i*3+1] = s[1];
    ch[i*3+2] = s[2];
  }

  cout << ch[0] << ch[4] << ch[8] << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using myui = uint64_t;
using myint = int64_t;

template<typename T>
T diff(const T& a, const T& b) {
    return a > b ? a - b : b - a;
}

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

    {
        myui n;
        string s;
        cin >> n;
        cin >> s;

        myui b = 0, r = 0;
        for(auto& c : s) {
            switch(c) {
                case 'B': b++;break;
                case 'R': r++;break;
            }
        }

        cout << (r > b ? "Yes" : "No") << endl;
    }

    return 0;
}


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

int N, A, B, C, l[8], min_cost = INT_MAX;

int nagasa, cost, use, flag;
void calc(vector<int>& v){
    // 使う竹を全て合成してから伸縮させる
    cost = 0;
    flag = 0;
    for(int i=1;i<=3;i++){
        nagasa = 0;
        use = 0;
        for(int j=0;j<N;j++){
            if(v[j] == i){
                nagasa += l[j];
                use++;
            }
        }
        // 合成にかかるMP
        cost += 10*(use - 1);
        // 無から竹を生成することはできません．．．
        if(use == 0)
            flag = 1;
        // 伸縮にかかるMP
        if(i == 1)
            cost += abs(A - nagasa);
        else if(i == 2)
            cost += abs(B - nagasa);
        else
            cost += abs(C - nagasa);
    }
    if(cost < min_cost && flag == 0)
        min_cost = cost;
}

void dfs(int d, vector<int>& v){
    if(d == N){
        calc(v);
    }else{
        for(int i=0;i<4;i++){
            v.push_back(i);
            dfs(d+1, v);
            v.pop_back();
        }
    }
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i=0;i<N;i++)
        cin >> l[i];
    
    // N本の竹それぞれについて、
    // 0.使わない, 1.Aに使う, 2.Bに使う, 3.Cに使う
    // の4通りで計4^N通り
    vector<int> v;
    dfs(0, v);

    cout << min_cost << endl;
    return 0;
}

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

vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
typedef pair<int, int> P;

vector<vector<int>> d(22, vector<int>(22, -1));
vector<vector<int>> d2(22, vector<int>(22, -1));

int H, W;

//sからスタートして、最遠点までの距離を返す
int bfs(vector<vector<char>> &maze, int sx, int sy) {
	d[sx][sy] = 0;
	queue<P> que;
	que.push(P(sx, sy));

	int res = 0;

	while(que.size()) {
		P p = que.front();
		que.pop();

		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];

			if (nx < 0 || nx >= H || ny < 0 || ny >= W || maze[nx][ny] == '#' || d[nx][ny] != -1) continue;
			que.push(P(nx, ny));
			d[nx][ny] = d[p.first][p.second] + 1;
			res = max(res, d[nx][ny]);
		}
	}
	return res;
}

int main() {
	cin >> H >> W;
	vector<vector<char>> maze(H, vector<char>(W));

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> maze[i][j];
		}
	}
	vector<int> ans;

	for (int sx = 0; sx < H; sx++) {
		for (int sy = 0; sy < W; sy++) {
			if (maze[sx][sy] == '#') continue;
			
			ans.push_back(bfs(maze, sx ,sy));
			d = d2;
				
		}
	}
	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());

	cout << ans[0] << endl;
}

Measured memory_bytes: 256
N=gets.to_i
a=gets.split.map(&:to_i)

h = Hash.new(0)

a.each{|m|
  h[m] += 1
}

ans = []
idx = 0
h.each{|k,v|
  if v>1 then
    ans<<k
    idx+=1
  end
}

ans.sort!.reverse!

if idx>1 then
  if h[ans[0]]>3 then
    puts ans[0]*ans[0]
  else
    puts ans[0]*ans[1]
  end
else
  puts 0
end


Measured memory_bytes: 14988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

int main(){
    int n,cnt=0,sum,num=0;
    cin>>n;
    vi a(n);
    rep(i,n+1)a[i]=0;

    for(int i=1;i<=105;i++){
        num++;
        for(int j=1;j<=105;j++){
            for(int k=1;k<=105;k++){
                
                 sum=pow(i,2)+pow(j,2)+pow(k,2)+i*j+j*k+i*k;
                 if(n>=sum){
                     //cout<<i<<" "<<sum<<endl; 
                     
                    a[sum]+=1;
                 }
            }
        }
    }
    for(int i=1;i<=n;i++)cout<<a[i]<<endl;
}
    


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

struct UnionFind {

	vi data;

	UnionFind(int n = 0) {
		data.assign(n, -1);
	}

	int find(int k) {
		if (data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int k) { return -data[find(k)]; }

};

int main() {

	int n, m;
	cin >> n >> m;
	vi a(n);
	rep(i, n)cin >> a[i];

	UnionFind uf(n);

	rep(i, m) {
		int x, y;
		cin >> x >> y;
		uf.unite(x, y);
	}

	int cnt = 0;
	rep(i, n)if (i == uf.find(i))cnt++;
	if (2 * (cnt - 1) > n) {
		cout << "Impossible" << endl;
		return 0;
	}
	if (cnt == 1) {
		cout << 0 << endl;
		return 0;
	}

	map<int, priority_queue<int, vi, greater<int>>> mp;
	rep(i, n)mp[uf.find(i)].push(a[i]);

	ll ans = 0;
	priority_queue<int, vi, greater<int>> pq;
	for (auto x : mp) {
		ans += x.second.top();x.second.pop();
		while (!x.second.empty()) {
			pq.push(x.second.top());x.second.pop();
		}
	}
	
	rep(i, cnt - 2) {
		ans += pq.top();
		pq.pop();
	}

	cout << ans << endl;

}

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

int main()
{
    int n,x;
    cin >> n >> x;
    int a[n];

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

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

    sort(a, a + n);

    int m;
    m = x / a[0];

    cout << n + m << endl;
}

Measured memory_bytes: 256
/* ABC173 A */

#include<stdio.h>

int main(void){
    int n, output;
    scanf("%d", &n);

    if(n%1000==0) output=0;
    else{
        output = n%1000;
        output = 1000-output;
    }
    printf("%d\n", output);
    return 0;
}


Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '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;}

int main () {
  while (true) {
    int n = in();
    if (n == 0) break;
    double x = 0, m = 0;
    rep(i,n) {
      double s;
      cin >> s;
      x += s*s;
      m += s;
    }
    x /= n;
    m /= n;
    double ans = sqrt(x - m*m);
    cout << fixed << setprecision(10) << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3272
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int N;
int a[100000];
int r[100001];

void solve()
{
	int res = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] <= 100000) {
		   r[a[i]]++;
		} else {
			res++;
		}
	}
	for (int i = 1; i < 100001; i++) {
		if (r[i] < i) {
			res += r[i];
		} else {
			res += r[i] - i;
		}
	}

	cout << res << endl;
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 640
n = int(input())
d = int(input())
p = 10**9+7
if d == 1:
    print(n % p)
    exit()
N = [int(i) for i in list(str(n))]
DP0 = [0] * d
DP1 = [0] * d
DP1[0] += 1
for i in N:
    DP0_ = [0] * d
    DP1_ = [0] * d
    for r in range(d):
        for j in range(i):
            DP0_[r] += DP1[(r-j) % d]
            DP1_[r] += DP1[(r-j) % d]
        DP0_[r] += DP0[(r-i) % d]
        DP1_[r] += DP1[(r-i) % d]
        for j in range(i+1, 10):
            DP0_[r] += DP0[(r-j) % d]
            DP1_[r] += DP0[(r-j) % d]
        DP0_[r], DP1_[r] = DP0_[r] % p, DP1_[r] % p
    DP0, DP1 = DP0_, DP1_
print((DP1[0]-1) % p)


Measured memory_bytes: 44764
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    vector<int> a(4);
    for(int i=0; i<4; i++) cin>>a[i];
    sort(a.begin(), a.end());

    if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 764
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let b = get!(String);
    if b == "A" {
        println!("T");
    } else if b == "T" {
        println!("A");
    } else if b == "C" {
        println!("G");
    } else if b == "G" {
        println!("C");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[a.size() - 1] - a[0];
	return 0;
}

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

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

	  System.out.println(sum);
  }
}



Measured memory_bytes: 38608
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int INF = 0xFFFFFFF;
	static long[][] hash = new long[32][32];
	static long finish;

	public static void main(String[] args) {
		Random rnd = new Random();
		for (int i = 0; i < 32; ++i) {
			for (int j = 0; j < 32; ++j) {
				hash[i][j] = rnd.nextLong();
			}
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 2; j <= 7; ++j) {
				finish ^= hash[i * 8 + j - 1][i * 8 + j];
			}
		}
		int T = sc.nextInt();
		for (int i = 0; i < T; ++i) {
			System.out.println(solve());
		}
	}

	static int solve() {
		ArrayList<Board> cur = new ArrayList<Board>();
		HashSet<Long> hashes = new HashSet<Long>(30000);
		cur.add(new Board());
		if (cur.get(0).h == finish) return 0;
		hashes.add(cur.get(0).h);
		int i = 0;
		for (; !cur.isEmpty(); ++i) {
			ArrayList<Board> next = new ArrayList<Board>(cur.size());
			for (Board b : cur) {
				for (int j = 1; j < 32; ++j) {
					if (b.f[j] == INF && (b.f[j - 1] & 7) != 7) {
						Board created = new Board(b, j);
						if (hashes.contains(created.h)) continue;
						if (created.h == finish) return i + 1;
						hashes.add(created.h);
						next.add(created);
					}
				}
			}
			cur = next;
		}
		return -1;
	}

	static class Board {
		int[] f;
		long h;

		Board() {
			f = new int[32];
			for (int i = 0; i < 4; ++i) {
				for (int j = 1; j <= 7; ++j) {
					int v = sc.nextInt();
					int suit = v / 10 - 1;
					int num = v % 10;
					int card = suit * 8 + num;
					if (num == 1) {
						f[i * 8 + j] = INF;
						f[suit * 8] = card;
					} else {
						f[i * 8 + j] = card;
						h ^= hash[i * 8 + j][card];
					}
				}
			}
		}

		Board(Board orig, int pos) {
			this.f = orig.f.clone();
			this.h = orig.h;
			final int target = orig.f[pos - 1] + 1;
			for (int i = 0; i < 32; ++i) {
				if (orig.f[i] == target) {
					this.f[i] = INF;
					this.h ^= hash[i][target];
					break;
				}
			}
			this.f[pos] = target;
			this.h ^= hash[pos][target];
		}
	}
}

Measured memory_bytes: 90352
N = int(input())
AB = [tuple([int(_) for _ in input().split()]) for i in range(N)]
CD = [tuple([int(_) for _ in input().split()]) for i in range(N)]

AB = sorted(AB, key=lambda x:x[1])
CD = sorted(CD, key=lambda x:x[0])

result = 0

for c, d in CD:
    xs = [x for x in AB if x[0] < c and x[1] < d]
    if xs:
        AB.remove(xs[-1])
        result += 1

print(result)




Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x1, y1, x2, y2, x3, y3, s;
  cin >> s;
  x1 = 0; y1 = 0;
  if(s == 1000000000000000000){
    x2 = 1000000000; y2 = 0;
    x3 = 0; y3 = 1000000000;
  }
  else{
    x2 = 1000000000; y2 = 1;
  x3 = 1000000000 - s % 1000000000; y3 = s / 1000000000 + 1;
  }
  cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e5+10;

struct edge {
  int u, v, i;
};

vector<edge> edges;
vector<edge> adj[N];
bool vis[N];
bool tree[N];
bool deg[N];

void dfs(int u) {
  vis[u] = 1;
  for (const edge& e : adj[u]) {
    if (!vis[e.v]) {
      tree[e.i] = 1;
      dfs(e.v);
    }
  }
}

void dfs2(int u, int p=-1) {
  vis[u] = 1;
  for (const edge& e : adj[u]) {
    if (!vis[e.v]) {
      assert(tree[e.i]);
      dfs2(e.v, u);
    }
  }
  if (p != -1) {
    if (deg[u]) {
      cout << u+1 << " " << p+1 << nl;
    } else {
      cout << p+1 << " " << u+1 << nl;
      deg[p] ^= 1;
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m; cin >> n >> m;
  if (m%2) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int u, v; cin >> u >> v; u--; v--;
    edge e = {u, v, i};
    edges.push_back(e);
    adj[u].push_back(e);
    adj[v].push_back({e.v, e.u, e.i});
  }
  dfs(0);
  for (const edge& e : edges) {
    if (!tree[e.i]) {
      cout << e.u+1 << " " << e.v+1 << nl;
      deg[e.u] ^= 1;
    }
  }
  memset(vis, 0, sizeof vis);
  dfs2(0);
  return 0;
}


Measured memory_bytes: 14772
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int k = scanner.nextInt();
			Set<Integer> set = new TreeSet<>();
			for (int i = a; i < a + k && i <= b; i++) {
				set.add(i);
			}
			for (int i = b; i > b - k && i >= a; i--) {
				set.add(i);
			}
			set.stream().forEach(val -> {
				System.out.println(val);
			});
		}
	}
}


Measured memory_bytes: 28884
#ABC174B

N,D = map(int,input().split())
X = []
Y = []
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

count = 0

for i in range(N):
    if D**2 >= X[i]**2 + Y[i]**2:
        count += 1
print(count)

Measured memory_bytes: 24780
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x,y;
	cin>>x>>y;
	int ans=1;
	while(x<=y)
	{
		x*=2;
		if(x<=y) ans++;
		else  break;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	string s;
	string k;
	cin >> s;
	reverse(s.begin(), s.end());
	int dp[11] = {};
	long long int number[11] = {};
	for (int i = 0; i < s.size(); i++) {
		number[i] = s[i] - '0';
	}

	map<long long int, long long int> sm;
	long long int ans = 0;
	for (int i = 0; i < pow(2, s.size() - 1); i++) {
		for (int j = 0; j < 10; j++) {
			if (dp[j] == 2) {
				dp[j + 1] = dp[j + 1] + 1;
				dp[j] = 0;
			}
		}
		dp[0] = dp[0] + 1;
		long long int sum = 0;
		long long int keta = 1;
		for (int i = 0; i < s.size()-1; i++) {	
			sum = sum + number[i] * keta;
			if (dp[i] == 1) {
				keta = 1;
			}
			else {
				keta = keta * 10;
			}
		}
		sum = sum + number[s.size() - 1] * keta;
		ans = ans + sum;
	}
	cout << ans;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    dp = [1] * N
    for p in range(2, N + 1):
        num = p
        while num < N:
            dp[num] += 1
            num += p
    print(sum(dp[1:]))



if __name__ == "__main__":
    main()


Measured memory_bytes: 88740
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>

#define MAXCHAR 255
#define ll long long

using namespace std;
const ll dividend = 1000000007;
const ll limit = pow(10, 18);

ll funcComb(int n, int k) 
{
	ll output = 1;
	int sum = n + k;
	vector<int> dividends;
	for (int i = 0; i < k; i++)
	{
		dividends.push_back(k - i);
	}
	for (int i = 0; i < k; i++)
	{
		output *= sum - i;
		for (auto it = dividends.begin(); it != dividends.end(); it++)
		{
			if (*it == 0)
				continue;
			if (output % *it == 0)
			{
				output /= *it;
				*it = 0;
			}
		}
		if (output > dividend)
		{
			output %= dividend;
		}
	}

	return output;
}

int main()
{
	int n;
	cin >> n;
	ll output = 1;
	bool overflow = false;
	for (int i = 0; i < n; i++)
	{
		ll number;
		cin >> number;
		if (number == 0)
		{
			output = 0;
			break;
		}
		
		if (output <= limit/number)
		{
			output *= number;
			continue;
		}
		overflow = true;
	}
	if (overflow && output != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	cout << output << endl;
	return 0;

}

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

int main(){
  int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1};//先にデータ入れ
  int x,y;
  cin>>x>>y;
  cout<<(a[x]==a[y]?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b;
  int n=0;
  cin >> a >> b;
  for (long unsigned int i=0;i<a.size();i++) {
    if(a.at(i)!=b.at(i)){
      n++;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 3836
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
int INF=2e+9+1;
int main(){
	int H,W;
	int flag=1;
	char s[52][52];
	scan(H);scan(W);
	for(int i=1;i<=H;i++){
		scanf("%s",s[i]+1);
	}
	rep(i,W+2){
		s[0][i]='.';
		s[H+1][i]='.';
	}
	rep(j,H+2){
		s[j][0]='.';
		s[j][W+1]='.';
	}
	rep1(i,H){
		rep1(j,W){
			if(s[i][j]=='#'&&s[i-1][j]=='.'&&s[i+1][j]=='.'&&s[i][j-1]=='.'&&s[i][j+1]=='.'){
				flag=0;
				break;
			}
		}
		if(flag==0) break;
	}
	if(flag) prin("Yes");
	else prin("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int p[6];
int q[6];

long double f(long double x) {
    long double ret = 0;
    for(int i = 0; i < 6; i++) {
        long double a = x * p[i];
        long double b = (1 - x) * q[i];
        ret += max(a, b);
    }
    return ret / 100;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 0; i < 6; i++) cin >> p[i];
    for(int i = 0; i < 6; i++) cin >> q[i];
    long double ub = 1;
    long double lb = 0;
    for(int _ = 0; _ <= 1e6; _++) {
        long double u1 = (2 * ub + lb) / 3;
        long double l1 = (ub + 2 * lb) / 3;
        if(f(u1) > f(l1)) ub = u1;
        else lb = l1;
    }
    /*
    for(long double x = 0.1; x <= 1.0; x += 0.1) {
        cerr << x << " " << f(x) << endl;
    }
    */
    cout << fixed << setprecision(30) << f(ub) << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

stairs = []
steps = []
MOD = 1000000007

n, m = map(int, input().split())
stairs = {int(input()):True for _ in range(m)}

step = defaultdict(int)
step[0] = 1

for i in range(n):
    if i in stairs.keys():
        step[i] = 0
    else:
        step[i+1] = (step[i] + step[i+1]) % MOD
        step[i+2] = (step[i] + step[i+2]) % MOD

print(step[n])


Measured memory_bytes: 30652
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=(1<<31)-1;
const double pi=acos(-1);

int n,a,b,ab,o;
char t;
string s;

int main(){
	while(cin>>n>>t>>s){
		if(s=="A") a++;
		else if(s=="B") b++;
		else if(s=="AB") ab++;
		else if(s=="O") o++;
	}
	cout<<a<<endl;
	cout<<b<<endl;
	cout<<ab<<endl;
	cout<<o<<endl;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>

using namespace std;

int N, A, B, C;
vector<int> v;

int dfs(int k, int a, int b, int c){
  if(k==N){
    return abs(a-A)+abs(b-B)+abs(c-C)+1e6*(a==0||b==0||c==0);
  }
  int c1 = dfs(k+1, a, b, c);
  int c2 = dfs(k+1, a+v[k], b, c)+(a==0?0:10);
  int c3 = dfs(k+1, a, b+v[k], c)+(b==0?0:10);
  int c4 = dfs(k+1, a, b, c+v[k])+(c==0?0:10);
  return min(c1,min(c2,min(c3,c4)));
}

int main(){
  cin>>N>>A>>B>>C;
  for(int i=0;i<N;i++){
    int l; cin>>l; v.push_back(l);
  }
  int ans = dfs(0,0,0,0);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
r1, c1, r2, c2 = map(int, input().split())
mod = 10**9+7

def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = cmb1(r2+1+c2+1, r2+1, mod)-cmb1(r2+1+c1, c1, mod)-cmb1(r1+c2+1, r1, mod)+cmb1(r1+c1, c1, mod)
print(ans%mod)

Measured memory_bytes: 132908
#include <stdio.h>
 
int main(void)
{
  int A,B;
  scanf("%d %d",&A,&B);
  if(A%3==0 || B%3 == 0||(A+B)%3==0)
  {
    printf("Possible");
  }else{
    printf("Impossible");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    string S;
    ll K;
    cin >> S >> K;
    int oneEnd = 0;
    for (int i = 0; S[i] == '1'; ++i) {
        ++oneEnd;
    }

    char res;
    if (S.size() == 1) res = S[0];
    else if (oneEnd > 0 and K > oneEnd) res = S[min(oneEnd, (int)S.size()-1)];
    else res = S[0];
    
    cout << res << "\n";
}

Measured memory_bytes: 256
class GraphBits
	def initialize(n)
		@n = n
		@bits = 1

		(n-1).times {
			@bits = (@bits << @n + 1) | 1
		}

		@ones = 1
		(n-1).times { @ones = (@ones << @n) | 1 }
		@select_mask = (0..@n-1).map{|i| @ones << i}

		@succ_ones = (1 << @n) - 1

		@pos = {}
		x = 1
		i = 0
		@n.times {
			@pos[x] = i
			x = (x << 1) | 1
			i += 1
		}
	end

	def add_edge(i, j)
		@bits |= (1 << i * @n + j)
		@select_mask[i] |= (@ones << j)
	end

	def del_node(i)
		tmp = @bits & (@ones << i)
		@bits -= tmp
	end

	def select_node(i)
		@bits -= (@bits & @select_mask[i])
	end

	def deleted?(i)
		@bits[i * @n + i] == 0
	end

	def deg_zero?(i)
		tmp = subbits(i)
		tmp & (tmp - 1) == 0
	end

	def deg_one?(i)
		tmp = subbits(i)
		tmp &= (tmp - 1) 
		tmp & (tmp - 1) == 0
	end

	def subbits(i)
		(@bits >> i * @n) & @succ_ones
	end

	def opposite(i)
		tmp = subbits(i)
		tmp -= (1 << i)
		@pos[(tmp ^ (tmp - 1))]
	end

	def next(i)
		tmp = @bits & @diag
		tmp ^= tmp - 1
		@hoge[tmp]
	end

	def inspect
		a = (0..@n-1).map{|i|
				[$name[i], (0..@n-1).select{|j| subbits(i)[j] == 1 }.map{|j| $name[j]}]
			}
		Hash[*a.flatten(1)]
	end

	def hash
		@bits.hash	
	end
end

def search(w, graph, i)
	return w if i >= $weight.size

	return $lower_bound if w + $accum[i] <= $lower_bound

	return search(w, graph, i+1) if graph.deleted?(i)
	
	return search(w + $weight[i], graph, i+1) if graph.deg_zero?(i)

	g = graph.dup
	g.select_node(i)
	x =  search(w + $weight[i], g, i+1)

	y = 0
	g = graph
	if g.deg_one?(i)
		k = g.opposite(i)
		g.select_node(k)
		y = search(w + $weight[k], g, i+1)		
	else
		g.del_node(i)
   		y = search(w, g, i+1)
	end

	ans = x > y ? x : y
	$lower_bound = ans if ans > $lower_bound
	ans
end

loop {
	n = gets.to_i
	break if n == 0

	index = {}
	graph = GraphBits.new(n)
	$weight = Array.new(n)
	$name = Array.new(n)
		
	n.times {
		country, $weight_str, _, *neighbours = gets.split

		i = (index[country] ||= index.size)
		$name[i] = country
		$weight[i] = $weight_str.to_i

		neighbours.each{|neighbour|
			j = (index[neighbour] ||= index.size)
			graph.add_edge(i, j)
		}
	}

	$lower_bound = 0
	#graph.select_node(0)
	$accum = $weight.reverse.inject([0]){|a, w| a + [a[-1] + w]}
	$accum = $accum[1..-1].reverse

	graph.select_node(0)
	p search($weight[0], graph, 1)
}

Measured memory_bytes: 7208
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
int N, M, Q;
signed main() {
    int A, B, N;
    cin >> A >> B >> N;
    if(B - 1 > N) {
        cout << A * N / B << endl;
    } else {
        cout << A - ((A + B - 1) / B) << endl;
    }
}


Measured memory_bytes: 3636
N = int(input())
A = list(map(int,input().split()))

min_four = N//2
four_count = 0
for a in A:
  if a%4==0:
    four_count+=4
  elif a%2==0:
    four_count+=2

if min_four*4 <= four_count:
  print("Yes")
else:
  print("No")

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

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

ll lcm(ll a, ll b){
	return (a/gcd(a, b))*b;
}

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

	ll n;
	cin >> n;

	if(n >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 3688
S = gets.chomp.chars
if S[0] == 'A'
  if S[2..-2].count('C') == 1
    if S.count { |ch| ch.upcase != ch } == S.size - 2
      puts 'AC'
    else
      puts 'WA'
    end
  else
    puts 'WA'
  end
else
  puts 'WA'
end


Measured memory_bytes: 1788
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(s: chars);
    let m = s.len();
    let mut cont = vec![];
    let mut cur = 'R';
    let mut cnt = 1;
    for i in 1..s.len() {
        if cur != s[i] {
            cont.push((cnt, i));
            cnt = 0;
        }
        cur = s[i];
        cnt += 1;
    }
    cont.push((cnt, m));
    let mut ans = vec![0; m];
    for i in 0..cont.len() / 2 {
        let (x, idx) = cont[2 * i];
        let (y, _) = cont[2 * i + 1];
        ans[idx - 1] += y / 2 + x - x / 2;
        ans[idx] = y - y / 2 + x / 2;
    }
    for v in ans {
        puts!("{}\n", v);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10748
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

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

vector<int> a(200010), sum(200010), x(200010);

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
		x[i] = x[i - 1] ^ a[i];
	}

	int l = 1, r = 1;
    ll ans = 0;
	while (l <= n) {
		while (r <= n && (x[r] ^ x[l - 1]) == sum[r] - sum[l - 1]) r++;
		ans += r - l;
		l++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  cout << (N-2)*180 << endl;

  return 0;
}

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

int main() {
	int sum[2] = {0}, num[10] = { 0 }, i, j;
	for (j = 0; j < 2; j++) {
		for (i = 0; i < 10; i++) {
			cin >> num[i];
		}
		sort(num, num + 10);
		sum[j] = num[7] + num[8] + num[9];
	}
	cout << sum[0] << " " << sum[1] << endl;
	return 0;
}

Measured memory_bytes: 3096
import math

N, K = [int(x) for x in input().split()]
As = sorted([int(x) for x in input().split()])
Fs = sorted([int(x) for x in input().split()], reverse=True)

def in_n_sec(n):
  total_training = sum(max(0, a-int(n/f)) for a, f in zip(As, Fs))
  return total_training <= K
  
current_worst_confirmed = 10**12
current_best_possible = 0
while current_worst_confirmed > current_best_possible:
  to_try = (current_worst_confirmed + current_best_possible ) // 2
  if in_n_sec(to_try):
    current_worst_confirmed = to_try
  else:
    current_best_possible = to_try + 1
print(current_worst_confirmed)
    
  


Measured memory_bytes: 122956
package main

import "fmt"

func main() {
	var n, m, l int
	fmt.Scan(&n, &m, &l)
	a := make([][]int, n)
	b := make([][]int, m)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&a[i][j])
		}
	}

	for i := 0; i < m; i++ {
		b[i] = make([]int, l)
		for j := 0; j < l; j++ {
			fmt.Scan(&b[i][j])
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < l; j++ {
			c := 0
			for k := 0; k < m; k++ {
				c += a[i][k] * b[k][j]
			}
			fmt.Print(c)
			if j < l-1 {
				fmt.Print(" ")
			} else {
				fmt.Println()
			}
		}
	}
}



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

typedef long long ll;
const int maxn = 100005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int n, m;
struct edge
{
	int to, next, w;
} e[maxn * 2];
int h[maxn], tot, ecnt, scnt, label;
int vis[maxn], f[3];

inline void add(int u, int v)
{
	e[++tot] = (edge) {v, h[u], 1}; h[u] = tot;
	e[++tot] = (edge) {u, h[v], 2}; h[v] = tot;
}

void dfs(int u, int d)
{
	vis[u] = d; f[d] += 1; ++scnt;
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next) {
		if (e[i].w == 1) ++ecnt;
		if (vis[v] == -1) dfs(v, (d + e[i].w) % 3);
		else if (vis[v] != (vis[u] + e[i].w) % 3) label = 0;
	}
}

int main()
{
	n = gi(); m = gi();
	for (int u, v, i = 1; i <= m; ++i) {
		u = gi(); v = gi();
		add(u, v);
	}

	memset(vis, -1, sizeof(vis));
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (vis[i] == -1) {
			label = 1; f[0] = f[1] = f[2] = 0; scnt = ecnt = 0; dfs(i, 0);
			if (label) {
				if (!min(f[0], min(f[1], f[2]))) ans += ecnt;
				else ans += (ll)f[0] * f[1] + (ll)f[1] * f[2] + (ll)f[2] * f[0];
			} else ans += (ll)scnt * scnt;
		}
	}

	printf("%lld\n", ans);
	
	return 0;
}


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

int N,W;
int v[1000],w[1000];
int dp[101][10001];
int inf = -1;
int infdp = 0;

int dfs(int i,int weight){
    int res;
    if(dp[i][weight] != inf){
        return dp[i][weight];
    }
    else if(i == N){
        res = 0;
    }
    else if(weight < w[i]){
        res = dfs(i+1,weight);
    }
    else{
        res = max(dfs(i,weight-w[i])+v[i],dfs(i+1,weight));
    }
    dp[i][weight] = res;
    return res;
}

int dpsolve(){
    int i=0,j=0;
    for(int i=N-1;i>=0;i--){
        for(int j=0;j<=W;j++){
            if(j < w[i]){
                dp[i][j] = dp[i+1][j];
            }
            else{
                dp[i][j] = max(dp[i][j-w[i]]+v[i],dp[i+1][j]);
            }
        }
    }
    return dp[0][W];
}

int main(){
    cin >> N >> W;
    for(int i=0;i<N;i++){
        cin >> v[i] >> w[i];
    }
    for(int i=0;i<=N;i++){
        for(int j=0;j<=W;j++){
            //dp[i][j] = inf;
            dp[i][j] = infdp;
        }
    }
    int ans;
    //ans = dfs(0,W);
    //cout << ans << endl;
    ans = dpsolve();
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 7052
#include<iostream>
#include<cstdlib>
#define R 3
#define L 3
#define total 9
#define TryCnt 45
using namespace std;

extern inline void down_0(void);
extern inline void up_0(void);
extern inline void right_0(void);
extern inline void left_0(void);

extern int  serch(int x, int y, int MaxCnt, int pre);

int num = 0;
int val[total] ={};


int main( void )
{
  int i = 0;
  int x,y = 0;

  for(i=0; i<total; i++)
    {
      cin>>val[i];
      if(val[i] == 0)
        {
      num = i;
        }
    }

  x = R - (num/L) -1;
  y = L - (num%L) -1;

  for(i=0; i<TryCnt; i++)
    {
      if( serch(x,y,i,4) == 1 )
        {
          cout<<i<<endl;
      break;
        }
    }
  return 0;
}
int serch(int x, int y, int MaxCnt, int pre)
{
  int result;
  int i=0;

  if(MaxCnt < (x + y) )
    {
      return 0;
    }

  if(MaxCnt==0)
    {
      for(i=0; i<total-1; i++)
        if(val[i] != (i+1)) return 0;
      return 1;
    }

 for(i=0; i<4; i++)
    {
      result = 0;
      switch(i)
        {
    case 0:
      if( (x > 0) && (pre != 3) )
        {
          down_0();
          result = serch(x-1, y, MaxCnt-1, 0);
          up_0();
        }
      break;
    case 1:
      if( (y > 0) && (pre != 2) )
        {
          right_0();

          result = serch(x, y-1, MaxCnt-1, 1);

          left_0();
        }
      break;
    case 2:
      if( (y < L -1 ) && (pre != 1) )
        {
          left_0();
          result = serch(x, y+1, MaxCnt-1, 2);
          right_0();
        }
      break;
    case 3:
      if( (x < R -1 ) && (pre != 0) )
        {
          up_0();
          result = serch(x+1, y, MaxCnt-1, 3);
          down_0();
        }
      break;
    default:
      break;
        }
      if(result)
        {
      return 1;
        }
    }

  return 0;
}

inline void down_0()
{
  val[num] = val[num + L];
  num = num + L;
}

inline void up_0()
{
  val[num] = val[num - L];
  num = num - L;
}

inline void right_0()
{
  val[num] = val[num +1];
  num = num + 1;
}

inline void left_0()
{
  val[num] = val[num -1];
  num = num - 1;
}
// 入力例                                                                       

// 1 3 0                                                                        
// 4 2 5                                                                        
// 7 8 6                                                                        

// 出力例                                                                       

// 4                                                                            





Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;

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

    int a[5];
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << i + 1 << '\n';
        }
    }

    fflush(stdout);
    return 0;
}


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

int main(){
	int max1=0,max2=0,max3=0,x,t=0;
	for(int i=0;i<10;i++){
		cin >>x;
		if(x>=max3) max3 = x;
		if(max3>=max2) {t=max3;max3=max2;max2=t;}
		if(max2>=max1) {t=max2;max2=max1;max1=t;}
		}
	cout<<max1<<"\n"<<max2<<"\n"<<max3<<endl;
	return 0;
	}

Measured memory_bytes: 1164