akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ACC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};
bool isvowel(char c)
{
    switch(c)
    {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':return true;
        default : return false;
    }
}
bool isValid(ll x,ll y,ll n,ll m)
{
    if(x<0||x>n-1||y<0||y>m-1)return false;
    return true;
}
bool comp(pair<ll,ll> x,pair<ll,ll> y)
{
    if(x.first==y.first)
        return x.second<y.second;
    return x.first<y.first;
}
int main()
{
    ACC
    int T;
    T=1;
    //cin>>T;
    while(T--)
    {
      ll n,i;
      cin>>n;
      ll a[n],s=0;
      for(i=0;i<n;i++)
      {
          cin>>a[i];
      }
      for(i=1;i<n;i++)
      {
          if(a[i]<a[i-1])
          {
              s+=a[i-1]-a[i];
              a[i]=a[i-1];
          }
      }
      cout<<s<<"\n";
    }
    return 0;
}


Measured memory_bytes: 5172
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
static const int NMAX = 100000;
static const int WMAX = 1000;
int N;

struct Edge {
  int target, weight;
};

vector<Edge> G[NMAX];

bool visited[NMAX];
int weights[NMAX];

void clear() {
  for (int i = 0; i < N; i++) {
    visited[i] = false;
    weights[i] = 0;
  }
}

void visit(int n, int w) {
  visited[n] = true;
  weights[n] = w;
}

int bfs(int n, int *maxn_store) {
  clear();
  queue<int> q;
  q.push(n);
  visit(n, 0);
  int maxw = 0;
  int max_node = 0;

  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : G[u]) {
      if (!visited[v.target]) {
        int w = weights[u] + v.weight;
        if (w > maxw) {
          maxw = w;
          max_node = v.target;
        }
        visit(v.target, w);
        q.push(v.target);
      }
    }
  }
  *maxn_store = max_node;
  return maxw;
}

int main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    G[s].push_back(Edge{t, w});
    G[t].push_back(Edge{s, w});
  }
  int maxn;
  bfs(0, &maxn);
  cout << bfs(maxn, &maxn) << endl;
}

Measured memory_bytes: 9900
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    A,B,C,D,E,F=MI()
    #dp[i][j]はi*100gのみずにjgの砂糖
    N=F//100+1
    dp=[[0]*(F+1) for _ in range(N)]
    
    dp[0][0]=1
    ansd=0
    ans=[100*A,0]
    
    AB=[A,B]
    CD=[C,D]
    
    for i in range(N):
        if dp[i][0]==1:
            for k in range(2):
                ii=i+AB[k]
                if ii<N:
                    dp[ii][0]=1
        for j in range(F+1):
            if dp[i][j]==1:
                for k in range(2):
                    jj=j+CD[k]
                    if jj<=F and i*100+jj<=F and jj<=E*i:
                        dp[i][jj]=1
                        d=jj/(100*i+jj)
                        if d>ansd:
                            ans=[100*i+jj,jj]
                            ansd=d
    print(' '.join(map(str, ans)))
    

    

main()


Measured memory_bytes: 40688
#include <iostream>

using namespace std;

int main(void){
int asum = 0,bsum = 0;
for(int i  = 0;i < 4;i++){
int x;
cin >> x;
asum += x;
}
for(int i = 0;i < 4;i++){
int x;
cin >> x;
bsum += x;
}
cout << max(asum,bsum) << endl;
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <deque>
using namespace std;
signed main() {
	deque<int>d;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b, c; cin >> a;
		if (a == 0) {
			cin >> b >> c;
			if (b == 0)d.push_front(c);
			else d.push_back(c);
		}
		else if (a == 1) {
			cin >> b;
			cout << d[b] << endl;
		}
		else {
			cin >> b;
			if (b == 0)d.pop_front();
			else d.pop_back();
		}
	}
	return 0;
}


Measured memory_bytes: 4648
#include <bits/stdc++.h>
using namespace std;
 int arr[100];
