akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,cnt;
vector<int>A;
void insertionSort(int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}
void shellSort(){
  int r=1;
  vector<int>G;
  while(r<=n){
    G.push_back(r);
    r*=2;
  }
  int m=G.size();
  reverse(G.begin(),G.end());
  cout<<m<<endl;
  for(int i=0;i<m;i++)cout<<G[i]<<" \n"[i==m-1];
  for(int i=0;i<m;i++)insertionSort(G[i]);
  cout<<cnt<<endl;
}
int main(){
  cin>>n;
  A.resize(n);
  for(int i=0;i<n;i++)cin>>A[i];
  shellSort();
  for(int i=0;i<n;i++)cout<<A[i]<<endl;
  return 0;
}



Measured memory_bytes: 6660
#include <bits/stdc++.h>
#define my_max(a, b) ((a) > (b) ? (a) : (b))
#define my_min(a, b) ((a) < (b) ? (a) : (b))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i, s, t) for(int i = (int)(s); i <= (int)(t); i++)
#define rev(i, t, s) for(int i = (int)(t); i >= (int)(s); i--)
#define lson rt << 1
#define rson rt << 1 | 1
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double lb;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<int> VI;
typedef std::vector<ll> VL;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbtree;
ll gcd(ll x, ll y) {
    return y % x == 0 ? x : gcd(y % x, x);
}
template<class T>T my_abs(T a) {
    if(a < 0)
        a = -a;
    return a;
}
inline ll read() {
    ll ret = 0, sign = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-')
            sign = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        ret = ret * 10 + c - '0';
        c = getchar();
    }
    return ret * sign;
}
inline void write(ll x) {
    if(x < 0) {
        putchar('-');
        x = -x;
    }
    if(x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

//void expand_stack_space(){
//    int size = 256 << 20; // 256MB
//    char *p = (char*)malloc(size) + size;
//    __asm__("movl %0, %%esp\n" :: "r"(p));
//}
const int maxn = 100 + 7;
int n, m, q;
ll ans;
int a[maxn], b[maxn], c[maxn], d[maxn];
int s[11];
void dfs(int p, int k) {
    if(p == n + 1) {
        ll sum = 0;
        for(int i = 1; i <= q; ++i) {
            if(s[b[i]] - s[a[i]] == c[i]) sum += d[i];
        }
        ans = max(ans, sum);
    }
    else {
        for(int i = k; i <= m; ++i) {
            s[p] = i;
            dfs(p + 1, i);
        }
    }
}
int main() {
#ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
    scanf("%d%d%d", &n, &m, &q);
    for(int i = 1; i <= q; ++i) {
        scanf("%d%d%d%d", a + i, b + i, c + i, d + i);
    }
    dfs(1, 1);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3804
#include<stdio.h>
int main()
{
  int i,j,mini,N,k,A[100],count=0;

  scanf("%d",&N);
  for(i = 0; i < N; i++) scanf("%d",&A[i]);
  
  for(i = 0; i < N-1; i++)
    {
      mini = i;
      for(j = i; j < N; j++)
	{
	  if(A[j] < A[mini]) mini = j;
	}
      if(i == mini) continue;
      k = A[i];
      A[i] = A[mini];
      A[mini] = k;
      count++; 
    }
  
  for(i = 0; i < N; i ++)
    {
      if(i == N-1)
	{
	  printf("%d",A[i]);
	  break;
	}
      printf("%d ",A[i]);
    }
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 600
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

a, b = na()
if b % a == 0:
    print(a+b)
else:
    print(b-a)

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

struct edge {
    int from, to, cost;
    edge(int to, int cost): to(to), cost(cost) {}
};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr LL INF = 1LL << 60;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

template <typename T = pair<int, int>>
void Dijkstra(int s, vector<vector<edge>> g, vector<LL> &d) {
    int numv = d.size();
    priority_queue<T, vector<T>, greater<T>> q;
    for (int i = 0; i < numv; ++i) d[i] = INF;
    d[s] = 0;
    q.emplace(0,s);

    while (!q.empty()) {
        T p = q.top(); q.pop();
        int v = p.second; // vertex
        if (d[v] < p.first) continue;
        for (int i = 0; i < g[v].size(); ++i) {
            edge e = g[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.emplace(d[e.to], e.to);
            }
        }
    }
}

void solve() {
    int n,a,b,c;
    cin >> n;
    vector<vector<edge>> es(n);
    REP(i,0,n-1) {
        cin >> a >> b >> c;
        es[a-1].pb(b-1, c);
        es[b-1].pb(a-1, c);
    }
    int q,k;
    cin >> q >> k;
    VLL d(n);
    Dijkstra(k-1, es, d);
    int x,y;
    REP(i,0,q) {
        cin >> x >> y;
        cout << d[x-1] + d[y-1] << endl;
    }
}

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

Measured memory_bytes: 16052
//#include <bits/stdc++.h>                          //include all library
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1


int main(){
	int N, L;
	cin >> N >> L;
	int m = L, M = N+L-1;
	if(m>=0) cout << (m+M)*N/2 - m<< endl;
	else if(M<=0) cout << (m+M)*N/2 - M << endl;
	else cout << (m+M)*N/2 << endl;
}



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

int main()
{
	long long N, tmp = 1, res = 0;
	cin >> N;
	for (int i = 0, a; i < N; i++) {
		cin >> a;
		if (a > tmp) {
			res += (a - 1) / tmp;
			tmp = max(tmp, 2ll);
		}
		else if(a == tmp)
			tmp++;
	}
	cout << res << endl;
	return 0;
}


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

set<string> correct;
string original = "AKIHABARA";

void dfs(int i, string t)
{
	if(i == original.size()) {
		correct.insert(t);
		return ;
	}
	if(original[i] == 'A') dfs(i + 1, t);
	dfs(i + 1, t + original[i]);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s; cin >> s;
	dfs(0, "");
	cout << (correct.count(s) == 1 ? "YES" : "NO") << endl;
	
	
	return 0;	
}

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

int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  int C;
  cin >> C;
  int K;
  cin >> K;
  int ans;
  if (K<=A) ans=K;
  else if (K<=A+B) ans=A;
  else ans=A-(K-(A+B));
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100001
#define NIL -1
using namespace std;

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

Node **T;

Node* newNode(int parent, int left, int right){
	Node* p = new Node;
	p->parent=parent; p->left=left; p->right=right;
	return p;
}

int pnt(int i){
	if(T[i]->parent==NIL) return i;
	return pnt(T[i]->parent);
}

void Preorder(int i){
	if(i == NIL) return;
	cout <<" "<< i;
	Preorder(T[i]->left);
	Preorder(T[i]->right);
}

void Inorder(int i){
	if(i==NIL) return;
	Inorder(T[i]->left);
	cout << " "<<i;
	Inorder(T[i]->right);
}

void Postorder(int i){
	if(i==NIL) return;
	Postorder(T[i]->left);
	Postorder(T[i]->right);
	cout << " "<< i;
}

int main(){
	int n;
	cin >> n;
	T = new Node*[N];
	for(int i=0;i<n;i++) T[i] = newNode(NIL, NIL, NIL);
	for(int i=0;i<n;i++){
		int id, left, right;
		cin >> id >> left >> right;
		T[id]->left = left;
		T[id]->right = right;
		if(left != NIL) T[left]->parent = id;
		if(right != NIL) T[right]->parent = id;
	}
	int p = pnt(0);
	cout << "Preorder" << endl;
	Preorder(p); cout << endl;
	cout << "Inorder" << endl;
	Inorder(p); cout << endl;
	cout << "Postorder" << endl;
	Postorder(p); cout << endl;
	for(int i=0;i<N;i++) delete T[i];
	delete[] T;
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>

using namespace std;

int main()
{
    int n;
    int total = 0;
    cin >> n;
    int *d = new int[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> d[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            total += d[i] * d[j];
        }
    }

    cout << total << endl;

    return 0;
}


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

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

    if((r * 100 + g * 10 + b) % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>  //std::cout<<fixed や std::cout<<setprecision() を使うための
using namespace std;
int main(int argc, const char * argv[]) {
    double r;
    cin >> r;
    cout << fixed;  //小数点の桁数を正確に指定(%fに相当)
    cout<< setprecision(6); //()で桁数を指定
    cout << r*r*M_PI <<" "<< 2*r*M_PI << endl;
    return 0;
}


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

using namespace std;

int main(){
	int N;
	long long A[200000];
	cin >> N;
	for (int i=0; i < N; i++) {
		long long k;
		cin >> k;
		A[i] = k - i - 1;
	}
	sort(A, A+N);
	long long b;
	if (N % 2 == 0) {
		b = (A[N/2] + A[N/2-1]) / 2;
	} else {
		b = A[N/2];
	}
	long long ans = 0;
	for (int i=0; i < N; i++) {
		long long diff = A[i] - b;
		if (diff <= 0) diff *= -1;
		ans += diff;
	}
	cout <<  ans << endl;



	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A,A+N);
  ll msum = 0;
  ll asum = 0;
  for (int i = 0; i < N; i++) {
    if (i < N / 2){
      msum += A[i];
    }
    else {
      asum += A[i];
    }
  }
  ll ans = 0;
  if (N % 2 == 1) {
    if (A[N/2] - A[N/2 - 1] > A[N/2 + 1] - A[N/2]) {
      ans = ((asum - msum) * 2) - A[N/2] - A[N/2 + 1];
    }
    else {
      msum += A[N/2];
      asum -= A[N/2];
      ans = (asum - msum) * 2 + A[N/2] + A[N/2 - 1];
    }
  }
  else {
    ans = (asum * 2) - (msum * 2) - A[N/2] + A[N/2 - 1];
  }
  cout << ans << endl;
  return 0;
}

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

public class Main {

	private static Scanner in;
	
	private static int n;
	private static double[] p;
	private static double[][] dp;
	private static final int MOD = (int)1e9+7;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		p =  new double[n];
		for(int i=0; i<n; i++) {
			p[i] = in.nextDouble();
		}
		
		dp = new double[n+1][n+1];
		
		for(int i=0; i<dp.length; i++)
			Arrays.fill(dp[i], -1);
		
		System.out.println(solve(0, 0));
	
	}
	
	private static double solve(int i, int heads) {
		
		if (i==n) {
			if (2*heads>n) return 1;
			else return 0;
		}
		
		if (dp[i][heads]!=-1) return dp[i][heads];
		
		double ans = 0;
		
		ans = p[i]*solve(i+1, heads+1)+(1-p[i])*solve(i+1, heads);
		
		return dp[i][heads]=ans;
	}

}


Measured memory_bytes: 123568
from queue import Queue as Q
INF = float('inf')
def bfs(s):
	dist = [INF]*(n+1)
	q = Q()
	q.put(s)
	dist[s] = 0
	while not q.empty():
		u = q.get()
		for v in adj[u]:
			if dist[v]==INF:
				dist[v] = 1+dist[u]
				pred[v] = u
				q.put(v)
				
n,m = map(int,input().split())
pred = [-1]*(n+1)
adj = [[] for i in range(n+1)]
for _ in range(m):
	u,v = map(int,input().split())
	adj[u]+=[v]
	adj[v]+=[u]
bfs(1)
	
if -1 in pred[2:]:
	print("No")
else:
	print("Yes")
	print(*(pred[2:]),sep = "\n")


Measured memory_bytes: 36100
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
 
int main(){
	string s;
	cin >> s;
	for(int i = 0; i < s.length() - 8; i++){
		cout << s.at(i);
	}
	cout << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int as=0,bs=0,abg=0,reg=0;
  for(int i=0;i<n;i++){
    string a;
    cin >> a;
    int q=a.size();
    for(int w=0;w<q-1;w++){if(a[w] == 'A' && a[w+1] == 'B'){reg++;}}
      if(a[0] == 'B' && a[q-1] == 'A'){abg++;
                                    continue;}
      if(a[q-1] == 'A'){as++;}
    if(a[0] == 'B'){bs++;}
  }
 if(abg == 0){cout << min(as,bs)+reg << endl;}
  else{if(as+bs>0){cout << abg + min(as,bs)+reg << endl;}else{cout << abg-1+reg << endl;}}
}


Measured memory_bytes: 256
N=int(input())
S=input()
R=[0]*N
G=[0]*N
B=[0]*N

for i in range(N):
    if S[i]=="R":
        R[i]=1
    elif S[i]=="G":
        G[i]=1
    else:
        B[i]=1
R_S=[0]*N
G_S=[0]*N
B_S=[0]*N
R_S[0] = R[0]
G_S[0] = G[0]
B_S[0] = B[0]
for i in range(1,N):
    R_S[i]=R_S[i-1]+R[i]
    G_S[i]=G_S[i-1]+G[i]
    B_S[i]=B_S[i-1]+B[i]

ans=0
for j in range(1,N-1):
    char=S[j]
    if char=="G":
        ans += R_S[j-1]*(B_S[N-1]-B_S[j])
        ans += B_S[j-1]*(R_S[N-1]-R_S[j])
        min_len=min(j,N-1-j)
        for i in range(1,min_len+1):
            if (S[j-i]=="R" and S[j+i]=="B") or (S[j-i]=="B" and S[j+i]=="R"):
                ans -= 1
    if char=="R":
        ans += G_S[j-1]*(B_S[N-1]-B_S[j])
        ans += B_S[j-1]*(G_S[N-1]-G_S[j])
        min_len=min(j,N-1-j)
        for i in range(1,min_len+1):
            if (S[j-i]=="G" and S[j+i]=="B") or (S[j-i]=="B" and S[j+i]=="G"):
                ans -= 1
    if char=="B":
        ans += G_S[j-1]*(R_S[N-1]-R_S[j])
        ans += R_S[j-1]*(G_S[N-1]-G_S[j])
        min_len=min(j,N-1-j)
        for i in range(1,min_len+1):
            if (S[j-i]=="G" and S[j+i]=="R") or (S[j-i]=="R" and S[j+i]=="G"):
                ans -= 1
print(ans)

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

int n;
std::vector<int> a;
std::vector<int> c;
long long res = 0;
void input()
{
    std::cin>>n;
    a.resize(n);c.resize(n-1);
    for(int i=0;i<n;i++){std::cin>>a[i];a[i]--;}
    for(int i=0;i<n;i++){int tmp;std::cin>>tmp;res+=tmp;}
    for(int i=0;i<n-1;i++)std::cin>>c[i];
}

int main()
{
    input();
    //1つ後と比較する
    for(int i=0;i<n-1;i++){
        if(a[i]+1==a[i+1])res+=c[a[i]];
    }
    std::cout<<res<<std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  long long n,x,sum=0,a[100005];
  cin>>n>>x;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=2;i<=n;i++){
    if(a[i-1]+a[i]>x){
      int sa=a[i-1]+a[i]-x;
      sum+=sa;
      if(a[i]<sa){
	sa-=a[i];
	a[i]=0;
	a[i-1]-=sa;
      }
      else{
	a[i]-=sa;
      }
    }
  }
  cout<<sum<<'\n';
  return 0;
}


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

int main() {
  int N, T, A, H, a = 0, b = 10000000;
  cin >> N >> T >> A;
  for (int i = 0 ; i < N ; i++) {
    cin >> H;
    int p = T * 1000 - H * 6;
    int d = abs(A * 1000 - p);
    if( d < b){
      b = d;
      a = i;
    }
  }
  cout << a + 1 << endl;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> a;
  load(a, n);

  sort(a);
  int x = 0, y = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      x += a[i];
    } else {
      y += a[i];
    }
  }
  p(abs(y - x));
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter printWriter = new PrintWriter(System.out);
        if (scanner.nextLine().equals("ABC")) {
            printWriter.println("ARC");
        }else {
            printWriter.println("ABC");
        }
        printWriter.flush();
    }
}


