akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int x;
	char s[100];

#if 1
	gets(s);
#else
	gets_s(s, 50);
#endif
	x = atoi(s);
	printf("%d\n", x*x*x);
	return 0;
}

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

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

using namespace std;
typedef long long int lli;
typedef long long ll;

int n,q;
vector<vector<int>> tree(200000, vector<int>());

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    int judge = (g*10+b) % 4;
    if(judge == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 4992
N,x=[int(i) for i in input().split()]
a=[int(i) for i in  input().split()]
a = sorted(a)
res=0

for num in a:
    if num<=x:
        x-=num
        res+=1
    else:
        break
if x != 0 and res == N:
    res-=1
print(res)


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

using namespace std;

int a, b, n;

int caut_binar(int st, int dr, int x, vector <int> v)
{
    int ans = st - 1;

    while (st <= dr)
    {
        int mij = (st + dr) / 2;
        if (v[mij] < x)
        {
            ans = mij;
            st = mij + 1;
        }
        else
        {
            dr = mij - 1;
        }
    }

    return ans;

}

int main()
{
    int NumberOfSolution = 0;
    cin >> n;
    vector <int> V(n);
    for (int i  = 0; i < n; i++)
        cin >> V[i];

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


    for (int i = 0; i < n ; i++)
        for (int j = i + 1; j < n; j++)
    {
        int mij = caut_binar(j + 1, n - 1, V[i] + V[j], V);
        //cout << mij << " ";
        NumberOfSolution += mij - j;
    }

    cout << NumberOfSolution;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main(void){
    ll h, w;
    cin >> h >> w;
    ll n;
    cin >> n;
    ll a[n];
    ll count = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        count += a[i];
    }
    ll ans[h][w];
    ll check = 1; ll cc = 0;
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++){
            ans[i][j] = check;
            cc++;
            if(cc==a[check-1]){
                cc=0;
                check++;
            }
        }
    }
    for(ll i = 1; i < h; i+=2){
        for(ll j = 0; j < w/2; j++){
            swap(ans[i][j], ans[i][w-j-1]);
            //cout << ans[i][j] << " " << ans[i][w-j] << endl;
        }
        
    }
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++)
            cout << ans[i][j] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
int main(){
    long x,y;cin>>x>>y;
    if(x<0&&y==0){
        cout<< -x;
    }
    if(x>=0&&y>=0){
        (y>x)?cout<<y-x:cout<<min(2+x-y,1+y+x);return 0;
    }
    else if(x<0&&y>0){
        (-x>y)?cout<<-x-y+1:cout<<1+x+y;return 0;
    }
    else if(x<0&&y<0){
        (y>x)?cout<<y-x:cout<<2+x-y;return 0;
    }
    else if(x>=0&&y<0){
        (-y>x)?cout<<-y-x+1:cout<<x+y+1;return 0;
    }
}
            


Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int num=0;
	while(a>=b){
		b*=2;
		num++;
	}
	while(c<=b){
		num++;
		c*=2;
	}
	if(num<=k) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

typedef long long ll;

const int inf = 1000000;

