akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#define mysign(x) (((x)>0)?1:(-1))
#define myabs(x)  (((x)>0)?(x):(-(x)))
int n;
int net[11][11];


void search_pos(int me,int *y,int *x)
{
  int i,j;

  for(i=3;i<8;i++)
    for(j=3;j<8;j++)
      if(net[i][j]==me)
	{
	  *y=i;*x=j;
	  return;
	}
  *x=*y=-1;
}

int ck_rel_pos(int y,int x,int y_,int x_)
{
  int i,j,r;

  if(y+2==y_)
    for(i=-3;i<=3;i++)
      if(x_==x+i)
	    {
	      r=-1;
	      for(j=0;myabs(j)<=myabs(i);j+=mysign(i))
		  r &= (net[y+1][x+j]!=0);

	      if(r)
		return(r);
	    }
  if(x+2==x_)
    for(i=-3;i<=3;i++)
      if(y_==y+i)
	    {
	      r=-1;
	      for(j=0;myabs(j)<=myabs(i);j+=mysign(i))
		{
		  r &= (net[y+j][x+1]!=0);
		}
	      if(r)
		return(r);
	    }
  return(0);
}

int count_dice()
{
  int i,j,r=0;
  for(i=3;i<8;i++)
    for(j=3;j<8;j++)
      if(net[i][j])
	r++;
  return(r);
}


int solve()
{
  int i,r[7];
  int px[7],py[7];

  if(count_dice()!=6)
    return(0);

  for(i=1;i<=6;i++)
    {
      search_pos(i,&py[i],&px[i]);
      if(py[i]==-1)
	return(0);
    }
  for(i=1;i<=6;i++)
    r[i]=ck_rel_pos(py[i],px[i],py[7-i],px[7-i]);
  return((r[1]||r[6]) && (r[2]||r[5]) && (r[3]||r[4]));
}
main()
{
  int i,j,k,ret;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      memset(&net[0][0],0,11*11);
      
      for(j=0;j<5;j++)
	for(k=0;k<5;k++)
	  scanf("%d",&net[j+3][k+3]);

      ret=solve();
      printf("%s\n",ret?"true":"false");
    }
  
  return(0);
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    long long x;
    cin >> x;
    long long y = 1, sum = 100;
    for (y = 1; y <= 3760; y++) {
        sum = (long long)(sum*1.01);
        if (sum >= x) break;
    }
    cout << y << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  n = (n%10);
  switch(n){
  case 0:case 1:case 6:case 8:cout << "pon" << endl;break;
  case 2:case 4:case 5:case 7:case 9:cout << "hon" << endl;break;
  default:cout << "bon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
from functools import reduce
# 入力
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N)))

# 1本あたりの値段が安い店から順に購入
ans = reduce(
    lambda acc, t: (
        acc[0] + t[0] * min(t[1], M - acc[1]),
        acc[1] + t[1]
    ) if acc[1] < M else
    acc,
    sorted(zip(A, B)),
    (0, 0)
)[0]

# 出力
print(ans)