Measured memory_bytes: 35792
#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int n,m;
int us[10];
string str;
int dp[100001][11];

int main(void){
	scanf("%d",&n);
	cin >> str;
	scanf("%d",&m);
	for(int i=0;i<m;i++)scanf("%d",&us[i]);
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			if(dp[i][j]>0){
				if(str[i]=='*'){
					for(int k=0;k<m;k++){
						int c=us[k];
						if((n-i)%2==0)c*=2;
						if(c>=10){
							int nc=c/10;
							c%=10;
							nc+=c;
							c=nc;
						}
						dp[i+1][(j+c)%10]+=dp[i][j];
						//printf("%d %d %d\n",i,j,(j+c)%10);
					}
				}else{
					int c=str[i]-'0';
					if((n-i)%2==0)c*=2;
					if(c>=10){
						int nc=c/10;
						c%=10;
						nc+=c;
						c=nc;
					}
					dp[i+1][(j+c)%10]+=dp[i][j];
					//printf("%d %d %d\n",i,j,(j+c)%10);
				}
			}
		}
	}
	printf("%d\n",dp[n][0]);
	return 0;
}

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


int main() {
  int N,M,Z;
  cin>>N>>M;
  for(int i=M/N;i>0;i--){
    if(M%i==0){
      Z=i;
      break;
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3632
n = int(input())
a = input().split()
a = [int(a[i]) for i in range(n)]
b = 0
for i in range(n-2):
	if ((a[i]< a[i+1]) and (a[i+1]<a[i+2])) or ((a[i]>a[i+1]) and (a[i+1]>a[i+2])):
		b+=1
print(b)

Measured memory_bytes: 3060
N, M = gets.split.map(&:to_i)
G = Array.new(3 * N + 1){ [] }
M.times do
  u,v = gets.split.map(&:to_i)
  3.times do |i|
    G[N * i + u] << N * ((i + 1) % 3) + v
  end
end


def bfs(s,t)
  used = Array.new(G.size, -1)
  q = [s]
  used[s] = 0
  
  until q.empty?
    u = q.shift
    break if u == t

    d = used[u]
    G[u].each do |v|
      if used[v] < 0
        used[v] = d + 1
        q << v
      end
    end
  end
  used[t]
end

S,T = gets.split.map(&:to_i)
ans = bfs(S,T)

puts  ans < 0 ? -1 : ans/3 


Measured memory_bytes: 29180
h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(m)]
hlist = [0]*(h+1)
wlist = [0]*(w+1)
for x,y in hw:
    hlist[x]+=1
    wlist[y]+=1
hmax=max(hlist)
h_index = {n for n, v in enumerate(hlist) if v == hmax}
wmax=max(wlist)
w_index = {n for n, v in enumerate(wlist) if v == wmax}
count = sum(x in h_index and y in w_index for x,y in hw)
print(hmax+wmax-(len(h_index)*len(w_index)==count))


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

struct union_find{
    vector<int> par;
    vector<int> rank;
    union_find(int n) : par(n), rank(n){
        for(int i = 0; i < n; i++){
            par[i] = i; rank[i] = 0;
        }
    }
    int root(int x){
        if(par[x] == x) return x;
        par[x] = root(par[x]);
        return par[x];
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
        }
        else{
            par[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n, m; cin >> n >> m;
    union_find uf(MAX * 2);
    rep(i, n){
        int k; cin >> k;
        rep(j, k){
            int l; cin >> l; l--;
            uf.unite(i, l + n);
        }
    }

    int p = uf.root(0);
    rep(i, n - 1){
        int q = uf.root(i + 1);
        if(p != q){
            out("NO"); return 0;
        }
    }
    out("YES");
}

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

using namespace std;

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

    int A[n], B[n];
    for(int i=0; i<n; i++) cin >> A[i] >> B[i];

    sort(A, A+n);
    sort(B, B+n);

    int left, right;
    if(n%2 == 0) {
        left = A[n/2-1] + A[n/2];
        right = B[n/2-1] + B[n/2];
    } else {
        left = A[n/2];
        right = B[n/2];
    }

    cout << right - left +1 << endl;

    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M; 
  vector<int> X(N+1), Y(M+1);
  cin >> X.at(0) >> Y.at(0);
  rep(i, N+1) cin >> X.at(i);
  rep(i, M+1) cin >> Y.at(i);
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  if(X.at(X.size()-1)<Y.at(0)) cout << "No War" << endl;
  else cout << "War" << endl;
}

Measured memory_bytes: 256
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main(){
    int N;cin >> N;
    vector<int> v;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        v.push_back(b);
    }
    vector<int> v1 = v;
    sort(v.begin(), v.end());
    vector<bool> f(N);
    int cnt = 0;
    for(int i = 0;i < N;i++){
        f[i] = v1[i] == v[i];
        if(v1[i] == v[i])cnt++;
    }
    if(N == cnt){
        cout<<0<<endl;
        return 0;
    }
    int Q;cin >> Q;
    for(int i = 0;i < Q;i++){
        int a,b;cin >> a >> b;
        a--,b--;
        swap(v1[a], v1[b]);
        if(v1[a] == v1[b])continue;
        if(v1[a] == v[a]){
            cnt++;
            f[a] = 1;
        }
        if(v1[a] != v[a] && f[a]){
            cnt--;
            f[a] = 0;
        }
        if(v1[b] == v[b]){
            cnt++;
            f[b] = 1;
        }
        if(v1[b] != v[b] && f[b]){
            cnt--;
            f[b] = 0;
        }
        if(cnt == N){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}



Measured memory_bytes: 5388
#include <bits/stdc++.h>
using namespace std;
int dp[100010];

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

	int n;
	cin>>n;
	if(n<6){
		cout<<n<<endl;return 0;
	}
	for(int i=1;i<=n;i++)dp[i]=1000000;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		int cnt=6;
		while(cnt<=i){
			dp[i]=min(dp[i],dp[i-cnt]+1);
			cnt*=6;
		}
		cnt=9;
		while(cnt<=i){
			dp[i]=min(dp[i],dp[i-cnt]+1);
			cnt*=9;
		}
	}
	int ans=10000;
	for(int i=1;i<=n;i++)ans=min(ans,dp[i]+(n-i));
	
	 cout<<ans<<endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			long s = Long.parseLong(scanner.next(), 16);
			int x = (int) (s & (1 << 31) - 1) >> 7;
			double y = (double) ((s & (1 << 8) - 1) * 0.0078125);
			String a = String.valueOf(y).substring(2);
			if (s >> 31 > 0)
				System.out.print("-");
			System.out.printf("%d.%s\n", x, a);
		}
	}
}

