akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		int aSize1 = input.nextInt();
		int[] arr1 = new int[aSize1];
		
		for (int i = 0; i < aSize1; i++) {
			arr1[i] = input.nextInt();
		}
		
		int aSize2 = input.nextInt();
		int[] arr2 = new int[aSize2];
		
		for (int i = 0; i < aSize2; i++) {
			arr2[i] = input.nextInt();
		}
		
		System.out.println(countBinarySearch(arr1, arr2));
	}
	
	public static int countBinarySearch(int[] arr1, int[] arr2) {
		int result = 0;
		for (int i = 0; i < arr2.length; i++) {
			if (searchBinary(arr1, arr2[i], 0, arr1.length - 1)) {
				result++;
			}
		}
		return result;
	}
	
	public static boolean searchBinary(int[] arr, int key, int start, int end) {
		/*
		if (start > end) {
			return false;
		} else {
			int mid = (start + end) / 2;
			if (arr[mid] == key) {
				return true;
			} else if (arr[mid] > key) {
				return searchBinary(arr, key, start, mid - 1);
			} else {
				return searchBinary(arr, key, mid + 1, end);
			}
		}
		*/
		
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] == key) {
				return true;
			} else if (arr[mid] > key) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		
		return false;
	}
}



Measured memory_bytes: 68836
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL 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;
}

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    A-=B;
    C-=A;
    if(C<=0) C=0;
    cout << C;
    }

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int> p(a),q(b),r(c);
    rep(i,a)cin>>p[i];
    rep(i,b)cin>>q[i];
    rep(i,c)cin>>r[i];
    sort(p.begin(),p.end(),greater<>());
    sort(q.begin(),q.end(),greater<>());
    sort(r.begin(),r.end(),greater<>());
    int i=0,j=0;
    int ans=0;
    rep(k,c){
        for(;i<x;i++){
            if(p[i]<r[k])break;
            ans+=p[i];
        }
        for(;j<y;j++){
            if(q[j]<r[k])break;
            ans+=q[j];
        }
        if(i==x&&j==y)break;
        if(i==x){
            ans+=r[k];
            y--;
        }
        else if(j==y){
            ans+=r[k];
            x--;
        }else{
            ans+=r[k];
            if(p[x-1]<q[y-1])x--;
            else y--;
        }
    }
    for(;i<x;i++){
        ans+=p[i];
    }
    for(;j<y;j++){
        ans+=q[j];
    }
    cout<<ans<<endl;
}


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

#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define ins insert

#define f(i,n) for(int i = 0 ;  i < n ; i ++)
#define f1(i,n) for(int i = 1 ; i<= n ; i++)

#define int long long int

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)





int32_t main()
{
	fast();
	string s, t;
	cin >> s >> t;

	int l1  = s.length();
	int l2 = t.length();



	t = t.substr(0,l1);

	if(s == t)
		cout<<"Yes";
	else
		cout<<"No";
		
	return  0 ;
	
}




Measured memory_bytes: 3584
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define int __int128
#define min(a,b) a<b?a:b 
template<class T>inline void read(T& x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s&15);s=getchar();}
	x*=f;
}
inline void print(int x,char s) {
    if(x>=10) { print(x/10,'S'); }
    putchar(x%10+'0');
    if(s!='S') putchar(s);
}
inline void print(int x) {
    if(x>=10) { print(x/10); }
    putchar(x%10+'0');
}
template<class T>inline T fabs(T a) { return a>0?a:-a; }
char s[102];
int n,num[102],x,f[102][4];
inline int dfs(int k,int sx,int cnt) {
	if(k>n) return (cnt==x);
	if(cnt>x) return 0;
	if(!sx&&f[k][cnt]) return f[k][cnt];
	int mx,ans=0;
	if(sx) mx=num[k];
	else mx=9;
	rep(i,0,mx) {
		if(i==0) ans+=dfs(k+1,(sx&&(i==mx)),cnt);
		else ans+=dfs(k+1,(sx&&(i==mx)),cnt+1);
	}
	return f[k][cnt]=ans;
}
signed main() {
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n) num[i]=s[i]-'0';
	read(x);
	print(dfs(1,1,0));
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL a;cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

/*-- template --*/

