akhauriyash/Code-Regression huggingface dataset:
N = int(input())
H = list(map(int, input().split()))

count = 0
result = 0

for i in range(N-1):
    if H[i]-H[i+1] >=0:
        count += 1
    else:
        result = max(count, result)
        count = 0

result = max(count, result)
print(result)


Measured memory_bytes: 63984
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	if a == b && b == c {
		fmt.Println("1")
	} else if a != b && b!= c && a != c {
		fmt.Println("3")
	} else {
		fmt.Println("2")
	}
}


Measured memory_bytes: 1828
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n+1)


signed main()
{
    FIO;
    ll cnt1=0,cnt2=0;
    ll a;
    vi v;
    for(ll i=0;i<3;i++)
    {
        cin>>a;
        v.pb(a);
    }
    sort(all(v));
    if(v[0]==5 and v[1]==5 and v[2]==7)cout<<"YES";
    else
    cout<<"NO";
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    bool ok = true;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3128
s = int(input())
l = [s]
cnt = 1

while 10000 >cnt:
    if s%2==0:
        s=s//2
        l.append(s)
    else:
        s=3*s+1
        l.append(s)
    if l.count(s)==2:
        cnt+=1
        break
    cnt+=1

print(cnt)
    

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    size_t V, W, T;

    cin >> a >> V;
    cin >> b >> W;
    cin >> T;    

    if(W >= V) 
    {
        cout << "NO" << endl;
        return 0;    
    }

    size_t diff = V - W;

    int sa = (a >= 0) ? 1 : -1;
    int sb = (b >= 0) ? 1 : -1;
    size_t A = static_cast<size_t>(sa * a);
    size_t B = static_cast<size_t>(sb * b);

    size_t dist;

    if( (sa == 1) && (sb == 1) ) { dist = (A >= B) ? (A - B) : (B -A);}    
    else if( (sa == -1) && (sb == -1)) { dist = (A >= B) ? (A - B) : (B -A);}
    else { dist = A + B;}    

    if( (diff * T) >= dist )
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> A(N);
    REP(i,N-1)A[in()-1]++;
    REP(i,N)cout << A[i] << "\n";
}

Measured memory_bytes: 3992
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        long n=nl(),a=nl(),b=nl();
        long d=Math.abs(a-b);
        if (d%2==0) System.out.print(d/2);
        else {
            long ans1=a+(b-a-1)/2;
            long ans2=n-b+1+(b-a-1)/2;
            System.out.println(Math.min(ans1,ans2));
        }
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <cstdlib>


int head,tail;
int n,q;


bool isFull(){
    return head==(tail+1)%(n+1);
}
bool isEmpty(){
    return head==tail;
}

void enqueue(int *time,std::string *queue,int t,std::string str){
    if(isFull()){
        std::cerr << "Size over!!\n";
        exit(1);
    }
    time[tail] = t;
    queue[tail] = str;
    if(tail==n){
        tail = 0;
    }else{
        tail++;
    }
}

int dequeue(int *time){
    if(isEmpty()){
        std::cerr << "Empty!!\n";
        exit(1);
    }
    int x = time[head];
    time[head] = -1;
    if(head==n){
        head = 0;
    }else{
        head++;
    }
    return x;
}

void initialize(int* sum1,std::string *queue,int *time){
    head = 0;
    tail = 0;
    std::string str;
    int t;
    for(int i=0;i<n;i++){
        std::cin >> str >> t;
        enqueue(time,queue,t,str);
        *sum1+=t;
    }
}

int main(){
    int sum1=0,sum2=0;
    int tmp;
    std::cin >> n >> q;
    std::string queue[n+1];
    int time[n+1];
    initialize(&sum1,queue,time);
    while(!isEmpty()){
        if(time[head]<=q){
            tmp = head;
            sum2 += dequeue(time);
            std::cout << queue[tmp] << " " << sum2 << "\n";
        }else{
            enqueue(time,queue,dequeue(time)-q,queue[head]);
            sum2 += q;
        }
    }
    return 0;
}