Measured memory_bytes: 49332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int n, x, ans=1; cin >> n >> x;
    int tmp = 0;
    for(int i=0;i<n;i++){
        int l; cin >> l;
        tmp = tmp+l;
        if(tmp<=x){
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <tuple>
#include <algorithm>
using namespace std;

int main(void){
    int n;
    double sum = 0;
    vector<pair<double, int>> a;
    cin >> n;
    for(int i = 0;i<n;i++){
        int buff;
        cin >> buff;
        a.push_back(make_pair(buff, i));
        sum += buff;
    }
    sum = sum / n;
    for(int i = 0;i<n;i++){
        double q;
        int w;
        tie(q, w) = a.at(i);
        // cout << abs(q - sum) << endl;
        a.at(i) = make_pair(abs(q - sum), w);
    }
    sort(a.begin(),a.end());
    cout << a.front().second << endl;
}

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

using namespace std;

const double PI = 3.1415926535;

int main() {
	
	int A, B;
	cin >> A >> B;

	int H, M;
	cin >> H >> M;

	const auto totalM = H * 60 + M;

	const double aAngle = PI * 2 * (double)totalM / (12 * 60);
	const double bAngle = PI * 2 * (double)M / 60;

	const auto dAngle = abs(aAngle - bAngle);

	const auto result = sqrt(A * A + B * B - 2 * A * B * cos(dAngle));

	cout << fixed << setprecision(10) << result << endl;

	return 0;
}


Measured memory_bytes: 4016
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>

#define int long long
//#define double long double

using namespace std;

long long n, m;
double ans = 1e18;
long long x[500000], y[500000];
char c[500000];

double get(double t)
{
    double minx, maxx, miny, maxy;
    for (int i = 0; i < n; i++)
    {
        double a = x[i], b = y[i];
        if (c[i] == 'D')
            b -= t;
        if (c[i] == 'U')
            b += t;
        if (c[i] == 'R')
            a += t;
        if (c[i] == 'L')
            a -= t;
        if (i == 0)
        {
            minx = a, miny = b;
            maxx = a, maxy = b;
        }
        else
        {
            minx = min(minx, a);
            miny = min(miny, b);
            maxy = max(maxy, b);
            maxx = max(maxx, a);
        }
    }
    return (maxx - minx) * (maxy - miny);
}

signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> x[i] >> y[i] >> c[i];
    double l = 0, r = 6e8;
    for (int i = 0; i < 1000; i++)
    {
        //printf("%.9f %.9f\n", l, r);
        double m1 = l + (r - l) * 1 / 3;
        double m2 = l + (r - l) * 2 / 3;
        double s1 = get(m1);
        double s2 = get(m2);
        if (s1 > s2)
            l = m1;
        else
            r = m2;
    }
    l = round(2 * l) / 2;
    //printf("%.9f\n", l);
    printf("%.9f", get(l));
}


Measured memory_bytes: 3200
def main():
    N, C = map(int, input().split())
    sushis = [(0, 0) for _ in range(N)]
    for i in range(N):
        x, v = map(int, input().split())
        sushis[i] = (x, v)
    ls, rs = 0, 0
    left = [(0, 0) for _ in range(N+1)]
    right = [(0, 0) for _ in range(N+1)]
    for i in range(N):
        ls += sushis[i][1]
        lx = sushis[i][0]
        rs += sushis[-i-1][1]
        rx = C - sushis[-i-1][0]
        left[i+1] = (max(ls-lx, left[i][0]),
                     max(ls-lx*2, left[i][1]))
        right[i+1] = (max(rs-rx, right[i][0]),
                      max(rs-rx*2, right[i][1]))
    ans = 0
    for i in range(N+1):
        ans = max([left[i][0] + right[N-i][1],
                   left[i][1] + right[N-i][0],
                   ans])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 58912
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

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;
}

