akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
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; }
typedef long long ll;
const int INF = 1e9;

int main(){
   int n; cin >> n;
   vector<ll> a(n);
   REP(i,n) cin >> a[i];
   int two = 0, four = 0;
   REP(i,n){
       if(a[i] % 4 == 0) ++four;
       else if(a[i] % 2 == 0) ++two;
   }

   if(four >= (n - two + two % 2) / 2) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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 gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
using namespace atcoder;

void solve(){
	int t;
	cin>>t;
	while(t--){
		ll n,m,a,b;
		cin>>n>>m>>a>>b;
		cout<<floor_sum(n,m,a,b)<<"\n";
	}
}


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


Measured memory_bytes: 3664
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
	int n;cin>>n;
	multiset<ll> mst;
	rep(i,n) {
		ll x;cin>>x;
		auto itr = mst.lower_bound(x);
		if (mst.begin()!=itr) --itr, mst.erase(itr);
		mst.insert(x);
	}
	cout << mst.size() << endl;
	return 0;
}

Measured memory_bytes: 4992
import scala.io.StdIn._
object Main extends App {
  var arr = readLine().split(" ").map(_.toInt)

  var count = 0
  while (arr(0) != arr(1) || arr(1) != arr(2)) {
    arr = arr.sorted
    if (arr(0) == arr(1)) {
      arr(0) += 1
      arr(1) += 1
      count += 1
    } else {
      arr(0) += 2
      count += 1
    }
  }
  println(count)
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int x=1;x<=100;x++){
        int sum = 0;
        bool ok = true;
        for(int i=0;i<n;i++){
            sum += a[i]-x;
            ok &= sum >= 0;
        }
        if(ok) ans = x;
        else break;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3104
N, M = map(int, input().split())

KS = [list(map(int, input().split()))[1:] for _ in range(M)]

P = list(map(int, input().split()))

# print(N, M)
# print(KS)
# print(P)

ans = 0
for i in range(pow(2, N)):
    bin_i = str(bin(i))[2:]
    if len(bin_i) != N:
        bin_i = '0' * (N - len(bin_i)) + bin_i
    # print(bin_i)

    # bin_i はi番目のスイッチの状態

    flg = True
    # 各電球でループする
    for i, ks in enumerate(KS):
        # print(ks)
        cnt = 0
        for j in ks:
            if bin_i[j-1] == '1':
                cnt += 1
        if cnt % 2 != P[i]:
            flg = False
            break

    if flg:
        ans += 1


print(ans)





Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N, dp[12], cur[12];
    while (~scanf("%d", &N)) {
          for (int i = 1; i <= 9; i++) dp[i] = -1;
          dp[0] = 0;
          for (int i = 0; i < N; i++) {
              int tmp;
              scanf("%d", &tmp);
              memset(cur, -1, sizeof(cur));
              for (int j = 0; j < 10; j++) {
                  int k = (tmp + j) % 10;
                  if (dp[j] >= 0) cur[k] = max(dp[j] + tmp, dp[k]);
              }
              for (int j = 0; j < 10; j++) dp[j] = max(dp[j], cur[j]);
          }
          int ans = 0;
          for (int i = 1; i < 10; i++) ans = max(ans, dp[i]);
          printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define m long long
using namespace std;
#define z else 
#define d(s,i,n) for(m i=s;i<n;i++)
m l[90],r[90],e[90][90],f[90][90];
int main(){m n;cin>>n;l[0]=1;r[0]=1;d(1,i,90)l[i]=r[i-1],r[i]=l[i-1]+r[i-1];d(0,i,89){e[i][0]=1,f[i][0]=1;d(1,j,90){if(i+1==j)f[i][j]=f[i][j-1]*2+e[i][j-1];z f[i][j]=f[i][j-1]+e[i][j-1];e[i][j]=f[i][j-1];}}d(0,i,n){m c,d;cin>>c>>d;if(d>c)swap(c,d);m k=0;d(0,j,90)if(c>=r[j]&&d>=l[j])k=j;m g;if(k==0)k=1,g=1;z if(k==1)if(d==1)g=c;z g=4;z{g=1;if(d>=r[k]&&c>=l[k]&&l[k]<r[k])g++;d(0,j,k)if(f[j][k]<=c&&e[j][k]<=d)g+=1+(c-f[j][k])/e[j][k];d(0,j,k)if(f[j][k]<=d)g+=1+(d-f[j][k])/e[j][k];}cout<<k<<" "<<g%1000000007<<endl;}}	


Measured memory_bytes: 4456
import java.util.*;

public class Main {
	public static void main(String args[]){
		int a,b,c, N;//
		Scanner sc = new Scanner(System.in);
		while(true){
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			if(a==0&&b==0&&c==0){
				System.exit(0);
			}
			N = sc.nextInt();
			int[] checking = new int[a+b+c];
			LinkedList<Integer>temp = new LinkedList<Integer>();
			Arrays.fill(checking, 0);
			for(int j=0;j<2;j++){
				for(int i=0;i<N;i++){
					if(j==0){
					int a1,b1,c1,check;
					a1 = sc.nextInt();
					b1 = sc.nextInt();
					c1 = sc.nextInt();
					check = sc.nextInt();
						if(check==1){
							checking[a1-1] = 1;
							checking[b1-1] = 1;
							checking[c1-1] = 1;
						}else{
							temp.add(a1);
							temp.add(b1);
							temp.add(c1);
						}
					}else{//j==1
						if(temp.isEmpty()){
							break;
						}
						int a2 = temp.pop();
						int b2 = temp.pop();
						int c2 = temp.pop();
						if(checking[a2-1]+checking[b2-1]+checking[c2-1]==2){
							if(checking[a2-1]!=1){
								checking[a2-1]=3;
							}else if(checking[b2-1]!=1){
								checking[b2-1] =3;
							}else{
								checking[c2-1]=3;
							}
						}
					}
				}
			}
			for(int contents : checking){
				int result;
				if(contents==3){
					result=0;
				}else if(contents==0){
					result=2;
				}else{
					result =1;
				}
				System.out.println(result);
			}
		}
	}
}

Measured memory_bytes: 28316
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int a, b;
    string s;
    cin >> a >> b >> s;
    bool f = 1;
    for (int i = 0; i < a; i++) {
        if (s[i] < '0' || s[i]>'9') f = 0;
    }
    if (s[a] != '-') f = 0;
    for (int i = a + 1;i < a + b + 1;i++) {
        if (s[i] < '0' || s[i]>'9') f = 0;
    }
    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int A,B,C,X,Y;
  int f,g,h,k;
  f=0;h=0;g=0;k=0;
  cin>>A>>B>>C>>X>>Y;
  if(X>Y)k=1;
  if(A+B>2*C)f=1;
  if(A>2*C)g=1;
  if(B>2*C)h=1;
  if(f==1){
  if(g==1&&h==1)cout<<max(X,Y)*C*2;
  if(g==1&&h==0&&k==1)cout<<Y*C*2+(X-Y)*C*2;
  if(g==1&&h==0&&k==0)cout<<X*C*2+(Y-X)*B;
  if(g==0&&h==0&&k==1)cout<<(X-Y)*A+Y*2*C;
  if(g==0&&h==0&&k==0)cout<<(Y-X)*B+X*2*C;
  if(g==0&&h==1&&k==1)cout<<Y*C*2+(X-Y)*A;
  if(g==0&&h==1&&k==0)cout<<X*C*2+(Y-X)*C*2;
}
if(f==0)cout<<A*X+B*Y;
cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	cin >> n;
	bool s = 1;
	while (n != 0) {
		if (n % 10 == 7) {
			cout << "Yes";
			s = !s;
			break;
		}
		n /= 10;
	}
	if (s) cout << "No";
	return 0;
}

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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

const int MAXN = 101;
int st[MAXN];
int top = 0;

bool isFull() {
	return MAXN - 1 == top;
}
bool isEmpty() {
	return top == 0;
}
void push(int n) {
	if (isFull()) {
		cout << "stack over flow" << endl;
		return;
	}
	++top;
	//cout << "push : " << n << endl;
	st[top] = n;
}
int pop() {
	if (isEmpty()) {
		cout << "stack under flow" << endl;
		return -9999999;
	}
	--top;
	return st[top + 1];
}

char s[(long)1e9];
void solve() {
	int i = 0;
	while(cin >> s) {
		//cout << (++i) << endl;
		//cout << s << endl;
		if (s[0] == '+') {
			int v1 = pop();
			int v2 = pop();
			push(v1 + v2);
		} else if (s[0] == '-') {
			int v1 = pop();
			int v2 = pop();
			push(v2 - v1);
		} else if (s[0] == '*') {
			int v1 = pop();
			int v2 = pop();
			push(v2 * v1);
		} else {
			//cout << "convert : " << atoi(s) << endl;
			push(atoi(s)); 
		}
	}
	cout << pop() << endl;
}

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

Measured memory_bytes: 3104
#include <iostream>

using namespace std;

int main(void)
{
    long long W, a, b;

    cin >> W >> a >> b;

    if(a+W < b){
        cout << b-(a+W) << endl;
    }

    else if(b+W < a){
        cout << a-(b+W) << endl;
    }

    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,d;
    cin>>n>>d;
    d=2*d+1;
    cout<<(n+d-1)/d<<endl;
    return 0;
}

Measured memory_bytes: 256
let m = 1039999

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let to_x = Array.make 128 0

let to_key s =
  let ret = ref 0 in
  let p = ref 1 in
  for i = 0 to String.length s - 1 do
    ret := !ret + !p * (to_x.(Char.code s.[i]));
    p := 5 * !p;
  done;
  !ret

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  let t = Array.make m "\000" in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if find s t then "yes" else "no")
    | [_; s] -> insert s t
    | _ -> assert false
  done

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)+n>90) cout << char(s.at(i)+n-26);
    else cout << char(s.at(i)+n);
  }
}

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