Measured memory_bytes: 6092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main() {
    int n,m,k;
    cin>>n>>m>>k;

    vector<vector<int>> G(n);
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        uf.merge(a,b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i,k){
        int c,d;
        cin>>c>>d;
        c--,d--;
        if(uf.issame(c,d)){
            G[c].push_back(d);
            G[d].push_back(c);
        }
    }

    rep(i,n){
        cout<<uf.size(i)-1-G[i].size()<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 7936
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}

string a[50];

int main(){
	int h,w,i,j;
	cin>>h>>w;
	for(i=0;i<h;i++){
		cin>>a[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(a[i][j]=='#')continue;
			int dx[8] = {1,0,-1,0,1,-1,-1,1};
			int dy[8] = {0,1,0,-1,1,-1,1,-1};
			int num=0;
			for(int d=0;d<8;d++){
				int ni = i + dy[d];
				int nj = j + dx[d];
				if(ni<0 || nj<0 || ni>=h || nj>=w)continue;
				if(a[ni][nj]=='#')num++;
			}
			a[i][j] = char(num + '0');
		}
	}
	for(i=0;i<h;i++){
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	n := readInt()
	t := make([]int64, n+2)
	for i := 1; i <= n; i++ {
		t[i] = readInt64()
	}
	lt := make([]int64, n+2)
	rt := make([]int64, n+2)
	for i := 1; i <= n; i++ {
		lt[i] = lt[i-1] + t[i]
	}
	for i := n; 1 <= i; i-- {
		rt[i] = rt[i+1] + t[i]
	}

	lsum := func(i int) int64 {
		return lt[i-1]
	}
	rsum := func(i int) int64 {
		return rt[i+1]
	}

	m := readInt()
	for i := 0; i < m; i++ {
		p := readInt()
		x := readInt64()
		println(lsum(p) + x + rsum(p))
	}
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(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 >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x)
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

template<typename T>
T gcd(T a, T b)
{
	T c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

template<typename T>
T bit_count(T N) {
	T cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

struct Point {
	int y, x;
	bool operator < (const Point& r) {
		if (x < r.x) return true;
		else return false;
	}
};

class Solver {
public:
	string s;

	int ans(int i, int sum, bool can_all) {
		if (i == s.size()) return sum;
		int a = s[i] - '0';
		if (can_all) a = 9;
		int b = ans(i + 1, sum + a, can_all);
		int c = ans(i + 1, sum + a - 1, true);
		if (s[i] == '0') return b;
		return max(b, c);
	}

	void solve() {
		cin >> s;
		cout << ans(0, 0, false) << endl;
	}
};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return


# inputs
N = 0
B = []


def set_inputs():
    global N, B
    N = get_int()
    B = get_list_of_int()
    return


# n: int, b: List[int]
def solve(b):
    if len(b) == 0:
        return []
    if sum(b) > len(b) * (len(b) + 1) // 2:
        return [-1]
    for i, v in enumerate(b):
        if v > i + 1:
            return [-1]
    possible_indices = []
    for i, v in enumerate(b):
        if i + 1 == v:
            possible_indices.append(i)
    if len(possible_indices) == 0:
        return [-1]
    for i in possible_indices:
        ans = solve(b[:i] + b[i+1:])
        if len(ans) == 1 and ans[0] == -1:
            continue
        return ans + [i+1]
    return [-1]


def main():
    setrecursionlimit(100000)
    set_inputs()
    for i in solve(B):
        print(i)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
from collections import deque
H, W, K = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
grid = [input() for _ in range(H)]


def inside(r, c):
    return 0 <= r < H and 0 <= c < W and grid[r][c] != '@'


dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
INF = 10**9
dist = [[INF]*W for _ in range(H)]
que = deque()
que.append([sx, sy])
dist[sx][sy] = 0
while que:
    [x, y] = que.popleft()
    for k in range(4):
        for d in range(1, K+1):
            nx = x + d*dx[k]
            ny = y + d*dy[k]
            if not inside(nx, ny) or dist[nx][ny] <= dist[x][y]:
                break
#             if not inside(nx, ny):
#                 break
#             if dist[nx][ny] <= dist[x][y]:
#                 break
            if dist[nx][ny] == INF:
                dist[nx][ny] = dist[x][y] + 1
                que.append([nx, ny])
if dist[gx][gy] == INF:
    print(-1)
else:
    print(dist[gx][gy])


Measured memory_bytes: 122508
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MD 1000000007

char sep[3] = " \n";
int i, j, k, l, m, n;

int main() {
  string s, t;
  int taro = 0, hanako = 0;
  cin >> n;
  rep(i,n) {
    cin >> s >> t;
    if (s > t) taro += 3;
    else if (s < t) hanako += 3;
    else taro++, hanako++;
  }
  cout << taro << " " << hanako << endl;

  return 0;
}
  

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long a[1000000],sum = 0;
    cin >> n;
    for (int i = 0;i < n*3;i++) cin >> a[i];
    sort(a,a+(n*3),greater<int>());
    for(int i = 1; i < n*2;i+=2){
        sum += a[i];
    }
    cout << sum << endl;

}


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

using namespace std;

int main(void) {
  int w, h, n;
  cin >> w >> h >> n;

  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }

  int ans = 0;
  for (int i = 1; i < n; i++) {
    int dx = x[i] - x[i - 1], dy = y[i] - y[i - 1];
    if (dx * dy > 0) {
      ans += max(abs(dx), abs(dy));
    } else {
      ans += abs(dx) + abs(dy);
    }
  }

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


Measured memory_bytes: 3112
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int N;
		cin>>N;
		if(N==0) break;
		vector<vector<bool> > map(21, vector<bool>(21, false));
		int set = 0;
		REP(i, N) {
			int x, y;
			cin>>x>>y;
			map[x][y] = true;
		}
		int nx = 10, ny = 10;
		int ans = 0;
		if(map[nx][ny]) {
			++ans;
			map[nx][ny] = false;
		}
		int M;
		cin>>M;
		REP(i, M) {
			char dir;
			int l;
			cin>>dir>>l;
			if(dir == 'E') {
				REP(j, l) {
					nx = nx + dx[0];
					ny = ny + dy[0];
					if(map[nx][ny]) {
						++ans;
						map[nx][ny] = false;
					}
				}
			}
			if(dir == 'N') {
				REP(j, l) {
					nx = nx + dx[1];
					ny = ny + dy[1];
					if(map[nx][ny]) {
						++ans;
						map[nx][ny] = false;
					}
				}
			}
			if(dir == 'W') {
				REP(j, l) {
					nx = nx + dx[2];
					ny = ny + dy[2];
					if(map[nx][ny]) {
						++ans;
						map[nx][ny] = false;
					}
				}
			}
			if(dir == 'S') {
				REP(j, l) {
					nx = nx + dx[3];
					ny = ny + dy[3];
					if(map[nx][ny]) {
						++ans;
						map[nx][ny] = false;
					}
				}
			}
		}
		if(ans == N) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3076
/**Which of the favors of your Lord will you deny ?**/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second
#define INF INT_MAX

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
                    TIn, null_type, less<TIn>,
                    rb_tree_tag, tree_order_statistics_node_update>;

/*
PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

*/

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

LL mod = 1e9+7;

LL sum[nmax];

int main()
{
    optimizeIO();

    LL n,k;
    cin>>n>>k;

    for(int i=1;i<=n;i++)
    {
        sum[i] = sum[i-1] + i;
    }

    LL ans = 0;

    for(int i=k;i<=n+1;i++)
    {
        LL minn = sum[i-1];
        LL maxx = sum[n] - sum[n-i];
//        DBG(minn);
//        DBG(maxx);
        ans = (ans+(maxx-minn+1))%mod;
    }

    cout<<ans<<endl;



    return 0;
}




Measured memory_bytes: 5152
#include <stdio.h>

long long int abs(long long int a){
	if(a>=0){
		return a;
	}
	return -a;
}

long long int min(long long int a, long long int b){
	if(a>b){
		return b;
	}
	return a;
}

int main(){
	long long int N;
	long long int a[200001];
	long long int b[200001];
	long long int i;
	b[0]=0;
	scanf("%lld",&N);
	for(i=1;i<=N;i++){
		scanf("%lld",&a[i]);
		b[i]=b[i-1]+a[i];
	}
	long long int S;
	S=b[N];
	long long int ans;
	ans=abs(S-2*b[1]);
	for(i=2;i<N;i++){
		ans=min(ans,abs(S-2*b[i]));
	}
	printf("%lld",ans);
}

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

int main(){
                                                                     

    int a, b, x;

    
    cin >> a >> b;

    x = ( a * a - a - 2 * a * b - b + b * b ) / 2 ;


    cout << x << endl;

    return 0;

    }

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

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {cin >> a[i]; a[i]--;}
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    vector<int> c(n-1);
    for (int i = 0; i < n-1; i++) cin >> c[i];
    
    int ans = b[a[0]];

    for (int i = 1; i < n; i++) {
        ans += b[a[i]];
        if (a[i] == a[i-1] + 1) ans += c[a[i-1]];
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 1000000007
#define MINV 1000000005
using namespace std;
typedef long long ll;

ll dp[5005][5005];
ll n,s_sz;
ll amo;
ll ans;
string s;

inline ll max(ll a, ll b){
	if (a>b) return a;
	return b;
}

ll calc(int sz, int n) {
	if (sz==s_sz && n==0) return 1;
	if (n==0) return 0;
	ll &ret = dp[sz][n];
	if (ret!=-1) return ret;
	ret = 0;
	ret = (ret+(calc(sz+1,n-1)<<1))%M;
	ret = (ret+(calc(max(sz-1,0),n-1)))%M;
	return ret;
}

ll pang(ll a, ll b) {
	ll ret = 1;
	while (b) {
		if (b&1) ret = (ret*a)%M;
		b>>=1;
		a=(a*a)%M;
	}
	return ret;
}


int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	memset(dp,-1,sizeof(dp));
	cin >> n;
	cin >> s;
	s_sz = s.size();
	amo = calc(0,n)%M;
	ans = (amo*pang(2,s_sz*MINV))%M;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 196224
N,X,Y=map(int,input().split())
ans=[0]*(N-1)
for i in range(1,N):
	for j in range(i+1,N+1):
		a=min(j-i,abs(i-X)+abs(Y-j)+1)
		ans[a-1]+=1
for i in range(N-1):
	print(ans[i])

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        String[] B = sc.next().split("\\.");

        int b1 = Integer.parseInt(B[0]);
        int b2 = Integer.parseInt(B[1]);
        //System.out.println(b1);
        //System.out.println(b2);

        int b = b1 * 100 + b2;
        long ans = A * b;
        System.out.println(ans/100);
        return;
    }

}

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

#define endl '\n'
#define rep(n)      for (int i = 0 ; i < n ; i++)
#define all(a)      a.begin(),a.end()
#define NumofDigits(n)    ((long long)log10(n)+1)
#define Unique(n)         (n).erase(unique(all(n)), (n).end())

void quick ()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}

void readFromText ()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
}

const double Pi = acos(-1.0);

 long long poww(long long base, long long power){
    if(power==0)
        return 1;
    if(power==1)
        return base;
    long long ans = pow(base, power/2);
    ans *= ans;

    if(power&1)
        return ans*base;
    return ans;
}

int main()
{
    quick();
//    readFromText();
    long long x ; cin >> x ;
    for (long long i = -200 ; i <= 200 ; i++){
        for (long long j = -200 ; j <= 200 ;j++){
            long long res = (poww(i,5)-poww(j,5));
            if (res==x){
//                cout << poww(-2,5) << endl ;
                return cout << i << " " << j , 0;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int a;
int main(){
    scanf("%d",&a);
    if(a>=30)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,b[110],a[110],sum=0,i;
    cin>>n;
    for(i=0;i<n-1;i++)
        cin>>b[i];
        a[0]=b[0];
        a[n-1]=b[n-2];
    for(i=1;i<n-1;i++)
    {
        if(b[i]>=b[i-1])
            a[i]=b[i-1];
        else
            a[i]=b[i];
    }
    for(i=0;i<n;i++)
        sum+=a[i];
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 256
N,C = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(C)]

# 3色を保持するための変数
g0=[0]*C # 斜め列1
g1=[0]*C # 斜め列2
g2=[0]*C # 斜め列3

# 以下のような斜めごとに列を3色に分けようとしたときの違和感(コスト)を考える
# □ ○ △ □
# ○ △ □ ○
# △ □ ○ △
# □ ○ △ □

for i in range(N):
    col=list(map(int,input().split()))
    # 各マスの各色を見ていく
    #   斜めの列3種類ごとに持つ色を保持しておく
    for j in range(N):
        col[j]-=1
        if (i+j)%3==0:
            g0[col[j]]+=1
        elif (i+j)%3==1:
            g1[col[j]]+=1
        else:
            g2[col[j]]+=1

ans=float('inf')
# 全探索して、何色に変えるのが最もコストが低いかを出す
for i in range(C): # g0の色(をiにした場合)
    for j in range(C): # g1の色(をjにした場合)
        for k in range(C): # g2の色(をkにした場合)
            if i==j or j==k or i==k: # g0とg1が同じ色になる、みたいなパターンはないのでその場合の色分けは考えなくて良いので飛ばす
                continue
            s=0
            for l in range(C):
                # d[l][i]*g0[l]: lの色をiに変えるのに必要なコストの合計
                #  lをiに変えるコスト * g0にあるlの色の数
                #  d[l][j], d[l][k]も同様の計算
                #    l(全色)を特定のiやjに変えたときのコストの合計を算出
                s+=d[l][i]*g0[l]+d[l][j]*g1[l]+d[l][k]*g2[l]
            ans=min(ans,s)
print(ans)

Measured memory_bytes: 9280
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k, q; cin >> n >> k >> q;
	VE a(n); rep(i, n)a[i] = k - q;
	rep(i, q) {
		int b; cin >> b;
		a[b - 1]++;
	}
	rep(i, n) {
		if (a[i] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
from sys import stdin
import numpy as np

n, k = map(int, stdin.buffer.readline().split())
a = np.fromstring(stdin.buffer.read(), dtype=np.int, sep=' ')

ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
    mid = (ok + ng) >> 1
    if np.sum(np.ceil(a / mid) - 1) <= k:
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 31616
#include <iostream>

using namespace std;

int sum(int n) {
  return (n * (1 + n)) / 2;
}

int main(){
  int a,b;
  int delta;

  cin >> a >> b;

  delta = b - a;
  int east  = sum(delta);

  cout << east - b;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#undef int
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, t[110];
int vl[40040], vr[40040], v[110];
int L;
int vmax[40040];
double suzuki = 0.5 * 0.5 * 0.5;

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> t[i];
        L += t[i];
    }
    for(int i = 0; i < N; i++){
        cin >> v[i];
    }
    int cur = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < t[i] * 2; j++){
            vl[cur] = v[i] * 10;
            if(cur > 0)vr[cur - 1] = v[i] * 10;
            //printf("init %2d %2d\n", cur / 2, v[i]);
            cur++;
        }
    }
    vl[0] = 5;
    vr[cur - 1] = 0;
    for(int i = 1; i < cur; i++){
        vl[i] = min(vl[i], vl[i - 1] + 5);
    }
    for(int i = cur - 2; i >= 0; i--){
        vr[i] = min(vr[i], vr[i + 1] + 5);
    }
    for(int i = 0; i < cur - 1; i++){
        vmax[i] = min(vl[i], vr[i]);
        //printf("%3d: %3d\n", i / 2, vmax[i]);
    }
    double ans = 0.0;
    for(int i = 0; i < cur; i++){
        if(vmax[i - 1] == vmax[i]){
            ans += (double)vmax[i] * 0.05;
        }
        else if(vmax[i - 1] < vmax[i]){
            ans += (double)vmax[i - 1] * 0.05 + suzuki;
        }
        else {
            ans += (double)vmax[i] * 0.05 + suzuki;
        }
        //printf("%2d: %.2f: %.2f\n", i / 2, (double)vmax[i] / 10.0, ans);
    }
    printf("%.10f\n", ans);

}
/*

*/




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

int main() {
	int a, z;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A') {
			a = i;
			break; 
		}
	}
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'Z') z = i;
	}
	cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll N;
  cin >> N;
  ll a, b;
  for(ll i=1; i*i<=N; i++){
    if(!(N%i)){a=i; b=N/i;}
  }
  ll ans = a + b -2;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import math
def combinations_count(n, r):
    return math.factorial(n)//(math.factorial(n-r) * math.factorial(r))


n = int(input())
a = list(map(int, input().split()))

b = [0 for i in range(n+1)]
for x in a:
    b[x]+=1

total = 0
for i in range(1,n+1):
    if b[i]>=2:
        total += combinations_count(b[i],2)

for i in range(n):
    print(total-b[a[i]]+1)



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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

	int N, K;
	cin >> N >> K;

	vector<vector<int>> P(N+1);
	fx(N-1) {
		int a, b;
		cin >> a >> b;
		pb(P[a], b);
		pb(P[b], a);
	}

	ll ans = K;

	queue<pair<int,int>> G;
	bool flag[110000] = { false, };
	G.push(make_pair(1,0));
	while (!G.empty()) {
		auto g = G.front(); G.pop();
		flag[g.first] = true;
		if(g.second==0) {
			int s = P[g.first].size();
			if (s>=K) {
				ce(0);
				return 0;
			}
			fx(s) {
				ans *= (ll)K - 1 - x;
				ans %= MOD;
			}
			fx(s) {
				G.push(make_pair(P[g.first][x],1));
			}
		}
		else if (g.second==1) {
			int s = P[g.first].size() - 1;
			if (s >= K) {
				ce(0);
				return 0;
			}
			if (s<=0) {
				continue;
			}
			fx(s) {
				ans *= (ll)K - 2 - x;
				ans %= MOD;
			}
			fx(s+1) {
				if (flag[P[g.first][x]]) { continue; }
				G.push(make_pair(P[g.first][x], 1));
			}
		}
		
	}
	ce(ans)
    return 0;
}



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