int main() {
    int N;
  	cin >> N;
    int x[N], y[N], h[N];
  	int x0, y0, h0;
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
      	if(h[i]>=1){
          x0 = x[i];
          y0 = y[i];
          h0 = h[i];
        }
    }
    int ansX=0, ansY=0, ansH=0;
    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j <= 100; j++)
        {
            int H = h0+abs(x0-i)+abs(y0-j);
            bool flag = true;
            for (int k = 0; k < N; k++)
            {
                int ash = max(H-abs(x[k]-i)-abs(y[k]-j), 0);
                if(h[k]!=ash) flag = false;
            }
            if(flag){
                    ansX = i;
                    ansY = j;
                    ansH = H;
             }
        }
        
    }
    
    cout << ansX << " " << ansY << " "  << ansH << endl;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll n,m;
    cin>>n>>m;
    ll a[105][105]={};
    ll b[105]={};
    REP(i,n)REP(j,m){
        cin>>a[i][j];
    }
    REP(i,m)cin>>b[i];
    REP(i,n){
        ll sum=0;
        REP(j,m){
            sum+=a[i][j]*b[j];
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#define MAX_INT  100005
using namespace std;

//??\???????????§???
#define MAX_X  22
#define MAX_Y  22

//?????°
char field[MAX_X][MAX_Y];
int X, Y;
int px, py;                     // players position


//?§????4?????????????????????
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1,  0, -1};


void initialize_field() {
  for (int y = 0; y < Y; y++ ) {
    for (int x = 0; x < X; x++ ) {
      field[x][y] = '#';
    }
  }
}

void print_field() {
  for (int y = 0; y < Y; y++ ) {
    for (int x = 0; x < X; x++ ) {
      cout << field[x][y];
    }
    cout << endl;
  }
  cout << endl;
}


void dfs(int x, int y) {

  field[x][y] = '$';            // ?¨????????????¨?????°

  for (int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];

    if(field[nx][ny] == '.') {
      dfs(nx, ny);
    }
  }

}