int main() {
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    ll sumA[N + 1];
    sumA[0] = 0;
    rep(i, N)
        sumA[i + 1] = A[i] + sumA[i];
    int cutL = 1, cutR = 3;
    ll ans = LLINF;
    for(int i = 2; i <= N - 2; ++i) {
        while(cutL < i && abs((sumA[i] - sumA[cutL]) - (sumA[cutL] - sumA[0])) >= abs((sumA[i] - sumA[cutL+1]) - (sumA[cutL+1] - sumA[0]))) {
            ++cutL;
        }
        if(cutR == i)cutR = i + 1;
        while(cutR < N && abs((sumA[N] - sumA[cutR]) - (sumA[cutR] - sumA[i])) >= abs((sumA[N] - sumA[cutR + 1]) - (sumA[cutR + 1] - sumA[i]))) {
            ++cutR;
        }
        ll minv = min(min(sumA[cutL] - sumA[0], sumA[i] - sumA[cutL]), min(sumA[N] - sumA[cutR], sumA[cutR] - sumA[i]));
        ll maxv = max(max(sumA[cutL] - sumA[0], sumA[i] - sumA[cutL]), max(sumA[N] - sumA[cutR], sumA[cutR] - sumA[i]));
        ans = min(ans, maxv - minv);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main() {
  long long int a, b, ans = 0, aaa;
  cin >> a >> b;
  int c[a];
  for(int i = 0; i < a; i++) {
    cin >> c[i];
  }
  for(int i = 0; i < a - 1; i++) {
    if(c[i] + c[i + 1] > b) {
      aaa = (c[i] + c[i + 1]) - b;
      ans += aaa;
      c[i + 1] -= aaa;
      if(c[i + 1] < 0) c[i + 1] = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
# A - Where's Snuke?
h, w = map(int, input().split())
alphabets = [chr(i) for i in range(65, 65+26)]

for i in range(h):
	s = list(input().split())
	
	for j in range(w):
		if s[j] == 'snuke':
			print(alphabets[j] + str(i+1))
			exit()

Measured memory_bytes: 3060
N=int(input())
S=[]
AC=0
WA=0
TLE=0
RE=0
for i in range(N):
  s=input()
  if s=="AC":AC+=1
  if s=="TLE":TLE+=1
  if s=="WA":WA+=1
  if s=="RE":RE+=1
print("AC","x",AC)
print("WA","x",WA)
print("TLE","x",TLE)
print("RE","x",RE)

Measured memory_bytes: 9204
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) (*find_by_order(i))
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
// #define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/
vi fre(1e6+5, 0), ans(1e6+5);
void solve(){
    int n;
    cin >> n;
    vi v(n);
    rep(i, 0, n){
        cin >> v[i];
        fre[v[i]]++;
    }
    rep(i, 1, 1e6+1){
        for(int j = i; j <= 1e6; j+=i)ans[j] += fre[i];
    }
    int cnt = 0;
    for(auto i : v){
        if(ans[i] == 1)cnt++;
    }
    cout << cnt;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 11912
class SegTree():
    def __init__(self, initial, operation, identity):
        n = len(initial)
        self.initial = initial
        self.operation = operation
        self.identity = identity
        self.num = 1 << (len(bin(n - 1)) - 2)
        self.tree = [identity] * (2 * self.num - 1)
        for i in range(n):
            self.tree[i + self.num - 1] = self.initial[i]
        for i in reversed(range(self.num - 1)):
            self.tree[i] = min(self.tree[2*i + 1], self.tree[2*i + 2])
    
    def update(self, k, x):
        k += self.num - 1
        self.tree[k] = x
        while k >= 1:
            k = (k - 1) // 2
            self.tree[k] = self.operation(self.tree[2*k + 1], self.tree[2*k + 2])
    
    def query(self, l, r):
        res = self.identity
        l += self.num - 1
        r += self.num - 1
        while l < r:
            if l % 2 == 0:
                res = self.operation(res, self.tree[l])
                l += 1
            if r % 2 == 0:
                res = self.operation(res, self.tree[r - 1])
            l = (l - 1) // 2
            r = (r - 1) // 2
        return res

N, Q = [int(i) for i in input().split()]

H, W = SegTree([N]*N, min, N), SegTree([N]*N, min, N)
revd = 0
for _ in range(Q):
    t, x = [int(i) for i in input().split()]
    if t == 1:
        h = H.query(x, N + 1)
        w = W.query(h, N + 1)
        revd += h - 2
        W.update(h, min(x, w))
    else:
        w = W.query(x, N + 1)
        h = H.query(w, N + 1)
        revd += w - 2
        H.update(w, min(x, h))

ans = (N - 2)*(N - 2) - revd
print(ans)

Measured memory_bytes: 132024
#include <stdio.h>
#include <math.h>

int soatari(int *, int , int );

int n;

int main(){

  int q,m,i;

  scanf("%d",&n);

  int A[n];

  for(i=0;i<n;i++){

    scanf("%d",&A[i]);

  }

  scanf("%d",&q);

  for(i=0;i<q;i++){

    scanf("%d",&m);

    if(soatari(A,0,m)==0) printf("no\n");
    else printf("yes\n");

  }

  return 0;

}

int soatari(int *A, int i, int m){

  if(m==0) return 1;
 
  if(i>=n) return 0;

  int res=soatari(A,i+1,m)||soatari(A,i+1,m-A[i]);

  return res;

}




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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))

class union_find {
public:
  vector<unsigned int> par, rank;
  union_find(unsigned int n) {
    for(unsigned int i = 0; i < n; i++){
      par.push_back(i);
      rank.push_back(1);
    }
  }
  unsigned int root(unsigned int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }
  unsigned int getrank(unsigned int x){
    return rank[root(x)];
  }
  bool same(unsigned int x, unsigned int y){
    return root(x) == root(y);
  }
  void unite(unsigned int x, unsigned int y){
    x = root(x);
    y = root(y);
    if (x == y){return;}
    if (rank[x] < rank[y]){
      par[x] = y;
      rank[y] += rank[x];
    } else {
      par[y] = x;
      rank[x] += rank[y];
    }
  }
};

int main(){
  INT(n);
  vector<int> xs, ys, x2y(n + 1, 0), y2x(n + 1, 0), checked(n + 1, 0);
  REP(n){
    INT(x); INT(y); xs.PB(x); ys.PB(y);
    x2y[x] = y; y2x[y] = x;
  }
  union_find uf(n + 1);
  int cur = n + 1, l = 0, r = y2x[n], miny = n;
  while (1 < cur){
    cur--;
    if (miny < cur){
      uf.unite(y2x[cur], y2x[miny]);
    }
    if (checked[cur]){continue;} 
    r = y2x[cur];
    REP(x, l + 1, r + 1){
      checked[x2y[x]] = 1;
      uf.unite(x, r);
      miny = min(miny, x2y[x]);
    }
    l = r;
  }  
  for(int x: xs){
    printf("%d\n", uf.getrank(x));
  }
  return 0;
}


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

using namespace std;

int main()
{
    char s[6];
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes" << endl;
    }
    else 
    {
        cout << "No" << endl;
    }
}

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

const int MAX_ROW = 630; // to be set appropriately
const int MAX_COL = 630; // to be set appropriately

struct BMAT {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BMAT(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BMAT &A, bool is_extended = false) {
    int rk = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rk; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rk]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rk && A[row][col]) A[row] ^= A[rk];
        }
        ++rk;
    }
    return rk;
}

