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

#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  int N, M;
  long long K;
  cin >> N >> M >> K;

  vector<long long> A(N+1, 0);
  repi(i, 1, N+1) {
    cin >> A[i];
    A[i] += A[i-1];
  }

  vector<long long> B(M+1, 0);
  repi(i, 1, M+1) {
    cin >> B[i];
    B[i] += B[i-1];
  }

  int r = 0, j = M;
  rep(i, N+1) {
    if (A[i] > K) break;
    while (B[j] > K - A[i]) {
      j -= 1;
    }
    // cout << i << " , " << j << endl;
    r = max(i+j, r);
  }

  // rep(i, N) { cout << A[i] << " "; } cout << endl;
  // rep(i, M) { cout << B[i] << " "; } cout << endl;

  cout << r << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 6368
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	a--; b--; c--; d--;
	string s;
	cin >> s;
	bool tmp = false;
	if (d < c) {
		for (int i = b - 1; i <= d - 1; i++) {
			if (i + 2 >= n)break;
			if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
				tmp = true;
				break;
			}
		}
	}
	else {
		tmp = true;
	}
	bool tmp2 = true;
	for (int i = a; i <= c - 1; i++) {
		if (s[i] == '#' && s[i + 1] == '#') {
			tmp2 = false;
		}
	}
	for (int i = b; i <= d - 1; i++) {
		if (s[i] == '#' && s[i + 1] == '#') {
			tmp2 = false;
		}
	}
	Yes(tmp && tmp2);
	return 0;
}

