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

class Cube {
    int x, y, z;
    Cube(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    @Override
    public boolean equals(Object obj) {
        Cube o = (Cube)obj;
        return x == o.x && y == o.y && z == o.z;
    }
    @Override
    public int hashCode() {
        return x * 503 * 503 + y * 503 + z;
    }
    @Override
    public String toString() {
        return String.valueOf(x) + "," + String.valueOf(y) + "," + String.valueOf(z);
    }
}

public class Main {
    int n, h;
    int cube;
    Scanner sc;
    Set<Cube> hole;
    enum C {XY, XZ, YZ;}

    Main() {
        sc = new Scanner(System.in);
    }

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

    boolean init() {
        n = sc.nextInt();
        h = sc.nextInt();
        if (n == 0 && h == 0) return false;
        hole = new HashSet<Cube>();

        for (int _h = 0; _h < h; _h++) {
            String c; int a, b;
            c = sc.next();
            a = sc.nextInt()-1;
            b = sc.nextInt()-1;
            switch (C.valueOf(c.toUpperCase())) {
                case XY:
                    for (int i = 0; i < n; i++) hole.add(new Cube(a, b, i));
                    break;
                case XZ:
                    for (int i = 0; i < n; i++) hole.add(new Cube(a, i, b));
                    break;
                case YZ:
                    for (int i = 0; i < n; i++) hole.add(new Cube(i, a, b));
                    break;
            }
        }
        return true;
    }