int linear_equation(BMAT A, vector<int> b, vector<int> &res) {
    int m = A.H, n = A.W;
    BMAT M(m, n + 1);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rk = GaussJordan(M, true);

    for (int row = rk; row < m; ++row) if (M[row][n]) return -1;

    res.assign(n, 0);
    for (int i = 0; i < rk; ++i) res[i] = M[i][n];
    return rk;
}

int main(){
    int s[33][33];
    int h,w,d;
    while(cin>>w>>h>>d,w){
        BMAT A(h*w,h*w);
        vector<int> ans(h*w,0),res;
        r(i,h)r(j,w)cin>>s[i][j];
        r(i,h)r(j,w){
            A[i*w+j][i*w+j]=1;
            r(k,h)r(l,w){
                if(abs(i-k)+abs(j-l)==d){
                    A[i*w+j][k*w+l]=1;
                }
            }
            if(!s[i][j])ans[i*w+j]=1;
        }
        if(linear_equation(A,ans,res)!=-1)cout<<1<<endl;
        else cout<<0<<endl;
    }
}


Measured memory_bytes: 3144
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

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

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

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

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]


def main():
    import sys

    input = sys.stdin.readline

    n, m = map(int, input().split())

    g = tuple(reversed(tuple((int(x) - 1 for x in input().split()) for _ in range(m))))
    t = n * (n - 1) // 2

    ret = [t]  # 最後反転
    uf = UnionFind(n)
    for a, b in g[:-1]:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ret.append(t)
        uf.unite(a, b)
    ret.reverse()
    print(*ret, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 92140
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[0]*n
for i in range(n):
    l[a[i]-1]+=1
l.sort()
i=0
while l[i]==0:i+=1
l=l[i:]
if len(l)<=k:print(0)
else: print(sum(l[:-k]))

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007ll
#define Mod 8223300057563100000ll
using namespace std;
int head[5005],nxt[10005],v[10005],tot=0,n;
int sz[5005],maxn[5005],p[5005],cnt=0,nsz=0;
ll fac[5005],inv[5005],f2[5005],i2[5005],dp[5005],ans=0;
inline void add(int a,int b)
{tot++;nxt[tot]=head[a];head[a]=tot;v[tot]=b;}
inline int max(int a,int b)
{return a>b?a:b;}
void dfs(int pos,int f)
{sz[pos]=1;
for (int i=head[pos];i;i=nxt[i])
{if (v[i]==f) continue;
dfs(v[i],pos);
sz[pos]+=sz[v[i]];
maxn[pos]=max(maxn[pos],sz[v[i]]);
}
maxn[pos]=max(maxn[pos],n-sz[pos]);
}
inline ll cal(int a,int b)
{return (((f2[a]*i2[a-b])%mod)*inv[b])%mod;}
inline ll qpow(ll a,ll b)
{ll res=1,tp=a;
while (b)
{if (b&1ll) res=res*tp%mod;
tp=tp*tp%mod;b>>=1ll;
}
return res;
}
inline void add(int sz)
{int i,j;
for (i=nsz;i>=0;i--)
{for (j=sz;j>=1;j--)
{dp[i+j]+=dp[i]*cal(sz,j);
if (dp[i+j]>Mod) dp[i+j]%=mod;
}
}
nsz+=sz;
for (i=0;i<=nsz;i++) dp[i]%=mod;
}
int main (){
	int i,a,b,msz=233333,num=0,pos;
	scanf ("%d",&n);
	fac[0]=1ll;
	for (i=1;i<=n;i++) fac[i]=fac[i-1]*((ll)(i))%mod;
	inv[n]=qpow(fac[n],mod-2);
	for (i=n-1;i>=0;i--) inv[i]=inv[i+1]*((ll)(i+1))%mod;
	for (i=0;i<=n;i++)
	{f2[i]=fac[i]*fac[i]%mod;
	i2[i]=inv[i]*inv[i]%mod;
	}
	for (i=1;i<n;i++)
	{scanf ("%d%d",&a,&b);
	add(a,b);add(b,a);
	}
	dfs(1,0);
	for (i=1;i<=n;i++)
	{msz=min(msz,maxn[i]);}
	for (i=1;i<=n;i++)
	{if (maxn[i]==msz)
	{pos=i;num++;}
	}
	if (num==2) {printf ("%lld\n",(fac[n/2]*fac[n/2])%mod);return 0;}
	for (i=head[pos];i;i=nxt[i])
	{if (sz[v[i]]>sz[pos]) continue;
	p[++cnt]=sz[v[i]];
	}
	dp[0]=1;
	p[++cnt]=n-sz[pos];
	sort(p+1,p+cnt+1);
	for (i=1;i<=cnt;i++) add(p[i]);
	for (i=0;i<=n;i++)
	{if (i&1) {ans-=dp[i]*fac[n-i];}
	else {ans+=dp[i]*fac[n-i];}
	ans%=mod;
	}
	if (ans<0) ans+=mod;
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
	
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}

int main(){
	deque<int> q;
	int n,a,b,c;
	cin >> n;
	
	rep(i,0,n){
	    cin >> a;
	    if(a == 0){
	        cin >> b >> c;
	        if(b){
	            q.push_back(c);
	        }
	        else{
	            q.push_front(c);
	        }
	    }
	    else if(a == 1){
	        cin >> b;
	        cout << q[b] << endl;
	    }
	    else{
	        cin >> b;
	        if(b){
	            q.pop_back();
	        }
	        else{
	            q.pop_front();
	        }
	    }
	}
  	return 0;
}






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

#ifdef _LOCAL_DEBUG
#include "templates/debug.h"
#else
#define debug(...)
#endif

int r, c, n;
vector<vector<ll>> a;
vector<vector<array<ll, 4>>> dp;

void maxi(ll& x, ll y) {
    x = max(x, y);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> r >> c >> n;
    a.resize(r, vector<ll>(c));
    dp.resize(2, vector<array<ll, 4>>(c));
    for (int x = 0; x < n; x++) {
        int i, j, v;
        cin >> i >> j >> v;
        a[i - 1][j - 1] = v;
    }
    dp[0][0][1] = a[0][0];
    for (int i = 0; i < r; i++) {
        dp[1].assign(c, {0, 0, 0, 0});
        for (int j = 0; j < c; j++) {
            for (int k = 0; k <= 3; k++) {
                if (i + 1 < r) {
                    maxi(dp[1][j][0], dp[0][j][k]);
                    if (a[i + 1][j] != 0)
                        maxi(dp[1][j][1], dp[0][j][k] + a[i + 1][j]);
                }
                if (j + 1 < c) {
                    maxi(dp[0][j + 1][k], dp[0][j][k]);
                    if (k < 3 && a[i][j + 1] != 0)
                        maxi(dp[0][j + 1][k + 1], dp[0][j][k] + a[i][j + 1]);
                }
            }
        }
        if (i + 1 < r)
            copy(dp[1].begin(), dp[1].end(), dp[0].begin());
    }
    cout << *max_element(dp[0][c - 1].begin(), dp[0][c - 1].end());
    return 0;
}

Measured memory_bytes: 73808
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
	int a, b,c=0;
	cin >> a>>b;
	for (int i = 1; i <= b - a; i++) {
		c += i;
	}
	cout << c - b << endl;
	
	return 0;
}

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