int main() {

  while(true) {

    initialize_field();

    cin >> X >> Y;

    if(X == 0 && Y == 0) break;

    for(int y = 0; y < Y; y++ ){
      for(int x = 0; x < X; x++ ){
        cin >> field[x][y];
        if( field[x][y] == '@' ) { px = x; py = y; }
      }
    }

    dfs(px, py);

    // ?¨?????????´????????°??????
    int res = 0;
    for(int y = 0; y < Y; y++ ){
      for(int x = 0; x < X; x++ ){
        if ( field[x][y] == '$' ) { res++; }
      }
    }
    cout << res << endl;
  }

  return 0;

}

Measured memory_bytes: 3096
/* Author haleyk10198 */
/* 作者:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
#define vi vector<int>
#define vvi vector<vi>
#define EPS 1e-9

using namespace std;

#include <cstdio>
#include <queue>

typedef ll flow_t;
const int MAXN = 110, MAXM = 600, DIRECTED = 0, UNDIRECTED = 1;
const flow_t INFTY = 0x3fffffff;
int N, S, T, now;

struct edge {
	flow_t remain;
	int endVertexId, nextEdgeId;
}e[MAXM << 1];

struct vertex {
	int firstEdgeId, level, firstUnsaturEdgeId;
}v[MAXN];

void _addEdge(int begin, int end, flow_t c) {
	e[now].remain = c;
	e[now].endVertexId = end;
	e[now].nextEdgeId = v[begin].firstEdgeId;
	v[begin].firstEdgeId = now++;
}

void addEdge(int begin, int end, flow_t c, int edgeType) {
	_addEdge(begin, end, c);
	_addEdge(end, begin, edgeType * c);
}

void init() {
	now = 0;
	for (int i = 0; i < N; ++i) v[i].firstEdgeId = -1;
}

bool markLevel(){
	for (int i = 0; i < N; ++i)
		v[i].level = -1, v[i].firstUnsaturEdgeId = v[i].firstEdgeId;
	v[S].level = 0;
	queue<int> Q;
	Q.push(S);
	while (!Q.empty()) {
		int x = Q.front();
		Q.pop();
		for (int i = v[x].firstEdgeId; i >= 0; i = e[i].nextEdgeId)
			if (e[i].remain && v[e[i].endVertexId].level < 0)
					v[e[i].endVertexId].level = v[x].level + 1, Q.push(e[i].endVertexId);
	}
	return v[T].level > 0;
}

flow_t extendFlow(int x, flow_t flow) {
	if (x == T) return flow;
	flow_t t, total = 0;
	for (int &i = v[x].firstUnsaturEdgeId; i >= 0; i = e[i].nextEdgeId) { // Reference!
		if (v[e[i].endVertexId].level == v[x].level + 1 && e[i].remain) {
			if (t = extendFlow(e[i].endVertexId, min(flow, e[i].remain)))
				e[i].remain -= t, e[i ^ 1].remain += t, flow -= t, total += t;
			if (0 == flow) break;
		}
	}
	return total;
}

flow_t Dinic() {
	flow_t flow, total = 0;
	while (markLevel())
		while (flow = extendFlow(S, INFTY))
			total += flow;
	return total;
}

int n, s, t, a[110];

void buildGraph() {
	// Assign N (number of vertices), S (source) and T (sink) here.
	// Vertices are numbered from 0 to N - 1. Hence S and T should be in [0, N).
	N = n+2;
	S = 0;
	T = N-1;
	init();
	for(int i = 1; i <= n; i++){
		if(a[i] <= 0)
			addEdge(S, i, -a[i], DIRECTED);
		else
			addEdge(i, T, a[i], DIRECTED);
		for(int j = i+i; j <= n; j+=i)
			addEdge(i, j, INFTY, DIRECTED);
	}
	
	return;
	// Add edges here
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	
	scanf("%d", &n);
	ll res = 0;
	for(int i = 1; i <= n; i++)
		scanf("%d", a+i), res += max(0, a[i]);
	buildGraph();
	cout << res-Dinic() << endl;
	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<int> v(n); cin >> v;
  int mini = v.front();
  ll sum = 0;
  for(auto e:v){
    sum += max(mini - e, 0);
    mini = max(mini,e);
  }
  cout << sum << endl;
}


Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
using namespace std;


int main(){
int n;cin>>n;
vector<vector<pp>>a(16,vector<pp>(16));
pp x;
vi A(n);
int aw=0;
rep(i,n){
    
    cin>>A.at(i);
    rep(j,A.at(i)){
        int f,s;
        cin>>f>>s;
        a.at(i).at(j)=make_pair(f,s);

    }
}
    bitset<16> bs;

for(int bits=1;bits<(1<<n);bits++){
    int flag=0;
    int ans=0;
    rep(i,n){
        if((1<<i)&bits){
        rep(j,A.at(i)){
            
            if(a.at(i).at(j).se==1){
            if(bits&(1<<(a.at(i).at(j).fi-1))){
                        //ans++;
            }else{flag=1; break;
            }
            }else{
                if(bits&(1<<(a.at(i).at(j).fi-1))){
                    flag=1;break;
                }
            }
            //ans++;
            
            //ans++;
        }
        }
if(flag)break;
if(i==n-1){
bs=bits;

if(aw<bs.count())aw=bs.count();
    }

}
    }
    //ans++;
    //bitset<16> bs=bits;
   /* if(bs.count()==ans){
        if(aw<ans)aw=ans;
    }*/