Measured memory_bytes: 58824
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    long n, y;
    scanf("%ld%ld", &n, &y);

    long i, j;
    for(i=0; i<=y/10000; i++) {
        if(i>n) break;
        long tmp = y- i*10000;
        for(j=0; j<=tmp/5000; j++) {
            if(i+j>n) break;

            long tmp2 = tmp-j*5000;
            long k = n-i-j;
            if(tmp2 == (n-i-j)*1000) {
                printf("%ld %ld %ld\n", i,j,k);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");

    return 0;
}


Measured memory_bytes: 128
import numpy as np

N=int(input())
A=np.asarray(list(map(int,input().split(" "))))
csum=0 # 回数

# 全てが2で割り切れなくなるまで、2で割り続ける
while True:
    cond=(A%2==0) # 条件
    c=(cond).sum() # 回数
    csum+=c # 合計回数に足す

    if c==0: # もし2で割り切れなくなったら終了
        break

    A=A[cond]//2 # 2で割る

print(csum)

Measured memory_bytes: 15196
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] xArr = new int[n];
		int[] yArr = new int[n];
		int[] hArr = new int[n];
		int hh = 0;
		int xx = 0;
		int yy = 0;
		for (int i = 0; i < n; i++) {
		    xArr[i] = sc.nextInt();
		    yArr[i] = sc.nextInt();
		    hArr[i] = sc.nextInt();
		    if (hArr[i] != 0 && hh == 0) {
		        hh = hArr[i];
		        xx = xArr[i];
		        yy = yArr[i];
		    }
		}
		for (int i = 0; i <= 100; i++) {
		    for (int j = 0; j <= 100; j++) {
		        int height = hh + Math.abs(xx - i) + Math.abs(yy - j);
		        boolean flag = true;
		        for (int k = 0; k < n; k++) {
		            if (Math.max(height - Math.abs(xArr[k] - i) - Math.abs(yArr[k] - j), 0) != hArr[k]) {
		                flag = false;
		                break;
		            }
		        }
		        if (flag) {
		            System.out.println(i + " " + j + " " + height);
		            return;
		        }
		    }
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll N;
    int Q;
    cin >> N >> Q;
    int k[Q], x[Q];
    int dx = N-2, dy = N-2;
    int cnt1[N-2], cnt2[N-2];
    vector<int> v1, v2;

    rep(i, Q){
        cin >> k[i] >> x[i]; x[i] -= 2;
        if(k[i] == 1) if(chmin(dx, x[i])) cnt1[x[i]] = dy, v1.pb(-x[i]);
        if(k[i] == 2) if(chmin(dy, x[i])) cnt2[x[i]] = dx, v2.pb(-x[i]);
    }

    sort(all(v1)), sort(all(v2));
    ll ans = (N-2)*(N-2);
    rep(i, Q){
        if(k[i] == 1) ans -= cnt1[-*lower_bound(all(v1), -x[i])];
        if(k[i] == 2) ans -= cnt2[-*lower_bound(all(v2), -x[i])];
    }
    cout << ans << endl;
}

Measured memory_bytes: 6432
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	if len(res)==0:
		res = [n]
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

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

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

		if x==y:
			return

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

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

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

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

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

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

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

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	data = [2]
	#data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	ans = [x for x in data if x!=0]
	#ans = data[:]
	return ans

n = readInt()
a = readInts()
a.sort()

max_a = a[-1]
ans = [0]*(max_a+1)

for i in a:
	ans[i]+=1
for i in set(a):
	if ans[i]:
		for j in range(i*2,len(ans),i):
			ans[j]=0

print(ans.count(1))

Measured memory_bytes: 40856
import fractions

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

def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)
  
num_lcm = a[0]
for i in range(1,n):
  num_lcm = lcm(num_lcm,a[i])
  
function = 0
const = num_lcm-1
for i in range(n):
  function += const % a[i]

print(function)

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

int dir[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};

int main()
{
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	long long sum = 0;
	while(b--){
		int t;
		cin >> t;
		sum += t;
	}
	if(a <= sum) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    ll n;
    ll dp[10][10] = {0};
    ll c,cnt;
    ll e = 0;
    cin >> n;
    if (n/10 == 0){
        PRINT(n);
        return 0;
    }
    rep(i,1,10){
        rep(j,1,10){
            c = 1;
            while(i*(ll)pow(10,c)+j <= n){
                c++;
            }
            cnt = 0;
            rep(k,1,c){
                if (k == c-1 && (i+1)*pow(10,c-1) > n){
                    cnt += (n-(i*pow(10,c-1)+j))/10+1;
                }
                else{
                    cnt += pow(10,k-1);
                }
            }
            if (i == j) cnt++;
            dp[i][j] = cnt;
        }
    }
    ll ans = 0;
    rep(i,1,10){
        rep(j,1,10){
            ans += dp[i][j]*dp[j][i];
        }
    }
    PRINT(ans);
}


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

