akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  int i=0;
  while(s.at(i) != 'A'){
    i++;
  }
  int j=s.size() -1 ;
  while(s.at(j) != 'Z'){
    j--;
  }
  int ans = j-i+1;
  
  cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb;
		StringBuffer tem;
		String change = null;

		String str = br.readLine();
		int count = Integer.parseInt(br.readLine());
		sb = new StringBuffer(str);

		for(int i = 0; i < count; i++){
			String menu = br.readLine();
			String[] s = menu.split(" ");
			menu = (s[0]);
			int start = Integer.parseInt(s[1]);
			int end = Integer.parseInt(s[2]);

			if(s.length == 4){
				 change = (s[3]);
			}
			if(menu.startsWith("rev")){
				tem = new StringBuffer(sb.substring(start, (end + 1)));
				tem.reverse();
				sb.replace(start, end+1, new String(tem));

			}else if(menu.startsWith("rep")){
				sb.replace(start, end + 1, change);

			}else if(menu.startsWith("p")){
				System.out.println(sb.substring(start, (end + 1)));
			}
		}
	}
}

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

using namespace std;

void solve()
{
	int N, M;
	cin >> N >> M;

	if (N >= M)
	{
		cout << 0 << endl;
		return;
	}

	vector<long> xs(M), ds(M-1);

	for (int i = 0; i < M; i++)
	{
		cin >> xs[i];
	}

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

	for (int i = 0; i < M-1; i++)
	{
		ds[i] = xs[i+1] - xs[i];
	}

	sort(ds.rbegin(), ds.rend());

	long ans = xs.back() - xs.front();

	for (int i = 0; i < N-1; i++)
	{
		ans -= ds[i];
	}

	cout << ans << endl;

}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<bool,int> P; 
 
int main(){
    int N;
  
    while(cin >> N, N){
	vector<P> vec;
	bool in;
	for(int i = 0 ; i < N ; i++){
	    int size = vec.size();
       
	    cin >> in;
	    if(((i+1) % 2) == 0){
		if(vec[size-1].first != in){
		    for(int j = size-1 ; j >= 0 ; j--){
			if(vec[j].first == in){
			    break;
			}else{
			    vec[j].first = in;
			}
		    }
		} 
	    }
	    if(i && vec[size-1].first == in){
		vec[size-1].second++;
	    }else{
		vec.push_back(P(in,1));
	    }
	}
	int ans = 0;
	for(int i = 0 ; i < (int)vec.size() ; i++){
	    if(!vec[i].first){
		ans += vec[i].second;
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n;
	cin >> n;

	vector<ll> a(n);
	for (auto &v : a) {
		cin >> v;
	}

	ll ans = a[0];
	for (int i = 1; i < n; i++) {
		ans = lcm(ans, a[i]);
	}

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



Measured memory_bytes: 3228
S = input()
left, right, area = [], [], []
for i, s in enumerate(list(S)):
    if s == '\\':
        left.append(i)
    if s == '/' and left != []:
        j = left.pop()
        a = i - j
        while right != [] and j < right[-1]:
            right.pop()
            a += area.pop()
        right.append(j)
        area.append(a)
print(sum(area))
print(len(area), *area)



Measured memory_bytes: 6340
import           Data.Char                      ( isSpace )
import qualified Data.Vector.Unboxed           as V
import qualified Data.ByteString.Char8         as C

main = do
    [n, m] <- map read . words <$> getLine :: IO [Int]
    a      <- V.unfoldr (C.readInt . C.dropWhile isSpace) <$> C.getLine
    let a_tot    = fromIntegral $ V.sum a :: Double
        ltborder = (>) (a_tot / fromIntegral (4 * m)) . fromIntegral
        count    = (-) n $ V.length $ V.filter ltborder a
    putStrLn $ if count >= m then "Yes" else "No"


Measured memory_bytes: 508
def solve(n,m):
  if not n:return 1
  n%=m
  return-~solve(n,bin(n).count('1'))
n=int(input())
s=input()
a=int(s,2)
*x,=map(int,s)
h=sum(x)
try:a,b=a%(h-1),a%(h+1)
except:b=a%(h+1)
for i in range(n):
  if x[i]:
    if not h-1:
      print(0)
      continue
    x[i]=0
    t=(a-pow(2,~i+n,h-1))%(h-1)
  else:
    x[i]=1
    t=(b+pow(2,~i+n,h+1))%(h+1)
  r=solve(t,bin(t).count('1'))
  x[i]^=1
  print(r)

Measured memory_bytes: 11276
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[3005][3005];
signed main() {
    int N,S;
    cin >> N >> S;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= S; j++) {
            dp[i+1][j] += dp[i][j]*2;
            if(j+A[i] <= S) {
                dp[i+1][j+A[i]] += dp[i][j];
            }
            dp[i+1][j] %= mod;
        }
    }
    cout << dp[N][S] << endl;
}

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

using namespace std;

typedef long long int ll;

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

  int n;
  cin >> n;
  vector < int > a;

  if (n == 3) {
    cout << "2 5 63\n";
    return 0;
  }

  int sum = 0;
  for (int i = 1; i <= 30000; i++) {
    if (i % 2 == 0 || i % 3 == 0) {
      a.push_back (i);
      sum += i;
    }
    if (a.size() == n) break;
  }

  int need = (6 - sum % 6) % 6;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] + need <= 30000 && ((a[i] + need) % 2 == 0 || (a[i] + need) % 3 == 0)) {
      a[i] += need;
      break;
    }
  }

  for (auto i : a) cout << i << " ";
  cout << '\n';
}