    void run() {
        while (init()) {
            System.out.println(n*n*n - hole.size());
        }
    }
}

Measured memory_bytes: 17000
N = int(input())
y = N % 10

if y == 3:
  print('bon')
elif y == 0:
  print('pon')
elif y == 1:
  print('pon')
elif y == 6:
  print('pon')
elif y == 8:
  print('pon')
else:
  print('hon')


Measured memory_bytes: 61820
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str1=input.readLine();
	int n=Integer.parseInt(str1);
	int a=0,b=0;
	for(int i=0;i<n;i++)
	    {
		String str3=input.readLine();
	String str2[]=str3.split(" ");
	if(str2[0].compareTo(str2[1])>0)a+=3;
	else if(str2[0].compareTo(str2[1])<0)b+=3;
	else if(str2[0].compareTo(str2[1])==0)
	    {
		a++;
		b++;
	    }

	    }
	System.out.println(a+" "+b);
    }
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool isPrime(int n){
    if(n==1)return false;
    if(n==2)return true;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        for(int i=n;i>=5;i--){
            if(isPrime(i) && isPrime(i-2)){
                cout<<i-2<<" "<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>

using namespace std;

int main(){
	int n[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	cout << n[k-1] << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#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 LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%d\n", MIN(a+b,MIN(b+c,c+a)));

    return;
}

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

	return 0;
}


Measured memory_bytes: 128
PROGRAM piyo
      IMPLICIT NONE
      character(4000) :: s
      integer(16) :: numR(1:4000)=0,numG(1:4000)=0,numB(1:4000)=0
      integer(16) :: rgb(3)=0,i,j,n,ans=0,notK
      
      read*,n
      read*,s(1:n)
      
      if( s(1:1)=='R' )then
          numR(1) = 1
      else if( s(1:1)=='G' )then
          numG(1) = 1
      else
          numB(1) = 1
      endif
      
      rgb(1:3) = 0
      do i = 2,n
        if( s(i:i)=='R' )then
          rgb(1) = 1
        else if( s(i:i)=='G' )then
          rgb(2) = 1
        else
          rgb(3) = 1
        end if
        
        numR(i) = numR(i-1) + rgb(1)
        numG(i) = numG(i-1) + rgb(2)
        numB(i) = numB(i-1) + rgb(3)
        rgb = 0
      end do
      
      ans = numR(n) * numG(n) * numB(n)
      
      do i = 1,n-2
        do j = i+1,n-1
          
          notK = 2*j-i
          if( notK>n ) cycle
          
          if( s(i:i)/=s(j:j) .and. s(j:j)/=s(notK:notK) .and. &
              s(i:i)/=s(notK:notK) )then
            ans = ans - 1
          end if
          
        end do
      end do
      
      
      print*,ans
      
      !debugg
  !    print*,numR(1:n)
  !    print*,numG(1:n)
  !    print*,numB(1:n)
      
      
      END PROGRAM

Measured memory_bytes: 2856
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    ab_list = [tuple(map(int, input().split())) for _ in range(n)]
    ab_list.sort(key=lambda x: x[1])
    time_elapsed = 0
    is_ok = True
    for ab in ab_list:
        time_elapsed = time_elapsed + ab[0]
        if time_elapsed > ab[1]:
            is_ok = False
            break
    if is_ok:
        print("Yes")
    else:
        print("No")

# 締め切りが早い順に並び替える
# 締め切りが早い順に取り掛かって、間に合わない仕事が１つでもあればNoなければYes


Measured memory_bytes: 83452
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(N-1+M)]

CLIST=[[] for i in range(N+1)]
PLIST=[[] for i in range(N+1)]

for x,y in EDGE:
    PLIST[y].append(x)
    CLIST[x].append(y)


ANSLIST=[-1]*(N+1)
check=[0]*(N+1)

for i in range(1,N+1):
    if PLIST[i]==[]:
        root=i
        break

#check[root]=1
ANSLIST[root]=0

QUE= deque()
QUE.append(root)

while QUE:
    x=QUE.pop()
    
    for next in CLIST[x]:
        count=0
        for j in PLIST[next]:
            if check[j]==1:
                continue
            count+=1
        if count==1:
            QUE.append(next)
            ANSLIST[next]=x
    check[x]=1

for a in ANSLIST[1:]:
    print(a)
    

Measured memory_bytes: 87388
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
Arr.shift();
Arr.forEach(function(v){
var arr=v.split(" ").map(Number);
arr.sort(function(a,b){return a-b;});
var a=arr[0];
var b=arr[1];
var c=arr[2];
var str="";
str=(c*c==a*a+b*b)?"YES":"NO";
console.log(str);
});

Measured memory_bytes: 10460
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll t[105];
int main() {
  IOS;
  int n;
  cin >> n;
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    ll g = __gcd(ans, t[i]);
    ans = ans / g * t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
def main():
    #ABCD入力を取得する。
    num = list(input())

    #op[1, -1]
    op = [1, -1]
    opc = ['+','-']

    ans = 0
    fin = False

    #全探索をする。(0:+, 1:-)
    for i in range(2):
        for j in range(2):
            for k in range(2):
                ans = int(num[0]) + op[i]*int(num[1]) + op[j]*int(num[2]) + op[k]*int(num[3])
                if ans == 7:
                    fin = True
                    break
                    
            if fin == True:
                break
        if fin == True:
            break

    print(num[0]+opc[i]+num[1]+opc[j]+num[2]+opc[k]+num[3]+'='+str(ans))

main()

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

bool check(ll n, ll m, ll k){
	return 2*k + 2*max(0LL, k - n) <= m;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll n, m;
	cin>>n>>m;
	ll lo = 0, hi = 1e13;
	while(lo < hi){
		ll mi = lo + (hi - lo + 1)/2;
		if(check(n, m, mi))lo = mi;
		else hi = mi - 1;
	}
	cout<<lo<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000
#define NIL -1

void print(int);
int rec(int,int);

struct node{

  int p;
  int l;
  int r;
  
  

};
  


  struct node T[MAX];
    int n;
    int D[MAX];


  int main()
  {
    int i,j,d,v,c,l,r;
    scanf("%d",&n);
    for(i=0;i<n;i++)
      {
	T[i].p=T[i].l=T[i].r=NIL;
	
      }
    for(i=0;i<n;i++)
      {
	scanf("%d",&v);
	scanf("%d",&d);
	for(j=0;j<d;j++)
	  {
	    scanf("%d",&c);
	    if(j==0)T[v].l=c;
	    else T[l].r=c;
	    l=c;
	    T[c].p=v;
	  }
	
      }

    for(i=0;i<n;i++)
      {
	if(T[i].p==NIL)r=i;
      }
    rec(r,0);

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

    return 0;
  }


void print(int u)
{
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r)
    {
      if(i) printf(", ");
      printf("%d",c);
    }
  printf("]\n");
  
}

int rec(int u,int p)
{
  D[u]=p;
  if(T[u].r!=NIL)rec(T[u].r,p);
  if(T[u].l!=NIL)rec(T[u].l,p+1);
}




Measured memory_bytes: 7256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, r = list(map(int, input().strip().split()))
    if n >= 10:
        print(r)
    else:
        print(100*(10-n) + r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

int t[1000000];
int n = 900000;
int sum(int r) {
	int result = 0;
	for (; r >= 0; r = (r & (r + 1)) - 1)
		result += t[r];
	return result;
}

void inc(int i, int delta) {
	for (; i < n; i = (i | (i + 1)))
		t[i] += delta;
}


int main()
{
#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	string str;
	cin >> str;

	vector<pair<int, int>> vv;
	bool been_odd = false;
	int odd_pos = 0;
	for (char c = 'a'; c <= 'z'; c++)
	{
		vector<int> pos;
		for (int j = 0; j < str.size(); j++)
		{
			if (str[j] == c)
				pos.push_back(j);
		}

		for (int i = 0, j = pos.size() - 1; i < j; i++, j--)
		{
			vv.push_back({ pos[i], pos[j] });
		}

		if (pos.size() % 2 == 1)
		{
			if (been_odd)
			{
				cout << -1;
				return 0;
			}
			odd_pos = pos[pos.size() / 2];
			been_odd = true;
		}
	}

	if (str.size() % 2 != been_odd)
	{
		cout << -1;
		return 0;
	}

	sort(vv.begin(), vv.end(), [&](pair<int, int>& a, pair<int, int>& b) {
		return a.second < b.second;
		});

	for (auto x : vv)
	{
		inc(x.first, 1);
	}

	long long resp = 0;



	for (auto x : vv)
	{
		if (been_odd && (odd_pos > x.second || odd_pos < x.first))
			resp++;
		resp += 2 * (sum(n - 1) - sum(x.second));
	}

	for (auto x : vv)
	{
		inc(x.first, -1);
		resp += (sum(x.second) - sum(x.first));
	}

	cout << resp;

	return 0;
}

Measured memory_bytes: 2828
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n,n){
		vector<string> s(n);
		for(int i=0;i<n;i++){
			cin >> s[i];
		}
		vector<int> v(n);
		for(int i=0;i<n;i++){
			int cnt=0;
			while(s[i][cnt]=='.')cnt++;
			v[i]=cnt;
			if(i)s[i][cnt-1]='+';
		}
		for(int i=1;i<n;i++){
			int u=i+1;
			while(u<n&&v[u]>v[i])u++;
			bool f=0;
			if(u<n&&v[u]==v[i])f=1;
			for(int j=i+1;j<u;j++){
				s[j][v[i]-1]=(f?'|':' ');
			}
		}
		for(int i=0;i<n;i++){
			cout << s[i] << "\n";
		}
	}
}



Measured memory_bytes: 3312
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean isA = false, isB = false, isC = false, isD = false;
        int[] index = new int[4];
        for (int i = 0; i < 4; i++) {
            index[i] = scanner.nextInt();
        }
        for (int i = 0; i < 4; i++) {
            int idx = index[i];
            if (idx == 1) {
                isA = true;
            } else if (idx == 9) {
                isB = true;
            } else if (idx == 7) {
                isC = true;
            } else if (idx == 4) {
                isD = true;
            }
        }
        System.out.println(isA && isB && isC && isD ? "YES" : "NO");
    }

}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for(auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vl g[MAX_N];
vl visited(MAX_N, 0), par(MAX_N, 0);
vl A;
void dfs(ll x, ll a) {
    visited[x] = 1;
    for(ll i : g[x]) {
        if(visited[i] == 0) {
            dfs(i, a + 1);
            par[i] = x;
        }
        if(i == k && w > a + 1) {
            p = 1;
            t = x;
            w = a + 1;
            A.clear();
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, m) {
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
    }

    w = INF;

    rep(i, n) {
        k = i;
        visited = vl(n, 0);
        p = 0;
        dfs(i, 0);
        if(p) {
            A.push_back(t);
            while(t != i) {
                t = par[t];
                A.push_back(t);
            }
        }
    }

    if(A.size() == 0)
        cout << -1 << endl;
    else {
        cout << A.size() << endl;
        for(ll j : A)
            cout << j + 1 << endl;
    }
}

Measured memory_bytes: 19840
import sys
input = sys.stdin.readline
L = int(input())

B = bin(L)[2:]
N = len(B)

ans = []
for i in range(1,N):
    ans.append((i,i+1,0))
    ans.append((i,i+1,2**(N-i-1)))

base = 2**(N-1)
for i,b in enumerate(B[1:]):
    if b == '1':
        ans.append((1,i+2,base))
        base += 2**(N-i-2)

print(N,len(ans))
for a in ans:
    print(*a)


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

int main() {
	int H, W;
	
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i == 0 || i == H - 1)cout << '#';
				else if (j == 0 || j == W - 1)cout << '#';
				else cout << '.';
			}
			cout << '\n';
		}
		cout << endl;
	}

	return 0;
}

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