int main() {
    ll N, Q;
    cin >> N;
    vector<ll>A(N);
    map<ll, ll>mp;
    ll total = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        total += A[i];
        mp[A[i]]++;
    }
    cin >> Q;
    vector<ll>v;
    for (int i = 0; i < Q; i++) {
        ll B, C;
        cin >> B >> C;
        total += mp[B] * (C-B);
        mp[C] += mp[B];
        mp[B] = 0;
        v.push_back(total);
    }
    for (int i = 0; i < Q; i++) {
        cout << v[i] << endl;
    }
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) printf("Left\n");
  else if (a + b < c + d) printf("Right\n");
  else printf("Balanced\n");

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        Solver s = new Solver();
        int test = 1;
        for (int i = 1; i <= test; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }

    static class Solver {
        void solve(int test_case, InputReader in, PrintWriter out) {
            String s = in.next();
            int c = 1, max = -1;
            for (int i = 1; i < s.length(); i++) {
                if (s.charAt(i) == s.charAt(i - 1)) c++;
                else c = 1;
                max = Math.max(c, max);
            }
            if (max >= 3) out.println("Yes");
            else out.println("No");
        }
    }

    static class InputReader {

        BufferedReader br;
        StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
int main() {
    int i1, i2, i3;
    cin >> i1 >> i2 >> i3;
    cout << int(i3/i1)*i2 << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10**8)

H, W = map(int, input().split()) 
S = [list(input()) for i in range(H)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
Dis =[[-1]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
Dis[0][0] = 0
a=deque()
while (q != a):
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and (Dis[ny][nx] ==-1):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

if (Dis[H-1][W-1]==-1):
    print(-1)
else:
    print(Shiro-Dis[H-1][W-1]-1)    

Measured memory_bytes: 3316
n,d = map(int,input().split())

plots = []

for i in range(n):
    plots.append(list(map(int,input().split())))

cnt = 0
    
for i in range(n):
    for j in range(n):
        if i == j:
            break
        dis = 0
        for l in range(d):
            dis += (plots[i][l]-plots[j][l])**2
        
        dis_sqrt = dis**(1/2)
        
        if float.is_integer(dis_sqrt):
            cnt += 1
    
print(cnt)

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


void solve(long long N){
  long long high = floor(sqrt(N));
  cout << high * high << endl;;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
    solve(N);
    return 0;
}


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

const int INF = 1e9+7;

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

  vector<int> d(n), c(m);
  rep(i,n)cin >> d[i];
  rep(i,m)cin >> c[i];

  vector< vector<int> > dp(n+1, vector<int>(m+1, INF));
  dp[0][0] = 0;

  rep(i,n){
    rep(j,m){
      chmin(dp[i][j+1], dp[i][j]);
      chmin(dp[i+1][j+1], dp[i][j] + d[i]*c[j]);
    }
  }

  cout << *min_element(dp[n].begin(), dp[n].end()) << endl;
}

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

using namespace std;

typedef long long ll;

const int maxn=1e5+10;
const int mod=998244353;
ll p[maxn];
ll q[maxn];

long long  Suan(long long  a, long long  n, long long  m)	//a的n次幂对m取模
{
    long long ans = 1;
    while(n)
    {
        if(n&1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}

int main()
{
    ll n,i;
    scanf("%lld",&n);
    for(i=0; i<n; ++i)
    {
        scanf("%lld",&p[i]);
        q[p[i]]++;
    }
    if(p[0]!=0||q[0]!=1)
    {
        printf("0\n");
    }
    else
    {
        long long sum=1;
        for(i=1; i<n; ++i)
        {
            sum=sum*Suan(q[i-1],q[i],mod)%mod;;
        }
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc071_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;
  int N = S.size();

  set<char> s;
  rep(i, N) { s.insert(S[i]); }

  char a = 'a';
  while (a <= 'z') {
    if (s.count(a))
      a++;
    else
      break;
  }

  if (a <= 'z') {
    cout << a << endl;
  } else {
    cout << "None" << endl;
  }
}

Measured memory_bytes: 512
s = STDIN.gets.chomp
t = STDIN.gets.chomp

sm = s.split('').inject({}) {|h, c| h[c] ? h[c] = h[c] + 1 : h[c] = 1; h }
tm = t.split('').inject({}) {|h, c| h[c] ? h[c] = h[c] + 1 : h[c] = 1; h }

puts sm.values.sort == tm.values.sort ? 'Yes' : 'No'

Measured memory_bytes: 22596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    ll x;
    cin>>x;
    ll ans = (x+11-1)/11;
    cout << (ans*11-5>=x ? ans*2-1:ans*2) << endl;
    
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dp[3005][3005];
int main() {
	ll n,t;
	cin>>n>>t;
	vector<pair<ll,ll>>a;
	for(ll i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		a.push_back(make_pair(x,y));
	}
	sort(a.begin(),a.end());
	for(ll i=0;i<n;i++){
		for(ll j=0;j<=3000;j++){
			ll x=a[i].first;
			ll y=a[i].second;
							dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+x<=3000){
				dp[i+1][j+x]=max(dp[i+1][j+x],dp[i][j]+y);
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		ans=max(ans,dp[i][t-1]+a[i].second);
	}
//	cout << dp[1][59]<<endl;;
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 70784
N,A,B,K = map(int,input().split())
sprime = 998244353 # approx 10**9
A,B = sorted((A,B))
if (A+B) * N < K:
	print(0)
	exit()
 
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
 
memo = [0] * (N+1)
memo[0] = memo[N] = 1
for i in range(1,N//2+1):
	v = memo[i-1] * (N-i+1) * modinv(i,sprime)
	v = v % sprime
	memo[i] = memo[N-i] = v
 
# max is A*N + B*N
sum = 0
for b in range(N+1):
  a = (K-b*B)//A
  if 0 <= a <= N and a*A+b*B == K:
    sum += memo[a]*memo[b]
    sum %= sprime
 
print(sum)

Measured memory_bytes: 10128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    System.out.println(a < b && b < c ? "Yes" : "No");

    sc.close();
  }
}


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

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

  bool ans = false;
  for (int i = 0; i < S.size() - 1; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      ans = true;
      break;
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

max_num, index = max(a), a.index(max(a))
a = sorted(a, reverse=True)

for i in range(n):
    if i == index:
        print(a[1])
    else:
        print(max_num)

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int n;
vector<int> a, b, neces;
LL ans = 0;
/**********************************************/

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

    cin >> n;
    a.assign(n, 0);
    b.assign(n, 0);
    neces.assign(n, 0);

    REP(i, n) cin >> a[i] >> b[i];
    
    for(int i = n-1; i >= 0; i--){
        neces[i] = ((ans + a[i]) % b[i] == 0 ? 0 : b[i] - (ans + a[i]) % b[i]);
        ans += neces[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include<string>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[N];
    int max=-200000;
    int min=200000;
    for(int i=0; i<N; i++){
        cin>>a[i];
    }
    for(int j=0; j<N; j++){
        if(a[j]>max){
            max=a[j];
            
        }
        if(a[j]<min){
            min=a[j];
        }
        
    }
    
    cout<<max-min;
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

int main(){
  int A, B;
  std::cin >> A >> B;
  if(A > 12) std::cout << B << std::endl;
  else if(A > 5) std::cout << B/2 << std::endl;
  else std::cout << 0 << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
constexpr int maxn = 10010;
typedef long long ll;
int mnp[maxn], p[maxn], cnt;
void sieve(int n) {
	for (int i = 2; i <= n; ++i) {
		if (!mnp[i]) mnp[i] = i, p[cnt++] = i;
		for (int j = 0; j < cnt && p[j] * i <= n; ++j) {
			mnp[p[j] * i] = p[j];
			if (i % p[j] == 0)
				break;
		}
	}
}
int n; ll a[600][600];
inline int get1(int x, int y) {
	if (x + y < 0 || (x + y) >> 1 >= n) return 1;
	return p[(x + y) >> 1];
}
inline int get2(int x, int y) {
	if ((y + n - x) >> 1 < 0 || (y + n - x) >> 1 >= n) return 1;
	return p[((y + n - x) >> 1) + n];
}
int main() {
	sieve(10000);
	std::cin >> n;
	if (n == 2) {
		std::cout << "4 7\n23 10\n";
		return 0;
	}
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			std::cout << ((i + j) % 2 == 0 ? 1ll * get1(i, j) * get2(i, j) : 1ll * get1(i, j - 1) * get1(i, j + 1) * get2(i, j - 1) * get2(i, j + 1) + 1) << "\n "[j != n - 1];
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define MAX 105


int main(){
    int m[MAX][MAX];
    int p[MAX];
    int n;
    //FILE *fw=fopen("a.txt","r");
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d %d",&p[i],&p[i+1]);
    }
    //printf("start\n");
    for(int i=1;i<=n;++i) m[i][i] = 0;
    for(int l=2;l<=n;++l){
        for(int i=1;i<=n-l+1;++i){
            int j = l+i-1;
            m[i][j] = 1<<21;
            for(int k=i;k<=j-1;++k){
                m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i]*p[k+1]*p[j+1]);
            }
        }
    }
    printf("%d\n",m[1][n]);
    return 0;
}




Measured memory_bytes: 3236
N, M = map(int,input().split())
max_l = 0
min_r = 10 ** 9
for _ in range(M):
    l, r = map(int,input().split())
    if l > max_l:
        max_l = l
    if r < min_r:
        min_r = r
print(max(min_r-max_l+1, 0))



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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1){
        c=c-b;
        if(c<=0){
            cout << "Yes" << endl;
            break;
        }
        a=a-d;
        if(a<=0){
            cout << "No" << endl;
            break;
        }
    }
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

bool score[10110];

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    score[0] = true;
    rep(i, n) {
        int s;
        cin >> s;
        repr(j, 10001, 0) if (score[j]) score[j + s] = true;
    }
    int maxi = 0;
    repr(j, 10001, 0) if (score[j] && j % 10 != 0) {
        maxi = j;
        break;
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,K = map(int,input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
CD = [tuple(map(int, input().split())) for _ in range(K)]

"""
Union-Find木実装のキモ(計算量削減)
1. Unionの工夫
   マージテク：大きい方を動かさずに小さい方をくっつける
2. Findの工夫
   経路圧縮 : 集合の要素を根に直接つなぎ変える.木をフラットにする.
"""

# Union-Findを用いて連結成分を考える(Union-Find木の実装)
class UnionFind:
    # まずは最初の状態を作る
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0

    # そのノードの根を返す過程で,集合の要素を根に直接つなぎかえる
    def root(self, a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]

    # aとbの根が同じ,つまり同じ連結成分内かどうかを返す
    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    # 連結成分同士を効率的に(rankが大きい方を動かさずにrankが小さい方をくっつける)
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

blocks = [[] for _ in range(N)]
for c, d in CD:
    c, d = c-1, d-1
    blocks[c].append(d)
    blocks[d].append(c)

# friendsは友達の数を保持する
friends = [0] * N
uf = UnionFind(N)
for a,b in AB:
    a, b = a-1, b-1
    friends[a] += 1
    friends[b] += 1
    # aとbが同連結成分内であれば何もする必要がない
    if uf.is_same(a, b): continue
    # 異なれば結合
    uf.unite(a, b)

for i in range(N):
    uf.root(i)

from collections import Counter
ctr = Counter()
for i in range(N):
    r = uf.root(i)
    ctr[r] += 1

ans = []
for i in range(N):
    tmp = ctr[uf.root(i)] - friends[i] -1
    for b in blocks[i]:
        if uf.is_same(i, b):
            tmp -= 1
    ans.append(tmp)
print(*ans)

Measured memory_bytes: 125656
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
int main(void){
	int n,x,t;
	cin>>n>>x>>t;
	cout<<(n+x-1)/x*t;
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

class Main{
        public static void main(String[] args){
                Scanner scanner=new Scanner(System.in);
                int x=scanner.nextInt();
                if(Math.abs(x-scanner.nextInt())<Math.abs(x-scanner.nextInt())){
                        System.out.println("A");
                }else{
                        System.out.println("B");
                }
                return;
        }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long

using namespace std;

const int N = 1e3 + 5, mod = 1e9 + 7;

int dp[N], a, b, c, d, n, fc[N], ans = 0, old[N], Fc[N], D[N][N];

int binpow (int a, int b)
{
    if (b == 0)
        return 1;
    if (b & 1)
        return a * binpow(a, b - 1) % mod;

    int x = binpow(a, b >> 1);

    return x * x % mod;
}
int Cnk (int n, int k, int l)
{
    return fc[n] * D[l][k] % mod * Fc[n - k * l] % mod * Fc[l] % mod;
}
main ()
{
    cin >> n >> a >> b >> c >> d;

    fc[0] = 1;
    Fc[0] = 1;

    for (int i = 1; i <= n; i++)
        fc[i] = i * fc[i - 1] % mod,
        Fc[i] = binpow( fc[i], mod - 2 );


    for (int j = 1; j <= n; j++)
    {
        D[0][j] = 1;
        for (int i = 1; i <= d; i++)
            D[i][j] = D[i - 1][j] * fc[j] % mod;
        for (int i = 1; i <= d; i++)
            D[i][j] = binpow(D[i][j], mod - 2);
    }
    dp[0] = 1;
    old[0] = 1;

    for (int i = a; i <= b; i++)
    {
        for (int j = c; j <= d; j++)
        {
            for (int l = i * j; l <= n; l++)
            {
                dp[l] += old[l - i * j] * Cnk( n - l + i * j, i,  j );
                dp[l] %= mod;
            }
        }
        for (int l = 1; l <= n; l++)
            old[l] = dp[l];
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 8192
n,k = map(int,input().split());
kk = n-k+2
a = [0]*kk

for i in range(kk):
    ii = i + k
    p = ii*(ii-1);
    q = ii*(2*n+1-ii);
    a[i] = (q//2)-(p//2)+1;
con = 0;
for v in range(kk):
    con = (con+a[v]) % 1000000007;
    
print(con);

Measured memory_bytes: 19640
N=int(input())
A=list(map(int, input().split()))
print(*A)
for i in range(1,N):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(*A)


Measured memory_bytes: 5980
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

output:
1
2
"""

import math
import sys

INIT_MAX = pow(2, 31) - 1


class SegmentTree(object):
    __slots__ = ('dat', 'ceil_n')

    def __init__(self, n):
        """
        Init a SegmentTree with update and find for range minimum queries.
        """
        self.ceil_n = pow(2, math.ceil(math.log2(n)))
        self.dat = [INIT_MAX] * (2 * self.ceil_n - 1)

    # let A[k]=a
    def update(self, k, a):
        k += self.ceil_n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    # get min(A[s] A[s+1] ... A[t])
    def find(self, s, t, k=0, left=0, right=float('inf')):
        if right <= s or t <= left:
            return INIT_MAX
        elif s <= left <= right <= t:
            return self.dat[k]
        else:
            vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
            vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
            return min(vl, vr)


def cmd_exec(queries, n_num):
    case = SegmentTree(n_num)
    end = pow(2, math.ceil(math.log2(n_num)))

    for query in queries:
        cmd, ele_1, ele_2 = map(int, query)
        if cmd == 0:
            case.update(ele_1, ele_2)
        elif cmd == 1:
            # assert ele_1 <= ele_2
            res = case.find(s=ele_1, t=ele_2 + 1, right=end)
            print(res)

    return None


def solve():
    _input = sys.stdin.readlines()
    n_num, q_num = map(int, _input[0].split())
    queries = map(lambda x: x.split(), _input[1:])

    cmd_exec(queries, n_num)
    return None


if __name__ == '__main__':
    solve()

Measured memory_bytes: 19580
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define ld long double
#define MAX 100007
#define pb push_back
#define MOD 1000000007
using namespace std;

int main()
{
    ll n,i;
    cin>>n;
    ll v[n+7],c[n+7];
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    ll ans=0;
    for(i=1;i<=n;i++)
    {
        cin>>c[i];
        if(v[i]>c[i])
            ans+=v[i]-c[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {


    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int N = Integer.parseInt(scan.next());
        int K = Integer.parseInt(scan.next());


        int[] treeArray = new int[N];
        for(int i =0; i < N; i++){
            treeArray[i] = Integer.parseInt(scan.next());
        }
        Arrays.sort(treeArray);


        int min = 999999999;
        int dif;
        for(int i =0; i <= N-K; i++ ){
            dif = treeArray[i+K-1] - treeArray[i];
            if(dif < min) min = dif;
        }


        System.out.println(min);
    }
}

Measured memory_bytes: 48604
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;
int n, m;
const int ma = 1e6 + 10;
int a[ma]; /* 
P p[ma]; */
map<int, int> mp;
main()
{
    scanf("%lld%lld", &n, &m);
    rep(i, n) scanf("%lld", a + i);
    /*     rep(i, m) scanf("%lld%lld",&p[i].first,&p[i].second); */
    /* sort(p, p + m, [&](P a, P b) {
        return a.second > b.second;
    }); */
    rep(i, m)
    {
        int b, c;
        scanf("%lld%lld", &b, &c);
        mp[c] += b;
    }
    sort(a, a + n);

    int ans = 0;
    rep(i, n)
    {
        if (mp.size() && mp.rbegin()->first > a[i])
        {
            a[i] = mp.rbegin()->first;
            mp.rbegin()->second--;
            if (mp.rbegin()->second == 0)
                mp.erase(mp.rbegin()->first);
        }
        ans += a[i];
    }

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

Measured memory_bytes: 7296
//Keep Working Hard
  // I__Like__Food  

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;
  const double PI = 3.1415926535898;


int32_t main()
{






  string s;
  cin >> s;
  int p = 2019;

  int n = s.length();

  int arr[n+1];

  for(int i = 1; i <= n; i++)
  {
    arr[i] = s[i-1] -'0';
  } 

  if(10%p == 0)
  {
    int ans = 0;

    for(int i = 1; i <= n; i++)
    {
      if(arr[i]%p == 0)ans +=i;
    }
    cout << ans;
    return 0;
  }

  int pre[n+1];
  pre[n] = arr[n]%p;

  int poww = 10;
  for(int i = n-1; i >= 1; i--)
  {
      pre[i] = (pre[i+1]%p + ((poww)*arr[i]) %p)%p;
    poww = (10*poww)%p;
  }

  pre[0] = 0;


  reverse(pre+1,pre+n+1);

  int ans = 0;

  vector<int> mp(p,0);

  for(int i = 0; i <=n; i++)
  {
    ans += mp[pre[i]];
    mp[pre[i]]++;
  }
  cout << ans;

    return 0;
}


Measured memory_bytes: 6844
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MP make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;
const int N= 1e5 +10;


int a[N];

int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	
	int mi= N, ans=0,n,k;
	cin>>n>>k;
	cout<<(n-1+k-2)/(k-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
class WarshallFloyd:
    #O(V^3)で任意２頂点の最短距離
    def __init__(self,n,_first_index=0):
        self.v = n
        self._first_idx=_first_index
        self.d = [[float("INF")]*(n) for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        f=self._first_idx
        self.d[x-f][y-f] = c
        self.d[y-f][x-f] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        return self.d
n,m,r=map(int,input().split())
rs=[x-1 for x in map(int,input().split())]
w=WarshallFloyd(n,1)
for i in range(m):w.path(*map(int,input().split()))
v=w.build()
from itertools import permutations as pe
print(min(sum(v[f][t]for f,t in zip(i,i[1:]))for i in pe(rs)))


Measured memory_bytes: 71016
import java.util.Scanner;

public class Main {
	
	public static int[][] floyd(final int[][] adj, final int num){
		int[][] ret = new int[num][num];
		for(int i = 0; i < num; i++){
			for(int j = 0; j < num; j++){
				ret[i][j] = adj[i][j];
			}
		}
		
		for(int k = 0; k < num; k++){
			for(int i = 0; i < num; i++){
				for(int j = 0; j < num; j++){
					ret[i][j] = Math.min(ret[i][j], ret[i][k] + ret[k][j]);
				}
			}
		}
		
		return ret;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int roters = Integer.parseInt(sc.nextLine());
		final int[][] adj_roter = new int[roters][roters];
		
		for(int i = 0; i < roters; i++){
			for(int j = 0; j < roters; j++){
				adj_roter[i][j] = Integer.MAX_VALUE / 3;
			}
		}
		
		for(int i = 0; i < roters; i++){
			final String[] strs = sc.nextLine().split(" ");
			
			final int start = Integer.parseInt(strs[0]) - 1;
			final int count = Integer.parseInt(strs[1]);
			
			for(int j = 0; j < count; j++){
				adj_roter[start][Integer.parseInt(strs[j + 2]) - 1] = 1;
			}
		}
		
		final int[][] adj_min = floyd(adj_roter, roters);
		
		
		final int packets = Integer.parseInt(sc.nextLine());
		
		for(int i = 0; i < packets; i++){
			final String[] strs = sc.nextLine().split(" ");
			final int start = Integer.parseInt(strs[0]) - 1;
			final int end = Integer.parseInt(strs[1]) - 1;
			final int lim = Integer.parseInt(strs[2]);
			
			if(adj_min[start][end] < lim){
				System.out.println(adj_min[start][end]+1);
			}else{
				System.out.println("NA");
			}
		}
		
	}
	
}

Measured memory_bytes: 13000
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

arr=list(ss())
mat=list(Counter(arr))
ans=10**100
for i in mat:
    tmp=deepcopy(arr)
    p=0
    while len(Counter(tmp))!=1:
        aa=[]
        for j in range(len(tmp)-1):
            if tmp[j] ==i or tmp[j+1]==i:
                aa.append(i)
            else:
                aa.append(tmp[j])
        tmp=deepcopy(aa)
        p+=1
    ans=min(ans,p)
print(ans)

    




Measured memory_bytes: 70244
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */




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

    int n; cin >> n;
    vector<double> p(n);
    rep(i, n) cin >> p[i];

    // dp[i][j] := コインを i 番目まで投げて j 回表が出る確率
    vector<vector<double>> dp(n+5, vector<double>(n+5, 0.0));
    dp[0][0] = 1;
    rep(i, n) rep(j, n){
        // dp[i][j] から遷移する
        dp[i+1][j] += dp[i][j]*(1-p[i]);
        dp[i+1][j+1] += dp[i][j]*p[i];
    }
    
    double ans = 0.0;
    repr(j, (n+1)/2, n+1) ans += dp[n][j];
    cout << setprecision(15) << ans << endl;

    return 0;
}

Measured memory_bytes: 70912
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)

n, m = map(int, input().split())
li = [(-1)*int(x) for x in input().split()]
heapify(li)
for _ in range(m):
    temp = heappop(li)
    temp *= -1
    temp //= 2
    temp *= -1
    heappush(li, temp)

print((-1)*sum(li))

Measured memory_bytes: 60600
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
#include<iomanip>
#include<bitset>
#include<math.h>
using namespace std;

 
int main(){
 
	int a,b;
	cin >> a >> b;
	int sum = 0;
	sum += a-1;
	if(b >= a){
		sum ++;
	}
	cout << sum << endl;
  	
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int main(){
    string s;
    cin>>s;
    s[3]='8';
    cout<<s<<endl;
}


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

using namespace std;

int main() {
	int n, ans = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n - 2; ++i)
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			++ans;
	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;
struct xydata {
    int x; int y;
};

bool cmp(const xydata &l, const xydata &r) {
    return l.x == r.x ? l.y < r.y : l.x < r.x;
}

int main() {
    cin >> n;
    vector<xydata> abvec(n);
    vector<xydata> cdvec(n);
    for(int i = 0; i < n; ++i) cin >> abvec.at(i).x >> abvec.at(i).y;
    for(int i = 0; i < n; ++i) cin >> cdvec.at(i).x >> cdvec.at(i).y;

    sort(abvec.begin(), abvec.end(), cmp);
    sort(cdvec.begin(), cdvec.end(), cmp);

    int cnt = 0;
    vector<bool> abft(n, false);
    for(int i = 0; i < n; ++i) {
        int bmax = 0;
        int abno = -1;
        for(int j = 0; j < n; ++j) {
            if(abvec.at(j).x < cdvec.at(i).x && !abft.at(j)) {
                if(abvec.at(j).y < cdvec.at(i).y) {
                    if(abvec.at(j).y >= bmax) {
                        bmax = abvec.at(j).y;
                        abno = j;
                    }
                }
            }   
        }
        if(abno != -1) {
            cnt++;
            abft.at(abno) = true;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
  public static void main(String args[]){
    new Main().run();
  }

  Scanner sc = new Scanner(System.in);
  void run(){
    while(true){
      int x = sc.nextInt();
      int y = sc.nextInt();
      int s = sc.nextInt();
      if((x|y|s)==0)break;

      int max = 0;
      for(int i = 1; i <= s-1; i ++){
        for(int j = 1; j <= s-1; j ++){
          if(tax(x,i) + tax(x,j) == s){
            max = Math.max(max, tax(y,i) + tax(y,j));
          }
        }
      }
      System.out.println(max);
    }
  }

  int tax(int x, int p){
    return p * (100 + x) / 100;
  }
}

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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int num=0;
	for(int i=a;i<=b;i++)
	{
		if(c%i==0)num++;
	}
	cout<<num<<endl;
	return 0;
}



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

constexpr int INF = 1 << 30;

void chmin(int &a, int b){
    a = min(a, b);
}

int cnt[1<<11][1<<11], dp[1<<11][1<<11];

int solve(){
    int m, n;
    cin >> m >> n;
    if(m==0) return 1;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        for(int j=0;j<m;j++){
            a[i] |= (s[j]-'0')<<j;
        }
    }
    for(int S=0;S<1<<m;S++){
        for(int T=S;;T=(T-1)&S){
            cnt[S][T] = 0;
            dp[S][T] = INF;
            for(int i=0;i<n;i++){
                if((S&a[i])==T) cnt[S][T]++;
            }
            if(T==0) break;
        }
    }
    for(int S=(1<<m)-1;S>=0;S--){
        for(int T=S;;T=(T-1)&S){
            if(cnt[S][T]<=1){
                dp[S][T] = 0;
            }else{
                for(int i=0;i<m;i++){
                    if((S>>i)&1) continue;
                    chmin(dp[S][T], max(dp[S|1<<i][T], dp[S|1<<i][T|1<<i])+1);
                }
            }
            if(T == 0) break;
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

int main(){
    while(solve()==0);
    return 0;
}



Measured memory_bytes: 29284
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



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

typedef long long ll;
typedef pair<ll, ll>pll;
typedef vector<int> vi;
const int MOD = 1000000007;
const int INF = 1 << 29;


int main() {
	
	int n;
	cin >> n;
	vi h(n+2),dp(n+2,INF);
	rep(n) { cin >> h[i]; }
	dp[0] = 0;
	rep(n) {
		chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
		chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));

	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#define DBG 0 //submission 0
#if DBG==1
    #include <algorithm>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <iostream>
#else
    #include <bits/stdc++.h>
#endif

using namespace std;

int main(){
    int ans = 0;
    int N,X,i,j,k,dist=0;
    cin >> N >> X;
    int L[N];
    for ( i = 0 ; i < N+1 ; i++ ) {
        cin >> L[i];
    }

    for ( i = 0 ; dist <= X ; i++ ) {
        ans++;
        dist += L[i];
    }

    cout << ans << endl;
}


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

using namespace std;

int main(){
  long long n,k;
  
  cin >> n >> k;
  
  long long ans = 0;
  for(long long i = k; i <= n+1; i++){
    ans += i*(n-i+1)+1;
  }
  
  cout << (ans)%(1000000007);
  
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int n, ans = 0;
    cin >> n;
    rep(i, 1, n + 1) {
        ans += i;
    }
    cout << ans << endl;
}

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

int main() {
	int R;
	cin >> R;
	if(R < 1200){
		cout << "ABC" << endl;
	} else if(R < 2800){
		cout << "ARC" << endl;
	} else {
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
	int n,i,k;
	string s,t;
	stringstream ss;
	while(cin>>n,n)
	{
		cin>>s;
		while(n--)
		{
			k=1;
			t="";
			for(i=0;i<s.size()-1;++i)
			{
				if(s[i]==s[i+1])++k;
				else ss.clear(),ss.str(""),ss<<k,t+=ss.str()+s[i],k=1;
			}
			ss.clear(),ss.str(""),ss<<k,s=t+ss.str()+s[i];
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


const long long INF = 1LL<<60;
int N;
long long X;
vector<long long> A;

long long solve() {
    long long res = INF;
    for (int i = 0; i < N; ++i) A.push_back(A[i]);
    vector<long long> bmin(N, INF);
    for (int k = 0; k < N; ++k) {
        long long tmp = 0;
        for (int i = 0; i < N; ++i) {
            chmin(bmin[i], A[i+k]);
            tmp += bmin[i];
        }
        chmin(res, tmp + X*k);

/*
        COUT("------------------");
        COUT(k);
        COUT(bmin);
        COUT(tmp);
        */
    }
    return res;
}

int main() {
    while (cin >> N >> X) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        cout << solve() << endl;
    }
}


Measured memory_bytes: 256
from collections import deque

S = deque(list(input()))
Q = int(input())
r = False
left = deque()
right = deque()
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        r = not r
    else:
        f, c = q[1:]
        if f == "1":
            if r:
                right.append(c)
            else:
                left.appendleft(c)
        else:
            if r:
                left.appendleft(c)
            else:
                right.append(c)

S, left, right = map(list, (S, left, right))
left.extend(S)
left.extend(right)
print("".join(left[::-1] if r else left))

Measured memory_bytes: 12260
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
      int N=sc.nextInt();
      long[] a=new long[N];
      long x=1;
      for(int i=0;i<N;i++){
      	a[i]=sc.nextLong();
       if(a[i]==0){
       	System.out.println(0);
         return;
       }
      }
      for(int i=0;i<N;i++){
      	if(a[i]<=1000000000000000000L/x){
       	x=x*a[i];
       }else{
       	System.out.println(-1);
         return;
       }
      }
      if(x<=1000000000000000000L){
      	System.out.println(x);
        return;
      }else{
      	System.out.println(-1);
        return;
      }
	}
}

Measured memory_bytes: 50116