int main() {
  int N,K,x;
  cin>>N>>K;
  x=1;
  for (int i=0;i<N;i++){
    int A,M;
    A=x+K;
    M=x*2;
    if(A<M){x=A;}
    else{x=M;}
  }
  cout<<x<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,ll>;
using Graph= vector<vector<P>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll dp[105][100005] ; 
int main(){
 ll n,A ;cin>>n>>A ;
 vector<ll> w(n),v(n) ;
 rep(i,n) cin>> w[i] >>v[i] ;
 rep(i,A+5) dp[0][i] =0 ;
 
  rep(i,n){
    rep2(j,0,A){
     if(j<w[i]) dp[i+1][j]=dp[i][j] ;
     else dp[i+1][j]=max(dp[i][j],
     dp[i][j-w[i]] +v[i]) ;
    }
  }
     cout<<dp[n][A]<<endl ;
  return 0;
  }

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define pi M_PI

int main(){
  int h, w;
  while(1){
    cin >> h >> w;
    if(h + w == 0) return 0;
    else{
      REP(i, h){
        REP(j, w){
          if((i + j) % 2 == 0) cout << "#";
          else cout << ".";
        }
        cout << endl;
      }
      cout << endl;
    }
  }
}



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

int main() {
  int n,count;
  cin>>n;
  count=0;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    vec.at(i)=l;
  }
  sort(vec.begin(),vec.end());
  vec.at(n-1)%=vec.at(0);
  if(vec.at(n-1)==0){
    for(int i=vec.at(0);i>0;i--){
    count=0;
    for(int j=0;j<n;j++){
      if(vec.at(j)%i!=0)count++;
    }
   if(count==0){
     cout<<i<<endl;
    break;
   }
  }
  }
  else{
    for(int i=vec.at(n-1);i>0;i--){
    count=0;
    for(int j=0;j<n;j++){
      if(vec.at(j)%i!=0)count++;
    }
   if(count==0){
     cout<<i<<endl;
    break;
   }
  }
  }
}


Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

