akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 1000 + 5;
const int mo = 1000000007;

LL n, m, k, cnt;
LL row, col;
LL a[3][3], t[3][3], c[3][3];

char s[N][N], ss[N][N];

LL pow(LL a, LL b) {
	LL ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mo;
		a = (a * a) % mo;
		b >>= 1;
	}
	return ans;
}

void QAQa() {
	for (int i = 1; i <= 1; i++)
		for (int j = 1; j <= 2; j++) {
			c[i][j] = 0;
			for (int k = 1; k <= 2; k++) (c[i][j] += a[i][k] * t[k][j]) %= mo;
		}
	for (int i = 1; i <= 1; i++)
		for (int j = 1; j <= 2; j++) a[i][j] = c[i][j];
}

void QAQt() {
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= 2; j++) {
			c[i][j] = 0;
			for (int k = 1; k <= 2; k++) (c[i][j] += t[i][k] * t[k][j]) %= mo;
		}
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= 2; j++) t[i][j] = c[i][j];
}

void pow(LL b) {
	while (b) {
		if (b & 1) QAQa();
		QAQt();
		b >>= 1;
	}
}

int main() {
	read(n), read(m), read(k);
	if (k == 0) while (1);
	for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; i++) if (s[i][1] == '#' && s[i][m] == '#') row++;
	for (int i = 1; i <= m; i++) if (s[1][i] == '#' && s[n][i] == '#') col++;
	if (col && row) {printf("1\n"); return 0;}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) if (s[i][j] == '#') cnt++;
	if (!col && !row) {printf("%lld\n", (pow(cnt, k - 1) + mo) % mo); return 0;}
	if (col) {
		row = col;
		swap(n, m);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				ss[i][j] = s[j][i];
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++) s[i][j] = ss[i][j];
	}
	LL tmp = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j + 1 <= m; j++)
			if (s[i][j] == '#' && s[i][j + 1] == '#') tmp++;
	a[1][1] = 1; a[1][2] = tmp;
	t[1][1] = cnt; t[1][2] = 0;
	t[2][1] = -1; t[2][2] = row;
	pow(k - 1);
	printf("%lld\n", (a[1][1] + mo) % mo);
	return 0;
}

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

struct UnionFind {
	vector<int> par;
	
	UnionFind(int n) : par(n) {
		for (int i = 0; i < n; i++) par[i] = i;
	}
	
	int root(int x) {
		return par[x] == x ? x : par[x] = root(par[x]);
	}
	
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	
	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;
		par[x] = y;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	UnionFind u(n);
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		u.unite(x, y);
	}
	int ans = 0;
	rep(i, n) {
		if (u.same(i, p[i])) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  
  vector<int>q(100000,0);
  for (int i = 0; i < N; i++) {
    if (p.at(i) == i+1){
      q.at(i)++;
    }
  }
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (q.at(i) == 1){
      if (i != N-1 && q.at(i+1) == 1){
        q.at(i+1) = 0;
      }
      count++;
    }
  }
  cout << count << endl;
}
  
  
      
    
  
   

Measured memory_bytes: 3972
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

const int MAX = 1000000;
vector<bool> getPrimeTable(int max)
{
	vector<bool> table(max + 1);
	
	for(int i = 2; i <= max; i++)
	{
		table[i] = true;
		
		for(int j = 2; j * j <= i; j++)
		{
			if(i % j == 0)
			{
				table[i] = false;
				break;
			}
		}
	}
	
	return table;
}