int main() {
	long long n,l;
	cin>>n>>l;
	long long a[n];
	long long i,s=0;
	long long min=INT_MAX,o=0;
	for(i=0;i<n;i++){
		a[i]=l+i;
		if(abs(a[i])<min){
		min=abs(a[i]);
		if(a[i]<0)
		o=1;
		else
		o=0;
		}
		s+=a[i];
	}
	if(o==1)
	cout<<s+min;
	else
	cout<<s-min;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[100][100]={},f[100]={},d[100]={},T[200]={};
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>a[u][j];
		}
	}
	T[1]=1;
	f[1]=1;
	int s=1;
	for(int time=2;time<=2*n;time++){
		for(int j=0;j<100;j++){
			if(a[T[time-1]][j]==0){
				d[T[time-1]]=time;
				if(f[T[time-1]]==s){
					for(int i=1;i<n;i++){
						if(f[i]==0){
							T[time+1]=i;
							time++;
							f[i]=time;
							break;
						}
					}
					s=time;
				}else{
					T[time]=T[f[T[time-1]]-1];
				}
				break;
			}
			else if(f[a[T[time-1]][j]]==0){
				f[a[T[time-1]][j]]=time;
				T[time]=a[T[time-1]][j];
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<i<<" "<<f[i]<<" "<<d[i]<<endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h;
    rep(i, n){ int tmp; cin >> tmp; h.push_back(tmp);}

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

    int ans = MOD;
    rep(i, n-(k-1)){
        int tmp = h[i+(k-1)] - h[i];
        //cout << tmp << endl;
        ans = min(ans, tmp);
    }

    cout << ans << endl;

}


Measured memory_bytes: 892
#include <cstdio>
using namespace std;
bool check(int x)
{
	if(x<=9) return true;
	else if(x<=99) return false;
	else if(x<=999) return true;
	else if(x<=9999) return false;
	else if(x<=99999) return true;
	else return false;
}

int main(void)
{
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(check(i)) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int x[n],y[n],h[n];
  REP(i,n) cin>>x[i]>>y[i]>>h[i];

  REP(posY,101) REP(posX,101) {
    int needH = -1;
    REP(i,n) {
      if (h[i] == 0) continue;
      int tmp = h[i]+abs(posY-y[i])+abs(posX-x[i]);
      if (needH == -1) needH = tmp;
      if (needH != tmp) { needH = -2; break; }
    }
    if (needH == -2) continue;

    REP(i,n) {
      if (h[i] > 0) continue;
      int dist = abs(posY-y[i])+abs(posX-x[i]);
      if (needH > dist) { needH = -2; break; }
    }
    if (needH == -2) continue;
    printf("%d %d %d\n",posX,posY,needH);
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int h,w,r = 0,i,j;
	char s[16];
	scanf("%d%d",&h,&w);
	for(i = 0;i < h;i++){
		scanf("%s",s);
		for(j = 0;j < w;j++){
			if(s[j] == '#'){r++;}
		}
	}
	if(h+w-1 == r){printf("Possible\n");}
	else{printf("Impossible\n");}
	return 0;
}

Measured memory_bytes: 128
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

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

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


s = IS()
s = sorted(s)
if len(s) != 4:
    print('No')
else:
    print('Yes' if s[0] == s[1] and s[2] == s[3] and s[0] != s[2] else 'No')



Measured memory_bytes: 68076
#include <iostream>

using namespace std;

int main() {
	int m, f, r;
	int exam_sum;
	char grade;

	cin >> m >> f >> r;

	while(m != -1 || f != -1 || r != -1) {
		if(m == -1 || f == -1) {
			grade = 'F';
		} else {
			exam_sum = m + f;

			if(80 <= exam_sum) {
				grade = 'A';
			} else if(65 <= exam_sum) {
				grade = 'B';
			} else if(50 <= exam_sum) {
				grade = 'C';
			} else if(30 <= exam_sum) {
				if(50 <= r) 
					grade = 'C';
				else
					grade = 'D';
			} else {
				grade = 'F';
			}
		}
		
		cout << grade << endl;

		cin >> m >> f >> r;
	}
	
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> v(n, -1);
    rep(i, m){
        int s, c;
        cin >> s >> c;
        if(s > n){
            cout << -1 << endl;
            return 0;
        }
        if(v[s-1] != -1 && v[s-1] != c){
            cout << -1 << endl;
            return 0;
        }
        v[s-1] = c;
    }

    if(n == 1){
        if(v[0] != -1) cout << v[0] << endl;
        else cout << 0 << endl;
        return 0;
    }

    if(v[0] == 0){
        cout << -1 << endl;
        return 0;
    }

    if(v[0] == -1) cout << 1;
    else cout << v[0];
    for(int i=1; i<n; i++){
        if(v[i] != -1) cout << v[i];
        else cout << 0;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n, p, v, per, i, max = 0, num;
  int a[1000001] = {0};

  scanf("%d%d", &n, &p);

  while(p){
    scanf("%d%d", &per, &v);
    a[per] += v;
    if(v>0){
      if(a[per] > max || a[per] == max && per < num){
      max = a[per];
      num = per;
      }
    }else if(per == num){
      if(a[per] <  max){
	num = 0; max = 0;
	for(i = 1; i <= n; i++){
	  if(a[i] > max){
	    max = a[i];
	    num = i;
	  }
	}
      }
    }
   
    printf("%d %d\n", num, a[num]);
    p--;
  }
  return 0;
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((int)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI 2 * acos(0)

#define maxn 400005

string s;

int main(){
	srand(1412);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);

	cin >> s;
	bool have[33];
	ms(have, 0);
	Rep(i, sz(s)){
		have[s[i] - 'a']++;
	}
	for(int i = 'a'; i <= 'z'; i++) if(!have[i - 'a']){
		cout << s << char(i) << endl;
		return 0;
	}
	ms(have, 0);
	for(int i = sz(s) - 2; i >= 0; i--) if(s[i] < s[i + 1]){
		string res = "";
		for(int j = 0; j < sz(s); j++){
			if(j < i){
				res.pb(s[j]);
				have[s[j] - 'a']++;
			} else if(j == i){
				for(char ch = 'a'; ch <= 'z'; ch++) if(ch > s[i] && !have[ch - 'a']){
					res.pb(ch);
					have[ch - 'a']++;
					break;
				}
			}
		}
		cout << res << endl;
		return 0;
	}

	cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
require 'prime'

#組み合わせ（小さい数用）
def combi(n, m)
  return 1 if m == 0
  return n if m == 1
  return combi(n, n - m) if m > n - m
  fact_s(n, n - m + 1) / fact_s(m, 1)
end
#階乗（小さい数用）
def fact_s(n, m)
  (m..n).to_a.inject(&:*)
end

N = gets.to_i

pr = Hash.new{|h, k| h[k] = 0}
N.downto(2){|n|
  n.prime_division.each{|k, v|
    pr[k] += v
  }
}
ans = 0
cnt3 = pr.count{|k, v| v >= 2}
cnt5 = pr.count{|k, v| v >= 4}
cnt15= pr.count{|k, v| v >= 14}
cnt25= pr.count{|k, v| v >= 24}
cnt75= pr.count{|k, v| v >= 74}
ans += combi(cnt5, 2) * combi(cnt3-2, 1) if cnt5 > 1
ans += combi(cnt15, 1) * combi(cnt5-1, 1) if cnt15 > 0
ans += combi(cnt25, 1) * combi(cnt3-1, 1) if cnt25 > 0
ans += combi(cnt75, 1) if cnt75 > 0

puts ans


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;
const int maxn = 300005;
ll a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] = a[i]-i;
        sum += a[i];
    }
    sort(a+1, a+1+n);
    int sum1 = n/2;
    int sum2 = n/2+1;
    int sum3 = n/2-1;
    ll ans1 = 0;
    ll ans2 = 0;
    ll ans3 = 0;
    for(int i =1 ; i <= n; i++)
    {
        ans1 += abs(a[i]-a[sum1]);
        ans2 += abs(a[i]-a[sum2]);
        ans3 += abs(a[i]-a[sum3]);
    }
    ll ans = min(min(ans1, ans2), ans3);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    vector<pair<ll, ll>> r(n), b(n);
    rep(i, n)   cin >> r[i].first >> r[i].second;
    rep(i, n)   cin >> b[i].first >> b[i].second;
    sort(ALL(r));   sort(ALL(b));
    ll res=0;
    rep(i, n){
        ll xew=-1, index=-1;
        rep(j, n){
            if(r[j].second<b[i].second && r[j].first<b[i].first){
                if(xew<r[j].second){
                    xew = r[j].second;
                    index = j;
                }
            }
            
        }
        if(index!=-1){
            res += 1;
            r[index] = {LINF, LINF};
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3640