A, B, C = map(int, read().split())

if A == B & B != C:
    print("Yes")
elif B == C & C != A:
    print("Yes")
elif C == A & A != B:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#import math
#import collections
n,k = map(int, input().split( ))
A = list(map(int, input().split( )))

arr = [0]*n
for i in range(n):
  arr[i] = (A[i]+1)/2

s = sum(arr[:k])
ans = s
for j in range(n-k):
  s = s - arr[j] + arr[j+k]
  ans = max(s,ans)
print(ans)

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

int main() {
 string S;
 cin >> S; 
  
  if (S[2] == S[3] && S[4] == S[5]){
    cout <<  "Yes" << endl; 
  }
  
  else {
    cout <<  "No" << endl; 
  }
    
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[20];

double dp[2][200010];

signed main(){
    cin>>N;rep(i,N)cin>>A[i];

    fill_n(*dp,2*200010,1001001001);

    dp[0][1]=0;
    rep(i,N){
        reps(j,1,200000+1){
            for(int k=j;k<=200000;k+=j){
                double tmp=(double)abs(A[i]-k)/A[i];
                chmin(dp[(i+1)&1][k],max(dp[i&1][j],tmp));
            }
            dp[i&1][j]=1001001001;
        }
    }

    double mi=1001001001;
    reps(j,1,200000+1)chmin(mi,dp[N&1][j]);
    printf("%.20f\n",mi);
    return 0;
}

Measured memory_bytes: 4312
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

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

    ll a, b;
    cin>>a>>b;

    ll g = gcd(a, b);
    ll r = sqrt(g);
    ll cnt = 1;
    for (int i = 2; i <= r; ++i) {
        bool div = false;
        while (g % i == 0) {
            g /= i;
            div = true;
        }
        if (div) cnt++;
    }
    if (g > 1) cnt++;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N, P;
        int[] A;
        long[][] dp;

        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            P = in.nextInt();
            A = in.nextIntArray(N);
            dp = new long[N + 1][2];
            dp[0][0] = 1;
            dp[0][1] = 0;

            for (int i = 1; i <= N; i++) {
                dp[i] = dp[i - 1].clone();
                int p = A[i - 1] % 2;
                dp[i][0] += dp[i - 1][p];
                dp[i][1] += dp[i - 1][1 - p];
            }

            out.println(dp[N][P]);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        int[] nextIntArray(int n) {
        	int[] arr = new int[n];
        	for (int i = 0; i < n; ++i) {
        		arr[i] = nextInt();
        	}
        	return arr;
        }

        long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; ++i) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 23380
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var ab = Sarray();
            var a = ab[0];
            var b = ab[1];
            var ans = -1;
            for(var i=0;i<1500;i++)
            {
                var aa = (int)(i * 0.08);
                var bb = (int)(i* 0.1);
                if (aa == a && bb == b)
                {
                    ans = i;
                    break;
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 19032
# -*- coding: utf-8 -*-
q,h,s,d = map(int,input().split())
n = int(input())

q = 4*q
h = 2*h

if n%2==0:
    t = q*n
    t = min(t, h*n)
    t = min(t, s*n)
    t = min(t, d*n//2)
else:
    t = q*n
    t = min(t, h*n)
    t = min(t, s*n)
    t = min(t, (n//2)*d + min(q,h,s))
print(t)


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main()
{   long long n;
    scanf("%lld",&n);
    long long cpy=n;
    int sum=0;
    int dig=0;
    while(cpy>0){
        sum+=cpy%10;
        cpy/=10;
        dig++;
    }
    int head=n/pow(10,(dig-1));
    if((sum-head)==9*(dig-1)){
        printf("%d",(dig-1)*9+head);
    }else{
        printf("%d",(dig-1)*9+head-1);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,sl,fh,ans,a[110],s[110];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();ans=1e9;
	for(int i=1;i<=n;++i) a[i]=rd(),s[i]=s[i-1]+a[i];
	for(int i=1;i<n;++i) ans=min(ans,abs(s[n]-s[i]-s[i]));
	printf("%d\n",ans);
	return 0;
}

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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr i64 INF = std::numeric_limits<i64>::max()/2;

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	i64 n, k;

	std::cin >> n >> k;

	std::vector<i64> h(n);

	for(i64 i=0; i<n; ++i)
	{
		std::cin >> h[i];
	}

	std::vector<i64> dp(n, INF);
	dp[0]=0;
	
	for(i64 i=0; i<n; ++i)
	{
		for(i64 j=1; j<=k; ++j)
		{
			if(i-j >= 0)
			{
				dp[i] = std::min(dp[i], dp[i-j]+std::abs(h[i-j]-h[i]));
			}
		}
	}

	std::cout << dp[n-1] << "\n";
	
	return 0;
}

Measured memory_bytes: 1792
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

cnt = Counter(A)

cmb = 0
for a, c in cnt.items():
    if c >= 2:
        cmb += c * (c - 1) // 2

for a in A:
    minus = 0 if cnt[a] < 2 else cnt[a] * (cnt[a]-1) // 2
    c = cnt[a] - 1
    plus = 0 if c < 2 else c * (c-1) // 2
    ans = cmb - minus + plus
    print(ans)


Measured memory_bytes: 26780
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  cin >> n;
  clr(d,0);
  rep(i,0,n){
    cin >> s;
    if(s[0] == 'M')d[0]++;
    if(s[0] == 'A')d[1]++;
    if(s[0] == 'R')d[2]++;
    if(s[0] == 'C')d[3]++;
    if(s[0] == 'H')d[4]++;
  }
  l = 0;
  rep(i,0,5){
    rep(j,i+1,5){
      rep(k,j+1,5){
        l += d[i] * d[j] * d[k];
      }
    }
  }
  print(l);
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 410
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,m,a[N][N],fa[N*N],size[N*N][2];
int trans(int x,int y){return (x-1)*m+y;}
int wx[4]={1,0,0,-1},wy[4]={0,1,-1,0};
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
    n=read(),m=read();
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            char c=getchar();
            while (c!='.'&&c!='#') c=getchar();
            a[i][j]=c=='.';
        }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            fa[trans(i,j)]=trans(i,j);
            size[trans(i,j)][a[i][j]]=1;
        }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            for (int k=0;k<4;k++)
            if (i+wx[k]>=1&&i+wx[k]<=n&&j+wy[k]>=1&&j+wy[k]<=m&&a[i+wx[k]][j+wy[k]]!=a[i][j])
            {
                int p=find(trans(i,j)),q=find(trans(i+wx[k],j+wy[k]));
                if (p!=q)
                {
                    fa[p]=q;
                    size[q][0]+=size[p][0],size[q][1]+=size[p][1];
                }
            }
    ll ans=0;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        if (find(trans(i,j))==trans(i,j)) ans+=1ll*size[trans(i,j)][0]*size[trans(i,j)][1];
    cout<<ans;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<lli>());
    int pivo = n - 1;
    rep(i, n)
    {
        if (a[i] <= i) {
            pivo = i - 1;
            break;
        }
    }
    int pivo_x = 0;
    while (a[pivo_x] > pivo) {
        pivo_x++;
    }
    //cout << pivo_x << " " << pivo << endl;
    if ((a[pivo] - pivo + 1) % 2 == 0 and (pivo_x - pivo + 1) % 2 == 0) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
}


Measured memory_bytes: 640
//PLUS ULTRA

#include<bits/stdc++.h>
using namespace std;
     
     
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define mp make_pair
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define nfor(i,st,n) for(int i = st; i >= n ; i--)

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

const int N = 1e5 + 10 , mod =  1000000007;

bool ispal(string str , int x , int y){
	x--;y--;

	while(x < y){
		if(str[x++] != str[y--])return false;
	}

	return true;
}

int main(){
    SPEED;

    string str;
    cin >> str;

    int n = str.size();

    if(n%2 == 0){
    	cout << "No" << endl;
    }else{

    	if(ispal(str , 1,n) && ispal(str ,1,(n-1)/2 ) && ispal(str ,(n+3)/2 , n )  ){
    		cout << "Yes" << endl;
    	}else cout << "No" << endl;

    }

    
    return 0;
}
      
       


Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[], int N) {
  int i;
  for (i=0; i<N; i++) {
    if(i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void selectionSort(int A[], int N) {
  int i, j, minj, count = 0;
  for (i = 0; i < N; i++) {
    minj = i;
    for (j = i; j < N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    if (minj != i) count++;
    int tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
  }
  trace(A, N);
  printf("%d\n", count);
}

int main() {
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", &A[i]);

  selectionSort(A, N);

  return 0;
}


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

#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define fi first
#define se second

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    int ans = INT_MAX;
    for (int i = 0; i < n; i++) {
        int c, te;
        cin >> c >> te;
        if (te <= t) ans = min(ans, c);
    }
    if (ans == INT_MAX) cout << "TLE\n";
    else cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
    
  int ans = 0;
  
  for (int i = 0; i < n; i++){
    int x; cin >> x;
    ans = __gcd(ans,x);
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
def rain(S):
	i = 0
	while(i<3 and S[i]!='R'):
	  i+=1

	if(i==3):
		return 0

	j = i+1
	while(j<3 and S[j]=='R'):
	  j+=1

	return j-i

S = input()
print(rain(S))

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

int main() {
  int n,m;cin>>n>>m;
  vector<vector<int>> s(m);
  rep(i,m){
    int k;cin>>k;
    rep(j,k){
      int a;cin>>a;
      a--;
      s[i].push_back(a);
    }
  }
  vector<int> p(m);
  rep(i,m)cin>>p[i];
  int ans=0;
  rep(bit,1<<n){
    bool ok=true;
    rep(i,m){
      int cnt=0;
      for(auto x:s[i]){
        if(bit&(1<<x))cnt++;
      }
      if(cnt%2!=p[i])ok=false;
    }
    if(ok)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
/*
	Author GaryMr
	线段树：左闭右开！ 
	代数设出每个值寻找关系？
	优先队列：priority_queue<类型> q;   
	priority_queue<vector<类>, less<类> > pq1; 　　　 // 使用递减less<int>函数对象排序
	priority_queue<vector<类>, greater<类> > pq2; 　　// 使用递增greater<int>函数对象排序
*/
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
typedef pair<pair<int,int>,pair<int,int> > mpair;
set<mpair> q; 
pair<int,int> Jtree[800001],Otree[800001];//[r,l)
int n,p[200001];
void build(int k,int l,int r){
//	cout<<k<<" "<<l<<  " "<<r<<endl;
	if(l==r-1){
		Jtree[k]=Otree[k]={0x3f3f3f3f,l};
		if(l%2) Jtree[k]={p[l],l};
		else Otree[k]={p[l],l};
		return;
	}
	int mid=(l+r)>>1;
	build(k*2,l,mid);
	build(k*2+1,mid,r);
	Jtree[k]=min(Jtree[k*2],Jtree[k*2+1]);
	Otree[k]=min(Otree[k*2],Otree[k*2+1]);
}
pair<int,int> getJ(int k,int a,int b,int l,int r){
	if(r<=a||l>=b) return {0x3f3f3f3f+1,l};
	if(r<=b&&l>=a) return Jtree[k];
	int mid=(l+r)>>1;
	return min(getJ(k*2,a,b,l,mid),getJ(k*2+1,a,b,mid,r));
}
pair<int,int> getO(int k,int a,int b,int l,int r){
	if(r<=a||l>=b) return {0x3f3f3f3f+1,l};//cout<<k<<" "<<a<<" "<<b<<" "<<l<<" "<<r<<endl;
	if(r<=b&&l>=a) return Otree[k];
	int mid=(l+r)>>1;
	return min(getO(k*2,a,b,l,mid),getO(k*2+1,a,b,mid,r));
}
pair<int,int> getminima(int l,int r){
	pair<int,int> fir,sec;
	if(l%2) {fir=getJ(1,l,r,1,n+1);sec=getO(1,fir.second+1,r,1,n+1);}
	else {fir=getO(1,l,r,1,n+1);sec=getJ(1,fir.second+1,r,1,n+1);}
	return {fir.first,sec.first};
}
int main(){
	int FinalN;
	scanf("%d",&n);FinalN=n; 
	for(int i=1;i<=n;i++) {
		scanf("%d",&p[i]);m[p[i]]=i;
	}
	build(1,1,n+1);
	q.insert({{getminima(1,n+1)},{1,n+1}});
	while(q.size()){
		mpair process=*q.begin();
		q.erase(q.begin());
		if(process.second.first>FinalN) continue;
		printf("%d %d ",process.first.first,process.first.second);
		int l=process.second.first,r=process.second.second,firwei=m[process.first.first],secwei=m[process.first.second];
		if(firwei>l){
			
			q.insert({{getminima(l,firwei)},{l,firwei}});
		}
		if(secwei>firwei+1){//cout<<firwei+1<<" "<<secwei<<endl;
			q.insert({{getminima(firwei+1,secwei)},{firwei+1,secwei}});
		}
		if(r>secwei+1){
			q.insert({{getminima(secwei+1,r)},{secwei+1,r}});
		}
	} 
	return 0;
} 

Measured memory_bytes: 25728
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while( x != NIL) {
        y = x;
        if (z -> key < x -> key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z -> parent = y;
    if( y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if (u==NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}
int main()
{
    int n, i, x;
    string com;
    cin >> n;
    REP(i, n) {
        cin >> com;
        if (com == "insert") {
            cin >> x;
            insert(x);
        } else if(com == "print") {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
int k[101] = {0};

int main()
{
    int n;
    cin >> n;
    //素因数分解
    for (int i = 2; i <= n; i++)
    {
        int amari = i;
        for (int j = 2; j * j <= amari; j++)
        {
            if (amari % j == 0)
            {
                while (amari % j == 0)
                {
                    amari /= j;
                    k[j]++;
                }
            }
        }
        k[amari]++;
    }

    int ans = 0;

    for (int i = 2; i < n; i++)
    {
        for (int j = i; j < n; j++)
        {
            for (int l = 2; l < n; l++)
            {
                if (k[i] >= 4){
                    int tmp1 = k[i];
                    k[i] += 1;
                    k[i] /= 5;
                    k[i] -= 1;
                    if(k[j] >= 4){
                        int tmp2 = k[j];
                        k[j] += 1;
                        k[j] /= 5;
                        k[j] -= 1;
                        if(k[l] >= 2){
                            ans++;
                        }
                        k[j] = tmp2;
                    }
                    k[i] = tmp1;
                }
            }
        }
    }

    cout << ans << endl;
}

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

c = m * 1900 + 100 * (n - m)
total = 0
for i in range(1, 1000):
    total += c * i *  (1 - 1 / 2 ** m) ** (i - 1) * (1 / 2 ** m)
print(round(total))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
using namespace std;
const int L=128,N=1000;
char ans[N],qr[N];
char ch[70];
int cnt,S,M=3;
struct nod{
	int size;
	char c[L+5];
	nod(){}
	bool operator<(const nod &b)const{return size>b.size;}
};
priority_queue<nod>A;
int qry(char *c,int len){
	++cnt;
	printf("? ");
	fo(i,1,len)putchar(c[i]);
	printf("\n");
	fflush(stdout);
	int v;scanf("%d",&v);
	return v;
}
int answer(char *c){
	printf("! ");
	fo(i,1,S)putchar(c[i]);
	printf("\n");fflush(stdout);
}
int main(){
	fo(i,1,26)ch[i]='a'+i-1;
	fo(i,1,26)ch[i+26]='A'+i-1;
	fo(i,0,9)ch[i+52+1]='0'+i;
	fo(i,1,62){
		fo(j,1,128)qr[j]=ch[i];
		int len=128-qry(qr,128);
		S+=len;
		if(len){
			nod a;
			a.size=len;
			fo(j,1,len)a.c[j]=ch[i];
			A.push(a);
		}
	}
	for(;;){
		nod a=A.top();A.pop();
		if(A.empty()){
			answer(a.c);
			break;
		}
		nod b=A.top();A.pop();
		int j=0;
		fo(i,1,a.size){
			for(;;++j){
				if(j==b.size){
					b.c[++b.size]=a.c[i];
					++j;
					break;
				}
				fo(k,1,j)qr[k]=b.c[k];
				qr[j+1]=a.c[i];
				fo(k,j+1,b.size)qr[k+1]=b.c[k];
				if(qry(qr,b.size+1)==S-(b.size+1)){
					fd(k,j+1,b.size)b.c[k+1]=b.c[k];
					b.c[j+1]=a.c[i];
					++b.size;
					++j;
					break;
				}
			}
		}
		A.push(b);
	}
}

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

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

    vector<int> a(N);

    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }

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

    for (int i = 0; i < N; i++)
    {
        x -= a.at(i);
        if (x < 0)
        {
            cout << i << endl;
            return 0;
        }
    }

    if (x == 0)
        cout << N << endl;
    else
        cout << N - 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000500
#define x first
#define y second
using namespace std;
typedef pair<int,int> pii;
pii t[N];
inline int rd() {int r;scanf("%d",&r);return r;}
int n,m;
int main() {
	n = rd(), m = rd();
	t[1] = pii(1,1);
	for (int i=2;i<=n;i++) t[i] = pii(0, 1);
	for (int i=1;i<=m;i++) {
		int a = rd(), b = rd();
		t[b].x |= t[a].x;
		t[b].y ++;
		t[a].y --;
		if (!t[a].y) t[a].x = 0;
	}
	
	int ans = 0;
	for (int i=1;i<=n;i++) if (t[i].x) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        }
        char c;
        std::deque<int> vote(26,0);
        int first=0,second=0;
        char first_c,second_c;
        int flag=0,ans=0;
        for (int i=0;i<n;i++) {
            cin>>c;
            int tmp=c-65;
            vote[tmp]++;
            if (vote[tmp]>first) {
                first=vote[tmp];
                first_c=c;
            } else if (vote[tmp]>second) {
                second=vote[tmp];
                second_c=c;
            }
            if (flag==0&&(first>n/2||second+n-(i+1)<first)) {
                ans=i+1;
                flag=1;
            }
        }
        if (flag==1) {
            cout<<first_c<<" "<<ans<<endl;
        } else {
            cout<<"TIE"<<endl;
        }
    }
    
}


Measured memory_bytes: 3008
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#define clc(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
vector<int>ans;
int main()
{
    int n,m,i,j,k,s,t,x;
    scanf("%d",&n);
    ans.clear();
    if(n==3)
    {
        ans.push_back(2);ans.push_back(5);ans.push_back(63);
    }else
    if(n<=100)
    {
        s=0;t=0;
        for(i=1;i<=200&&t<n-2;i++)
        if(i%2==0||i%3==0)
        {
            t++;
            s+=i;
            ans.push_back(i);
        }
        for(i=205;i<=500;i++)
        if(i%2==0||i%3==0)if((i+s)%6!=1&&(i+s)%6!=5){ans.push_back(i);s+=i;break;}
        for(i=501;i<=800;i++)
        if(i%2==0||i%3==0)if((i+s)%6==0){ans.push_back(i);break;}
    }else
    {
        s=n/22-1;t=n%22+22;
        if(s%2==1){s--;t+=22;}
        for(i=1;i<=s*30;i++)if(i%2==0||i%3==0||i%5==0)ans.push_back(i);
        for(i=n/22+1;i<=n/22+t;i++)ans.push_back(i*30);
    }
    for(i=0;i<ans.size()-1;i++)printf("%d ",ans[i]);
    printf("%d\n",ans[ans.size()-1]);
    //x=0;for(i=0;i<ans.size();i++)x+=ans[i];printf("%d %d %d %d %d %d\n",ans.size(),x,x%30,s,t);
    return 0;
}


Measured memory_bytes: 512
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


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

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N;
vector<Pii> G[MAXN];

void input()
{
    read(N);
    for (int i = 1; i < N; ++i) {
        int u, v, w;
        read(u); read(v); read(w);
        G[u].push_back(MP(v, w));
        G[v].push_back(MP(u, w));
    }
}

int size[MAXN];
LL ans;

void dfs(int u, int f, int c)
{
    size[u] = 1;
    int maxsize = 0;
    for (int i = 0; i < SZ(G[u]); ++i) {
        int v = G[u][i].x, w = G[u][i].y;
        if (v == f)
            continue;
        dfs(v, u, w);
        size[u] += size[v];
        chkmax(maxsize, size[v]);
    }
    ans += (LL)c * std::min(size[u], N - size[u]) * 2;
    chkmax(maxsize, N - size[u]);
    if (maxsize * 2 < N) {
        int t = +oo;
        for (int i = 0; i < SZ(G[u]); ++i) {
            chkmin(t, G[u][i].y);
        }
        ans -= t;
    } else if (size[u] * 2 == N) {
        ans -= c;
    }
}

void solve()
{
    dfs(1, 0, 0);

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

int main()
{
#ifdef __DEBUG
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif

    input();
    solve();
}

// 十年无梦得还家，独立青峰野水涯。
//     -- 谢枋得《武夷山中》


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,x;
  cin >> n >> x;
  int l[n];
  for(int i = 0; i<n ;i++) cin >>l[i];
  int i;
  int s = 0;
  for(i=0; i<n; i++){
    s += l[i];
    if(s > x) break;
  }
  cout << i+1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

long max(long x,long y){
	if(x>y){
		return x;
	}
	else{
		return y;
	}
}

main(){
	long i,j,n,k;
	long *A,*B,*C;
	scanf("%ld",&n);
	mymalloc(A,n+1);
	mymalloc(B,n+1);
	k=0;
	for(i=1;i<=n;i++){
		scanf(" %ld",&A[i]);
		k=max(A[i],k);
	}
	mymalloc(C,k+1);
	for(j=0;j<=k;j++){
		C[j]=0;
	}
	for(i=1;i<=n;i++){
		C[A[i]]++;
	}
	for(j=1;j<=k;j++){
		C[j]+=C[j-1];
	}
	for(i=n;i>0;i--){
		B[C[A[i]]]=A[i];
		C[A[i]]--;
	}
	for(i=1;i<=n;i++){
		printf("%ld",B[i]);
		if(i!=n){
			printf(" ");
		}
	}
	printf("\n");
	free(A);free(B);free(C);
	return 0;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char a;
    cin>>a;
    if('a'<=a&&a<='z'){
    	cout<<"a";
	}
	else{
		cout<<"A";
	}
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N;
  string b;
  char a;
  char c = '*';
  cin >> b;
  cin >> K;
  a = b[K-1];
  for (int j = 0;j<N;j++){
    if (b.at(j) != a){
      b.at(j) = c;
      cout << b.at(j);
    }
    else {
      cout << b.at(j);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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 LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};

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 main(){
    int n;cin >> n;
    LL m;cin >> m;
    vector<int> a(n);
    vector<int> c(n,0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        int t = a[i];
        while(t%2==0){
            t/=2;
            c[i]++;
        }
        a[i] /= 2;
    }
    for (int i = 1; i < n; i++) {
        if(c[i]!=c[i-1]){
            puts("0");
            return 0;
        }
    }
    LL k = a[0];
    for (int i = 0; i < n; i++) {
        k = lcm(k, a[i]);
        if(k>m){
            puts("0");
            return 0;
        }
    }
    cout << (m-k>=0?1 + (m-k) / (2*k):0) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int	main()
{
	int	A, B, C, X;
	int	a, b, c, count = 0;
	int	i, n;

	scanf("%d\n%d\n%d\n%d", &A, &B, &C, &X);
	while (A >= 0)
	{
		a = X - (500 * A);
		if (a > 0)
		{
			i = B;
			while (i >= 0)
			{
				b = a - 100 * i;
				if (b > 0)
				{
					n = C;
					while (n > 0)
					{
						c = b - 50 * n;
						if (c == 0)
							count++;
						n--;
					}
				}
				else if (b == 0)
					count++;
				i--;
			}
		}
		else if (a == 0)
			count++;
		A--;
	}
	printf("%d\n", count);
	return (0);
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int n;
  cin >> n;
  int p[n];
  REP(i, n){
    int x;
    cin >> x;
    p[i] = x-1;
  }
  int q[n];
  REP(i, n){
    q[p[i]] = i;
  }
  int ans = 0, tmp = 1;
  FOR(i, 1, n){
    if(q[i] > q[i-1]) tmp++;
    else{
      ans = max(ans, tmp);
      tmp = 1;
    }
  }
  ans = max(ans, tmp);
  cout << n-ans << endl;
  return 0;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc;
vector<ll> va,vb,vc;

int main(){
    cin>>a>>b>>c>>n;
    
    C(max(a*b,c*n));
}

Measured memory_bytes: 256
#include <iostream>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl
#define SIZE 302

using namespace std;

int dp[SIZE][SIZE], w[SIZE];

int f(int j, int k) {
	int maxf = -1;
	if (dp[j][k] >= 0) return dp[j][k];
	// printf("f(%d, %d)\n", j, k);
	if (k - j <= 0) return dp[j][k] = 0;
	if (k - j == 1) {
		dp[j][k] = ((abs(w[j] - w[k])) <= 1 ? 2 : 0);
		/*if (abs(w[j] - w[k]) <= 1) {
			debug(j);
			debug(k);
		}*/
		/*debug(j);
		debug(k);
		debug(dp[j][k]);*/
		return dp[j][k];
	}
	if (k - j == 2) {
		dp[j][k] = max(f(j + 1, k), f(j, k - 1));
		return dp[j][k];
	}
	for (int i = j + 1; i + 1 < k; i++) {
		maxf = max(maxf, f(j, i) + f(i + 1, k));
		// debug(i);
		// debug(maxf);
	}
	dp[j][k] = max(f(j + 1, k - 1) + ((abs(w[j] - w[k]) <= 1 && f(j+1, k-1)==k-j-1) ? 2 : 0), maxf);
	/*if (abs(w[j] - w[k]) <= 1) {
		debug(j);
		debug(k);
		debug(dp[j][k]);
	}*/
	return dp[j][k];
}

int main() {
	while (1) {
		int n;

		cin >> n;
		if (n == 0) break;
		REP(i, n) cin >> w[i];
		REP(j, n) { REP(k, n) dp[j][k] = -1; }

		 cout << f(0, n - 1) << endl;
	}
	return 0;
}



Measured memory_bytes: 3424