using namespace std;

int main(){
    int N;
    vector<string> S;
    S.resize(200001);

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

    map<string, int> count;
    for (int i = 1; i <= N; ++i){
        map<string, int>::iterator it = count.find(S[i]);
        if(it != count.end()){
            count[S[i]]++;
        }
        else{
            count[S[i]] = 1;
        }
    }

    int max = 0;
    for(decltype(count)::iterator it = count.begin(); it != count.end(); ++it){
        if(max < it->second){
            max = it->second;
        }
    }
    vector<string> ans;
    for(decltype(count)::iterator it = count.begin(); it != count.end(); ++it){
        if(it->second == max){
            ans.push_back(it->first);
        }
    }
    sort(ans.begin(), ans.end());

    for(decltype(ans)::iterator it = ans.begin(); it != ans.end(); ++it){
        cout << *it << endl;
    }

    return 0;
}

Measured memory_bytes: 30064
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner stdIn = new Scanner(System.in);

        int R = 0;

        do {
            R = stdIn.nextInt();
        } while (R < 0 || 4208 < R);

        if (R < 1200) {
            System.out.println("ABC");
        }

        else if (1200 <= R && R < 2800) {
            System.out.println("ARC");
        }

        else if (2800 <= R) {
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+10;
int main(){
	int n;
	scanf("%d",&n);
	int a[M];
	int ans=0;
	int maxx=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(i!=0){
			if(a[i]<=a[i-1]){
				ans++;
				if(ans>maxx){
					maxx=ans;
				}
			}else{
				ans=0;
			}	
		}	
	}
	printf("%d\n",maxx);
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn= new Scanner(System.in);
        int x = stdIn.nextInt();
        int a,b,c;
        long y=0;
        for(a=1;a<=x;a++){
            for(b=1;b<=x;b++){
                for(c=1;c<=x;c++){
                    int min=a;
                    if(min>b)min=b;
                    if(min>c)min=c;
                    for(;;min--){
                        if(a%min==0&&b%min==0&&c%min==0){
                            y=y+min;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(y);
    }
}

Measured memory_bytes: 35732
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int size = Integer.parseInt( sc.nextLine() );
		final String N = sc.nextLine();
		int targetIndex = Integer.parseInt( sc.nextLine() );
		StringBuilder result = new StringBuilder();
		char targetChar = N.charAt(targetIndex-1);

		for( int i = 0; i < size; i++ ) {
			if( N.charAt(i) == targetChar ) {
				result.append(targetChar);
			} else {
				result.append("*");
			}
		}
		System.out.println( result.toString());
	    
		sc.close();
	}
}

Measured memory_bytes: 22740
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n,w;
    cin>>n>>w;
    vl u,v;
    rep(i,n)
    {
        ll a,b;
        cin>>a>>b;
        u.pb(a);
        v.pb(b);
    }
    ll dp[n+1][w+1]={0};
    for(int i=0;i<u[0];i++)
        dp[0][i]=0;
    for(int i=u[0];i<=w;i++)    
        dp[0][i]=v[0];
    for(int i=1;i<n;i++)
    {
        ll temp=LONG_MIN;
        for(int j=w;j>=0;j--)
        {
            if(j-u[i]>=0)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-u[i]]+(v[i]));
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    // for(int i=0;i<n;i++)
    //     cout<<dp[i][w]<<'\n';
    cout<<dp[n-1][w];
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000007;
const static int inf = INT_MAX;
const static llong INF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

const static int N = 15;

void solve() {
    int n;
    cin >> n;
    vector<vector<int> > X(n), Y(n);
    rep(i, n) {
        int a;
        cin >> a;
        rep(_, a) {
            int x, y;
            cin >> x >> y;
            X[i].push_back(x);
            Y[i].push_back(y);
        }
    }

    int ans = 0;
    bool flag;
    for (int bit = 0; bit < (1 << n); ++bit) {
        flag = true;
        bitset<N> bs(bit);
        for (int digit = 0; digit < n; ++digit) {
            if (bs[digit]) {
                rep(i, (int)X[digit].size()) {
                    if (bs[X[digit][i] - 1] != Y[digit][i]) {
                        flag = false;
                        break;
                    }
                }
            }
            if (! flag) break;
        }
        if (flag) ans = max(ans, (int)bs.count());
    }

    cout << ans << endl;

}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
//#define scanf scanf_s
int main()
{
	int n, m, s, sum = 1, i;
	scanf("%d %d", &n, &m);
	s = n + m;
	for (i = s-1; i <= s; i++)
		sum *= i;
	sum /= 2;
	printf("%d", sum - n * m);
}

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

#define ll long long int

ll tree[8*100005];
	ll dp[200005];
void update(ll node,ll l,ll r){
	if(l==r){
		tree[node]=dp[l];
		return ;
	}
	
	ll mid=(l+r)/2;
	update(2*node,l,mid);
	update(2*node+1,mid+1,r);
}

void build(ll node,ll l,ll r,ll val,ll i){
	if(l==r){
		tree[node]=val;
	//	cout<<"hello "<<i<<' '<<val<<'\n';
		return ;
	}
	
	ll mid=(l+r)/2;
	
	if(mid<i){
		build(2*node+1,mid+1,r,val,i);
	}
	else{
		build(2*node,l,mid,val,i);
	}
	tree[node]=max(tree[2*node],tree[2*node+1]);
	return ;
}

ll query(ll node,ll l,ll r,ll st,ll end){
	
	if(st>r || end<l){return 0;}
	ll mid=(l+r)/2;
	
	if(st<=l && end>=r){
		return tree[node];
	}
	
//	if(end<=mid){
	ll p=	query(2*node,l,mid,st,end);
//	}
//	else if(st>mid){
	ll q=	query(2*node+1,mid+1,r,st,end);
//	}
	return max(p,q);
	
}

int main(){
	ll n;
	cin>>n;
//	cout<<"rrrr\n";
	ll hrr[n+1];
	ll arr[n+1];
	for(ll i=0;i<n;i++){
		cin>>hrr[i];
	}
//	cout<<"rrrr\n";
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
//	cout<<"rrrr\n";

	memset(dp,0,sizeof(dp));
//	dp[0]=arr[0];
	
//	memset(tree,0,sizeof(tree));
	update(1,1,n);
//	build(1,1,n,dp[0],hrr[0]);
	for(ll i=0;i<n;i++){
		ll x=0;
		if(hrr[i]>1){
		 x=query(1,1,n,1,hrr[i]-1);}
	//	x=max(0,)
		dp[hrr[i]]=x+arr[i];
		//cout<<i<<' '<<dp[hrr[i]]<<' '<<x<<' '<<hrr[i]<<'\n';
		build(1,1,n,dp[hrr[i]],hrr[i]);
	//	cout<<dp[i]<<' ';
		
	}
	ll ans=tree[1];
	cout<<ans<<'\n';
}

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

int main() {
    int a, b, ans;
    cin >> a >> b;
    if(a <= b) ans = a;
    else ans = a - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()





template <int MOD>
struct ModInt {
    using lint = long long;
    int val;
 
    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };
 
    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }
 
    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }
 
    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
 
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
 
    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};
 
constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
 
mint comb(int n, int r){
    r=min(r,n-r);
    mint ans=1;
    rep(i,r){
        ans*=(n-i);
        ans*=(mint(i+1).inv());
    }
    return ans;
}



int main(){
    int n,a,b;
    cin>>n>>a>>b;
    mint ans=mint(2).pow(n)-1;
    ans-=comb(n,a);
    ans-=comb(n,b);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char a[4];
  scanf("%c%c%c%c",a,a+1,a+2,a+3);
  int ans = 0;
  for(int i = 0;i < 4;i++){
    if(a[i]=='+'){
      ans++;
    }else if(a[i] == '-'){
      ans--;
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main () {

  ll A, B, C;
  cin >> A >> B >> C;

  if ( ((A==B) and (B!=C)) or
       ((B==C) and (C!=A)) or
       ((C==A) and (A!=B)) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> n >> a;
       if(n<=a){
           Cout("Yes");
       }
       else{
          while(a>0){
              if(n%500==0){
                  Cout("Yes");
                  return 0;
              }
              n-=1;
              a-=1;
          }
           if(n%500==0){
               Cout("Yes");
           }
           else{
               Cout("No");
           }
       }
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)

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

    if (N % 2 == 0)
    {
        cout << N << endl;
    }
    else
    {
        cout << 2 * N << endl;
    }
}

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

#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)),  __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() {;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); }
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl


int32_t main() {
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);

   int n, sum = 0;
   cin >> n;
   vector <int> a(n + 1);
   for (int i = 1; i <= n; i++)
      cin >> a[i];
   vector <vector <int>> dp(n + 1, vector <int> (n + 1));

   for (int i = 1; i <= n; i++) {
      dp[i][i] = a[i];
      sum += a[i];
   }
   for (int len = 2; len <= n; len++) {
      for (int i = 1; i <= n - len + 1; i++) {
         int j = i + len - 1;
         if (len % 2)
            dp[i][j] = max(a[i] + dp[i + 1][j], a[j] + dp[i][j - 1]);
         else
            dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]);
      }
   }

   if (n % 2 == 0)
      cout << sum - 2 * dp[1][n] << '\n';
   else
      cout << 2 * dp[1][n] - sum << '\n';

   return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    int N, M;
    cin >> N >> M;
    int s[M+1], c[M+1];
    REPS (i, M) {
        cin >> s[i] >> c[i];
    }

    bool can = true;
    int check[4] = {-1, -1, -1, -1};
    REPS (i, M) {
        if (N != 1 && s[i] == 1 && c[i] == 0) {
            can = false;
            break;
        }
        if (check[s[i]] != -1 && check[s[i]] != c[i]) {
            can = false;
            break;
        }
        check[s[i]] = c[i];
    }
    int ans = 0;
    if (N > 1 && (M == 0 || check[1] == -1)) {
        ans = 1 * pow(10, N-1);
    }
    if (can) {
        REPS (i, N) {
            if (check[i] == -1) {
                continue;
            }
            ans += check[i] * pow(10, N-i);
        }
    } else {
        ans = -1;
    }

    cout << ans << endl;
}

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

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


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