Measured memory_bytes: 3780
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var s=Console.ReadLine();
			if(s==null)break;
			var d=int.Parse(s);
			Sol mySol = new Sol(d);
			Console.WriteLine(mySol.Ans);
		}
	}
}

class Sol{
	int ans;
	public int Ans{
		get{return ans;}
		set{this.ans=value;}
	}
	public Sol(int d){
		int[,] Arr=new int[2,d+1];
		for(int i=0;i<=d;i++)Arr[0,i]=0;
		Arr[0,1]=1;
		for(int i=2;i<=d;i++){
			if(Arr[0,i]==0){
				int k;
				for(k=2;k*i<=d;k++)Arr[0,k*i]=1;
			}
		}
		for(int i=1;i<=d;i++){
			Arr[1,d-i+1]=Arr[0,i];
		}
		int cnt=0;
		for(int i=1;i<=d;i++){
			if(Arr[0,i]==0 && Arr[1,i]==0)cnt++;
		}
		ans=cnt;
	}
}	

Measured memory_bytes: 5856
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S/3600;
        int m = S%3600/60;
        int s = S%3600%60;
    System.out.println(h+":"+m+":"+s);

    }
}


Measured memory_bytes: 26280
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int A=sc.nextInt();
	int B=sc.nextInt();
	if(A-B*2<=0) {
		System.out.println(0);
	}else {
		System.out.println(A-B*2);
	}
}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void){
	int X;
	char str[1000];
 
	fgets(str, sizeof(str), stdin);
	X=atoi(strtok(str," "));

	if(X >= 30){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 2024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
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;}
const long long INF=1LL<<60;
//set<int>::iterator it;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	ll n,a,b,max,min;
	cin>>n>>a>>b;
	if(a>b){
		cout<<0<<endl;
		return 0;
	}
	max=a+b*(n-1);min=a*(n-1)+b;
	if(max-min+1<0){
		cout<<0<<endl;
		return 0;
	}
	cout<<max-min+1<<endl;
	
	
	
	
	
	
	
	
	return 0;
}


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

int main(){
    int K;
    cin>>K;
    vector <int> S = {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};
    cout<<S.at(K-1)<<endl;
}


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

int main(){
  string s;
  cin >> s;
  
  if(s == "Sunny") cout << "Cloudy" << endl;
  else if (s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  
}

Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.Scanner;

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 b[] = new long[N];

		long c[] = new long[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();
			c[i] = a[i] + b[i];
		}
		Arrays.sort(c);

		long tk = 0;
		long ao = 0;

		for (int i = 1; i <= N; i++) {
			if (i%2 != 0) {
				tk += c[N-i];
			}
				ao += b[i-1];
		}
		System.out.println(tk - ao);
	}
}


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

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

  vector<int> c(26);
  rep(i,26){
    cin >> c[i];
  }

  vector<vector<int>> s (D,vector<int>(26));
  rep(d, D){
    rep(i,26){
      cin >> s[d][i];
    }
  }

  vector<int> t(D);

  rep(d, D){
    vector<int>::iterator iter = max_element(s[d].begin(), s[d].end());
    t[d] = distance(s[d].begin(), iter);
    t[d] +=1;
    cout << t[d] << endl;
  }