cout<<aw<<endl;

}

Measured memory_bytes: 256
H = int(input().rstrip())
ret = 0
if H == 1:
    ret = 1
elif H in [2, 3]:
    ret = 3
else:
    count = 0
    while H != 1:
        H = H // 2
        count += 1
    ret = 3
    for i in range(count-1):
        ret = 2*ret + 1
print(ret)


Measured memory_bytes: 2940
a,b,c,d=input()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
s=10*a+b
t=10*c+d

if (s>0 and s<=12) and (t>0 and t<=12):
        print("AMBIGUOUS")
elif s>0 and s<=12:
        print("MMYY")
elif t>0 and t<=12:
        print("YYMM")
else:
        print("NA")

Measured memory_bytes: 3064
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	long long n;
	cin >> n;
	long long ans = 0;
	for (long long i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
import collections
n = int(input())
l = [input() for s in range(n)]

c = collections.Counter(l)
result = c.most_common()

m = 0
ans = []
for i in result:
    if i[1]<m:
        break
    else:
        ans.append(i[0])
        m = i[1]

ans = sorted(ans)
for i in ans:
    print(i)

Measured memory_bytes: 49232
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

#define all(n) n.begin(),b.end()
#define F first
#define S second
#define INF (1<<10)

using namespace std;

typedef pair<int, int> P;

P operator-(const P& a, const P& b){
    return P(a.first-b.first, a.second-b.second);
}
int norm(const P& a){
    return a.first*a.first+a.second*a.second;
}

typedef vector<P> VP;
int n;

bool cmp(const P& a, const P& b){
    if(a.S != b.S)
        return a.S < b.S;
    return false;
}

pair<P,P> closest_pair(vector<P>::iterator begin, vector<P>::iterator end){
    int len = end - begin;
    if(len <= 1) return make_pair(P(), P(INF,INF));
    auto mid = begin + len / 2;
    int x = mid->F;
    pair<P,P> res = min(closest_pair(begin, mid), closest_pair(mid, end));
    int range = norm(res.first - res.second);
    inplace_merge(begin, mid, end, cmp);
    VP b;
    for(int i = 0; i < len; i++){
        if(abs(begin[i].F - x) >= range) continue;
        for(int j = b.size() - 1; j >= 0; j--) {
            int dx = begin[i].F - b[j].F;
            int dy = begin[i].S - b[j].S;
            if(dy >= range)
                break;
            if(dx*dx + dy*dy < range){
                range = dx*dx + dy*dy;
                res = make_pair(begin[i], b[j]);
            }
            range = min(range, dx*dx + dy*dy);
        }
        b.push_back(begin[i]);
    }
    return res;
}

int main(){
    cin >> n;
    vector<P> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i].F >> a[i].S;
    sort(a.begin(), a.end());
    auto ans = closest_pair(a.begin(), a.end());
    cout << norm(ans.first - ans.second) << endl;
    return 0;
}