int main()
{
    vector<bool> table(getPrimeTable(MAX));
	
	for(int n; cin >> n && n;)
	{
		int res = table[n - 2];
		
		for(int i = 3; i * 2 <= n; i += 2)
		{
			res += table[i] && table[n - i];
		}
		
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

int main(){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		cout << GCD(a,b) << " " << a/GCD(a,b)*b << endl;
	}
}


Measured memory_bytes: 3220
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long p = sc.nextLong();
		sc.close();

		Map<Long, Integer> soinsu = bunkai(p);
		long ans = 1;
		for (Long l : soinsu.keySet()) {
			long v = soinsu.get(l) / n;
			for (int i = 0; i < v; i++) {
				ans *= l;
			}
		}
		System.out.println(ans);
	}

	static Map<Long, Integer> bunkai(long n) {
		Map<Long, Integer> soinsu = new HashMap<>();
		int end = (int) Math.sqrt(n);
		long d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int ans = 0;
	REP(i, n) {
		int a = i + 1;
		int b = log10(a) + EPS;
		if (b % 2 == 0)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(2**20)

class Node:
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right

d = {} # {id: depth}
def get_all_depth(t, u, p): # (Tree, id, depth)
    d[u] = p
    if t[u].right is not None:
        get_all_depth(t, t[u].right, p)
    if t[u].left is not None:
        get_all_depth(t, t[u].left, p+1)

def return_children(t, u):
    children = []
    c = t[u].left
    while c is not None:
        children.append(c)
        c = t[c].right
    return children

n = int(input())
t = {k: Node(None, None, None) for k in range(n)}
for _ in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0: # 子なし
        continue
    t[tmp[0]].left = tmp[2] # 最も左の子
    t[tmp[2]].parent = tmp[0] # 親
    prev_sib = tmp[2]
    for sib in tmp[3:]:
        t[prev_sib].right = sib # すぐ右の子
        t[sib].parent = tmp[0] # 親
        prev_sib = sib

for node in range(n):
    if t[node].parent is None:
        get_all_depth(t, node, 0)
        break

for node in range(n):
    node_type = "internal node" if t[node].left is not None else "leaf"
    if t[node].parent is None:
        parent = -1
        node_type = "root"
    else:
        parent = t[node].parent
    children = return_children(t, node)
    print(f"node {node}: parent = {parent}, depth = {d[node]}, {node_type}, {children}")


Measured memory_bytes: 141952
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>
//#include "show_vector.hh"


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  string S;
  cin >> S;
  int Ws;
  vector<int> W_vec(0);
  for(int i = 0; i < S.length(); i++){
    if(S[i] == 'W'){
      Ws++;
      W_vec.push_back(i);
    }
  }

  long long int count = 0;
  for(int i = 0; i < Ws; i++){
    count += W_vec[i] - i;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1532
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
ll q, l, r, pri[110000];
int main(void){
    // Your code here!
    cin >> q;
    for (ll i = 3; i < 100001; i++) {
        ll ans = 0;
        for (ll j = 2; j <= sqrt(i); j++) {
            if (i % j == 0) ans++;
        }
        ll a = (i + 1) / 2;
        for (ll j = 2; j <= sqrt(a); j++) {
            if (a % j == 0) ans++;
        }
        pri[i] = pri[i - 1] + (ans == 0 ? 1 : 0);
    }
    for (ll i = 0; i < q; i++) {
        cin >> l >> r;
        cout << pri[r] - pri[l - 1] << endl;
    }
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n - h + 1) * (n - w + 1) << endl;
  return 0;
}

Measured memory_bytes: 3600
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    auto d = stdin.byLine().map!(s=>s.split(",").map!(to!int).array()).array();
    auto dp = d[0].dup;
    foreach(a;d[1..$])
    {
        auto dpn = new int[a.length];
        foreach(i;0..dp.length)
        {
            if(0<=i && i<dpn.length)
                dpn[i]=max(dpn[i],dp[i]+a[i]);
            auto j = i+(dpn.length-dp.length);
            if(0<=j && j<dpn.length)
                dpn[j]=max(dpn[j],dp[i]+a[j]);
        }
        swap(dp,dpn);
    }
    writeln(dp[0]);
}

Measured memory_bytes: 1248
#include <iostream>

int main()
{
    int a{}, b{};
    std::cin >> a >> b;

    long long i = 1, j = 1;
    if (a > b) {
        if (a % b == 0) {
            std::cout << a << std::endl;
            return 0;
        }
        i = a / b;
    } else {
        if (b % a == 0) {
            std::cout << b << std::endl;
            return 0;
        }
        j = b / a;
    }    

    while (i * a != j * b) {
        while (i * a < j * b) {
            i++;
        }
        while (i * a > j * b) {
            j++;
        }

    }
    std::cout << i * a << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <cstdio>
using namespace std;
using ll = long long;

const int inf = 1e9;
const int go_w[] = {1, 0, -1, 0};
const int go_h[] = {0, 1, 0, -1};

int main() {
	int ans;
	int h, w;
	cin >> h >> w;
	int sh, sw, eh, ew;
	cin >> sh >> sw >> eh >> ew;
	sh--; sw--; eh--; ew--;
	vector<string> maze(h);
	deque<pair<int, int>> dq;
	vector<vector<int>> cost(h, vector<int>(w, inf));
	for (int i = 0; i < h; ++i) {
		cin >> maze[i];
	}
	cost[sh][sw] = 0;
	dq.emplace_back(sh, sw);
	while (!dq.empty()) {
		int ci = dq.front().first, cj = dq.front().second;
		dq.pop_front();
		int c = cost[ci][cj];
		for (int i = 0; i < 4; ++i) {
			int mi = ci + go_h[i];
			int mj = cj + go_w[i];
			if (mi < 0 || mi >= h || mj < 0 || mj >= w)
				continue;
			if (maze[mi][mj] == '#')
				continue;
			if (cost[mi][mj] <= c)
				continue;
			cost[mi][mj] = c;
			dq.emplace_front(mi, mj);
		}
		for (int i = -2; i < 3; ++i) {
			for (int j = -2; j < 3; ++j) {
				int mi = ci + i;
				int mj = cj + j;
				if (mi < 0 || mi >= h || mj < 0 || mj >= w)
					continue;
				if (maze[mi][mj] == '#')
					continue;
				if (cost[mi][mj] <= c + 1)
					continue;
				cost[mi][mj] = c + 1;
				dq.emplace_back(mi, mj);
			}
		}
	}
	ans = cost[eh][ew] == inf ? -1 : cost[eh][ew];
	cout << ans << endl;
	return 0;
}


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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    string S; cin >> S;
    
    cout << S.substr(0,3) << endl;
    return 0;
}


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

hmax = max(H)
ans = 0

def calc(H):
  n = 0
  count = 0
  for i in H:
    if i == 0:
      if count != 0:
        n += 1
      count = 0
    else:
      count += 1
  return n

for i in range(hmax):
  H.append(0)
  ans += calc(H)
  del H[-1]
  H = list(map(lambda x: max(0, x - 1), H))

print(ans)

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

ll gcd(ll a,ll b){ //ユークリッドの互除法で最大公約数を求める
  if(b==0) return a;
  return gcd(b,a%b);
}

ll lcm(ll a,ll b){//a*b=lcm(a,b)*gcd(a,b)の関係式からa,bのlcm最小公倍数が求まる。
    ll g=gcd(a,b);
  return a/g*b;
}

int main(){
 ll n;
 cin >> n;
 ll stl=1LL;
 vector<ll> clock(n);
  for(int i=0;i<n;i++){
    ll t;
    cin >> t;

  stl=lcm(t,stl);
}
  cout << (ll)stl << endl;
}

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

int N;
int fid[100010];
int ans[100010];
char S[] = {'S','W'};

void solve()
{
    for(int i = 0; i < 2; i++)
    {
        for(int j = 0; j < 2; j++)
        {
            ans[0] = i;
            ans[1] = j;
            for(int k = 1; k < N + 1; k++)
            {
                if((bool)ans[k] ^ (bool)fid[k])
                {
                    ans[k + 1] = (ans[k - 1] + 1) % 2;
                }
                else
                {
                    ans[k + 1] = ans[k - 1];
                }
            }
            if(ans[0] == ans[N] && ans[1] == ans[N + 1])
            {
                for(int k = 0; k < N; k++)
                {
                    printf("%c",S[ans[k]]);
                }
                printf("\n");
                return;
            }
        }
    }
    printf("-1\n");
    return;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        char s;
        scanf(" %c",&s);
        if(s =='o')
        {
            fid[i] = 0;
        }
        else
        {
            fid[i] = 1;
        }
    }
    fid[N] = fid[0];
    solve();
    return 0;
}