Measured memory_bytes: 640
unittest
{
	assert( [ "3", "2", "1 2", "10", "2", "1 1", "10", "6", "2 3 4 5 6 7", "111000" ].parse.expand.solve == "1\n0\n0" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto t = input.front.to!( long );
	auto asss = new Tuple!( long[], dchar[] )[ t ];
	foreach( ref ass; asss )
	{
		input.popFront;
		input.popFront;
		auto as = input.front.split.to!( long[] );
		input.popFront;
		auto s = input.front.to!( dchar[] );
		ass = tuple( as, s );
	}
	return tuple( asss );
}

auto solve( Tuple!( long[], dchar[] )[] asss )
{
	auto anss = new long[ asss.length ];
	foreach( ref ans, ass; lockstep( anss, asss ) )
	{
		long[] bs;		// 最上位bitが全部違う数の集合
		
		// ゲームの終わりから遡って考える
		foreach_reverse( a, c; lockstep( ass[ 0 ], ass[ 1 ] ) )
		{
			// aの立っているbitをできるだけ下ろす
			foreach( b; bs )
			{
				a = min( a, a ^ b );		// bの最上位bitと同じ位置のaのbitを下ろす
			}
			
			if( a == 0 ) continue;
			
			if( c == '0' )
			{
				// 元のaとa^bではなく、最上位bitがbsのどれとも違う状態にしてからbsに加えることでパターン数を圧縮する
				bs ~= a;
			}
			else
			{
				// このaを使えば、残りのターンを全て使っても絶対 x==0 にできないので結果が確定する
				ans = 1;
				break;
			}
		}
	}
	return anss.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 4508
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Info{

	ll x,y,z;
};

struct Data{
	Data(int arg_index,ll arg_value){
		index = arg_index;
		value = arg_value;
	}
	bool operator<(const struct Data &arg) const{

		return value < arg.value;
	}
	int index;
	ll value;
};

int N,M;
Info info[1005];

int main(){

	scanf("%d %d",&N,&M);

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

		scanf("%lld %lld %lld",&info[i].x,&info[i].y,&info[i].z);
	}

	ll ans = 0;

	vector<Data> V;

	for(int a = -1; a <= 1; a += 2){
		for(int b = -1; b <= 1; b += 2){
			for(int c = -1; c <= 1; c += 2){

				V.clear();
				for(int i = 0; i < N; i++){

					ll tmp = info[i].x*a+info[i].y*b+info[i].z*c;
					//if(tmp <= 0)continue;

					V.push_back(Data(i,tmp));
				}

				sort(V.rbegin(),V.rend());

				ll sum_x = 0,sum_y = 0,sum_z = 0;
				for(int i = 0; i < M; i++){
					if(i == M)break;

					sum_x += info[V[i].index].x;
					sum_y += info[V[i].index].y;
					sum_z += info[V[i].index].z;
				}

				ans = max(ans,abs(sum_x)+abs(sum_y)+abs(sum_z));
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 3840
S = input().strip()
T = input().strip()
k = len(T)
dmin = len(S)
for i in range(len(S)-k+1):
    cnt = 0
    for j in range(k):
        if S[i+j]!=T[j]:
            cnt += 1
    dmin = min(dmin,cnt)
print(dmin)

Measured memory_bytes: 67456
package main

import (
	"fmt"
	"sort"
)

func nextInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func main() {
	n := nextInt()
	k := nextInt()

	ps := make([]pair, n)
	for i := range ps {
		a := nextInt()
		b := nextInt()
		ps[i] = pair{a, b}
	}
	sort.Sort(pairs(ps))

	var ans int
	for k > 0 {
		ans = ps[0].x
		k -= ps[0].y
		ps = ps[1:]
	}
	fmt.Println(ans)
}

type pair struct{ x, y int }
type pairs []pair

func (ps pairs) Len() int           { return len(ps) }
func (ps pairs) Swap(i, j int)      { ps[i], ps[j] = ps[j], ps[i] }
func (ps pairs) Less(i, j int) bool { return ps[i].x < ps[j].x }


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

def f(n):
    if n&1:
        return 3*n+1
    else:
        return n//2

def main():
    s=int(input())
    p=s
    ss={s}
    for i in range(2,1000001):
        n=f(p)
        if n in ss:
            print(i)
            return
        ss.add(n)
        p=n

main()

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

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << "\t|";
  __f(comma + 1, args...);
}
 

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

vector<vector<int>> subsets(vector<int>& nums) {
    int n = nums.size(), p = 1 << n;
    vector<vector<int>> subs(p);
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                subs[i].push_back(nums[j]);
            }
        }
    }
    return subs;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n, k; cin >> m >> n >> k;
    vector<string> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i];
    }
    vector<int> row, col;
    for (int i = 0; i < m; i++) {
        row.push_back(i);
    }
    for (int i = 0; i < n; i++) {
        col.push_back(i);
    }
    vector<vector<int>> rows = subsets(row);
    vector<vector<int>> cols = subsets(col);
    int ans = 0;
    for (auto row : rows) {
        for (auto col : cols) {
            int cnt = 0;
            for (auto i : row) {
                for (auto j : col) {
                    if (v[i][j] == '#') {
                        cnt++;
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000009;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int n;
vector<int> G[100010];
int d1[100010],d2[100010];
void dfs(int i,bool f){
    for(auto e:G[i]){
        if(f){
            if(d1[e]||e==1)continue;
            d1[e]=d1[i]+1;
        }else{
            if(d2[e]||e==n)continue;
            d2[e]=d2[i]+1;
        }
        dfs(e,f);
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1,1);
    dfs(n,0);
    int c1=0;int c2=0;
    for(int i=2;i<n;i++){
        if(d1[i]<=d2[i]){
            c1++;
        }else{
            c2++;
        }
    }
    if(c1>c2){
        cout<<"Fennec"<<endl;
    }else{
        cout<<"Snuke"<<endl;
    }
    return 0;
}


Measured memory_bytes: 11136
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (s.length() % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < s.length() / 2; ++i) {
		if (s[i] != s[i + s.length() / 2]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //aからb - 1まで
#define print(x) cout<<x<<endl  //xを改行付きで出力
#define scan(x) cin>>x //xを入力
const int INF = 1000000007;  //最大値兼MOD
//  cin.tie(0);
//  ios::sync_with_stdio(false);
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
  int a = 0;
  int b = 0;
  string s;
  while(1){
    cin>>a>>s>>b;
    if(s == "?")break;
    else if(s == "+")cout<<a+b<<endl;
    else if(s == "-")cout<<a-b<<endl;
    else if(s == "*")cout<<a*b<<endl;
    else cout<<a / b<<endl;
  }
  return 0;
}


Measured memory_bytes: 3124
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    rep(i, n) {
        int a; cin >> a;
        mp[a]++;
    }
    ll ans = 0;
    for (auto p : mp) {
        if (p.second >= p.first) ans += p.second - p.first;
        else ans += p.second;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n;cin>>n;
    ll ans=0;
    for(ll i=1;i*i<=n;i++){
        if(n%i)continue;

        ll m = (n/i)-1;
        if(m>i)ans+=m;
    }
    cout<<ans;
}





Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
	int x,y=1,z;

	while(1){
	   scanf("%d %d\n", &x, &y);
	   if ( x==0 && y==0 ){break;}

	   else if ( x > y )
		printf("%d %d\n",y ,x);
	   else 
		printf("%d %d\n",x ,y);
	   }

	return 0;
}


Measured memory_bytes: 2104
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let mut v: Vec<_> = (0..n)
        .map(|_| (sc.read::<f64>(), sc.read::<f64>()))
        .collect();
    v.sort_by(|&(x1, y1), &(x2, y2)| y1.atan2(x1).partial_cmp(&y2.atan2(x2)).unwrap());
    let tmp = v.clone();
    v.extend(tmp);

    let mut ans = 0.0;
    for head in 0..n {
        for tail in head..(head + n) {
            let (x, y) = (head..(tail + 1))
                .map(|i| v[i])
                .fold((0.0, 0.0), |(x, y), (vx, vy)| (x + vx, y + vy));
            update_max(&mut ans, x * x + y * y);
        }
    }
    println!("{}", ans.sqrt());
}

fn update_max<T: PartialOrd>(a: &mut T, b: T) {
    if *a < b {
        *a = b;
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4732
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n, T = map(int, input().split())
cost = False
for i in range(n):
    c, t = map(int, input().split())
    if t > T:
        pass
    else:
        if cost == False:
            cost = c
        else:
            if cost > c:
                cost = c
if cost == False:
    print("TLE")
else:
    print(cost)

Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int arr[100001];

int calAbsoluteValue(int x)
{
	if(x >= 0)
	{
		return x;
	}
	else
	{
		return -x;
	}
}

int calDis(int x,int y)
{
	if(x > 0 && y > 0)
	{
		return x > y ? x : y;
	}
	else if(x < 0 && y < 0)
	{
		return x < y ? -x : -y;
	}
	else
	{
		int a = calAbsoluteValue(x);
		int b = calAbsoluteValue(y);
		if(a < b)
		{
			return  2 * a + b;
		}
		else
		{
			return 2 * b + a;
		}
	}
}

int main() {

	int N,K;

	cin >> N >> K;

	int nIndex = 0;
	for(int i = 0; i < N; ++i)
	{
		cin >> arr[i];

		if(arr[i] <= 0)
		{
			nIndex = i;
		}
	}

	int nResult = -1;

	if(nIndex <= K)
	{
		if(arr[nIndex] < 0)
		{
			nResult = calDis(arr[0],arr[K - 1]);
			for(int i = 1; i <= nIndex + 1; ++i)
			{
				if(i + K <= N)
				{
					int nTemp = calDis(arr[i],arr[K - 1 + i]);
					if(nTemp < nResult)
					{
						nResult = nTemp;
					}
				}
			}
		}
		else
		{
			nResult = calDis(arr[0],arr[K - 1]);
			for(int i = 1; i <= nIndex; ++i)
			{
				if(i + K <= N)
				{
					int nTemp = calDis(arr[i],arr[K - 1 + i]);
					if(nTemp < nResult)
					{
						nResult = nTemp;
					}
				}
			}
		}


	}
	else
	{
		if(arr[nIndex] < 0)
		{
			nResult = calDis(arr[nIndex + 1 - K],arr[nIndex]);
			for(int i = nIndex - K + 2; i <= nIndex + 1; ++i)
			{
				if(i + K <= N)
				{
					int nTemp = calDis(arr[i],arr[K - 1 + i]);
					if(nTemp < nResult)
					{
						nResult = nTemp;
					}
				}
			}
		}
		else
		{
			nResult = calDis(arr[nIndex + 1 - K],arr[nIndex]);
			for(int i = nIndex - K + 2; i <= nIndex; ++i)
			{
				if(i + K <= N)
				{
					int nTemp = calDis(arr[i],arr[K - 1 + i]);
					if(nTemp < nResult)
					{
						nResult = nTemp;
					}
				}
			}
		}

	}

	cout << nResult << endl;

	return 0;
}

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

struct Node {
    int key;
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(com[0] == 'f') {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        } else if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


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

long long mod;

template<typename T>
struct rerooting {
	struct rr_edge {
		long long from;
		long long to;
		long long weight;
		T dp;
		long long reverse_idx;
	};

	long long n;
	std::vector<std::vector<rr_edge>> adj_list;
	std::vector<std::vector<T>> left_sum;
	std::vector<std::vector<T>> right_sum;
	std::vector<T> dp;
	T id_e = 1;

	rerooting(long long n) : n(n) {
		adj_list.resize(n);
		left_sum.resize(n);
		right_sum.resize(n);
		dp.resize(n, id_e);
	}

	void make_egde(long long s, long long t, long long w) {
		adj_list[s].push_back({s, t, w, id_e, (long long)adj_list[t].size()});
		adj_list[t].push_back({t, s, w, id_e, (long long)adj_list[s].size() - 1});
	}

	void calculate() {
		dfs1(-1, 0, -1);
		dfs2(-1, 0, -1);
	}

	T f(T t, long long prev, long long idx) {
		if (prev == -1) return t;
		else return (t + 1) % mod;
	}

	T merge(T a, T b) {
		return a * b % mod;
	}

	void make_sum(long long now) {
		long long m = adj_list[now].size();
		left_sum[now].resize(m + 1, id_e);
		right_sum[now].resize(m + 1, id_e);
		for (long long i = 0; i < m; i++) {
			left_sum[now][i + 1] = merge(left_sum[now][i], adj_list[now][i].dp);
		}
		for (long long i = m - 1; i >= 0; i--) {
			right_sum[now][i] = merge(right_sum[now][i + 1], adj_list[now][i].dp);
		}
	}

	void dfs1(long long prev, long long now, long long idx) {
		long long ans = id_e;
		for (long long i = 0; i < adj_list[now].size(); i++) {
			if (adj_list[now][i].to == prev) continue;
			dfs1(now, adj_list[now][i].to, i);
			ans = merge(ans, adj_list[now][i].dp);
		}
		if (now == 0) {
			make_sum(0);
			dp[0] = f(ans, prev, idx);
		} else adj_list[prev][idx].dp = f(ans, prev, idx);
	}

	void dfs2(long long prev, long long now, long long idx) {
		if (now > 0) {
			adj_list[now][adj_list[prev][idx].reverse_idx].dp = f(
				merge(
					left_sum[prev][idx],
					right_sum[prev][idx + 1]
				),
				now,
				adj_list[prev][idx].reverse_idx
			);
			make_sum(now);
			dp[now] = f(left_sum[now].back(), -1, -1);
		}
		for (long long i = 0; i < adj_list[now].size(); i++) {
			if (adj_list[now][i].to == prev) continue;
			dfs2(now, adj_list[now][i].to, i);
		}
	}
};

int main() {
	long long n;
	std::cin >> n >> mod;
	rerooting<long long> rr(n);
	for (long long i = 0; i < n - 1; i++) {
		long long s, t;
		std::cin >> s >> t;
		s--; t--;
		rr.make_egde(s, t, 1);
	}

	rr.calculate();
	for (auto i : rr.dp) std::cout << i << std::endl;
}

Measured memory_bytes: 32744
#include <iostream>
#include <cmath>
using namespace std;
int main () {
    int a[5], ans=0, mini=10, k=0;
    for (int i=0; i<5; i++) {
        cin>>a[i];
        if (a[i]%10<mini && a[i]%10!=0) mini=a[i]%10, k=i; 
    }
    for (int i=0; i<5; i++) {
        if (i!=k) {
            ans+=ceil(0.1*a[i])*10;
        }
    }
    cout<<ans+a[k]<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    vector<int> v;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    
    sort(v.begin(), v.end());
    
    
    double ans = 0.0;
    for (int i = 1; i < N; i++) {
        if (i == 1) {
            ans = (v[0] + v[i]) * 0.5;
            continue;
        }
        
        ans = (ans + v[i]) * 0.5;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

bool NG(string s, string t){
    map<char,int>mp1,mp2;
    rep(i,s.size())mp1[s[i]]++;
    rep(i,t.size())mp2[t[i]]++;
    for(auto&p:mp2){
        if(mp1[p.first]==0)return true;
    }
    return false;
}

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    if(NG(s,t)){cout<<-1<<endl; return 0;}
    s+=s;
    ll ans=0;
    rep(i,t.size()){
        string x=s.substr(ans%n);
        int next=x.find(t[i]);
        ans+=next+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3904
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

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

    if (S[0] == '7' || S[1] == '7' || S[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
package main

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

func main() {
	fmt.Println(resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	n, k := scanInt(sc), scanInt(sc)
	sum := 0
	for i := 0; i < n; i++ {
		x := scanInt(sc)
		sum += 2 * min(x, k-x)
	}
	return sum
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

//繰り返し二乗法
ll EX(ll x,ll n){
    if(n == 0) return 1;
    else if(n%2 == 1) return EX(x,n-1)*x%mod;
    else return EX(x*x%mod,n/2)%mod;
}

vector<bool> prime_flag;
//エストラテネスのなんとか
void flag_prime(ll max){
    if(max +1 > prime_flag.size()) prime_flag.resize(max+1,true);
    prime_flag[0] = false;
    prime_flag[1] = false;
    for(int i = 2; i*i < max+1; i++){
        if(prime_flag[i]){
            for(int j = 2; i*j < max+1; j++) prime_flag[i*j] = false;
        }
    }
}

vector<int> prime_num;
void num_prime(int max){
    for(int i = 0; i < max+1; i++){
        if(prime_flag[i]) prime_num.push_back(i);
    }
}

int main(){
    ll n,k;
    cin >> n >> k;
    map<ll,ll> mp;
    flag_prime(k+1);
    num_prime(k+1);
    for(int i = 1; i <= k; i++){
        mp[i] = EX(k/i,n);
    }
    ll ans = 0;
    for(int i = k; i >= 1; i--){
        for(int j = i*2; j <= k; j += i){
            mp[i] += -mp[j];
        }
    }
    for(int i = 1; i <= k; i++){
        ans += mp[i]*i;
        ans %= mod;
    }
    cout << (ans+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 9844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	ll m = min({a, b, c, d, e});
	cout << (n + m - 1) / m + 4 << endl;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,X;
  cin>>N>>X;
  vector<int>L(N);
  for(int i=0;i<N;i++)cin>>L[i];
  int now=0;
  int c=1;
  for(int i=0;i<N;i++){
    now+=L[i];
    if(now>X)break;
    c++;
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int K, S;
    int count = 0;

    cin >> K >> S;

    //cout << "K = " << K << ", S = " << S << endl;

    for(int X = 0; X <= K; X++){
        for(int Y = 0; Y <= K; Y++){
    //      cout << "X = " << X << ", Y = " << Y << endl;
            if(0 <= (S - X - Y) && (S - X - Y) <= K){
    //          cout << "OK : X = " << X << ", Y = " << Y << endl;
                count++;
            }
        }
    }

    cout << count;

    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

n1, n2, n4 = 0, 0, 0
for i in a:
    if i%4==0:
        n4 += 1
    elif i%2==0:
        n2 += 1
    else:
        n1 += 1

if n2==0:
    if n1-1 <= n4:
        print('Yes')
    else:
        print('No')
else:
    if n1 <= n4:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14252
#include<stdio.h>

int main(){
	int p,q,r;
	int ac=0,ab=0,bc=0;
	int fast=0;

	scanf("%d" "%d" "%d",&p,&q,&r);
	ab=p+q;
	ac=p+r;
	if(ac>ab){
	fast=ab;
    }else{
	fast=ac;
    }
	bc=q+r;
	if(bc>fast){
	fast=fast;
    }else{
	fast=bc;
    }
	printf("%d\n",fast);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>
#include <bitset>

using namespace std;
int main()
{

    ///vector<int> A(N);
    /*
    double A, B, K, restA, restB;
    cin >> A;
    cin >> B;
    cin >> K;

    if (K <= A)
    {
        restA = A - K;
        restB = B;
    }
    else if (K <= A+B)
    {
        restA = 0;
        restB = B + (A - K);
    }
    else
    {
        restA = 0;
        restB = 0;
    }

    if (restA < 0)
    {
        restA = 0;
    }
    if (restB < 0)
    {
        restB = 0;
    }



    cout << restA << " " << restB;
    return 0;
    */

    int N ,heal=0;
    int ans = 0;
    cin >> N;
    vector<int> d(N);

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

    for (int j = 0;  j < N;  j++)
    {
        for (int k = j+1; k < N; k++)
        {
            heal = heal + d[j] * d[k];
        }
    }


    cout << heal;
    return 0;

}

Measured memory_bytes: 256
def insertion_sort(A, N, gap):
    global cnt
    for i in range(gap, N):
        tmp = A[i]
        j = i - gap
        while j>=0 and A[j] > tmp:
            A[j+gap] = A[j]
            j = j - gap
            cnt += 1
        A[j+gap] = tmp

def shell_sort(A, N):
    gaps = [int((3**item-1)/2) for item in range(1, 100) if int((3**item-1)/2) <= N][::-1]
    m = len(gaps)
    for gap in gaps:
        insertion_sort(A, N, gap)
    print(m)
    print(' '.join([str(gap) for gap in gaps]))
    print(cnt)
    print('\n'.join([str(item) for item in A]))

cnt = 0
N = int(input())
A = [int(input()) for i in range(N)]

shell_sort(A, N)

Measured memory_bytes: 127956
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
typedef tuple<LL, LL, LL> TP;  // AxF, A, F

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

LL N, K;
vector<TP> v;

bool check(LL x) {
  LL cnt = 0;
  for (auto [X, A, F] : v) {
    double d = max(X - x, 0LL);
    cnt += ceil(d/F);
  }
  if (cnt <= K) return true;
  else          return false;
}

int main() {
  cin >> N >> K;
  vector<LL> A(N), F(N); cin >> A >> F;
  sort(A.rbegin(), A.rend());
  sort(F.begin(), F.end());
  LL sum = 0;
  for (int i = 0; i < N; ++i) {
    sum += A[i];
    v.push_back({A[i]*F[i], A[i], F[i]});
  }
  if (sum <= K) {
    cout << 0 << endl;
    return 0;
  }

  LL ok = 1e18, ng = 0;
  while(abs(ok-ng)>1) {
    LL mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else            ng = mid;
  }
  cout << ok << endl;
}


Measured memory_bytes: 12704
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let N = Number(xs[0]);
   let s = xs[1].split('');
   let count = 0;
   for(let i=0; i<N; i++){
      if(s[i]=='R'){
         count++
      }
   }
   if(count>N-count){
      console.log('Yes');
   }else{
   console.log('No');
   }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <map>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

int main() {
    map<string, int> str;

    int n;
    cin >> n;
    REP(i, n) {
        string s;
        cin >> s;
        str.insert(make_pair(s, 0));
        str[s]++;
    }

    int m;
    cin >> m;
    REP(i, m) {
        string t;
        cin >> t;
        str.insert(make_pair(t, 0));
        str[t]--;
    }

    int ans = 0;
    for (auto i : str)
        chmax(ans, i.second);

    if (ans < 0) cout << 0 << '\n';
    else cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; ll K;
ll A[505], sum;
vector <ll> P;

int Prepare(){
  scanf("%d%lld", &N, &K);
  for (int i = 0; i < N; i++){
    scanf("%lld", A + i);
    sum += A[i];
  }
  for (ll i = 1; i * i <= sum; i++){
    if (sum % i != 0) continue;
    P.push_back(i); P.push_back(sum / i);
  }
  sort(P.begin(), P.end());
  return 0;
}

ll ans = 0, now[int(500)];
int Solve(ll num){
  ll cnt = 0;
  for (int i = 0; i < N; i++) now[i] = A[i] % num;
  sort(now, now + N);

  int R = N - 1;
  for (int i = 0; i < N; i++){
    if (now[i] % num == 0) continue;
    cnt += now[i];

    while (now[i] > 0){
      if (now[i] + now[R] >= num){
        now[i] -= num - now[R];
        now[R] = num;
        R--;
      }else{
        now[R] += now[i]; now[i] = 0;
      }
    }
  }

  if (cnt <= K) ans = max(ans, num);

  return 0;
}

int main(){
  Prepare();
  for (int i = 0; i < P.size(); i++) Solve(P[i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3748
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912;
double a,b,x;
int main()
{
	cout<<setprecision(10);
	cin>>a>>b>>x;
	double d=(a*a*b)/2;
	if(d>x)
	{
		double t=(a*b*b)/(2*x);
		cout<<(180*atan(t)/PI);
	}
	else
	{
		double t=(2*(a*a*b-x))/(a*a*a);
		cout<<180*atan(t)/PI<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
<?php

fscanf(STDIN, "%s", $S);
$n = strlen($S);

$r = 0;
$b = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($S[$i] == 0) ++$r;
    if ($S[$i] == 1) ++$b;
}

echo 2 * min($r, $b);


Measured memory_bytes: 4856
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Integer> bottom = new ArrayList<Integer>();
        
        while (scanner.hasNext()) {
            int car = scanner.nextInt();
            
            if (car == 0) {
                int exitCar = bottom.get(bottom.size()-1);
                System.out.println(exitCar);
                bottom.remove(bottom.size()-1);
            } else {
                bottom.add(car);
            }
        }
    }
}

Measured memory_bytes: 17216
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    a, b, c, d = intin()

    if abs(a - c) <= d:
        print('Yes')
        return
    if abs(a - b) <= d and abs(c - b) <= d:
        print('Yes')
        return

    print('No')


if __name__ == '__main__':
    main()


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

using namespace std;

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

    int N, W;
    cin >> N >> W;
    int v[N], w[N];
    for (int i = 0; i < N; ++i) {
        cin >> v[i] >> w[i];
    }

    int dp[W + 1];
    memset(dp, 0, sizeof(dp));

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

    cout << dp[W] << '\n';

    return 0;
}



Measured memory_bytes: 3220
using System;

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

            var  str = Console.ReadLine().Split(' ');
            var a = int.Parse( str[0]);
            var b = int.Parse(str[1]);

            Console.WriteLine(a - ((b < a) ? 1 : 0));
        }
    }
}


Measured memory_bytes: 11092
import pprint
import itertools

N, M = [int(s) for s in input().split()]

AB = []
for i in range(N):
    AB.append(tuple([int(s) for s in input().split()]))

CD = []
for j in range(M):
    CD.append(tuple([int(s) for s in input().split()]))

for i in range(N):
    mi = 0
    di = abs(CD[0][0] - AB[i][0]) + abs(CD[0][1] - AB[i][1])
    for j in range(1, M):
        md = abs(CD[j][0] - AB[i][0]) + abs(CD[j][1] - AB[i][1])
        if md < di:
            mi, di = j, md
    print(mi + 1)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V, string sep = " ", string end_ = "endl") {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << sep;
    }
    if(end_ == "endl")
        cout << endl;
    else
        cout << end_;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << (N % 2 ? (N - 1) * (N - 1) / 2 : N * (N - 2) / 2) << "\n";
    int M = N % 2 ? N - 1 : N;
    for(int i = 1; i < M; i++) {
        for(int j = i + 1; j <= M; j++) {
            if(i + j != M + 1) cout << i << " " << j << "\n";
        }
    }
    if(M != N) {
        rep(i, 1, N) cout << i << " " << N << "\n";
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    unsigned int i;
    int data_set;
    int a[3];
    
    scanf("%d",&data_set);
    
    for(i=0;i<data_set;i++)
    {
        scanf("%d%d%d",&a[0],&a[1],&a[2]);
        
        if(a[0]*a[0] == a[1]*a[1] + a[2]*a[2])
        {
            printf("YES\n");
        }
        else if(a[1]*a[1] == a[0]*a[0] + a[2]*a[2])
        {
            printf("YES\n");
        }
        else if(a[2]*a[2] == a[0]*a[0] + a[1]*a[1])
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");            
        }
    }
    
    return 0;
}

Measured memory_bytes: 580
def main():
    n = int(input())
    s = input()
    east = [0 for _ in range(n)]
    west = [0 for _ in range(n)]
    if s[0] == "E":
        east[0] = 1
    else:
        west[0] = 1
    for i in range(1, n):
        east[i] = east[i - 1]
        west[i] = west[i - 1]
        if s[i] == "E":
            east[i] += 1
        else:
            west[i] += 1
    answer = east[-1] - east[0]
    for i in range(1, n):
        answer = min(answer, west[i - 1] + east[-1] - east[i])
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 17996
#set
s_arr = gets.chomp.split("")
s_length = s_arr.length
count = 0

#main
0.upto((s_length - 1) / 2) do |i|
  count += 1 if s_arr[i] != s_arr[s_length - 1 - i]
end

print ("#{count}\n")

Measured memory_bytes: 3836
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<vector>
using std::vector;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define reg register
typedef long long ll;
inline int read(){
    reg int x=0,f=1;reg char ch=getchar();
    for(;!isdigit(ch);f=ch=='-'?-1:1,ch=getchar());
    for(;isdigit(ch);x=x*10+(ch^48),ch=getchar());
    return x*f;
}
const int MN=1e5+5;
int n,m;
class UFset{
	public:
		int par[MN];
		inline int find(int x){return x==par[x]?x:par[x]=find(par[x]);}
		inline void init(int x){for(reg int i=0;i<x;i++)par[i]=i;}
		inline void unite(int x,int y){x=find(x);y=find(y);par[y]=x;}
		inline bool isfa(int x){return find(x)==x;}
}S;
int v[MN],cnt,id[MN],a[MN];
vector<int>pts[MN];
int main(){
	n=read();m=read();S.init(n);if(n==m+1)return 0*puts("0");
	for(reg int i=0;i<n;i++)v[i]=read();
	for(reg int i=1;i<=m;i++)S.unite(read(),read());
	for(reg int i=0;i<n;i++)if(S.isfa(i))id[i]=++cnt,pts[cnt].push_back(v[i]);
	for(reg int i=0;i<n;i++)if(!S.isfa(i))pts[id[S.find(i)]].push_back(v[i]);
	if(n<((cnt-1)<<1))return 0*puts("Impossible");
	for(reg int i=1;i<=cnt;i++)std::sort(pts[i].begin(),pts[i].end());
	reg ll ans=0;reg int tot=0;
	for(reg int i=1;i<=cnt;i++)ans+=pts[i][0];
	for(reg int i=1;i<=cnt;i++)for(reg int j=1;j<pts[i].size();j++)a[++tot]=pts[i][j];
	std::sort(a+1,a+1+tot);
	for(reg int i=1;i<=cnt-2;i++)ans+=a[i];
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 6912
N,M,*abs=$<.read.split.map(&:to_i)

def build(abs,x,y)
    h = {}
    abs.each_slice(2) do |a,b|
        next if a == x && b == y
        h[a] ||= []
        h[a] << b
        h[b] ||= []
        h[b] << a
    end
    h
end

def check(abs,a,b)
    h = build(abs,a,b)
    visited = {}
    q = h[a].dup || []
    until q.empty?
        x = q.shift
        next if visited[x]
        visited[x] = true
        if x == b
            return true
        end
        q += h[x] || []
    end

    false
end

count = 0
abs.each_slice(2) do |a,b|
    count += 1 unless check(abs,a,b)
end
puts count

Measured memory_bytes: 14344
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
const int twx=+100;
const int inf=0x7fffffff;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n;
int ans;
string s;
void init()
{
	n=read();
    cin>>s;
    f1(0,n-1,i)
    {
        if(s[i]!=s[i+1])
        {
            ans++;
        }
    }
    printf("%d\n",ans);
}
void work()
{
	
}
void print()
{
	
}
int main()
{
    init();
	return 0;
}

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

int main() {
	int n,k;
	cin >> n >> k;
	vector<long long> a(n-1);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n-k;i++){
		if(a[i]<a[i+k]) cout << "Yes" << endl;
		else cout << "No" <<endl;
	}
}

Measured memory_bytes: 4840
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int N; cin >> N;
	vector<int>d(N);
	for (int i = 0; i < N; ++i)cin >> d[i];
	sort(d.begin(), d.end());
	int key = INF;
	for (int i = 0; i < N; ++i) {
		if (lower_bound(d.begin(), d.end(), d[i]) - d.begin() == N / 2) {
			key = i;
			break;
		}
	}
	if (key == INF) {
		cout << 0 << endl;
	}
	else {
		cout << d[key] - d[key - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>

int P[10000];

void init(int N)
{
    for (int i = 0; i < N; i++)
    {
        P[i] = i;
    }
}

int root(int a)
{
    if (P[a] == a)
    {
        return a;
    }
    else
    {
        return (P[a] = root(P[a]));
    }
}

bool is_same_set(int a, int b)
{
    return root(a) == root(b);
}

void unite(int a, int b)
{
    P[root(a)] = root(b);
}

int main()
{
    int n, weight = 0;
    std::cin >> n;
    init(n);
    std::vector<std::tuple<int, int, int>> edge;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int a;
            std::cin >> a;
            if (j >= i + 1 && a != -1)
            {
                edge.push_back(std::make_tuple(a, i + 1, j + 1));
            }
        }
    }
    sort(edge.begin(), edge.end());
    for (int i = 0; i < edge.size(); i++)
    {
        //        std::cout << std::get<0>(edge.at(i)) << " " << std::get<1>(edge.at(i)) << " " << std::get<2>(edge.at(i)) << std::endl;
        if (is_same_set(std::get<1>(edge.at(i)), std::get<2>(edge.at(i))) == 0)
        {
            weight += std::get<0>(edge.at(i));
            unite(std::get<1>(edge.at(i)), std::get<2>(edge.at(i)));
        }
    }
    std::cout << weight << std::endl;
    return 0;
}



Measured memory_bytes: 3176