Measured memory_bytes: 10704
/**
 *     author: nayakashutosh9
 *     college: National Institute of Technology, Rourkela
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 200005;

/*******************************************************************/




int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	// int t, z = 1; cin >> t;
	// cin.ignore();
	// while (t--) {

	// }
	int n; cin >> n;
	vector<int> a(n);
	int x = 0;
	for (int i = 0; i < n; i++) cin >> a[i], x ^= a[i];
	for (int i = 0; i < n; i++) cout << (x ^ a[i]) << " ";
	return 0;
}


Measured memory_bytes: 4704
n = int(input())
a =list(map(int,input().split()))
b = sorted(a)
c = 0
for i in range(n-1):
    t = cnt = 0
    x = a.index(b[i])
    while x != i:
        y = a.index(b[x])
        a[x],a[y] = b[x],b[i]
        cnt += 1
        t += b[x]+b[i]
        x =y
    if cnt:
        c+= min(t,(b[i]+b[0])*2+t-(b[i]-b[0])*cnt)

print(c)


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

int M[105][105];
int n;
int d[105];
int INFTY =(1<<21);

void bfs(int s){
  queue<int> q;
  q.push(s);
  rep(i,n) d[i]=INFTY;
    d[s]=0;
    int u;
    while(!q.empty()){
      u=q.front();
      q.pop();
      rep(v,n){
        if(M[u][v]==0||d[v]!=INFTY) continue;
        d[v]=d[u]+1;
        q.push(v);
      }
    }
    rep(i,n){
      cout<<i+1<<" "<<((d[i]==INFTY)?(-1):d[i])<<endl;
    }

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
      rep(j,n) M[i][j]=0;
    }
    rep(i,n){
      int u,k;
      cin>>u>>k;
      u--;
      rep(j,k){
        int v;
        cin>>v;
        v--;
        M[u][v]=1;
      }
    }
    bfs(0);
    return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int t = i ^ j;
			printf("%d ", __builtin_ctz(t) + 1);
		}
		printf("\n");
	}
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

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

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	ll N;
	cin >> N;
	vector<ll> T(N);
	for(int i=0; i<N; i++) cin >> T[i];

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

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
string tt;
map<string, int> idx;
int dp[555], n;
bool b[555];
string name[555];
struct node {
	int da, f;
	int ind;
}s[555];
bool cmp(node a, node b) {
	if(a.da != b.da) return a.da < b.da;
	return a.f < b.f;
}
int gao() {
	int len = tt.length();
	if(len != 3 && len != 4) while(1);
	if(len == 3) {
		tt = "0" + tt;
	}
	int h = tt[0] * 10 + tt[1];
	h -= 6;
	int mi = tt[2] * 10 + tt[3];
	return h * 60 + mi;
}
int DP() {
	fill(dp, dp + 520, -1);
	s[0].da = -100;
	dp[0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = i - 1; j >= 0; j--) {
			if(s[j].da < s[i].da || s[i].f - s[j].f >= 30) {
				if(dp[j] == -1) continue;
				dp[i] = max(dp[j] + 1, dp[i]);
			}
			if(b[s[j].ind]) break;
		}
		if(b[s[i].ind] && dp[i] == -1) return -1;
	}
	int ans = 0;
	for(int i = n; i >= 1; i--) {
		ans = max(ans, dp[i]);
		if(b[s[i].ind]) break;
	}
	return ans;
}
int main() {
	while(cin >> n) {
		if(n == 0) break;
		idx.clear();
		memset(b, 0, sizeof(b));
		for(int i = 1; i <= n; i++) {
			cin >> name[i] >> s[i].da >> tt;
			idx[name[i]] = i;
			s[i].f = gao();
			s[i].ind = i;
		}
		sort(s + 1, s + 1 + n, cmp);
		memset(b, false, sizeof(b));
		int q; cin >> q;
		while(q--) {
			cin >> tt;
			b[idx[tt]] = true;
		}
		printf("%d\n", DP());
	}
	return 0;
}

Measured memory_bytes: 1328