int main() {
    int a,b;
    cin>>a>>b;
    for (int i=1;i<=1000;i++){
        if (floor(i*0.08)==a and floor(i*0.1)==b ){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 256
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var a = "abcdefghijklmnopqrstuvwxyz";
        var s = Console.ReadLine().Trim();
        var t = '?';
        for (int i = 0; i < a.Length; i++)
            if (!s.Contains(a[i])) { t = a[i]; break; }
        Console.WriteLine(t == '?' ? "None" : t.ToString());
    }
}



Measured memory_bytes: 13536
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>


#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define Yes_RTN s_cout("Yes");return 0
#define No_RTN  s_cout("No");return 0
#define YES_RTN s_cout("YES");return 0
#define NO_RTN  s_cout("NO");return 0


int i_cins(int n, int* A);
int l_cins2(int n, long* A,long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);

int s_asorts(const void* a, const void* b);


int main(void) {
	int N,D,X,i,j;
	int A[101],cnt=0;

	i_cin(N); i_cin(D); i_cin(X);
	i_cins(N, A);

	for (i = 0; i < N; i++) {
		for (j=0; A[i] * j + 1 <= D;j++) {
		}
		cnt += j;
	}
	i_cout(X + cnt);

	return 0;
}
	
//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}	
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a -*(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600123456789

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

  vector<long> x(m),y(m),t(m);
  rep(i,m) cin>>x[i]>>y[i]>>t[i];
  rep(i,m) x[i]--, y[i]--;

  long v0,a,b,c;
  cin>>v0>>a>>b>>c;

  vector<vector<pair<long, int>>> vec(2*n*c, vector<pair<long,int>>());
  rep(i,m) rep(j,c){
    long cost = j*t[i];
    long nj = (j*a+b)%c;
    vec[x[i]*c+j].pb(mp(cost, y[i]*c+nj));
    vec[y[i]*c+j].pb(mp(cost, x[i]*c+nj));

    x[i] += n;
    if(y[i]!=n-1) y[i]+=n;
    vec[x[i]*c+j].pb(mp(cost, y[i]*c+nj));
    vec[y[i]*c+j].pb(mp(cost, x[i]*c+nj));
    x[i] -= n;
    if(y[i]!=n-1) y[i]-=n;
  }

  vector<long> d(2*n*c, INF);
  d[v0] = 0;
  priority_queue<pair<long, int>, vector<pair<long,int>>, greater<pair<long,int>>> pq;
  pq.push(mp(0,v0));
  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    long dd = p.fi, idx = p.se;
    if(dd > d[idx]) continue;
    for(auto pp : vec[idx]){
      long nd = dd + pp.first;
      int ni = pp.second;
      if(nd < d[ni]){
        pq.push(mp(nd, ni));
        d[ni] = nd;
      }
    }
  }

  long ans = INF;
  rep(i,c) ans = min(ans, d[n*c+i]);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 28428
/// Code by Leonardo16
///   “It is not the strength of the body, but the strength of the spirit.”   —  J.R.R. Tolkien
#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

#define int long long
#define ll long long
#define sz size
#define ull unsigned long long
#define ld long double
#define ii pair<int,int>
#define fst first
#define scd second
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
#define pf push_front
#define fl '\n'
#define el endl
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
/// Functions
#define db(x) cerr << #x << ": " << (x) << '\n';
#define random() __builtin_ia32_rdtsc()
#define lg2(x) 31-__builtin_clz(x)
#define lg2ll(x) 63-__builtin_clzll(x)
#define pi acos(-1)
#define YN(x) cout<<((x)?("YES"):("NO"))<<fl;
#define yn(x) cout<<((x)?("Yes"):("No"))<<fl;
#define des(x,s1,s2,end1,end2) cout<<((x)?(s1):(s2))<<fl;if(x){end1;}else{end2;}
#define precision(x) cout.setf(ios::fixed);cout.precision(x);
/// Red-Black Tree Template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
//#define less_than(n) order_of_key(n)
//#define en_pos(n) find_by_order(n)
/// Prime numbers  173,179,311,331,737,1009,2011,2027,3079,4001,100003
///=====================================================================
int n;
int mk[10000007];

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

    for(int i=1;i<=10000001;i++){
        for(int j=i;j<=10000002;j+=i){
            mk[j]++;
//            if(j/i>10000){
//                mk[j]++;
//            }
        }
    }

    cin>>n;

    int ans=1LL;
    for(ll i=2LL;i<=n;i++){
        ll d=(mk[i]);
        ans+=(i*d);
    }
    cout<<ans;
return 0;}