main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    string s,t;
    cin>>s>>t;

    int n=s.size(),m=t.size();
    
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=m;i++){
        dp[0][i]=0;
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    int k=dp[n][m];
    int i=n,j=m;
    string ans="";
    while(k>0){
        if(s[i-1]==t[j-1]){
            ans+=s[i-1];
            i--;
            j--;
            k--;
        }
        else{
            if(dp[i-1][j]>dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
    }    

    reverse(ans.begin(),ans.end());
    cout<<ans;

    return 0;
}

Measured memory_bytes: 70656
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

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

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

int main(){
	int n,x;
	scanf("%d %d",&n, &x);
	if(x==1 || x==2*n-1){
		puts("No");
		return 0;
	}
	if(n==2){
		puts("Yes\n1\n2\n3");
		return 0;
	}
	int nb=2*n-1; //bottomの数
	int center[4];

	int l,r,skip;
	if(x==2){
		center[0]=3;
		center[1]=1;
		center[2]=2;
		center[3]=nb;
		skip=3;
		l=nb/2-2;
		r=nb/2+2;
	}else{
		center[0]=1;
		center[1]=x;
		center[2]=nb;
		center[3]=x-1;
		skip=x-1;
		l=nb/2-1;
		r=nb/2+3;
	}
	printf("Yes\n");
	int num=2;
	for(int i=0;i<l;i++){
		while(num==x || num==skip) num++;
		printf("%d\n",num++);;
	}
	rep(i,4) printf("%d\n",center[i]);
	for(int i=r;i<nb;i++){
		while(num==x || num==skip) num++;
		printf("%d\n",num++);
	}

	return 0;
}

Measured memory_bytes: 1536
import numpy as np
n = int(input())
a = list(map(int,input().split()))
for i in range(n): a[i] -= i+1
a=np.array(a)
a.sort()
x= a[(n-1)//2] if n%2==1 else round((a[n//2-1]+a[n//2])/2.)
a=a-x
print(int(sum(abs(a))))


Measured memory_bytes: 34188
#include <cstdio>
#include <iostream>
using namespace std;
inline char nc() {
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f; 
}
const int maxn = 1e5 + 5;
const int maxm = 1e5 + 5;
typedef long long ll;
int n, m, E[maxm][2]; ll an[maxm];
int siz[maxn];
struct UnionSet {
	int fa[maxn];
	void init() {
		for(int i = 1; i <= n; ++i) {
			fa[i] = i, siz[i] = 1;
		}
	}
	int find(int a) {
		return a == fa[a] ? a : fa[a] = find(fa[a]);
	}
} us;
void sol() {
	us.init();
	ll now = (ll)n * (n - 1) / 2;
	for(int i = m; i >= 1; --i) {
		an[i] = now;
		int u = us.find(E[i][0]);
		int v = us.find(E[i][1]); if(u > v) swap(u, v);
		if(u != v) {
			now -= (ll)siz[u] * siz[v];
			siz[u] += siz[v];
			us.fa[v] = u;  
		}
	}
}
int main() {
//	freopen("testdata.in", "r", stdin);
	read(n), read(m);
	for(int i = 1; i <= m; ++i) {
		read(E[i][0]), read(E[i][1]); 
	}
	sol();
	for(int i = 1; i <= m; ++i) {
		printf("%lld\n", an[i]);
	}
	return 0;
}

Measured memory_bytes: 3712
'use strict'

function main(s) {

  const seqs= s.split('\n').slice(1, -1).map(el => el.split(' ').map(num => Number(num)));

  const isSeated = Array(100001).fill(0);

  for (const seq of seqs) {
    for (let i = seq[0]; i <= seq[1]; i++) {
      isSeated[i] = 1;
    }
  }

  const ans = isSeated.filter(num => (num === 1)).length;
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define mod 1000000007

#define rep(i, n) for(int i=0; i<n; ++i)

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int n;
	
	cin >> n;
	
	vector<int> a(n);
	
	rep(i, n)
		cin >> a[i];
		
	sort(a.begin(), a.end());
	
	double mid = double(a[n - 1]) / 2.0, mini = 1e9;
	int num;

	rep(i, n){
		double diff = abs(mid - a[i]);
		if(diff < mini){
			num = i;
			mini = diff;
		}
	}
	
	cout << a[n - 1] << " " << a[num] << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

int main()
{
  int n, k, gc=0, mx=0;
  scanf("%d%d", &n, &k);

  REP(i, n) {
    int x;
    scanf("%d", &x);
    mx = max(mx, x);
    gc = __gcd(gc, x);
  }

  printf("%s\n", ((k % gc) || mx < k) ? "IMPOSSIBLE" : "POSSIBLE");

  return 0;
}


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


int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n+1);
    for(ll j=1;j<=n;j++)
    {
        cin>>a[j];
    }
    ll dp[n+1];
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(ll j=3;j<=n;j++)
    {
        dp[j]=min(dp[j-1]+abs(a[j]-a[j-1]),dp[j-2]+abs(a[j]-a[j-2]));
    }
    //for(ll j=1;j<=n;j++)cout<<dp[j]<<" ";
    //cout<<endl;
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1792
using System;

public class Program
{
	public static void Main()
	{
		string T = Console.ReadLine();
		string P = Console.ReadLine();
		for (int i = 0; i < T.Length - P.Length + 1; i++)
		{
			if (T.Substring(i, P.Length) == P)
			{
				Console.WriteLine(i);
			}
		}
	}
}

Measured memory_bytes: 9284
printFrame [h,w] = unlines $ e : (center (h-2) (w-2)) ++ [e]
	where e = replicate w '#'

center 0 _ = []
center n w = ('#' : replicate w '.' ++ ['#']) : center (n-1) w

main = getContents >>= mapM_ putStrLn . map (printFrame . map read . words) . init . lines

Measured memory_bytes: 4856
#include <iostream>
#include <algorithm>

typedef long long ll;
const int MAXN = 1e6+5;

int N;
int low_factor[MAXN], A[MAXN], cnt[MAXN];

void prepare_factors() {
  for (int i = 0; i < MAXN; ++i)
    low_factor[i] = i;
  for (ll i = 2; i < MAXN; ++i) {
    if (i != low_factor[i]) continue;
    for (ll j = i*i; j < MAXN; j += i)
      low_factor[j] = i;
  }
}

bool is_pairwise_coprime() {
  for (int i = 0; i < MAXN; ++i)
    cnt[i] = 0;
  //std::cout << "N: " << N << "\n";
  for (int i = 0; i < N; ++i) {
    int x = A[i];
    //std::cout << i << " " << N << " " << x << "\n";
    while (x != 1) {
      int lf = low_factor[x];
      //std::cout << x << " | " << low_factor[x] << "\n";
      cnt[lf]++;
      if (cnt[lf] >= 2)
        return false;
      while (x % lf == 0)
        x /= lf;
    }
  }
  return true;
}

bool is_setwise_coprime() {
  int g = A[0];
  for (int i = 1; i < N; ++i)
    g = std::__gcd(g, A[i]);
  return g == 1;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);

  prepare_factors();

  std::cin >> N;
  for (int i = 0; i < N; ++i)
    std::cin >> A[i];

  if (is_pairwise_coprime())
    std::cout << "pairwise coprime\n";
  else if (is_setwise_coprime())
    std::cout << "setwise coprime\n";
  else
    std::cout << "not coprime\n";

  return 0;
}


Measured memory_bytes: 15352
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e5+4;

int main()
{
	
	long double a,b; cin>>a>>b;

	a*=b;

	cout<<fixed<<setprecision(0)<<trunc(a);

    return 0;
}

Measured memory_bytes: 3796
(n,m)=gets.split.map(&:to_i);

a = ARGF.map {|s|s.split.map(&:to_i)}
s = a.take(a.size-1).map{|a|a.drop(1)}
p = a[-1] 
r = [0,1].product(*([[0,1]]*(n-1))).to_a.select {|x| (0...m).all?{|i| (s[i].map{|k|x[k-1]}.reduce(:+) % 2) == p[i] } }

p r.size

Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define MOD 1000000007

int main(void){
    ll n,k,s;
    ll a;
    cin >> n >> k >> s;
    if(s==1e9){
        a=1;
    }else{
        a=s+1;
    }
    rep(_,k) cout << s << ' ';
    rep(_,n-k) cout << a << ' ';
}

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

int main(){
    int N,M[3],mn=100000000;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>M[i];
        mn=min(mn,M[i]);
    }
    for(int i=1;i<=mn;i++){
        for(int j=0;j<N;j++){
            if(M[j]%i!=0) break;
            else if(j==N-1){
                printf("%d\n",i);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1144
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.split("\n");

  const allAtack = input[1].split(" ").map(e => parseInt(e));
  let damege = 0;

  allAtack.map(e => (damege += e));

  if (input[0].split(" ")[0] <= damege) {
    console.log("Yes");
  } else {
    console.log("No");
  }
}


Measured memory_bytes: 27652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
# define pb push_back
typedef long long ll;



int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    int count=0;
    rep(i,10000){
        int max = *max_element(h.begin(),h.end());
        if(max == 0){
            break;
        }
        int min = *min_element(h.begin(),h.end());
        if(min != 0){
            rep(i,n){
                h[i] -= 1;
            }
        }
        else{
            vector<int> min_sets;
            min_sets.pb(-1);
            rep(i,n){
                if(h[i]==min){
                    min_sets.pb(i);
                }
            }
            min_sets.pb(n);
            int len = min_sets.size();
            rep(i,len-1){
                if(min_sets[i] != min_sets[i+1] -1){
                    reps(j,min_sets[i]+1,min_sets[i+1]){
                        h[j] -= 1;
                    }
                    break;
                }
            }
        }
        count ++;
    }
    cout << count;
}

Measured memory_bytes: 256
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a

def solve(a,b):
  return a*b//gcd(a,b)

ans=1
N=int(input())
for i in range(N):
  a=int(input())
  ans=solve(ans,a)
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

vector<pair<int, pii > > v;
set<int > s;
set<int >::iterator it;

int main() {
  int n;
  S(n);
  rep(i,0,n) {
    int x,y;
    S2(x,y);
    v.pb(mp(x, mp(y, 0)));
  }
  rep(i,0,n) {
    int x,y;
    S2(x,y);
    v.pb(mp(x, mp(y, 1)));
  }
  sort(all(v));
  int ans = 0;
  rep(i,0,v.size()) {
    if(v[i].SS.SS) {
      int x = -1;
      for(it = s.begin(); it != s.end(); it++) {
        if(*it < v[i].SS.FF) {
          x = *it;
        }
      }
      if(x != -1) {
        s.erase(x);
        ans++;
      }
    } else {
      s.insert(v[i].SS.FF);
    }
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
string S;
int W[200002];
int B[200002];

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

  cin >> N;
  cin >> S;

  W[0] = S[0]=='.'?1:0;
  rep(i, N-1){
    if (S[i+1]=='.') W[i+1]=W[i]+1;
    else W[i+1]=W[i];
  }
  B[N-1] = S[N-1]=='#'?1:0;
  rep_down(i, N-1){
    if (S[i]=='#') B[i]=B[i+1]+1;
    else B[i]=B[i+1];
  }
  int ans = N - B[0];
  rep(i, N){
    if (i==N-1){
      ans = min(ans, N - W[N-1]);
      break;
    }
    ans = min(ans, N-W[i]-B[i+1]);
  }

  cout << ans << "\n";
  return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;

int W, H;
string c[71];
string dp[71][71];

bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

string maxString(string s, string t) {
    if (s.length() > t.length()) return s;
    if (s.length() < t.length()) return t;
    return (s >= t) ? s : t;
}


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

    while (cin >> W >> H && W) {
        rep(i, H) cin >> c[i];

        rep(i, H + 1) rep(j, W + 1) dp[i][j] = "";
        string ans = "";
        rep2(i, 1, H + 1) {
            rep2(j, 1, W + 1) {
                int ci = i - 1, cj = j - 1;
                if (!isdigit(c[ci][cj])) continue;
                string maxS = maxString(dp[i - 1][j], dp[i][j - 1]);
                if (maxS == "" && c[ci][cj] == '0') {
                    dp[i][j] = "";
                } else {
                    dp[i][j] = maxS + c[ci][cj];
                    ans = maxString(ans, dp[i][j]);
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(){
  int a, b, res;
  char op;
  while(1){
    scanf("%d %c %d", &a, &op, &b);
  if(op == '?'){break;}
  if(op == '+'){res = a + b;}
  else if(op == '-'){res = a - b;}
  else if(op == '*'){res = a * b;}
  else if(op == '/'){res = a / b;}
  printf("%d\n",res);
  }
  return 0;
}



Measured memory_bytes: 2736
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;

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

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


	int ans = 1000000000;

	for(int i = -100;i <= 100;i++){
		int now = 0;
		for(int j = 0;j < n;j++){
			now += (i - a[j]) * (i - a[j]);
		}
		ans = min(ans,now);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{

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

      while(true){
      int H=sc.nextInt();
      int W=sc.nextInt();
      
      if(H==0&&W==0) break;
          
      for(int i=0;i<H;i++){
       for(int j=0;j<W;j++)
        System.out.print("#");
        System.out.print("\n");
      }
      System.out.print("\n");
}
}

}


Measured memory_bytes: 37204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> ans(n);
    rep(i, n) ans[i] = a[i];
    rep(i, k) {
        bool flg = true;
        vector<ll> pre(n);
        swap(pre, ans);
        vector<ll> x(n+1);
        rep(j, n) {
            ll l = j - pre[j];
            chmax(l, 0LL);
            ll r = j + pre[j] + 1;
            chmin(r, n);
            x[l] += 1LL;
            x[r] -= 1LL;
        }
        rep(j, n) {
            if (j==0) ans[j] = x[j];
            else {
                ans[j] = ans[j-1] + x[j];
            }
            if (ans[j]<n) flg = false;
        }
        if (flg) break;
        
    }
    
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 9592
// Contest: AtCoder Beginner Contest 151 (https://atcoder.jp/contests/abc151)
// Problem: C: Welcome to AtCoder (https://atcoder.jp/contests/abc151/tasks/abc151_c)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cpp_lib_nonmember_container_access >= 201411
#   define sz(x) ((int)size(x))
#else
#   define sz(x) ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define all(a)         (a).begin(),(a).end()
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __has_cpp_attribute(maybe_unused) >= 201603
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18;
//endregion }}}

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

    int n, m; cin >> n >> m;
    vi pen(n);
    vector<bool> done(n);
    string s;
    rep(i, m) {
        int pi; cin >> pi >> s; --pi;
        if (done[pi]) continue;
        if (s == "WA")
            ++pen[pi];
        else
            done[pi] = true;
    }

    int cor = 0, totpen = 0;
    rep(i, n)
        cor += done[i], totpen += done[i] ? pen[i] : 0;

    cout << cor << ' ' << totpen << '\n';

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    map<int, int> m;
    rep(i, n) {
        int a; cin >> a;
        if(!m.count(a)) m[a] = 1;
        else m[a]++;
    }
    ll sum = 0;
    for(auto x : m) sum += x.first * x.second;
    int q; cin >> q;
    rep(i, q) {
        ll b, c; cin >> b >> c;
        if(m.count(b)) {
            sum -= b * m[b];
            sum += c * m[b];
            if(!m.count(c)) m[c] = 0;
            m[c] += m[b];
            m.erase(b);
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 6524
n = int(input())
lis = list(map(int, input().split()))

if 0 in lis:
    print(0)
    exit()

res = 1
for i in lis:
    if res > 10**18:
        print(-1)
        exit()
    else:
        res *= i
print(res if res <= 10**18 else -1)


Measured memory_bytes: 21664
solve :: [Int] -> Int
solve [n, x] = length $ filter (\y -> x == y) [a + b + c | a <- [1 .. n], b <- [a + 1 .. n], c <- [b + 1 .. n]]

main :: IO ()
main = interact (unlines . map (show . solve) . takeWhile (\xs -> any (/= 0) xs) . map (map read . words) . lines)

Measured memory_bytes: 4536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class BOneClue
    {
        static void Main(string[] args)
        {
            var kx = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToList();
            int k = kx[0];
            int x = kx[1];

            int point = x - k + 1;
            var answers = new List<int>();
            for (int i = 1; i < k * 2; i++)
            {
                answers.Add(point);
                point++;
            }

            Console.WriteLine(string.Join(" ", answers.Where(a => -1000000 < a && a < 1000000).ToList()));
            Console.ReadLine();
        }
    }
}

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

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi acos(-1.0)
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int main (){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	cout << s;
	if(s.back() == 's') cout << "es\n";
	else cout << "s\n";
	
	return 0;
}

Measured memory_bytes: 3660
import math
A,B,H,M=map(int,input().split())
if 30*H-6*M>=0:
    y=abs(30*H-6*M)+M/2
else:
    y=abs(30*H-6*M)-M/2
if y==90 or y==270:
    ans=(A**2+B**2)**(0.5)
else:
    ans=(A**2+B**2-2*A*B*math.cos(math.radians(y)))**(0.5)
print(ans)



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

int main(){
    int n;
    cin >> n;
    vector<int> d(0);
    int input;
    for(int i=0;i<n;i++){
        cin >> input;
        d.push_back(input);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int h,w,k;
char s[10][1001];

int solve(vector<int> id)
{
    //cout << "in ";
    //for(int i=0;i<h;i++) cout << id[i] << " ";
    //cout << endl;
    vector<int> cnt(h,0);
    int res=0;
    for(int i=0;i<w;i++)
    {
        bool ok=1;
        for(int j=0;j<h;j++)
        {
            cnt[id[j]]+=(s[j][i]=='1');
            if(cnt[id[j]]>k) ok=0;
        }
        if(!ok)
        {
            for(int j=0;j<h;j++) cnt[id[j]]=0;
            for(int j=0;j<h;j++) cnt[id[j]]+=(s[j][i]=='1');
            for(int j=0;j<h;j++) if(cnt[id[j]]>k) return h+w-2;
            //cout << "cut before " << i << endl;
            res++;
        }
    }
    return res;
}

int main()
{
    scanf("%d%d%d",&h,&w,&k);
    for(int o=0;o<h;o++) scanf("%s",s[o]);
    int res=h+w-2;
    for(int i=0;i<(1<<(h-1));i++)
    {
        int idx=0;
        vector<int> id(h,0);
        for(int j=0;j<h;j++)
        {
            id[j]=idx;
            if(i&(1<<j)) idx++;
        }
        res=min(res,solve(id)+idx);
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,m,k,ans1,ans2,ans3,x,y,z,a,b,f[2039][2039],ql[2039][2039],qr[2039][2039],q[2039][2039];
char s;
int main(){
	register int i,j;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			s=getchar();
			while(s<'0'||s>'9') s=getchar();
			f[i][j]=s-'0';
			q[i][j]=f[i][j];
			if(f[i][j]&&f[i][j-1]) ql[i][j]=f[i][j];
			if(f[i][j]&&f[i-1][j]) qr[i][j]=f[i][j];
			q[i][j]+=q[i-1][j]+q[i][j-1]-q[i-1][j-1];
			ql[i][j]+=ql[i-1][j]+ql[i][j-1]-ql[i-1][j-1];
			qr[i][j]+=qr[i-1][j]+qr[i][j-1]-qr[i-1][j-1];
		}
	}
	for(i=1;i<=k;i++){
		scanf("%d%d%d%d",&x,&y,&a,&b);
		ans1=q[a][b]-q[x-1][b]-q[a][y-1]+q[x-1][y-1];
		ans2=ql[a][b]-ql[x-1][b]-ql[a][y]+ql[x-1][y];
		ans3=qr[a][b]-qr[x][b]-qr[a][y-1]+qr[x][y-1];
		printf("%d\n",ans1-ans2-ans3);
	}
}

Measured memory_bytes: 65708
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn  main() {
    let n = read::<i32>();
    let dx = read_vec::<i32>();
    let mut an = Vec::new();
    for _ in 0..n {
        an.push(read::<i32>());
    }
    let mut ans  = 0;
    for i in 0..n{
        if  dx[0] % an[i as usize] == 0 {
             ans += dx[0] / an[i as usize]
        } else {
        ans += dx[0] / an[i as usize] + 1;
        }
    }
    println!("{}",ans+ dx[1]);
}

Measured memory_bytes: 4352
use proconio::input;
use proconio::marker::Usize1;
use std::collections::HashMap;
use std::cmp;

fn main() {
    input! {
        r: usize,
        c: usize,
        k: usize,
        items: [(Usize1, Usize1, isize); k],
    }

    let mut dp = vec![vec![vec![0; 4]; c]; r];
    let mut map = HashMap::new();

    for item in &items {
        map.insert((item.0, item.1), item.2);
    }

    if let Some(&value) = map.get(&(0,0)) {
        dp[0][0][1] = value;
    }

    for i in 0..r {
        for j in 0..c {
            for k in 0..4 {
                if let Some(&value) = map.get(&(i, j)) {
                    if i > 0 {
                        dp[i][j][1] = cmp::max(dp[i][j][1], dp[i-1][j][k] + value);
                        dp[i][j][0] = cmp::max(dp[i][j][0], dp[i-1][j][k]);
                    }
                    if j > 0 {
                        if k < 3 {
                            dp[i][j][k+1] = cmp::max(dp[i][j][k+1], dp[i][j-1][k] + value);
                        }
                        dp[i][j][k] = cmp::max(dp[i][j][k], dp[i][j-1][k]);
                    }
                } else {
                    if i > 0 {
                        dp[i][j][0] = cmp::max(dp[i][j][0], dp[i-1][j][k]);
                    }
                    if j > 0 {
                        dp[i][j][k] = cmp::max(dp[i][j][k], dp[i][j-1][k]);
                    }
                }
            }
        }
    }

    let mut ans = 0;
    for &value in &dp[r-1][c-1] {
        ans = cmp::max(ans, value);
    }

    println!("{}", ans);
}


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

#ifdef DEBUG_MD
	#define debug(format, ...) fprintf(stderr, format, __VA_ARGS__)
#else
	#define debug(format, ...) 0
#endif

typedef long long LL;

const int MAXN = 1e5 + 10;

int N, Q, A[MAXN], MAX_DELTA, MINA = 1e9 + 100, MAXA;
LL sum[MAXN], sume[MAXN], sumo[MAXN];

void solve();

int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; i++) {
		scanf("%d", A + i);
		MINA = std::min(MINA, A[i]);
		MAXA = std::max(MAXA, A[i]);
	}

	MAX_DELTA = MAXA - MINA;
	for (int i = 1; i <= N; i++) {
		sum[i] = sum[i - 1] + A[i];
		sumo[i] = sumo[i - 1] + LL(i & 1 ? A[i] : 0);
		sume[i] = sume[i - 1] + LL(i & 1 ? 0 : A[i]);
	}

	for (int i = 0; i < Q; i++) solve();

	return 0;
}

void solve() {
	int X;
	scanf("%d", &X);

	int p = std::lower_bound(A + 1, A + 1 + N, X) - A;
	if (p >= N || !MAX_DELTA || p + 1 == N && A[p] == X)
		return (void)printf("%lld\n", N & 1 ? sumo[N] : sume[N]);
	if (p == 1)
		return (void)printf("%lld\n", sum[N] - sum[N / 2]);

	int l = 0, r = 1e9 + 1, left, right;	// [l, r)
	while (r - l > 1) {
		int mid = l + r >> 1;
		debug("  [%d, %d), mid=%d, range[%d, %d]\n", l, r, mid, std::max(0, X - mid), X + mid);
		left = std::lower_bound(A + 1, A + 1 + N, std::max(0, X - mid)) - A,
		right = std::upper_bound(A + 1, A + 1 + N, X + mid) - A - 1;
		debug("   Now: left=%d, A[left]=%d, right=%d, A[right]=%d\n", left, A[left], right, A[right]);
		if (right - left + 1 > N - right)	// Aoki get more
			r = mid;
		else	// Takahashi get more
			l = mid;
	}

	left = std::lower_bound(A + 1, A + 1 + N, std::max(0, X - l)) - A,
	right = std::upper_bound(A + 1, A + 1 + N, X + l) - A - 1;
	debug("l=%d, interval: [%d, %d]\n", l, left, right);
	if (right - left + 1 != N - right) left = std::max(1, right - N + right + 1);
	printf("%lld\n", (left & 1 ? sume[left - 1] : sumo[left - 1]) + sum[N] - sum[right]);
}


Measured memory_bytes: 4480
#include <iostream>

typedef long long ll;

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  ll ans = 1;
  for (ll i = 1; i <= n; i++) {
    ans = i * i <= n ? i * i : ans;
  }

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


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int[] l = new int[n];
		for(i=0;i<n;i++) {
			l[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		int d = 0;
		for(i=0;i<n;i++) {
			d+=l[i];
			if(d>x) break;
		}
		System.out.println(i+1);
	}
}


Measured memory_bytes: 22100
n = int(input())
alp = 'abcdefghijklmnopqrstuvwxyz'
z = []
for i in range(n):
    s = input()
    t = []
    for i in range(26):
        t.append(s.count(alp[i]))
    z.append(t)


x = ''
for i in range(26):
    cnt = min([j[i] for j in z])
    x += alp[i]*cnt
print(x)


Measured memory_bytes: 3060