Measured memory_bytes: 1152
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
      Scanner in=new Scanner(System.in);
      // BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=in.nextInt();
       Map<Integer,int[][]>map=new HashMap<>();
       for(int i=0;i<n;i++){
       	int a=in.nextInt();
       	int[][] arr=new int[a][2];
       	for(int j=0;j<a;j++){
       		arr[j]=new int[]{in.nextInt()-1,in.nextInt()};
       	}
       	map.put(i,arr);
       }

       int res=0;
       for(int i=0;i<(1<<n);i++){
       	boolean b=true;
       	for(int j=0;j<n;j++){
       		if((i&1<<j)==0){continue;} // if jth person is not honest
          //else checks if all of his/her testimonials arr true for all honest
          // person then this combination is a valid one update the result
          // we should not check testimonials of unkind person bcz if we do then
          // it will be either true or false..and both are valid bcz he/she is unkind
       		for(int[] t:map.get(j)){
       			if((t[1]==0&&(i&1<<t[0])!=0)||(t[1]==1&&(i&1<<t[0])==0)){
       				b=false;break;
       			}
       		}
       	}
       	if(b){
       			res=Math.max(res,Integer.bitCount(i));
       		}
       }
       out.write(res+"");
       out.flush();
      }
        }
    


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;

int main()
{
    string s,t; int ans=0;
    cin>>s>>t;
    FOR(i,0,s.length()) ans+=s[i]==t[i];
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  long long k;
  cin >> s >> k;
  for(int i = 0; i < min((long long)s.size(), k); i++){
    if(s[i] != '1'){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> C(N - 1), S(N - 1), F(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }

    vector<int> ans(N);
    for (int i = 0; i < N - 1; i++) {
        //iから出発
        int time = S[i];
        for (int j = i; j < N - 1; j++) {
            time += C[j];
            if (j != N - 2) {
                //次の出発時刻
                if (time % F[j + 1] != 0) {
                    time += F[j + 1] - (time % F[j + 1]);
                }
                time = max(S[j + 1], time);
            }
        }
        ans[i] = time;
    }
    ans[N - 1] = 0;

    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <tuple>
#include <vector>
using namespace std;

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

struct node_t {
	shared_ptr<node_t> left_child, right_child;

	inline bool is_leaf() const {
		return left_child == nullptr;
	}

	node_t():left_child(nullptr), right_child(nullptr) {}
};

constexpr int MAX_S = 6;

typedef array<vector<shared_ptr<node_t>>, MAX_S + 1> T_array;
typedef tuple<int, double, double> result;
enum { WEIGHT, LEFT, RIGHT };

T_array init_trees() {
	T_array trees;

	trees[1].emplace_back(shared_ptr<node_t>(new node_t));

	for(int s = 2; s <= 6; ++s) {
		for(int l = 1; l < s; ++l) {
			const int r = s - l;

			for(const auto &p1 : trees[l]) {
				for(const auto &p2 : trees[r]) {
					shared_ptr<node_t> p(new node_t);
					p->left_child = p1;
					p->right_child = p2;
					trees[s].emplace_back(p);
				}
			}
		}
	}

	return trees;
}

result dfs(const shared_ptr<node_t> &node, vector<int>::const_iterator &it) {
	if(node->is_leaf()) {
		const result res(*it, 0.0, 0.0);
		++it;
		return res;
	}

	const auto l_result = dfs(node->left_child, it);
	const auto r_result = dfs(node->right_child, it);

	const int weight = get<WEIGHT>(l_result) + get<WEIGHT>(r_result);

	const double left_pos = -static_cast<double>(get<WEIGHT>(r_result)) / weight;
	const double right_pos = static_cast<double>(get<WEIGHT>(l_result)) / weight;

	const double left = min(get<LEFT>(l_result) + left_pos, get<LEFT>(r_result) + right_pos);
	const double right = max(get<RIGHT>(l_result) + left_pos, get<RIGHT>(r_result) + right_pos);

	return result(weight, left, right);
}

void solve(const T_array &trees) {
	double r;
	int s;
	cin >> r >> s;

	vector<int> w(s);
	for(auto &e : w) cin >> e;

	sort(w.begin(), w.end());

	double ans = -1;
	do {
		for(const auto &root : trees[s]) {
			auto it = w.cbegin();
			const auto tmp = dfs(root, it);
			const double width = get<RIGHT>(tmp) - get<LEFT>(tmp);
			if(width < r) chmax(ans, width);
		}

	} while(next_permutation(w.begin(), w.end()));


	if(ans < 0) {
		cout << "-1" << endl;
	}
	else {
		cout << ans << endl;
	}
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);

	const auto trees = init_trees();

	int T;
	cin >> T;

	while(T--) solve(trees);

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1320
# frozen_string_literal: true

n = gets.to_i
p = gets.split.map(&:to_i)

count = 0
2.upto(n - 1) do |i|
  min = [p[i - 1], p[i - 2], p[i]].min
  max = [p[i - 1], p[i - 2], p[i]].max
  count += 1 if p[i - 1] != min && p[i - 1] != max
end
puts count


Measured memory_bytes: 1788
#include<stdio.h>
#include<stdlib.h>
#define N 100000
#define NIL -1
struct Node{
  int parent;
  int depth;
  int root;
};
struct Node A[N];
int B[N];

void res(int r, int w)
{
  
  B[r] = w;
  if(A[r].root !=NIL) res(A[r].root,w);
  if(A[r].depth != NIL) res(A[r].depth,w+1);
}

void output(int n)
{
  int i,p;
  printf("node %d: parent = %d, depth = %d, ",n,A[n].parent,B[n]);
    if(A[n].parent ==NIL) printf("root, [");
    else if(A[n].depth ==NIL) printf("leaf, [");
    else printf("internal node, [");

    for(i=0, p=A[n].depth; p!=NIL; i++,p=A[p].root){
      if(i)printf(", ");
      printf("%d",p);
    }
    printf("]\n");
}
int main()
{
  int i,j,n,m,l,s,q,r;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    A[i].parent =A[i].depth =A[i].root =NIL;
  }
  for(i=0; i<n; i++){
    scanf("%d",&m);
    scanf("%d",&l);
    
    for(j=0; j<l; j++){
      scanf("%d",&s);
      
      if(j==0)A[m].depth = s;
      else A[q].root =s;
      q = s;
      A[s].parent = m;
    }
  }
  for(i=0; i<n; i++)if(A[i].parent==NIL) r = i;
  res(r, 0);
  for(i=0; i<n; i++) output(i);
    
    return 0;
}



Measured memory_bytes: 6464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

int n,k;
int arr[100005];
bool red[100005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	for (int x=1;x<=n;x++) arr[x]=1;
	red[1]=true;
	
	int a,b;
	while (k--){
		cin>>a>>b;
		arr[a]--;
		arr[b]++;
		if (red[a]) red[b]=true;
		if (arr[a]==0) red[a]=false;
	}
	
	int ans=0;
	for (int x=1;x<=n;x++) if (red[x]) ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 768
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = (1000000000 + 7);

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("file.1", "r", stdin);

  ll n;
  string s;
  cin >> s;
  int i, j;
  ll abc = 0;
  int acnt = 0;
  int flag = 0;
  if (s.size() < 3) {
    cout << 0 << endl;
    return 0;
  }
  i = 0;
  // while (i < s.length() - 1) {
  while (i < s.size() - 1) {
    // cout << i << ":" << abc << ":" << acnt << endl;
    if (s[i] == 'A') {
      acnt++;
      i++;
    } else if (s[i] == 'B' && s[i + 1] == 'C') {
      abc += acnt;
      // acnt = 1;
      i += 2;
    } else if (s[i] != 'A') {
      acnt = 0;
      i++;
    } else {
      i++;
    }
  }
  cout << abc << endl;
  return 0;
}

Measured memory_bytes: 720
def resolve():
    x, y = map(int, input().split())

    g1 = [1, 3, 5, 7, 8, 10, 12]
    g2 = [4, 6, 9, 11]
    g3 = 2

    ans = str()
    if x in g1 and y in g1:
        ans = "Yes"
    elif x in g2 and y in g2:
        ans = "Yes"
    elif x == g3 and y == g3:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
resolve()

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

using namespace std;

#define mod 1000000007

int main()
{
	long long int a, b;
	cin >> a >> b;
	for(int i = 0; i <= 1000; i++){
		if(i * 8 / 100 == a && i * 10 / 100 == b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A;
  int B;
  cin>>A;
  cin>>B;
if (B%2 == 0)
    {
      if (A >= 13)
      {
        cout<< B;
      }
      else if(A <= 12 && A >= 6)
      {
        cout<< B/2;
      }
      else 
      {
        cout<<0;
      } 
    }

}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int my_sort(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(int argc, void **arg)
{
    long long n;
    int a[200000];
    int b[200000];
    long long i, j;

    scanf("%lld", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }

    memcpy(b, a, n*sizeof(int));
    qsort(b, n, sizeof(int), my_sort);

    for (i = 0; i < n; i++)
    {
        if( a[i] != b[0] ) {
            printf("%d\n", b[0]);
        }
        else {
            printf("%d\n", b[1]);
        }
    }

    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
int main(void)
{
	int m, f, r;
	m = f = r = 0;

	scanf("%d %d %d", &m, &f, &r);

	while ((m != -1) || (f != -1) || (r != -1))
	{

		if ((m == -1) || (f == -1))
		{
			printf("F\n");
		}
		else
		{
			if (m + f >= 80)
			{
				printf("A\n");
			}
			if ((m + f < 80) && (m + f >= 65))
			{
				printf("B\n");
			}
			if (((m + f < 65) && (m + f >= 50)) || ((m + f < 50) && (m + f >= 30) && (r >= 50)))
			{
				printf("C\n");
			}
			if ((m + f < 50) && (m + f >= 30) && (r < 50))
			{
				printf("D\n");
			}
			if (m + f < 30)
			{
				printf("F\n");
			}
		}

		scanf("%d %d %d", &m, &f, &r);

	}


	return 0;
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

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

    int n;
    cin >> n;

    vvi b(n, vi(n));
    rep(i, n) {
        rep(j, n) {
            b[i][j] = (i + j) % 2; // 0:black, 1:white
        }
    }

    int K = 0;
    vvi a = b;
    for (int i = 1; i < n; i += 3) {
        rep(j, n) {
            if (a[i][j]) {
                a[i][j] ^= 1;
                K++;
            }
        }
    }

    rep(j, n) {
        if (a[n-1][j]) {
            a[n-1][j] ^= 1;
            K++;
        }
    }

    rep(i, n) {
        if (a[i][0]) {
            a[i][0] ^= 1;
            K++;
        }
    }

    cout << K << endl;
    rep(i, n) {
        rep(j, n) {
            if (b[i][j] && !a[i][j]) {
                cout << j << " " << i << endl;
            }
        }
    }


}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin>>h>>w;
  vector<string> str(50);
  for(int i=0;i<h;++i) cin>>str[i];
  vector<int> x={1,1,1,0,0,-1,-1,-1};
  vector<int> y={1,0,-1,1,-1,1,0,-1};
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(str[i][j]=='#')continue;
      int num=0;
      for(int k=0;k<8;++k){
        int ni=i+x[k];
        int nj=j+y[k];
        if(ni<0||ni>=h)continue;
        if(nj<0||nj>=w)continue;
        if(str[ni][nj]=='#')++num; 
    }
      str[i][j]=num+'0'; 
    }
  }
  for(int i=0;i<h;++i)cout<<str[i]<<endl; 
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        HashMap<Integer, Integer> h = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            h.merge(a, 1, Integer::sum);
        }
        sc.close();
        List<Integer> s = new ArrayList<>(h.values());
        Collections.sort(s);
        int ans = 0;
        for (int i = s.size() - k - 1; i >= 0; i--) {
            ans += s.get(i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 70772
#include<cstdio>
#include<algorithm>
#include<iostream>
#define N 1e9
#define int long long
using namespace std;
const int maxn = 3e5 + 5;
namespace SGT {
	struct node {
		int mn, add, ch[2];
	}t[maxn * 32];
	int cnt, root;
	int Create(int l, int r) {
		return t[++cnt] = (node) {l, 0, 0, 0}, cnt;
	}
	void push_up(int rt, int l, int r) {
		int mid = l + r >> 1;
		if(!t[rt].ch[0]) t[rt].ch[0] = Create(l, mid);
		if(!t[rt].ch[1]) t[rt].ch[1] = Create(mid + 1, r);
		t[rt].mn = min(t[t[rt].ch[0]].mn, t[t[rt].ch[1]].mn);
	}
	void push_down(int rt, int l, int r) {
		if(t[rt].add) {
			int mid = l + r >> 1, *ls = &t[rt].ch[0], *rs = &t[rt].ch[1];
			if(!*ls) *ls = Create(l, mid);
			if(!*rs) *rs = Create(mid + 1, r);
			t[*ls].add += t[rt].add, t[*ls].mn += t[rt].add;
			t[*rs].add += t[rt].add, t[*rs].mn += t[rt].add;
			t[rt].add = 0;
		}
	}
	int Q(int l, int r, int tl, int tr, int & rt = root) {
		if(!rt) rt = Create(tl, tr);
		if(l == tl && r == tr) 
			return t[rt].mn;
		int mid = tl + tr >> 1;
		push_down(rt, tl, tr);
		if(r <= mid) return Q(l, r, tl, mid, t[rt].ch[0]);
		else if(l > mid) return Q(l, r, mid + 1, tr, t[rt].ch[1]);
		else return min(Q(l, mid, tl, mid, t[rt].ch[0]), Q(mid + 1, r, mid + 1, tr, t[rt].ch[1]));
	}
	void add(int l, int r, int tl, int tr, int dt, int & rt = root) {
		if(!rt) rt = Create(tl, tr);
		if(tl == l && tr == r) 
			return t[rt].add += dt, t[rt].mn += dt, void();
		int mid = tl + tr >> 1;
		push_down(rt, tl, tr);
		if(r <= mid) add(l, r, tl, mid, dt, t[rt].ch[0]);
		else if(l > mid) add(l, r, mid + 1, tr, dt, t[rt].ch[1]);
		else add(l, mid, tl, mid, dt, t[rt].ch[0]), add(mid + 1, r, mid + 1, tr, dt, t[rt].ch[1]);
		push_up(rt, tl, tr);
	}
}
int n, a[maxn], ans;
signed main() {
	scanf("%lld", &n);
	for(register int i = 1; i <= n; ++i)
		scanf("%lld", &a[i]);
	for(register int i = 1; i <= n; ++i) {
		ans += SGT :: Q(a[i], N, 0, N) - a[i];
		SGT :: add(0, a[i] - 1, 0, N, 1);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 145152
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    let mut count = vec![0; n];
    for i in 1..=100 {
        for j in 1..=100 {
            for k in 1..=100 {
                let x = i * i + j * j + k * k + i * j + j * k + k * i;
                if x <= n {
                    count[x - 1] += 1;
                }
            }
        }
    }
    for i in 0..n {
        println!("{}", count[i]);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2072
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_L 10000
int main(void)
{

    int N;
    scanf("%d", &N);
    char S[MAX_L];
    scanf("%s", S);
    for (int i = 0; i < strlen(S); i++)
    {
        if(S[i]+N>=65&&S[i]+N<=90){
        S[i] += N;
        }else{
            S[i] += (N-26);
        }
    }
    printf("%s", S);
    return 0;
}

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

int main()
{
  string s,t;
  int ans=0;
  cin >> s >> t;
  for(int i=0; s[i]!='\0';i++){
    if(s[i]!=t[i]) ans++;
  }

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

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

int main() {
    int N, L; cin >> N >> L;
    int A[N+10];
    int ans;

    for(int i=0;i<N;i++){
      A[i]=L+i;
    }

    if(L<=0){
      if(N>abs(L)) {
        for(int i=0;i<N;i++){
          ans+=A[i];
        }
      }
      else{
        for(int i=0;i<N-1;i++){
          ans+=A[i];
        }
      }
    }
    if(L>0){
      for(int i=1;i<N;i++){
        ans+=A[i];
      }
    }
   cout << ans << endl;
   return 0;
 }


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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

  

  cin >> n >> m;
  ans = n * 3 + m;
  cout << ans / 2 << endl;





  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main(){
  int N;
  while(cin>>N && N){
    ll sum = 0;
    REP(i, N){
      int t; cin>>t;
      sum += t;
    }
    vector<int> p(N - 1);
    REP(i, N - 1) cin>>p[i];
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    ll ans = sum * N;
    REP(i, N - 1){
      ll diff = - sum + p[i] * (N - 1 - i);
      if(diff > 0){
        ans += diff;
        sum += p[i];
      }else{
        break;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3284
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            if(NextInt() * NextInt() % 2 != 0) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(long long i=a;i<=(b);++i)
#define dF(i,a,b) for(long long i=a;i>=(b);--i) 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 2e5+10; 
const int N = 1e5+10;
const int E = 1e6+10;  
int n,k,p,h,w;
ll a[maxn];

int main(){
	cin>>n;
	ll ans = 0;
	F(i,1,n){
		ans+= (n-i+2)*(n-i+1)/2;
	}
	ll u,v;
	F(i,1,n-1){
		cin>>u>>v;
		if(u>v) swap(u,v);
		ans-=u*(n-v+1);
	}
	cout<<ans<<endl;
}
/*
6 4
-2 -7 -8 -9 8 2
*/


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> rc(N, 0);
  rep(j, M) {
    int a, b;
    cin >> a >> b;
    rc.at(a-1)++;
    rc.at(b-1)++;
  }
  rep(i, N) {
    cout << rc.at(i) << endl;
  }
}


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

int main(){
    int A, B, ans;
  cin >> A >> B;
  ans = A+B;
  if(ans < A-B) {ans = A-B;
                }
  if(ans < A*B) {ans = A*B;
                }
  cout << ans << endl;
}


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

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

  int res = 0;
  for (int x = 0; x <= k; ++x) {
    for (int y = 0; y <= k; ++y) {
      int num = s - x - y;
      if (0 <= num && num <= k) {
        res++;
      }
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 256
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const n: number = Number(tmp[0]);
    const list: [number, string, number][] = [];
    for (let i = 1; i <= n; ++i) {
      const t: string[] = tmp[i].split(" ");
      list.push([i, t[0], Number(t[1])]);
    }
    list.sort(([n1, s1, p1], [n2, s2, p2]) => s1 < s2 ? -1 :
                                              s1 > s2 ? 1 :
                                              p2 - p1);
    return `${list.map(([i, s, p]) => i).join("\n")}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7500
from math import ceil
n, m = map(int, input().split())

base = (n-m)*100+1900*m
allok = pow(2,m)

"""
1回目はbase秒かかる
2回目の期待値は、1回目の時点から考えるとbase + (allok-1)*y
"""

print(base*allok)



Measured memory_bytes: 8896
#include <bits/stdc++.h>
using namespace std;
 
long long a, b, x;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin >> a >> b >> x;
    long long ans = (b/x) - (max(0LL, a-1)) / x;
    if (a == 0LL) {
    	ans++;
    }
    cout << ans << '\n';
   	
    return 0;
}

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

// @@ !! LIM(sieve)
// --> sieve
// ---- inserted library file sieve.cc

// sieve(upto) returns the list of prime numbers up to upto.
//   Size: upto(1e8).size() ... 5.7e6,  upto(1e9).size() ... 5.1e7
//   Performance: upto(1e8) ... 0.7sec,   upto(1e9) ... 9.2sec
vector<int> sieve(int upto) {
  vector<int> res;
  vector<bool> tbl(upto+1);
  ll lim = (int)(sqrt((double)upto)) + 1;
  for (int x = 2; x <= upto; x++) {
    if (tbl.at(x))  continue;
    res.push_back(x);
    if (x > lim)  continue;
    for (int y = x * 2; y <= upto; y += x) tbl.at(y) = true;
  }
  return res;
}

/*
  Prime Factorization
    Two versions:
      - prfac(n)
      - prfac(n, primes)
 */

vector<pair<ll, int>> prfac(ll n, const vector<int>& primes) {
  //      primes should contain prime numbers at least up to sqrt(n)
  vector<pair<ll, int>> res;
  ll x = n;
  for (ll p : primes) {
    if (x == 1)  break;
    if (p * p > x)  break;
    if (x % p != 0)  continue;
    int c = 1;
    x /= p;
    while (x % p == 0) {
      c += 1;
      x /= p;
    }
    res.push_back(make_pair(p, c));
  }
  if (x != 1)  res.push_back(make_pair(x, 1));
  return res;
}

vector<pair<ll, int>> prfac(ll n) {
  return prfac(n, sieve((int)(sqrt((double)n)) + 1));
}

/*
    List of divisors
      - getDivisors(n)
    Note: the results are NOT sorted
 */

// gdsub ... aux function used in getDivisors()
vector<ll> gdsub(int i, int n, auto fs) {
  if (i == n) { return vector<ll>({1}); }
  auto part = gdsub(i+1, n, fs);
  ll p  = fs.at(i).first;
  int r = fs.at(i).second;
  ll pp = p;    // pp = p^m, for m \in [1, r]
  int partOrigLen = part.size();
  for (int m = 1; m <= r; m++) {
    for (int j = 0; j < partOrigLen; j++) {
      part.push_back(pp * part.at(j));
    }
    pp *= p;
  }
  return part;
}

vector<ll> getDivisors(ll n) {
  auto fs = prfac(n);
  return gdsub(0, fs.size(), fs);
}

// ---- end sieve.cc
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  bool first = true;
  for (ll p : sieve(55555)) {
    if (p % 5 == 1) {
      if (first) first = false;
      else       cout << " ";
      cout << p;
      if (--N == 0) break;
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 3005
using namespace std;

int n,m,s[N],a[N],b[N],dp[N][N],cbn[N][N]; char ch[N];
int main(){
	scanf("%d%d%s",&n,&m,ch+1);
	int i,j,k;
	for (i=1; i<=n; i++) s[i]=s[i-1]+(ch[i]=='1');
	m++; a[1]=b[1]=1;
	for (i=2; i<=m; i++){
		scanf("%d%d",&a[i],&b[i]);
		if (a[i]==a[i-1]){
			b[i-1]=max(b[i-1],b[i]); i--; m--; continue;
		}
		if (b[i]<=b[i-1]){ i--; m--; continue; }
		while (a[i]>b[i-1]+1){
			a[i+1]=a[i]; b[i+1]=b[i];
			a[i]=b[i]=b[i-1]+1;
			i++; m++;
		}
	}
	for (; b[m]<=n; m++) a[m+1]=b[m+1]=b[m]+1;
	dp[0][0]=1;
	for (i=0; i<=n; i++)
		for (j=cbn[i][0]=1; j<=i; j++) cbn[i][j]=(cbn[i-1][j]+cbn[i-1][j-1])%mod;
	for (i=1; i<m; i++){
		for (j=max(a[i+1]-1-b[i]+s[b[i]],0); j<=s[b[i]]; j++)
			for (k=0; k<=a[i+1]-a[i] && k<=j; k++) dp[i][j]=(dp[i][j]+(ll)dp[i-1][j-k]*cbn[a[i+1]-a[i]][k])%mod;
	}
	printf("%d\n",dp[m-1][s[n]]);
	return 0;
}


Measured memory_bytes: 50176
#include<stdio.h>
int main(void)
{
	int W, H, x, y, r;
	
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	
	if(W>=x+r && 0<=x-r && H>=y+r && 0<=y-r){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
} 

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, K, Q;
    scanf("%lld %lld %lld", &N, &K, &Q);
    map<ll, ll> mp;
    ll ans[N];
    REP(int, i, 0, N){
        ans[i] = K - Q;
    }
    for ( ll i = 0; i < Q; i++ ){
        ll A;
        cin >> A;
        mp[A-1]++;
    }
    for ( auto &p : mp ){
        ll s = p.first;
        ll CorNum = p.second;
        ans[ s ] += CorNum;
    }
    REP(int, i, 0, N){
        if ( ans[i] <= 0 ) printf("No\n");
        else printf("Yes\n");
    } 
    return 0;
}

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


int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){cin >> a.at(i);}

  sort( a.begin() , a.end() );

  int ans =0;
  for (int i = 0; i < N; i++){
    if(i%2==0)ans += a[N-1-i];
    else ans -= a[N-1-i];
  }
  cout << ans << endl;
  //cout << a[0] << "/" <<a[N-1] << endl;
}

Measured memory_bytes: 256