Measured memory_bytes: 81816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var iroha = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            iroha = iroha.OrderBy(i => i).ToArray();
            Console.WriteLine(iroha[0] == 5 && iroha[1] == 5 && iroha[2] == 7 ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 11220
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

k = int(input())
a = list( map(int, input().split()))

if a[-1]!=2:
    print(-1)
    exit()

ma = 2

for i in reversed(range(k)):
    ma = ma//a[i]*a[i] + (a[i]-1)

    if a[i] > ma:
        print(-1)
        exit()

mi = 2

for i in reversed(range(k)):

    mi = -(-mi//a[i])*a[i]

if mi > ma:
    print(-1)
    exit()

print(mi,ma)



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

const int N = 10001;

int main()
{
    // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    char c;
    cin >> c;
    if(c >= 97 && c <= 122) cout << "a" << '\n';
    else cout << 'A' << '\n';
    
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n1,n2,n3,n4,n5,A,B,d;
  int c=0;
  cin >> A >> B;
  d=B-A+1;
  for(int i=1; i<=d; i++){
    n5=A/10000;
    n4=A/1000-n5*10;
    n3=A/100-n5*100-n4*10;
    n2=A/10-n5*1000-n4*100-n3*10;
    n1=A-n5*10000-n4*1000-n3*100-n2*10;
    A++;
    if(n1==n5){
      if(n2==n4){
        c++;
      }
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int x;
		for (int i = 1; i <= n; i++) {
			x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			do {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
				x /= 10;
			} while(x != 0);
		}
		System.out.println();
	}
}



Measured memory_bytes: 28596
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element



//---------- 1000000007 ----------
const int MOD = 1000000007;
int m_add(int a, int b)
{
	return (a + b) % MOD;
}
int m_sub(int a, int b)
{
	return (a + MOD - b) % MOD;
}
int m_mul(int a, int b)
{
	return (a * b) % MOD;
}
int m_pow(int x, int n)
{
	if (n == 0) return 1;
	ll res = m_pow((x * x) % MOD, n / 2);
	if (n & 1) res = (res * x) % MOD;
	return res;
}
int m_divide(int a, int b)
{
	return m_mul(a, m_pow(b, MOD - 2));
}
int m_comb(int n, int r)
{
	int i;
	int p = 1;
	for (i = 1; i <= r; i++)
	{
		p = m_mul(p, (n - i + 1));
		p = m_divide(p, i);
	}
	return p;
}
int m_comb_with_rep(int n, int r)
{
	return m_comb(n + r - 1, r);
}



int N, M;
int dp[100010];
bool flg[100010];

signed main()
{
	cin >> N >> M;
	REP(i, M)
	{
		int a;
		cin >> a;
		flg[a] = true;
	}

	if (!flg[1]) dp[1] = 1;
	if (!flg[2]) dp[2] = 1;

	for (int i = 2; i <= N; i++)
	{
		if (!flg[i])
		{
			dp[i] = m_add(dp[i - 1], dp[i]);
			dp[i] = m_add(dp[i - 2], dp[i]);
		}
	}

	cout << dp[N] << endl;
}



Measured memory_bytes: 4452
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,flag=0,count=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    while(flag!=1){
        for(i=0;i<n;i++){
            if(a[i]%2!=0){
                flag++;
                break;
            }
            a[i]=a[i]/2;
        }
        count++;
    }
    cout<<count-1;

}

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

using namespace std;

typedef long long ll;

#define FOR(_i, _a, _b) for (int _i=_a; _i<_b; ++_i)

const int INF = 1e9+7;

int main()
{
    int N;
    ll W;
    cin >> N >> W;
    vector <ll> price(N+1, 0);
    vector <ll> weight(N+1, 0);
    vector <vector <ll>> dp(N+1, vector <ll> (W+1, 0));

    FOR(i, 1, N+1)
        cin >> weight[i] >> price[i];

    FOR(i, 1, N+1)
    {
        FOR(w, 1, W+1)
        {
            dp[i][w] = dp[i-1][w];
            if (weight[i] <= w)
                dp[i][w] = max(dp[i][w], dp[i-1][w-weight[i]] + price[i]);
        }
    }

    cout << dp[N][W];

    return 0;
}

Measured memory_bytes: 80256
#include <cstdio>
int main(){
	int n;
	scanf("%d", &n);
	int a[n], min = 2147483647, c = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if (a[i] < min){
			min = a[i];
			c++;
		}
	}
	printf("%d\n", c);
}

Measured memory_bytes: 896
#include <stdio.h>
#define N 101
#define null (-1)
#define INF (1 << 21)
#define WHITE 0
#define BLACK 1;
#define GRAY 2

void BFS(int);
void Enqueue(int);
int Dequeue();
int G[N][N];
int vertex[N];
int color[N];
int d[N];
int queue[N];
int n;
int head, tail;
int e[N];

int main(void){

  int i, j;
  scanf("%d",&n);
  
  for(i = 1;i <= n;i++){
    scanf("%d", &vertex[i]);
    scanf("%d", &e[vertex[i]]);
    
    for(j = 1;j <= e[vertex[i]];j++)
      scanf("%d", &G[i][j]);
  }

  BFS(vertex[1]);  
  
    for(i = 1;i <= n;i++)
  printf("%d %d\n",vertex[i], d[vertex[i]]);
  
  return 0;
  
}

void BFS(int s){
  
  int i, u, v;
  int next;
  int empty;
 
  for(u = 1; u <= n;u++){
    color[u] = WHITE;
    d[u] = INF;
  }

  color[s] = GRAY;
  d[s] = 0;
  empty = 0;

  //最初はsをキューに入れる。
  Enqueue(s);
  empty++;

  //空じゃなかったら
  while(empty != 0 ){    
    u = Dequeue();
    empty--;

    //取り出したキューがエッジを持つなら、訪問する。
    for(v = 1;v <= e[u];v++){
      next = G[u][v];
      if(next && (color[next] == WHITE)){
	color[next] = GRAY;
	d[next] = d[u] + 1;
	Enqueue(next);
	empty++;
      }
    }
    
    //訪問した場所は黒くする。
    color[u] = BLACK;
  }

  //一度も訪問されなければWHITEのままなので、 -1 を入れる。
  for(i = 1;i <= n;i++){
    if(color[i] == WHITE)
      d[i] = null;
  }
}

void Enqueue(int v){

  if(tail == N)
    tail = 0;
  queue[tail++] = v;
}

int Dequeue(){

  if(head == N)
    head = 0;
  return queue[head++];
}

Measured memory_bytes: 636
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int n;
int p[MAX_N];

int main(void)
{
  cin >> n;
  REP(i, n) scanf("%d", &p[i]);
  int cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1]) cnt++;
    if (p[i + 1] < p[i] && p[i] < p[i - 1]) cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}


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