/*
  vector<int> last(26);
  vector<int> v(D);

  rep(d, D){
    last[t[d]] = d+1;

    int desc=0;
    rep(i, 26){
      desc += c[i]*(d+1-last[i]);
    }

    if(d==0){
      v[d] = s[d][t[d]] - desc;
    }else{
      v[d] = v[d-1] + s[d][t[d]] - desc;
    }
    cout << v[d] <<endl;
  }
  */
  return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	int ans = 1;
	int res = 1;
	for(int i=1;i<n+1;i++){
		int now = 0;
		int copy = i;
		while(copy%2==0){
			copy/=2;
			now++;
		}
		if(now>=ans){
			res = i;
			ans = now;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int W,H,N,x,y,a,xi=0,xz=100,yi=0,yz=100;
  scanf("%d %d %d",&W,&H,&N);
  xz=W;
  yz=H;
  for(int i=0;i<N;i++){
    scanf("%d %d %d",&x,&y,&a);
    switch(a){
      case 1:
        if(x>xi){
          xi=x;
        }
        break;
      case 2:
        if(x<xz){
          xz=x;
        }
        break;
      case 3:
        if(y>yi){
          yi=y;
        }
        break;
      case 4:
        if(y<yz){
          yz=y;
        }
        break;
    }
  }
  if((xz-xi)<0){
    xi=xz;
  }
  if((yz-yi)<0){
    yi=yz;
  }
  printf("%d\n",(xz-xi)*(yz-yi));  
  return 0;
}

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

int main() {

	int A, B, K;

	cin >> A >> B >> K;

	if (K % 2 == 0) {
		for (int i = 0; i < K / 2; i++) {

			if (A % 2 == 1) {
				A = A - 1;
			}
			A = A / 2;
			B = B + A;

			if (B % 2 == 1) {
				B = B - 1;
			}
			B = B / 2;
			A = A + B;
		}
	}
	else {
		for (int i = 0; i < K / 2; i++) {

			if (A % 2 == 1) {
				A = A - 1;
			}
			A = A / 2;
			B = B + A;

			if (B % 2 == 1) {
				B = B - 1;
			}
			B = B / 2;
			A = A + B;
		}
		if (A % 2 == 1) {
			A = A - 1;
		}
		A = A / 2;
		B = B + A;
	}

	cout << A << endl;
	cout << B << endl;


	return 0;
}

Measured memory_bytes: 256
n = int(input())

start = 1
end = int(n**0.5)

res = 0
for i in range(start, end+1):
    target = n // i
    if n % i == 0:
        target -= 1
    res += target*2
    if target >= i:
        res -= 1
print(res-(end-1)*(end))

Measured memory_bytes: 9440
s = input()
m = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
if s[:2] not in m and s[2:] not in m:
    print('NA')
elif s[:2] not in m:
    print('YYMM')
elif s[2:] not in m:
    print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 8980
N = 1000
def ee(a, b, c):
	arr = [[1,0,a],[0,1,-b]]

	while arr[1][2]!=0:
		for j in range(3):
			arr[0][j] -= arr[1][j]*(arr[0][2]//arr[1][2])
			arr[0][j], arr[1][j] = arr[1][j], arr[0][j]
	
	x0 = c*arr[0][0]
	y0 = c*arr[0][1]
	
	if arr[0][2]==-1:
		x0 *= -1
		y0 *= -1

	t = max(-(x0//b), -(y0//a))

	x0 = x0+b*t
	y0 = y0+a*t

	return x0, y0

def main():
	n = int(input())
	t0, a0 = [int(i) for i in input().split()]

	for ctr in range(1,n):
		t, a = [int(i) for i in input().split()]
		d =  ee(a,t,t*a0-a*t0)
		t0 += d[0]
		a0 += d[1]

	print(t0+a0)

main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

#define INF 0xfffffff

using namespace std;
typedef pair<int, int> P;

int main() {
	int n, m, s, g1, g2;
	cin >> n >> m >> s >> g1 >> g2;
	if ((n | m | s | g1 | g2) == 0) {
		return 0;
	}
	s--;
	g1--;
	g2--;
	vector< vector<int> > d(n, vector<int>(n, INF));
	for (int i = 0; i < m; i++) {
		int from, to, cost;
		cin >> from >> to >> cost;
		d[--from][--to] = cost;
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			d[i][i] = 0;
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int ans = INF;
	for (int i = 0; i < n; i++) {
		ans = min(ans, d[s][i] + d[i][g1] + d[i][g2]);
	}
	cout << ans << endl;
	return main();
}

Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

int main() {
  int N; cin >> N;
  vector<P> vec(N);
  for(int i = 0; i < N; i++) {
    int a; cin >> a; a--;
    vec[i] = P(a, i+1);
  }
  sort(vec.begin(), vec.end());
  for(int i = 0; i < N; i++) {
    cout << vec[i].second;
    if(i == N-1) cout << endl;
    else cout << " ";
  }
  return 0;
}


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

int main()
{
  int A,B,C,D;
  int flag=0;
  while(cin>>A>>B){
    for(C=1;C<=3;C++){
     D=A*B*C;
     if(D%2==0)flag=0;
     if(D%2==1)flag=1;
     }
     if(flag==1)cout<<"Yes"<<endl;
     if(flag==0)cout<<"No"<<endl;




  }
  return 0;
}

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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

using pint = pair<int,int>;
int main () {
    int N, M;
    cin >> N >> M;
    vector<set<int> > dame(N);
    UnionFind uf(N);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a, b);
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int mem = uf.size(i);
        ans = max(ans,mem);
    }
    cout << ans << endl;
}


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

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

const int N = 100005;
vector<int> g[N];

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

	int n, m;
	cin>>n>>m;
	for(int i = 0; i < n; i++){
		int a, b; cin>>a>>b;
		if(a > m)continue;
		g[m - a + 1].push_back(b);
	}
	priority_queue<int> pq;
	int ans = 0;
	for(int i = m; i >= 1; i--){
		for(auto x : g[i]){
			pq.push(x);
		}
		if(!pq.empty()){
			int x = pq.top(); pq.pop();
			ans += x;
		}
	}
	cout<<ans<<endl;
	

	return 0;
}

Measured memory_bytes: 5632
function Main(input) {
  input = input.split(' ');
  const sheeps = parseInt(input[0]);
  const wolves = parseInt(input[1]);
  console.log('%s', sheeps > wolves ? 'safe' : 'unsafe');
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29620
#include <bits/stdc++.h>
#define print(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)   for(int i=a;i<=b;i++)
#define tez         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;


void solve()
{

  int n,k,sum=0;
  cin>>n>>k;
while(n>0)
 {
    int a;
    cin>>a;
    if(a>=k)
        sum++;
    n--;
 }
 cout<<sum;

}


signed main() {

  tez;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

/*if(n%2==0) cout<<"0.5000000000";
 else
 {
     n=n/2;
     //cout<<n;
     cout<<setprecision(10)<<(n+1)*1.0/((2*n)+1);
 }
*/



Measured memory_bytes: 256
<?php
  list($n,$m) = explode(" ", trim(fgets(STDIN)));
  
  $route = [];
  for($i=0; $i<$m; $i++) {
    list($a,$b) = explode(" ", trim(fgets(STDIN)));
    if(!isset($route[$a])) $route[$a]=[];
    if(!isset($route[$b])) $route[$b]=[];
    $route[$a][$b]=true;
    $route[$b][$a]=true;
  }

  $x = $route[1];
  foreach($x as $key => $value){
    if(isset($route[$key][$n])){
      echo "POSSIBLE";
      exit;
    }
  }

  echo "IMPOSSIBLE";

Measured memory_bytes: 106160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N; cin>>N;
    vector<ll> A(N+2,0);
    rep1(i,N){
        cin>>A[i];
    }
    //      i
    // 0 -> 1 -> N -> N+1
    // 0   A[1]        0
    
    ll sum=0;
    rep(i,N+1){
        sum+=abs(A[i+1]-A[i]);
    }
    
    rep1(i,N){
        cout<<sum-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])<<endl;
    }
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <algorithm>
#define Freopen(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define int long long
using namespace std;
int X,fiv[100],cnt;
signed main()
{
	scanf("%lld",&X);
	fiv[0]=0;fiv[1]=1;
	for(int i=2;fiv[i-1]-fiv[i-2]<=X;i++,cnt=i-1)
		fiv[i]=i*i*i*i*i;
	for(int i=0;i<=cnt;i++)
	{
		for(int j=0;j<=cnt;j++)
			if(fiv[i]-fiv[j]==X)
				{printf("%lld %lld\n",i,j);return 0;}
			else if(fiv[i]+fiv[j]==X)
				{printf("%lld %lld\n",i,-j);return 0;}
	}
	return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
map<char, ll>n;

int main(){
	string s;
	cin>>s;
	for(char c : s){
		++n[c];
	}
	//auto me = max_element(n.begin(), n.end(),[](const pair<char,ll>& p1, const pair<char,ll>& p2) {
	//	return p1.second<p2.second;
	//});
	//ll meval=me->second;
	//vector<char>mevals;
	//for(auto itr=n.begin();itr!=n.end();++itr){
	//	if(itr->second==meval)mevals.push_back(itr->first);
	//}
	ll ret=105;
	for(auto itr=n.begin();itr!=n.end();++itr){
		ll temp=0;
		ll tempRet=-1;
		for(char cs : s){
			if(itr->first==cs){
				if(temp>tempRet){
					tempRet=temp;
				}
				temp=0;
				continue;
			}
			++temp;
		}
		if(temp>tempRet)tempRet=temp;
		if(ret>tempRet)ret=tempRet;
	}
	cout<<ret<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n+1];
		long[] vol=new long[n+1];
		long two=1;
		vol[0]=1;
		for(int i=0; i<=n; i++){
			a[i]=sc.nextInt();
			if(a[i]>vol[i]){
				System.out.println(-1);
				return;
			}
			if(i!=n){
				vol[i+1]=Math.min(10000000000000L,two=(two-a[i])*2);
				two=Math.min(10000000000000L,two);
			}
		}
		long ans=0;
		long num=0;
		for(int i=n; i>=0; i--){
			num+=a[i];
			num=Math.min(vol[i],num);
			ans+=num;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 61460
N,M = map(int, input().split())
K = []
S = []
for i in range(M):
    k,*s = map(int, input().split())
    K.append(k)
    tmp = 0
    for j in s:
        tmp += 1<<(j-1)
    S.append(tmp)
P = list(map(int, input().split()))

result = 0
for i in range(1<<(N)):
    cnt = 0
    # print(i)
    for j in range(M):
        tmp = S[j] & i
        val = str(bin(tmp)).count('1')
        #print(bin(i), bin(tmp), val % 2)
        if val % 2 == P[j]:
            cnt += 1
    #print(cnt, 'cnt')
    if cnt == M:
        result += 1

print(result)
#print(K,S, P)
#print(1<<N)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
   string s;
     cin>>s;
  string str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
  for(int i=0;i<s.length();i++)
  {
     s[i]=str[(s[i]-'A'+n)%26];
  }
  cout<<s;
   return 0;
}

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

typedef long long ll;
typedef long double ld;

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

    string O, E;
    cin >> O >> E;

    bool re = true;

    for(int i = 0; i < O.length() + E.length(); i++) {
        if(re) cout << O[i / 2];
        else cout << E[i / 2];
        re = !re;
    }

    cout << endl;
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"11009 11332"# => r#"4"#,
r#"31415 92653"# => r#"612"#,
}


fn solve(src: &str) -> String {
    input! {
        source = src,
        a: usize,
        b: usize,
    }
    let mut ans = 0;

    for i in a..b+1 {
        let v = i % 10;
        let w = i / 10 % 10;
        let y = i / 1000 % 10;
        let z = i / 10000 % 10;

        if v == z && w == y {
            ans += 1;
        }
    }

    ans.to_string()
}

Measured memory_bytes: 4352
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B = I()
print(min(N*A,B))

Measured memory_bytes: 77184
N,A,B=map(int,input().split())
S=input()
accept=0
accept_f=0
ans=[]
for i in range(N):
    if S[i]=='a':
        if accept < A+B:
            ans.append('Yes')
            accept = accept+1
        else:
            ans.append('No')
    elif S[i]=='b':
        if accept< A+B and accept_f<B:
            ans.append('Yes')
            accept = accept+1
            accept_f=accept_f+1
        else:
            ans.append('No')
    else:
        ans.append('No')
for n in range(N):
    print(ans[n])


Measured memory_bytes: 4784
from functools import reduce
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return b // gcd(a, b) * a
n=int(input())
a=list(map(int,input().split()))
x=reduce(lambda x,y: lcm(x,y), a)
ans=0
for i in a:
  ans+=x//i
ans%=1000000007
print(ans)

Measured memory_bytes: 4708
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int W,H,N;
int xs0[100*1000];
int xs1[100*1000];
int ys0[100*1000];
int ys1[100*1000];
int main() {
	scanf("%d%d%d",&W,&H,&N);
	for(int i=0;i<N;i++){
		scanf("%d%d",xs0+i,ys0+i);
		xs1[i]=xs0[i];
		ys1[i]=ys0[i];
	}
	LL ret=1LL<<60;
	int rx=0,ry=0;
	for(int i=0;i<=(N+1)%2;i++){
		for(int j=0;j<=(N+1)%2;j++){
			int x;
			if(i==0){
				nth_element(xs1,xs1+(N+i-1)/2,xs1+N);
				x=xs1[(N+i-1)/2];
			}
			else
			{
				x=*min_element(xs1+N/2,xs1+N);
			}
			int y;
			if(j==0){
				nth_element(ys1,ys1+(N+j-1)/2,ys1+N);
				y=ys1[(N+j-1)/2];
			}
			else
			{
				y=*min_element(ys1+N/2,ys1+N);
			}
			LL m=0;
			LL sum=0;
			for(int i=0;i<N;i++){
				LL d=abs(xs0[i]-x);
				d+=abs(ys0[i]-y);
				m=max(m,d);
				sum+=2*d;
			}
			sum-=m;
			if(sum<ret){
				ret=sum;
				rx=x;
				ry=y;
			}
		}
	}
	printf("%lld\n%d %d\n",ret,rx,ry);
}

Measured memory_bytes: 2764
import java.util.Scanner;

public class Main {

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

	int N;
	int M;
	int R;
	int D[][];
	int r[];
	int INF=1000000000;
	int ans = INF;
	boolean used[];
	public void run() {
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();
		M=sc.nextInt();
		R=sc.nextInt();
		r=new int[R];
		for(int i=0; i<R; i++) {
			r[i]=sc.nextInt();r[i]--;
		}
		D=new int[N][N];
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				D[i][j]=INF;
				if(i==j) {
					D[i][j]=0;
				}
			}
		}
		for(int i=0; i<M; i++) {
			int a=sc.nextInt();a--;
			int b=sc.nextInt();b--;
			int c=sc.nextInt();
			D[a][b]=c;
			D[b][a]=c;
		}
		for(int k=0; k<N; k++) {
			for(int i=0; i<N; i++) {
				if(D[i][k]==INF) continue;
				for(int j=0; j<N; j++) {
					if(D[k][j]==INF) continue;
					D[i][j] = Math.min(D[i][j], D[i][k]+D[k][j]);
				}
			}
		}
		used = new boolean[R];
		for(int i=0; i<R; i++) {
			used[i]=true;
			dfs(1,0,i);
			used[i]=false;
		}
		System.out.println(ans);
		sc.close();
	}

	private void dfs(int c, int sum, int prev) {
		if(c==R) {
			ans = Math.min(ans, sum);
		}else {
			for(int i=0; i<R; i++) {
				if(!used[i]) {
					used[i]=true;
					dfs(c+1, sum + D[r[prev]][r[i]], i);
					used[i]=false;
				}
			}
		}
	}

}