using namespace std;
#define int long long
int n,m;
char a[1005][1005];
int f[1005][1005],base=1e9+7;
int F(int i,int j)
{
	if(f[i][j]!=-1) return f[i][j];
	else if(i==n&&j==m) 
	{
		return 1;
	}
	else
	{
		int res=0;
		if(i+1<=n&&a[i+1][j]=='.') 
		{
			res=(res+F(i+1,j))%base;
		}
		if(j+1<=m&&a[i][j+1]=='.')
		{
			res=(res+F(i,j+1))%base;
		}
		f[i][j]=res;
		return res;
	}
}
main()
{
	cin>>n>>m;
	memset(f,-1,sizeof(f));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) cin>>a[i][j];
	}
	cout<<F(1,1);
}

Measured memory_bytes: 9216
#include <array>
#include <iostream>
#include <string>

int main()
{
    std::array<long long, 5> count = {{0, 0, 0, 0, 0}};
    long long N;
    std::cin >> N;
    for (long long i = 0; i < N; i++) {
        std::string name;
        std::cin >> name;
        if (name[0] == 'M') {
            count[0]++;
        } else if (name[0] == 'A') {
            count[1]++;
        } else if (name[0] == 'R') {
            count[2]++;
        } else if (name[0] == 'C') {
            count[3]++;
        } else if (name[0] == 'H') {
            count[4]++;
        }
    }

    long long res = 0;

    for (unsigned int i = 0; i < 3; i++) {
        for (unsigned int j = i + 1; j < 4; j++) {
            for (unsigned int k = j + 1; k < 5; k++) {
                res += (count[i] * count[j] * count[k]);
//                std::cout << i << j << k << res << '\n';
            }
        }
    }

    std::cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
		sum += s[i]
	}
	s = append(s, 0)

	sort.Ints(s)
	for i := 0; i < len(s); i++ {
		t := sum - s[i]
		if t%10 != 0 {
			fmt.Println(t)
			return
		}
	}

	fmt.Println(0)
}