#define MAXC 10000
#define MAXR 10
int arr[MAXR][MAXC], arr2[MAXR][MAXC], tempA[MAXR][MAXC];
int R, C;
int maxv;

void copyArr(int chk[]) {
    for (int i = 0; i < R; i++) {
        if (chk[i] == 0) {
            for (int j = 0; j < C; j++) {
                tempA[i][j] = arr[i][j];
            }
        } else{
            for (int j = 0; j < C; j++) {
                tempA[i][j] = arr2[i][j];
            }
        }
    }
}

int getRes(int chk[]) {
    copyArr(chk);
    int sum = 0, res = 0;
    for (int i = 0; i < C; i++) {
        sum = 0;
        for (int j = 0; j < R; j++) {
            if (tempA[j][i] == 1) sum++;
        }
        if (sum > R/2) res += sum;
        else res += R - sum;
    }
    return  res;
}

int solve(int chk[], int idx) {
    if (idx == R) return getRes(chk);
    int tempchk1[R], tempchk2[R];
    for (int i = 0; i < R; i++) {
        tempchk1[i] = tempchk2[i] = chk[i];
    }
    tempchk2[idx] = 1;
    return std::max(solve(tempchk1, idx+1), solve(tempchk2, idx+1));
}

int main()
{
    int tmp;
    while(1) {
        std::cin >> R >> C;
        if (R == 0 && C == 0) break;
        int chk[R];
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                std::cin >> tmp;
                arr[i][j] = tmp;
                arr2[i][j] = tmp ^ 1;
            }
            chk[i] = 0;
        }
        std::cout << solve(chk, 0) << std::endl;
    }
    return 0;
}



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

int main()
{
    int n,k;
    cin >> n >> k;
    if((k&1))
    {
        cout << (long long)powl(n/k,3);
    }
    else
    {
        long double res = powl(2*n/k - n/k,3) + powl(n/k,3);
        cout << (long long)res;
    }
    
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)	
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	cout<<a*b/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n,k;
    int a[100001]={0};
    int i,j;
    int sum;
    int mem=0;
    while(1){
        for(i=0;i<10000;i++){
            a[i]=0;
        }
        scanf("%d%d",&n,&k);
        if(n==0&&k==0){
            break;
        }
        mem=0;
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sum=0;
        for(i=0;i<n;i++){
            if(i<k){
                sum=sum+a[i];
            }
            else if(i>=k){
                sum=sum+a[i];
                sum=sum-a[i-k];
            }
            if(i==k-1){
                mem=sum;
            }
            if(i>=k-1){
                if(mem<sum){
                    mem=sum;
                }
            }
        }
        printf("%d\n",mem);
    }
    return 0;
}

Measured memory_bytes: 996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int X;
  cin >> X;
  string s = to_string(X);
  int ssize = (int)s.size();
  ll sum = 0;
  rep(i,ssize){
    sum += (s[i] - '0');
  }
  if(X % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int MAXN=210000;
typedef long long ll;
ll mymin(ll x,ll y) {return x<y?x:y;}
ll mymax(ll x,ll y) {return x>y?x:y;}

int n;
ll sum[MAXN];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&sum[i]);
        sum[i]+=sum[i-1];
    }

    ll ans=1ll<<60;

    //1~mid1,mid1+1~mid2,mid+1~mid3,mid3+1~n
    int mid1=1,mid3=3;
    for(int mid2=2;mid2<=n-2;mid2++)
    {
        while( sum[mid1]<sum[mid2]-sum[mid1] ) mid1++;
        while( sum[mid3]-sum[mid2]<sum[n]-sum[mid3] ) mid3++;

        ll A,B,C,D;

        A=sum[mid1],B=sum[mid2]-sum[mid1];
        C=sum[mid3]-sum[mid2],D=sum[n]-sum[mid3];
        ans=mymin(ans,mymax( mymax(A,B),mymax(C,D) )-mymin( mymin(A,B),mymin(C,D) ));

        A=sum[mid1-1],B=sum[mid2]-sum[mid1-1];
        C=sum[mid3]-sum[mid2],D=sum[n]-sum[mid3];
        ans=mymin(ans,mymax( mymax(A,B),mymax(C,D) )-mymin( mymin(A,B),mymin(C,D) ));

        A=sum[mid1],B=sum[mid2]-sum[mid1];
        C=sum[mid3-1]-sum[mid2],D=sum[n]-sum[mid3-1];
        ans=mymin(ans,mymax( mymax(A,B),mymax(C,D) )-mymin( mymin(A,B),mymin(C,D) ));

        A=sum[mid1-1],B=sum[mid2]-sum[mid1-1];
        C=sum[mid3-1]-sum[mid2],D=sum[n]-sum[mid3-1];
        ans=mymin(ans,mymax( mymax(A,B),mymax(C,D) )-mymin( mymin(A,B),mymin(C,D) ));
    }

    printf("%lld",ans);
}