Measured memory_bytes: 48640
import math
li = input()
n = int(li.split()[0])
d = int(li.split()[1])
max_distance = math.sqrt(d**2)
ans = 0
for _ in range(n):
    li = input()
    x = int(li.split()[0])
    y = int(li.split()[1])
    distance = math.sqrt(x**2 + y**2)
    if distance <= max_distance:
        ans += 1
print(ans)

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

ll binpow(ll a,ll b ,ll m){
	a%=m;
	ll res(1);
	while(b){
		if(b&1)res=((res%m)*(a%m)) % m;
		b>>=1;
		a=((a%m)*(a%m)) % m;
	}
	return res%m;
}


 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.in","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	ll i,j,t,n;
   	cin>>n;
   	ll ans(0),m(1e9+7);
   	ans+=binpow(10LL,n,m);
   	ans+=binpow(8LL,n,m);
   	ans%=m;
   	ans-=(2*binpow(9LL,n,m));
   	ans%=m;
   	ans+=m;
   	ans%=m;
   	cout<<ans;
	
	
 
 
 
 
 
 
 
	return 0;
}

Measured memory_bytes: 3692
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int A,B; cin >> A >> B;
    repr(i,10,10000){
        if(8*i/100 == A && i/10 == B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> gate(n+1,0);
  rep(i,0,m) {
    int l,r;
    cin >> l >> r;
    gate[l-1]++; gate[r]--;
  }
  rep(i,1,n+1) {
    gate[i] += gate[i-1];
  }
  int ans = 0;
  rep(i,0,n) {
    if (gate[i] == m) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int gcd( int m, int n )
{
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}

int lcmfunction(int m, int n )
{
	return ((m / gcd(m, n)) * n);
}

int main() {
	bitset<8368800> flgs;

	while(1){
		flgs.reset();
		int m,n;
		// ?????????????????£????????°
		int loop = 0;
		cin >> m >> n;
		if(m == 0 && n == 0) break;
	  int lcm = lcmfunction(n, m);

		if(m > n){
				cout << m + n << "\n";
		}else{
			int i;
	  	for(i = m ; loop <= n ; i++){
				if(flgs.test(i)){
				}else{
					loop++;
					for(int j = 1 ; i * j < 8368800 ; j++){
						flgs.set(i * j);
					}
		//			cout << "i = " << i << " loop = " << loop << "\n";
				}
			}

			cout << i - 1 << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 4092
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    input<int>();
    string s;
    cin >> s;

    cout << (std::count(ALL(s), 'R') > std::count(ALL(s), 'B') ? "Yes\n" : "No\n");
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int n;
    cin >> n;
    cout << (n + 1) / 2 << 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.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2)=='C')
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);

    int cnt = 0, sum = 0;
    while (cnt < N && sum < x) {
        sum += a[cnt];
        cnt++;
    }
    // 子供 iはちょうど ai個のお菓子を貰うと喜びます。
    System.out.println(sum == x ? cnt : cnt - 1);
  }
}


Measured memory_bytes: 23252
import java.util.*;

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

		for (int i=0; i<q; i++) {
			String com = stdIn.next();
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();

			if(com.equals("reverse")){
				String rev = s.substring(a,b+1);
				String temp = s.substring(b+1);
				s = s.substring(0,a);
				for (int index=rev.length()-1; index>=0; index--) {
					s += rev.charAt(index);
				}
				s += temp;

			}else if(com.equals("replace")){
				String p = stdIn.next();
				s = s.substring(0,a) + p + s.substring(b+1);

			}else{
				String temp = s.substring(a,b+1);
				System.out.println(temp);
			}
		}
	}
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    ll n,m;
    cin >> n >> m;

    if(m==2){
    	if(n>=1){
    		cout << 1 << endl;
    		return 0;
    	}else{
    		cout << 0 << endl;
    		return 0;
    	}
    }
    
    if(m/2<=n){
    	cout << m/2 << endl;
    	return 0;
    }

    ll res=min(n,m/2);
    n-=res;
    m-=2*res;

    res+=m/4;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  string s;
  int a;
  cin >> a >> s;
  if(a >= 3200) cout << s;
  else cout << "red";
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def a(i):
    return i*(i+1)//2