Measured memory_bytes: 512
read n
s=()
t=()
for i in `seq $n`
do
    read si ti
    s+=($si)
    t+=($ti)
done
read x
v=`echo ${s[@]} | tr ' ' '\n' | grep -n $x | tr -dc 0-9`
c=0
for i in `seq $v $((n-1))`
do
    c=$((c+t[i]))
done
echo $c


Measured memory_bytes: 984
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n = 0; // ????????????????????°
		long unitPrice = 0; // ?£??????????
		long soldNum = 0; // ?£?????????°
		long number[] = new long[4001]; // ????????????????????????
		boolean flag = false;
		boolean judge[] = new boolean[4001]; // ????????°
		ArrayList<Integer> answer = new ArrayList<Integer>();
		Scanner sc = new Scanner(System.in);
		/**
		 * ???????????\???
		 */
		while (true) {
			n = sc.nextInt();
			int data[] = new int[n]; // ??\???????????????????????¨??????
			if (n == 0) {
				break; // 0??§??????
			}
			for (int i = 0; i < 4001; ++i) {
				number[i] = 0; // ?????????????????????
			}
			for(int i = 0 ; i < 4001; ++i ){
				judge[i] = false; // ?????????k
			}
			for (int j = 0; j < n; ++j) {
				data[j] = sc.nextInt(); // map???????????????????£?,??????????????\???.
				unitPrice = sc.nextLong();
				soldNum = sc.nextLong();
				number[data[j]] += unitPrice * soldNum; // ????????¨?£?????????°??????????????????????????????????´?
			}
			// ??????
			for (int i = 0; i < n; ++i) {
				if (number[data[i]] >= 1000000 && judge[data[i]]!= true) {
					answer.add(data[i]);
					judge[data[i]] = true;
					flag = true;
				}
			}
			if(flag == false){
				answer.add(-1);
			}
			flag = false;
		}
		//??¨???
		for (int i = 0; i < answer.size(); ++i){
			if(answer.get(i) == -1){
				System.out.println("NA");
			}
			else{
		System.out.println(answer.get(i));
			}
		}
		sc.close();
	}

}

Measured memory_bytes: 35652
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int k=1;
  int c=0;
  int i=0;
  while(i<n)
  {
    if(a[i]==k)
      k++;
    else
      c++;
    i++;
  }
  if(c==n)
    cout<<-1<<"\n";
  else
  cout<<c<<"\n";
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n;
int dp[100000][3],a[100000][3];
int solve(int pos , int last)
{
    if(pos==n+1)
    return 0;
    if(dp[pos][last]!=-1)
    return dp[pos][last];
    
    int best = INT_MIN;
    for(int i=0;i<=2;i++)
    {
        if(i!=last)
        {
            best = max(best,a[pos][i]+solve(pos+1,i));
        }
    }
    dp[pos][last] = best;
    return dp[pos][last];
}