Measured memory_bytes: 1664
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

class SegmentTree:
    def __init__(self, N, func, I):
        self.func = func
        self.I = I
        self.sz = 2**(N-1).bit_length()
        self.seg = [I] * (self.sz * 2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in reversed(range(1,self.sz)):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def main():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    N = int(readline())
    L = list(map(int,read().split()))
    seg = SegmentTree(N , gcd , 0)
    for i,n in enumerate(L):
        seg.assign(i , n)
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


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

int main(){
    int h,w;cin>>h>>w;
    for(int i =0;i<h+2;i++,cout<<endl){
        for(int j=0;j<w+2;j++){
            if(j == 0 || j == w+1 || i == 0 || i == h+1){
                cout<<"#";
            }
            else{
                char c;cin>>c;
                cout<<c;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l1 = list(map(int,list(input().split())))
l2 = list(map(int,list(input().split())))

ans = 0
for i in range(n):
  s = 0
  for j in range(i+1):
    s += l1[j]
  for j in range(i,n):
    s += l2[j]
  if ans < s:
    ans = s

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int n,l,i,k=0;

	scanf("%d%d",&n,&l);

	int a[n];

	for(i=0;i<n;i++)
		a[i]=l+i;
	if(l>=0){
		for(i=1;i<n;i++)
			k+=a[i];
		printf("%d",k);
		return 0;
	}
	else{
		for(i=0;i<n;i++)
			k+=a[i];
		if(a[n-1]<0)
			k-=a[n-1];
		printf("%d",k);
		return 0;
	}
}

Measured memory_bytes: 128
MyString=Union{String,SubString{String},Char}
MyStringArray=Union{Array{String,1},Array{SubString{String},1},Array{Char,1}}
parseInt(x::MyString) = parse(Int, x)
parseInt(x::Real) = trunc(Int, x)
parseBigInt(x::MyString) = parse(BigInt, x)
parseBigInt(x::Real) = trunc(BigInt, x)
parseFloat(x::MyString) = parse(Float64, x)
parseFloat(x::Real) = trunc(Float64, x)
parseBigFloat(x::MyString) = parse(BigFloat, x)
parseBigFloat(x::Real) = trunc(BigFloat, x)
parseMap(x::MyStringArray) = map(parseInt, x)
parseMapBig(x::MyStringArray) = map(parseBigInt, x)

function main()
    s=chomp(readline())
    ans=""
    for i in s
        if i=='0'
            ans*=string(0)
        elseif i=='1'
            ans*=string(1)
        elseif length(ans)>0
            ans=string(ans[1:end-1])
        end
    end
    println(ans)
end
main()

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

int main()
{
	int x,y,i=0;	
	do{
		cin>>x>>y;
		i++;
		if (x==0&&y==0)
			break;
		else{
			if(x<=y)
				cout<<x<<" "<<y<<endl;
			else
				cout<<y<<" "<<x<<endl;
		}		
	} while(i<=3000);
	return 0;
}


Measured memory_bytes: 3060
#include <stdio.h>

#define M 10000

int main(){
  int n,q,i,j,S[M],T,res = 0;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&T);
    for(j = 0 ; j < n ; j++){
      if(T == S[j]){
        ++res;
        break;
      }
    }
  }
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    int n,m,t;
	while(~scanf("%d%d%d",&n,&m,&t)){
		int count=0;
		for(int i=1;;i++){
			if(i*t>=n&&i*t<=m) count++;
			if(i*t>m) break;
		} 
		cout << count <<endl;
	}
	return 0;
}

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


typedef long long ll;

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

    ll n = 0, m = 0;
    cin >> n >> m;
    vector<ll> v(n , 0);
    vector<ll> v1[n];
    for(int i = 0; i < n; i++) cin >> v[i];

    ll a = 0, b = 0;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        v1[a - 1].push_back(b - 1);
        v1[b - 1].push_back(a - 1);
    }

    ll ans = 0;
    // for(int i = 0; i < n; i++) {
    //     cout << v[i] << "-----> ";
    //     for(int j = 0; j < v1[i].size(); j++) {
    //         cout << "(" << v1[i][j] << " " << v[v1[i][j]] << ")" << " ";
    //     }
    //     cout << endl;
    // }



    for(int i = 0; i < n; i++) {
        int great = 1;
        if(v1[i].size() == 0) {
            ans++;
            continue;
        }
        for(int j = 0; j < v1[i].size(); j++) {
            if(v[v1[i][j]] >= v[i]) great = 0;
        }
        if(great) ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 9800
#include<iostream>
using namespace std;
int main(void)
{
  int i,j,k,n,t[100001],x[100001],y[100001],z[100001];
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>t[i+1]>>x[i+1]>>y[i+1];
  }
  t[0]=0;
  x[0]=0;
  y[0]=0;
           
  for(i=0;i<=n;i++)
  {
    z[i]=x[i]+y[i];
  }
  for(i=0;i<n;i++)
  {
    j=abs(z[i+1]-z[i]);
    k=t[i+1]-t[i];
    if(k%2!=j%2||j>k)
    {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 5160
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    long long int n, ans;

    std::cin >> n;

    for(int i = 1;i * i<= n;i++){
        ans = i * i;
    }

    std::cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define ll long long
int main(){
	ll a,b,c; cin>>a>>b>>c;
	if(a==b and a==c) cout<<"No";
	else if(a==b or b==c or a==c) cout<<"Yes";
	else cout<<"No";
}


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

using namespace std;

void Main() {
    int a, b, h;
    cin >> a >> b >> h;

    cout << (a + b) * h / 2 << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

int arr[N];
int visited[N];
int com[N];
vi adj[N];
int n,m,t=1;

void dfs(int node)
{
    com[node]=t;
    for(auto i : adj[node])if(com[i]==0)dfs(i);
}

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    cin>>n>>m;
    forn(i,1,n)cin>>arr[i];
    forn(i,1,m)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    
    forn(i,1,n)
    {
        if(com[i]==0)dfs(i),t++;
    }
    int ans=0;
    forn(i,1,n)ans += com[arr[i]]==com[i];
    cout<<ans;

     return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int n, q;
vector<int> S, T;

bool binarySearch(int key)
{
    int left = 0, right = n;
    int mid;
    while (left < right) {
        mid = (left + right) / 2;
        if (key > S[mid]) {
            left = mid + 1;
        } else if (key < S[mid]) {
            right = mid;
        } else {
            return true;
        }
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    S.resize(n);
    rep(i, n) { cin >> S[i]; }
    cin >> q;
    T.resize(q);
    rep(i, q) { cin >> T[i]; }
    int cnt = 0;
    for (auto t : T) {
        if (t < S[0] || S[n - 1] < t) {
            continue;
        }
        if (binarySearch(t)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
int w,h;
int n;
int c[110][110];
int main(){
	cin>>h>>w;
	cin>>n;
	int nowh=0,noww=0;
	bool flag=0;
	for(int i=1;i<=n;i++){
		int a;cin>>a;
		for(int j=0;j<a;j++){
		//cout<<"nowh="<<nowh<<"noww="<<noww<<endl;
		//cout<<"i="<<i<<endl;
			c[nowh][noww]=i;
			if(flag){
				nowh--;
				if(nowh==-1){
					nowh++;
					noww++;
					flag=0;
				}
			}else{
				nowh++;
				if(nowh==h){
					nowh--;
					noww++;
					flag=1;
				}
			}
			//cout<<i<<endl;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout<<c[i][j];
			if(j!=w-1)cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node
{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
} Node;

void insert(int k);
void inorder(Node *x);
void preorder(Node *x);
Node * find(int k, Node *x);

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 *x)
{
  if(x == NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}

void preorder(Node *x)
{
  if(x == NIL) return;
  printf(" %d", x->key);
  preorder(x->left);
  preorder(x->right);
}
  
Node * find(int k, Node *x)
{
  while(x != NIL && k != x->key){
    if(k<x->key){
      x=x->left;
    }
    else {
      x=x->right;
    }
  }
  return x;
}

int main()
{
  int i, o, k, f;
  char s[100];

  scanf("%d", &o);

  for(i=0; i<o; i++){
    scanf("%s", s);

    if(strcmp(s, "insert") == 0){
      scanf("%d", &k);
      insert(k);
    }
    else if(strcmp(s,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(strcmp(s,"find") == 0){
      scanf("%d", &f);
      if(find(f, root) != NIL){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
    else 
      continue;
  }
  return 0;
}

Measured memory_bytes: 19364
n,a,b = map(int,input().split())

mod = 10**9+7

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

sum = pow(2,n,mod)
case = combination(n,a,mod) + combination(n,b,mod) + 1
ans = sum-case
while ans < 0 :
    ans += mod

print(ans)

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

using namespace std;

int main()
{
    string S;
    cin >> S;
    
    if(S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3))
        cout << "Bad" << endl;
    else
        cout << "Good" << endl;
    
    return 0;
}

Measured memory_bytes: 3612
<?php
fscanf(STDIN, "%d %d",$n,$k);
$s = strval(trim(fgets(STDIN)));
$sumArray = array();
$sum = 0;
$total = 0;
$ans = 0;
$j = 0;
//0,1の連続で配列作成
for ($i=0;$i<=$n;$i++){
	if ($s[$i]== 0 && $i == 0){
		$sum--;
	}else if ($s[$i]== 1 && $i == 0) {
		$sum++;
	}else if ($s[$i]== 0 && $s[$i] == $s[$i-1]){
		$sum--;
	}else if ($s[$i]== 1 && $s[$i] == $s[$i-1]){
		$sum++;
	}else if ($s[$i]== 0 && $s[$i] != $s[$i-1]){
		$sumArray[] += $sum;
		$sum = 0;
		$sum--;
	}else if ($s[$i]== 1 && $s[$i] != $s[$i-1]){
		$sumArray[] += $sum;
		$sum = 0;
		$sum++;
	}
}
//print_r($sumArray);
$arraySize = count ($sumArray);
for ($i=0;$i<$arraySize;$i++){
	if ($sumArray[0] > 0){
		if ($i == 0){
			for ($j=0;$j<2 * $k + 1;$j++){
				$total += abs($sumArray[$j]);
				$ans = $total;
			}
			//echo $i." ". $j."\n";
		}else {
			//左の尺を進める
			$total -= abs($sumArray[$i-1]);
			//右の尺を進める
			$total += abs($sumArray[$j]);
			$j++;
		}
	}
	if ($sumArray[0] < 0){
	 if ($i == 0){
	 for ($j=0;$j<2 * $k;$j++){
	 $total += abs($sumArray[$j]);
	 $ans = $total;
	 }
	 }else {
	 	if ($i == 1) {
	 		$total += abs($sumArray[$j]);
	 		$j++;
	 	}
	 //左の尺を進める
	 $total -= abs($sumArray[$i-1]);
	 //右の尺を進める
	 $total += abs($sumArray[$j]);
	 $j++;
	 }
	 }
	if ($ans < $total && $sumArray[$i] > 0){
		$ans = $total;
	}
}
echo $ans;
?>

Measured memory_bytes: 18060
def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def cul(n,x):
    l=len(x)
    b=[x[i] for i in range(l)]
    b.pop(n)
    tmp=b[0]
    for i in range(1,l-1):
        tmp=gcd(tmp,b[i])
    return tmp

import sys
p=50
N=int(input())
if p>N: p=N
a=list(map(int,input().split()))

ans=0
for i in range(p):
    s=cul(i,a[:p])
    if s>ans: ans=s

print(ans)

Measured memory_bytes: 14452
#include <iostream>
using namespace std;
int main() {
    int n,k,x,a;
    cin >> n >> k;
  x=a=0;
    for(int i = 0; i < n; ++i){
        cin >> x;
        if(x>=k){
            a++;
        }
    }
    cout << a << endl;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i=1;i<n;i++) {
        int m = 0;
        for (int j=0;j<n-i;j++) {
            if (s[i+j] == s[j] && i>m ) {
                m++;
            } else {
                ans = max(m, ans);
                m = 0;
            }
        }
        ans = max(m, ans);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define mp make_pair
#define what_is(x) cerr << #x << " is " << x << endl;

typedef tree<
        int,
        null_type,
        less<int>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1e9 + 7;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p;
    return s;
}

int sub(int a, int b) {
    int s = (a-b);
    s = s%p;
    if (s<0) s+=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

vector<int> Z(vector<int> s)
{
    int n = s.size();
    vector<int> z(n);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R-L] == s[R]) R++;
            z[i] = R-L; R--;
        } else {
            int k = i-L;
            if (z[k] < R-i+1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R-L] == s[R]) R++;
                z[i] = R-L; R--;
            }
        }
    }
    return z;
}

mt19937 rnd(time(0));
/*
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct CHT : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b); }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};
*/


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

    int n;
    cin>>n;
    vector<vector<int>> a(n, vector<int>(n, -1));
    for (int bit = 20; bit>=0; bit--)
    {
        for (int i = 0; i<n; i++)
            for (int j = i+1; j<n; j++) if (a[i][j]==-1)
            {
                if ((i&(1<<bit)) != (j&(1<<bit))) a[i][j] = bit;
            }
    }
    for (int i = 0; i<n-1; i++)
    {
        for (int j = i+1; j<n; j++) cout<<a[i][j]+1<<' ';
        cout<<endl;
    }
}


Measured memory_bytes: 1536
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;;){
			int k = sc.nextInt();
			if(k ==0){
				break;
			}
			
			long ans = 0;
			
			for(int i  =0 ; i <k * (k-1)/2 ; i++){
				ans+=sc.nextLong();
			}
			ans/=(k-1);
					System.out.println(ans);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

int main() {
  int H,W;
  cin >>H>>W;
 
  vector<string> vec(H);
  for(int i=0;i<H;i++)
    cin>>vec.at(i);
  
  for(int i=0;i<W+2;i++)
    cout<<"#";
  
  cout<<endl;
  
  for(int i=0;i<H;i++) 
    cout<<"#"<<vec.at(i)<<"#"<<endl;
  
  for(int i=0;i<W+2;i++)
    cout<<"#";
 
}


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

#define MOD_1000000007 (1000000007LL)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i, n) for (long long i = 1; i < (long long)(n); i++)
#define rep0c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)

using std::vector;
using std::set;
using std::map;
typedef long long ll;

int N, as[200020], bs[200020], cs[200020];

set<int> divisors(int n) {
  set<int> res;
  int ub = (int)std::ceil(std::sqrt(n));
  rep1c(i, ub) if(n%i==0) {
    res.insert(i);
    res.insert(n/i);
  }
  return res;
}

void solve() {
  repc1(N, i) if(as[i] != cs[i]%2) {
    set<int> ds = divisors(i);
    for(const int& d : ds) cs[d]++;
    bs[i] = 1;
  }
  int M = 0;
  rep1c(i, N) if(bs[i]) M++;
  printf("%d\n", M);
  if(M>0) {
    bool first = true;
    rep1c(i, N) if(bs[i]) {
      if(first) {
        first = false;
      } else {
        printf(" ");
      }
      printf("%d", i);
    }
    printf("\n");
  }
}

int main() {
  scanf("%d", &N);
  rep1c(i, N) scanf("%d", &as[i]);
  solve();
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main(){
    int n, m , k ;
    cin >> n >> m >> k ;
    vector<int> a (n);
    vector<int> b (m);
    rep(i, n) cin >> a[i] ;
    rep(i, m) cin >> b[i] ;
    
    ll t = 0 ;
    rep(i, m) t += b[i] ;
    int j = m ;
    int ans = 0 ;
    rep(i, n+1){
        while(j > 0 && t > k){
            --j ;
            t -= b[j] ;
        }
        if (t > k) break ;
        ans = max(ans, i + j) ;
        if(i == n) break ;
        t += a[i] ;
    }
    cout << ans << endl ;
}

Measured memory_bytes: 4828
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=1000000 +117;
const int MM=1000000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
LL a[NN]={},p[NN]={};
int len;
const int mod=998244353;
LL ksm(LL a,LL b){
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ret=ret*a%mod;
	return ret;
}
void fwt(LL a[],int len,int sym){
	for(int d=1;d<len;d<<=1){
		for(int st=0;st<len;st+=d<<1){
			for(int k=0;k<d;++k){
				LL x=a[st+k],y=a[st+d+k];
				a[st+k]=(x+y)%mod;
				a[st+d+k]=(x-y)%mod;
			}
		}
	}
	if(sym==-1){
		LL bas=ksm(len,mod-2);
		for(int i=0;i<len;++i){
			a[i]=a[i]*bas%mod;
		}
	}
}
int main(){
	//open();
	n=read();
	len=1<<n;
	LL s=0;
	for(int i=0;i<len;++i){
		s+=(p[i]=read());
	}
	s=ksm(s,mod-2);
	for(int i=0;i<len;++i){
		p[i]=p[i]*s%mod;
	}
	(p[0]-=1)%=mod;
	for(int i=0;i<len;++i){
		a[i]=-1;
	}
	a[0]+=len;
	fwt(a,len,1);
	fwt(p,len,1);
	for(int i=0;i<len;++i)a[i]=a[i]*ksm(p[i],mod-2)%mod;
	fwt(a,len,-1);
	for(int i=len-1;i>=0;--i){
		(a[i]-=a[0])%=mod;
		a[i]=(a[i]+mod)%mod;
	}
	for(int i=0;i<len;++i){
		printf("%lld\n",a[i]);
	}
	close();
	return 0;
}

Measured memory_bytes: 11008
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Stack;

public class Main {
    private static final Reader reader = new Reader();
    private static final int MAX = 100000;
    public static void main(String[] args) throws Exception{
        int n = reader.readInt();
        int[] nums = reader.readIntArray();
        int[] freq = new int[MAX+10];
        long sum =0;
        for(int i=0;i<n;i++){
            freq[nums[i]]++;
            sum+=nums[i];
        }
        int q = reader.readInt();
        while(q-->0){
            int[] temp = reader.readIntArray();
            int b = temp[0]; int c = temp[1];
            long toRemove = 1L*freq[b]*b;
            long toAdd = 1L*freq[b]*c;
            freq[c]+=freq[b];
            freq[b]=0;
            sum+=(toAdd-toRemove);
            System.out.println(sum);
        }
    }


    private static class Reader{
        private final BufferedReader br;
        public Reader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int readInt() throws Exception{
            return Integer.parseInt(br.readLine());
        }
        public long readLong() throws Exception {
            return Long.parseLong(br.readLine());
        }
        public double readDouble() throws Exception {
            return Double.parseDouble(br.readLine());
        }
        public String readLine() throws Exception{
            return br.readLine();
        }
        public int[] readIntArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            int[] nums = new int[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Integer.parseInt(tokens[i]);
            }
            return nums;
        }
        public long[] readLongArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            long[] nums = new long[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Long.parseLong(tokens[i]);
            }
            return nums;
        }
        public double[] readDoubleArray() throws Exception {
            String[] tokens = br.readLine().split(" ");
            double[] nums = new double[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Double.parseDouble(tokens[i]);
            }
            return nums;
        }
        public String[] readWords() throws Exception {
            return br.readLine().split(" ");
        }
    }
}

Measured memory_bytes: 54200