def main():
    n = I()
    k = -1
    for i in range(1, 10**3):
        if n == a(i):
            k = i
            break
    if k == -1:
        print("No")
        return

    print("Yes")

    print(2 * n // k)
    ans = [[] for __ in range(2 * n // k)]
    for i in range(k):
        ans[0].append(i+1)
    filled = 1
    next_to_use = [1]
    cur_max = k
    for i in range(k-1):
        remain = k
        for j in range(len(next_to_use)):
            ans[i+1].append(next_to_use[j])
            next_to_use[j] += 1
            remain -= 1
        first = True
        while remain:
            cur_max += 1
            ans[i+1].append(cur_max)
            remain -= 1
            if first:
                next_to_use.append(cur_max)
                first = False
    for i in range(k):
        ans[-1].append(ans[i][-1])

    for i in range(len(ans)):
        l = len(ans[i])
        print(str(l) + ' ' + ' '.join([str(x) for x in ans[i]]))
main()



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

int main() {
  int n, ans=0;
  cin >> n;
  int d[n];

  rep(i, n)
  {
    cin >> d[i];
  }
  sort(d, d+n);

  int pre = 0;
  rep(i, n)
  {
    if(pre == d[i])
      continue;
    ans++;
    pre = d[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef tuple<int,int,int> ti3;

void Main()
{
	string S;
	cin >> S;
	map<char,int> mci;
	rep(i, S.length())
	{
		if (!mci[S[i]]) {
			mci[S[i]] = 1;
		} else {
			mci[S[i]] += 1;
		}
	}
	if (mci.size() != 2) {
		cout << "No";
		return;
	}
	for(auto i = mci.begin(); i != mci.end(); ++i) {
		if (i->second != 2) {
			cout << "No";
			return;
		}
	}
	cout << "Yes";
	return;
}

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


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

using namespace std;

int main() {
	int h, w;

	cin >> h >> w;
	vector<string> a(h);
	vector<string> b(h, string(w, '.'));
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}

	b[0][0] = '#';
	int x = 0;
	int y = 0;

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

	while(1) {
		bool update = false;
		for (int i = 0; i < 2; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];

			if (nx < w && ny < h && a[ny][nx] == '#') {
				b[ny][nx] = '#';
				x = nx;
				y = ny;
				update = true;
				break;
			}
		}
		if (x == w - 1 && y == h - 1) {
			break;
		}
		if (!update) {
			break;
		}

	}

	string ans = "Possible";
	for (int i = 0; i < h; i++) {
		if (a[i] != b[i]) {
			ans = "Impossible";
			break;
		}
	}

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


Measured memory_bytes: 256
S = str(input())
alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

n = 0

for i in range(26):

	if alpha[n] not in S:
		print(alpha[n])
		break
	if n == 25:
		print("None")
		break
		
	n += 1


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;

    llint x, y;
    cin >> x >> y;
    if (x % y == 0)
        cout << -1;
    else {
        for (llint i = 1;; i++) {
            llint p = x * i;
            if (p % x == 0 && p % y != 0) {
                cout << p;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3540
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

ll dfs(int k, vector<vector<int>> &graph, int now, int from)
{
	int c;
	if (from == -1){
		c = k - 1;
	} else {
		c = k - 2;
	}
	if(k < graph[now].size()) {
		return 0;
	} else {
		ll cn = 1;
		for (auto g : graph[now]) {
			if (g == from) {
				continue;
			}
			cn *= c;
			c--;
			cn %= mod;
		}
		for (auto g : graph[now]) {
			if (g == from) {
				continue;
			}
			cn *= dfs(k, graph, g, now);
			cn %= mod;
		}
		return cn;
	}
}

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

	cin >> N >> K;

	vector<vector<int>> graph(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	ll ans = K * dfs(K, graph, 0, -1);
	ans %= mod;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
ll po(ll n)
{
	ll k=0;
	while(n%2==0)
	{
		k++;
		n=n/2;
	}
	return k;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,k,n;
    	cin>>n>>k;
    	ll h[n+1];
    	repi(i,1,n)
    	cin>>h[i];
    	ll dp[n+1];
    	dp[1]=0;
    	repi(i,2,n)
    	dp[i]=mod;
    	repi(i,2,n)
    	{
    		if(i>k)
    		{
    			repi(j,1,k)
    			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			}
			else
			{
				repi(j,1,i-1)
				{
					dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
				}
			}
		}
    	cout<<dp[n];
    }
    
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n;i>s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

ll a[10000];
ll b[10000];
ll sumA;
ll sumB;
int main() {
	ll n; cin >> n;
	rep(i, 0, n) {
		cin >> a[i];
		sumA += a[i];
	}
	rep(i, 0, n) {
		cin >> b[i];
		sumB += b[i];
	}
	ll cnt = sumB - sumA;
	if (cnt < 0) {
		cout << "No" << endl;
		return 0;
	}

	ll P = 0;
	rep(i, 0, n) {
	/*	if (a[i] > b[i]) {
			P += a[i] - b[i];
		}*/
		if (a[i] < b[i]) {
			P += ((b[i] - a[i]) + 1) / 2;
		}
	}

	cout << ((cnt >= P) ? "Yes" : "No") << endl;

	return 0;
}

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

using namespace std;

int main()
{
    string s, t;

    cin >> s >> t;

    string res = "Yes\n";

    for(int i = 0; i < s.size(); i++)
        if(s[i] != t[i])
            res = "No\n";

    cout << res;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)

int main(){
	int n;
	int t[10010];
	
	scanf("%d",&n);
	rep(i,n-1){
		scanf("%d",&t[i]);
	}
	
	int dp[2][5010];
	rep(i,2)rep(j,5010)dp[i][j] = 1000000000;
	dp[0][1] = 0;
	
	rep(i,n-1){
		for(int j=n/2;j>0;j--){
			dp[1][j] = min ( dp[0][j] + t[i] , dp[1][j] );
			dp[0][j] = min ( dp[0][j-1] , dp[1][j-1] + t[i] );
		}
	}
	
	printf("%d\n",min ( dp[0][n/2] , dp[1][n/2] ) );
}

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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;

void solve() {
	int s,w;
	cin >> s >> w;
	if(s <= w) cout << "unsafe";
	else cout << "safe";
}

int32_t main() {_
	//tc(t)
		solve();
}



Measured memory_bytes: 3656