#define MOD 998244353
long long power(long long x, long long y) 
{ 
    long long res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % MOD; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % MOD;  // Change x to x^2 
    } 
    return res; 
}


int main() {
    // oh hi mark
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,m,v, p ; cin >> n >> m >> v >> p;
    int a[n];
    for(int i = 0; i< n; i++) cin >> a[i];
    long long c[n],up[n];
    sort(a, a+n);
    for(int i = 0; i < n; i++) {
        if(i == 0) {
            c[i] = a[i]; 
            up[i] = a[i]+m;
        }
        else {
            c[i] = c[i-1] + a[i];
            up[i] = up[i-1] + (a[i] + m);
        }

    }

    

    int pth = a[n-p];
    
    long long left = 0;
    long long right = (p-1) * m;
    long long gap = n - p;
    for(int i = 0; i < n; i++) {
        left += m;
        long long dis = m*v;
        dis -= left;
        dis -= right;

        int ind = upper_bound(a, a+n, a[i]+m) - a;
        if(ind <= n-p) continue;
       // cout << " ind L " << ind << endl;
        long long sum = c[max(i+1, min((int)n - (int)p,ind-1))] - c[i];
        long long safe = (long long)(a[i] + m) * (max(i+1, min((int)n - (int)p,ind-1)) - i);
        
        

        long long canabsorb = max(0LL, safe - sum);

        // cout << i << "safe : " << safe << " - sum " << sum  << endl;
        // cout << "can absorb: " << canabsorb << endl;
        long long extra = dis - canabsorb;
        
        if(extra  <= 0) {
            cout << n-i << endl;
            break;
        }
        gap--;
    }
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define mod 1000000007
int main()
{
  int n,k;
  cin>>n>>k;
  int a[101]={0};
  for(int i=0;i<k;i++)
  {
      int d;
      cin>>d;

      for(int j=0;j<d;j++)
      {
          int p;
          cin>>p;
          a[p]=1;
      }
  }
  int c=0;
  for(int i=1;i<n+1;i++)
  {
      if(a[i]==0)
         c++;
  }
  cout<<c<<"\n";
return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include<sstream>
using namespace std;

int main() {
	int D, N;
	cin >> D >> N;
	int ans = 1;
	for (int i = 0; i < D; i++) ans *= 100;
	if (N != 100) ans *= N;
	else ans *= 101;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*input
9
4 2 5 8 3 6 1 7 9
6 8 8 4 6 3 5 7 5
*/

//sometimes it's the people who no one imagines anything of 
//who do the things that no one can imagine.

//code author: iamxlr8

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

#define ll long long
#define endl "\n"
#define all(c) c.begin(),c.end()
#define mod 1000000007
#define inf 1000000000000000001
#define F first
#define S second
#define dbg(x) cout << #x << " = " << x << '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


// Min Query Segment tree

#define N 200005
ll h[N],v[N],dp[N];
ll lo[4*N+1], hi[4*N+1], mi[4*N+1], delta[4*N+1];
ll n;

void build(ll i,ll a,ll b)
{
    lo[i]=a;
    hi[i]=b;

    if(a==b)
        return;

    ll m=(a+b)/2;
    build(2*i,a,m);
    build(2*i+1,m+1,b);
}

void prop(ll i)
{
    delta[2*i]+=delta[i];
    delta[2*i+1]+=delta[i];
    delta[i]=0;
}

void update(ll i)
{
    mi[i]=max(mi[2*i]+delta[2*i],mi[2*i+1]+delta[2*i+1]);
}

void increment(ll i,ll a,ll b,ll val)
{
    if(b<lo[i]||hi[i]<a)
        return;
    if(a<=lo[i]&&hi[i]<=b)
    {
        delta[i]+=val;
        return;
    }

    prop(i);

    increment(2*i,a,b,val);
    increment(2*i+1,a,b,val);

    update(i);
}

ll query(ll i,ll a,ll b)
{   
    if(b<lo[i]||hi[i]<a)
        return -inf;
    if(a<=lo[i]&&hi[i]<=b)
        return mi[i]+delta[i];

    prop(i);

    ll minLeft=query(2*i,a,b);
    ll minRight=query(2*i+1,a,b);

    update(i);

    return max(minLeft,minRight);
}


void solve()
{
    cin>>n;
    for(ll i=1;i<=n;i++)
        cin>>h[i];
    for(ll i=1;i<=n;i++)
        cin>>v[h[i]];
    build(1,0,n);
    for(ll flower=1;flower<=n;flower++)
    {
        ll x=dp[h[flower]];
        // cout<<x<<" ";
        ll y=query(1,0,h[flower]-1);
        // cout<<y<<" ";
        increment(1,h[flower],h[flower],y+v[h[flower]]);
        // cout<<query(1,h[flower],h[flower])<<endl;
        // for(ll p=0;p<h[flower];p++)
        //     dp[h[flower]]=max(dp[h[flower]],dp[p]+v[h[flower]]);

        // cout<<h[flower]<<" "<<dp[h[flower]]<<endl;
    }
    cout<<query(1,0,n);
}

int main() 
{
    off;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
        solve();
    }
    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  ll n; std::cin >> n;
  set<ll> ans;
  ans.insert(n);
  if (n > 2) ans.insert(n-1);
  ll nn = n-1;
  for (ll i = 2; i*i <= nn; i++) {
    if (nn%i) continue;
    ans.insert(i);
    if (i != nn/i) ans.insert(nn/i);
  }
  for (ll i = 2; i*i <= n; i++) {
    if (n%i) continue;
    ll tmp = n;
    while (tmp%i == 0) tmp/=i;
    if (tmp%i == 1) ans.insert(i);
  }
  std::cout << ans.size() << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll L, R;
    cin >> L >> R;
    if (L % 2019 == 0 || (L / 2019 != R / 2019)) {
        cout << 0 << endl;
    } else {
        ll ans = 1e18;
        for (ll i = L; i <= R; i++) {
            for (ll j = i + 1; j <= R; j++) {
                ll sum = i * j % 2019;
                ans = min(ans, sum);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a, b, goc;
		while (in.hasNext()) {
			a = in.nextInt();
			b = in.nextInt();
			System.out.print(goc = goc(a, b));
			System.out.print(" ");
			System.out.println(a / goc * b);
		}
	}

	static int goc(int a, int b) {
		if (b != 0) return goc(b, a % b);
		else return a;
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);
    	String a=sc.next();
    	String b=sc.next();

    	Integer x=Integer.parseInt(a+b);

    	for(int i=1;i*i<=x;i++) {

    		if(i*i==x) {
    			System.out.println("Yes");
    			return;
    		}
    	}

		System.out.println("No");

    }


}



Measured memory_bytes: 21844
def solve(n, SP):
    return [i for i, _, _ in sorted([(i + 1, s, p) for i, (s, p) in enumerate(SP)], key=lambda v: (v[1], -int(v[2])))]

_n = int(input())
_SP = [input().split() for _ in range(_n)]
print(*solve(_n, _SP), sep='\n')

Measured memory_bytes: 3060
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      string s;
      cin >> s;
      lld f = 1;
      for(lld i = 1; i < 4; i++){
      	if (s[i] == s[i-1]){
      		f = 0;
      		break;
      	}
      }
      if (f == 1)
      	cout << "Good";
      else
      	cout <<  "Bad";
      return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000


int main(){
  unsigned short *A,*B;
  int C[VMAX+1];
  int n,i,j;

  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

 for(i=0;i<=VMAX;i++)C[i]=0;

 for(j=1;j<=n;j++){
   scanf("%hu",&A[j]);
   C[A[j]]++;
  
 }


 
 for(i=1;i<=VMAX;i++)
   {
     C[i]=C[i]+C[i-1];
     
   }
 for(j=n;j>=1;j--)
 {
   B[C[A[j]]]=A[j];
   C[A[j]]--;
 }


  
  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%hu",B[i]);
  }

  printf("\n");
  return 0;
}


  





Measured memory_bytes: 9568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n);
  ll res = n;
  for(int i = 0;i < n;i++)cin >> a[i],x -= a[i];
  sort(a.begin(),a.end());
  res += x / a[0];
  cout << res << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define rg register
#define ll long long
#define mod 1000000007
int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
ll fac[1000005],inv[1000005];
ll qpow(ll b,ll p)
{
    ll ans=1;
    while(p)
    {
        if(p&1) ans=ans*b%mod;
        b=b*b%mod;
        p>>=1;
    }
    return ans;
}
void init(int x)
{
    fac[0]=1;
    for(rg int i=1;i<=x;i++)
        fac[i]=fac[i-1]*i % mod;
    inv[x]=qpow(fac[x],mod-2);
    for(rg int i=x-1;i>=0;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
}
ll C(int x,int y)
{
    return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
   
    int n,m,x,y;
    n=read(),m=read(),x=read(),y=read();
    init(n+m);
    ll ans=0;
    for(int i=1;i<=y;i++)
    {
        ll tem=C(i-1+n-x-1,n-x-1)*C(x-1+m-i,m-i)%mod;
        ans=(ans+tem)%mod;
    }
    ll an=(C(n-1+m-1,n-1)-ans+mod)%mod;
    printf("%lld\n",an);
    return 0;
}

Measured memory_bytes: 5888
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1005;

void print(char a[N][N], int n)
{
	for(int i=0;i<n;i++, cout << '\n')
    {
        for(int j=0;j<n;j++)
        	cout << a[i][j];
    }
    exit(0);
}

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
		char ans[N][N];

    	char ans3[N][N]={
		    "aa.",
		    "..b",
		    "..b"
		};

		char ans4[N][N]={
		    "aacd",
		    "bbcd",
		    "cdgg",
		    "cdhh"
		};

		char ans5[N][N]={
		    "abbc.",
		    "a..ck",
		    "daa.k",
		    "d.fii",
		    "ggfhh"
		};

		char ans6[N][N]={
		    "aad..f",
		    "..daaf",
		    "bba..k",
		    "..abbk",
		    "ccg..n",
		    "..ghhn"
		};

		char ans7[N][N]={
		    "aa.bb.c",
		    "b.a...c",
		    "b.a.aa.",
		    ".bba.hh",
		    "c..a.a.",
		    "c....af",
		    ".ddee.f"
		};

    	int n;
    	cin >> n;

	    if(n <= 2) 
	    	cout << "-1\n";
	    else if(n == 3)
	    	print(ans3, 3);
	    else if(n == 4)
	        print(ans4, 4);
	    else if(n == 5)
	        print(ans5, 5);
	    else if(n == 6)
	        print(ans6, 6);
	    else if(n == 7)
	        print(ans7, 7);
	    else
	    {
	        int nc = n, r = 0, c = 0;
	        memset(ans, '.', sizeof(ans));

	        if(n & 1)
	        {
	            for(int i=0;i<5;i++)
	            {
	                for(int j=0;j<5;j++)
	                	ans[r+i][c+j] = ans5[i][j];
	        	}
	            r += 5;
	            c += 5;
	            n -= 5;
	        }
	        if(n % 4)
	        {
	            for(int i=0;i<6;i++)
	            {
	                for(int j=0;j<6;j++)
	                	ans[r+i][c+j] = ans6[i][j];
	        	}
	            r += 6;
	            c += 6;
	            n -= 6;
	        }
	        while(n)
	        {
	            for(int i=0;i<4;i++)
	            {
	                for(int j=0;j<4;j++)
	                	ans[r+i][c+j] = ans4[i][j];
	        	}
	            r += 4;
	            c += 4;
	            n -= 4;
	        }
            print(ans, nc);
	    }

    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 7168
use strict;
use warnings;

my $n = <STDIN>;
chomp $n;
my @a;
{
    my $in = <STDIN>;
    @a = split(" ", $in);
}
my $ans = 0;
my $b = 1;
while ($b)
{
    for(@a)
    {
        $b = 0 unless $_%2==0;
    }
    @a = map{$_/2} @a;
    $ans++ if $b;
}

print "$ans\n";

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int max_dist = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        max_dist = a[0] + (k - a[n - 1]);
        for(int i = 0; i < n - 1; i++){
            max_dist = Math.max(max_dist, a[i + 1] - a[i]);
        }
        System.out.println(k - max_dist);
    }
}