int main() {
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
        dp[i][0]=-1;
        dp[i][1]=-1;
        dp[i][2]=-1;
    }
    cout<<max(solve(1,0),max(solve(1,1),solve(1,2)))<<endl;
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

  rep(i,s.size()){
    if((char)s[i]+n <= 'Z') s[i] = (char)s[i] + n;
    else s[i] = (char)s[i] + n - 26;
  }

  cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	string s, t;
	int i, j;
	int ans = 1001;
	int tmp;
	cin >> s;
	cin >> t;
	for(i = 0; i < s.length(); i++) {
		tmp = 0;
		for (j = 0; j < t.length() && i+j<s.length(); j++) {
			if (s[i+j] != t[j]) {
				tmp++;
			}
		}
		if (j == t.length()) {
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> ans(n);
  rep(i, 0, n) rep(j, i + 1, n) {
    int mn = min(j - i, abs(x - i) + 1 + abs(y - j));
    ans[mn]++;
  }
  rep(i, 1, n) cout << ans[i] << '\n';

  return 0;
}

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

int main(){
  int cnt;
  rep(i,3){
    char g;
    cin >> g;
    if(g == 'o'){
      cnt++;
    }
  }
  cout << 700 + cnt*100 << endl;
        
}
      
  
        
        
        
    
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<vector<ll>> g;


int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        m[a[i]]++;
    }
    ll ret = 0;
    ll c = 0;
    ll cc = 0;
    for (auto itr = m.begin(); itr != m.end(); ++itr)
    {
        if (itr->second != 1)
        {
            c++;
            cc += itr->second;
        }
        else
        {
            ret++;
        }
    }
    
    ll ccc = cc - c;
    ccc %= 2;
    
    if (ccc)
    {
        c--;
    }
    
    cout << ret + c << endl;
    
    return 0;
}

Measured memory_bytes: 7296
N, M = map(int, input().split())
nums = list(map(int, input().split()))
tik = 0
while tik < M:
    nums.sort(reverse=True)
    nums[0] = nums[0] // 2 
    tik += 1
    if tik == M:
        break
    for i in range(1,N):
        if tik == M:
            break
        if nums[i] > nums[0]:
            nums[i] = nums[i] // 2
            tik += 1
        else:
            break
print(sum(nums))

Measured memory_bytes: 14224
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