Measured memory_bytes: 60568
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  signed int A,B;
  cin >> A >> B;
  cout << max(A+B,max(A-B,A*B)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=a+b;
  int y=c+d;
  if(x>y){
    cout<<"Left";}
  else if(x<y){
    cout<<"Right";}
  else{
    cout<<"Balanced";}
  system("pause"); 
  return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int l[1005],r[1005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i]>>r[i];
    }
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=(r[i]-l[i]+1);

    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
import Data.List.Split (splitOn)

isObese :: Double -> Double -> Bool
isObese w h = (w / h / h) >= 25

main :: IO ()
main = putStr . unlines . map show . map round . map head . filter (\[_, w, h] -> isObese w h) . map (map read). map (splitOn ",") . lines =<< getContents

Measured memory_bytes: 4116
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n,mn,ans;
	cin >> n;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
	}
	ans = 0;
	mn = arr[0];
	
	for(int j=0;j<=n-1;j++)
	{
		if(mn >= arr[j])
		{
			ans += 1;
			mn = min(mn,arr[j]);
		}
		else
		{
			mn = min(mn,arr[j]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int coun1[100001];
int coun2[100001];

int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int x;
		cin>>x;
		if(i%2==0){
			coun1[x]++;
		} else {
			coun2[x]++;
		}
	}
	int maxa=-1,maxb=-1,numa,numb;
	for(int i=1;i<100001;i++){
		if(maxa<coun1[i]){
			maxa=coun1[i];
			numa=i;
		}
		if(maxb<coun2[i]){
			maxb=coun2[i];
			numb=i;
		}
	}
	if(numa!=numb){
		cout<<N-maxa-maxb<<'\n';
	} else {
		int seca=-1,secb=-1,numA,numB;
		for(int i=1;i<100001;i++){
			if(i!=numa){
				if(seca<coun1[i]){
					seca=coun1[i];
					numA=i;
				}
			}
			if(i!=numb){
				if(secb<coun2[i]){
					secb=coun2[i];
					numB=i;
				}
			}
		}
		cout<<N-max(maxa+secb,maxb+seca)<<'\n';
	}
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, x, m;
  cin >> n >> x >> m;
  ll now = x;
  ll s = 0,e = 0;
  vector<ll> mtop(m+1, -1);
  vector<ll> acc(m+2, 0);
  for(int i = 1; i <= m+1; i++){
    acc[i] = now + acc[i-1];
    if(mtop[now%m] >= 0){
      s = mtop[now%m];
      e = i;
      break;
    }
    mtop[now%m] = i;
    now = now * now % m;
  }

  if(n > m) cout << acc[s-1] + (acc[e] - acc[s]) * ((n-s)/(e-s)) + acc[n - (n-s)/(e-s) * (e-s)] - acc[s-1] << endl;
  else cout << acc[n] << endl;


  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

typedef long long int llint;

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

  memset(a, 0, sizeof(a));
  int sum = 0;
  int now = 0;

  for(int i = 1; i <= n; i++) cin>> a[i];

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

  for(int i = 1; i <= n; i++) {

    cout<< sum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) <<endl;
  }
  
  return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define data pair<int,pii>

int H, W;
int Ch, Cw;
int Dh, Dw;
char fid[1010][1010];
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
priority_queue<data, vector<data>, greater<data>> pq;
int ans[1010][1010];

bool in_range(pii p)
{
    return 0 <= p.first && p.first < H && 0 <= p.second && p.second < W;
}

char get_fid(pii p)
{
    return fid[p.first][p.second];
}

int get_ans(pii p)
{
    return ans[p.first][p.second];
}

signed main()
{
    cin >> H >> W;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;
    Ch--;
    Cw--;
    Dh--;
    Dw--;
    rep(i, H)rep(j, W)cin >> fid[i][j];

    pq.push({1, {Ch, Cw}});
    while(pq.size())
    {
        data d = pq.top();
        pq.pop();
        pii pos = d.second;
        int dist = d.first;
        if(get_ans(pos))continue;
        ans[pos.first][pos.second] = dist;
        rep(i, 4)
        {
            pii np = {pos.first + dx[i], pos.second + dy[i]};
            if(in_range(np) && get_fid(np) == '.')pq.push({dist, np});
        }
        for(int i = -2; i <= 2; i++)for(int j = -2; j <= 2; j++)
        {
            pii np = {pos.first + i, pos.second + j};
            if(in_range(np) && get_fid(np) == '.')pq.push({dist + 1, np});
        }
    }
    
    cout << ans[Dh][Dw] - 1 << endl;

    return 0;
}


Measured memory_bytes: 17280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,S=0,d=0,f=0;
    cin>>n;
	f=n;
	while(n!=0)
	{
		d=n%10;
		S=d+S;
		n=n/10;
	}
	if(f%S==0)
	printf("Yes");
	else
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//g++ -std=c++11
using namespace std;
typedef long long int ll;
const int MAXN = 100;
const ll MOD = 1000000007;
const int INF = 1000000000;

vector <int> v(MAXN+1);

int main() {

    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a,b;
    cin >> a >> b;
    cout << a*b << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


int main()
{
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];

    vector<pair<bool, int> > box(n);
    for(int i = n; i > 0; --i){
        int tmp = n / i;
        int total = 0;
        for(int j = tmp; j > 0; --j){
            if(box[j * i - 1].first) {
                total += box[j * i - 1].second;
            }
        }

        box[i - 1].first = true;
        if(a[i - 1] == 0 && total % 2== 0){
            box[i - 1].second = 0;
        }
        else if(a[i - 1] == 0 && total % 2 == 1){
            box[i - 1].second = 1;
        }
        else if(a[i - 1] == 1 && total % 2 == 0){
            box[i - 1].second = 1;
        }
        else if(a[i - 1] == 1 && total % 2 == 1){
            box[i - 1].second = 0;
        }
    }
    vector<int> ans;
    for(int i = 0; i < n; ++i){
        if(box[i].second == 1){
            ans.push_back(i + 1);
        }
    }
    cout << ans.size() << endl;

    if(ans.size() != 0){
        for(int i = 0; i < ans.size() - 1; ++i){
            cout << ans[i] << " ";
        }
        cout << ans[ans.size() - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3832