int main()
{
    ll N = input<int>();
    vector<ll> d(N, 0);
    input(d);

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

    if (d[N / 2] == d[N / 2 - 1])
    {
        cout << 0 << endl;
    }
    else
    {
        cout << d[N / 2] - d[N / 2 - 1] << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  priority_queue<P> que;
  rep(i, n) {
    que.emplace(a[i], i);
  }

  ll ans = 0;

  vvll dp(n + 1, vll(n + 1, -INF));
  dp[0][0] = 0;

  rep(i, n) {
    auto p = que.top();
    que.pop();
    ll pos = p.second;
    ll a = p.first;
    rep(l, i + 1) {
      ll r = n - 1 - i + l;
      chmax(dp[i + 1][l], dp[i][l] + a * abs(r - pos));
      chmax(dp[i + 1][l + 1], dp[i][l] + a * abs(l - pos));
    }
  }

  cout << *max_element(all(dp[n])) << endl;

  return 0;
}


Measured memory_bytes: 34624
class UnionFind
  attr_accessor :rank, :parent, :size
  def initialize(s)
    @rank = Array.new(s,0)
    @parent = Array.new(s,&:itself)
    @size = Array.new(s,1)
  end

  def union(x,y)
    x_parent = get_parent(x)
    y_parent = get_parent(y)
    return if x_parent == y_parent

    if rank[x_parent] > rank[y_parent]
      parent[y_parent] = x_parent
      size[x_parent] += size[y_parent]
    else
      parent[x_parent] = y_parent
      size[y_parent] += size[x_parent]
      rank[y_parent] += 1 if rank[x_parent]==rank[y_parent]
    end
  end

  def get_parent(id)
    parent[id] == id ? id : parent[id] = get_parent(parent[id])
  end
end

n,m=gets.split.map(&:to_i)
u = UnionFind.new(n)
m.times do
  a,b = gets.split.map(&:to_i)
  u.union(a-1,b-1)
end
p u.size.max


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

const ll mod=1000000007;

int main() {
  int n,m,x,ans=10000000;
  cin >> n >> m >> x;
  int c[n];
  vector<vector<int>> v(n,vector<int>(m,0));
  r(i,n){
    cin>>c[i];
    r(j,m){
      cin >> v[i][j];
    }
  }
    
  for(int bit=1;bit<(1<<n);bit++){
    int a[m],count=0;
    r(i,m)a[i]=0;
    r(i,n){
      if(bit&(1<<i)){
        r(j,m)a[j]+=v[i][j];
        count+=c[i];
      }
    }
    bool flag=true;
    r(i,m)if(a[i]<x)flag=false;
    if(flag){
      ans=min(ans,count);
    }
  }
  
  if(ans==10000000)cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>

int main()
{
  char str[10];
  scanf("%s", str);
  int i, cnt = 0;
  for(i = 0; i < 4; ++i) {
    cnt += (str[i] == '+') ? 1 : -1;
  }
  printf("%d\n", cnt);
  return 0;
}

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

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  int N,T,A; cin >> N >> T >> A;
  double diff = 1000;
  int ans;
  rep(i,N) {
    int H; cin >> H;
    double temp = T - H * 0.006;
    if(abs(temp - A) < diff) {
      diff = abs(temp - A);
      ans = i+1;     
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

ll llmax(ll a, ll b){
  if(a > b) return a;
  return b;
}
int main(int argc, char const *argv[]) {
  ll N, K, ans = 0;
  std::cin >> N >> K;
  std::vector<ll> S(N, 0), A(N), plus(N);
  for(int i=0;i<N;i++){
    std::cin >> A[i];
    S[i] = (i==0?A[0]:S[i-1]+A[i]);
    plus[i] = (i==0?0:plus[i-1]) + (A[i]>0?A[i]:0);
  }
  for(int i=0;i<N-K+1;i++){
    //std::cout << plus[N-1] << " " << plus[i+K-1] << " " << (i==0?0:plus[i-1]) << '\n';
    //std::cout << llmax(0, S[i+K] - (i==0?0:S[i-1])) << '\n';
    ans = max(ans, plus[N-1] - plus[i+K-1] + (i==0?0:plus[i-1]) + llmax(0, S[i+K-1] - (i==0?0:S[i-1])));
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N;
ll x[100010];
combination comb( 100010 );
mint ans;

int main()
{
  std::cin >> N;

  ll cnt = 0;

  ans = 1;

  rep( i, N )
  {
    std::cin >> x[i];

    if( x[i] < 2*cnt+1 )
    {
      ans *= (cnt+1);
      --cnt;
    }

    ++cnt;
  }

  ans *= comb.fact[cnt];

  std::cout << ans.x << std::endl;

  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int i,j,k,A,B,C,D,tmp;
    string ope1,ope2,ope3;
    cin >> A;
    B=(A%1000)/100;
    C=(A%100)/10;
    D=A%10;
    A=A/1000;

    for(i=0;i<2;i++){
      for(j=0;j<2;j++){
        for(k=0;k<2;k++){
          tmp=A;
          if(i==0)tmp+=B;else tmp-=B;
          if(i==0)ope1='+';else ope1='-';
          if(j==0)tmp+=C;else tmp-=C;
          if(j==0)ope2='+';else ope2='-';
          if(k==0)tmp+=D;else tmp-=D;
          if(k==0)ope3='+';else ope3='-';
          if(tmp==7){
            cout << A << ope1 << B << ope2 << C << ope3 << D << "=7";
            return 0;
          }
        }
      }
    }
    return 0;
}


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

dp = [10**9] * (n+1)
dp[0] = 0
for i in range(n):
    if i+1 < n:
        dp[i+1] = min(dp[i] + abs(h[i]-h[i+1]), dp[i+1])
    if i+2 < n:
        dp[i+2] = min(dp[i] + abs(h[i]-h[i+2]), dp[i+2])
print(dp[n-1])

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int max = 100, mark;
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i);
    if (a.at(i) >= max) {
      max = a.at(i);
      mark = i;
    }
  }

  int sum = 0;
  for (int i = 0; i < n; i ++) {
    if (i == mark) {
      sum += a.at(mark) / 2;
    } else {
      sum += a.at(i);
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256