akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll L[210];

int main() {
  std::cin >> N;

  rep( i, N )
    std::cin >> L[i];

  std::sort( L, L+N );

  ll ans = 0;

  rep( i, N ) rep( j, i ) rep( k, j ) {
    if( L[i] != L[j] && L[j] != L[k] && L[i] != L[k] && L[i] < L[j]+L[k] ) {
      ++ans;
    } 
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
string a,b;
ll dp[3001][3001]; 
ll fun(int x,int y)
{
    if(x==a.length())
    {
        return 0;
    }
    else if(y==b.length())
    {
        return 0;
    }
    if(a[x]==b[y])
    {
        if(dp[x+1][y+1]==-1)
        {
            return dp[x][y]=1+fun(x+1,y+1);
        }
        else
        {
            return dp[x][y]=1+dp[x+1][y+1];
        }
    }
    else
    {
        if(dp[x+1][y]==-1)
        {
            dp[x][y]=fun(x+1,y);
        }
        else
        {
            dp[x][y]=dp[x+1][y];
        }
        if(dp[x][y+1]==-1)
        {
            dp[x][y]=max(dp[x][y],fun(x,y+1));
        }
        else
        {
            dp[x][y]=max(dp[x][y],dp[x][y+1]);
        }
        return dp[x][y];
    }
}
void solve()
{
    cin>>a>>b;
    fr(i,0,a.length())
    {
        fr(j,0,b.length())
        {
            dp[i][j]=-1;
        }
    }
    fun(0,0);
    int i=0,j=0;
    ll cnt=0;
    while(dp[0][0]>0)
    {
        if(i+1<a.length()&&dp[i][j]==dp[i+1][j])
        {
            i++;
        }
        else if(j+1<b.length()&&dp[i][j]==dp[i][j+1])
        {
            j++;
        }
        else if(dp[i+1][j+1]+1==dp[i][j])
        {
            cnt++;
            cout<<a[i];
            if(cnt==dp[0][0])
            {
                break;
            }
            i++;
            j++;
        }
    }
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*





























*/

Measured memory_bytes: 74220
from typing import List


def answer(n: int, k: int, xs: List[int]) -> int:
    moving_distance = 0
    reference_value = k / 2
    for x in xs:
        if x <= reference_value:
            moving_distance += x * 2
        else:
            moving_distance += (k - x) * 2

    return moving_distance


def main():
    n = int(input())
    k = int(input())
    xs = list(map(int, input().split()))
    print(answer(n, k, xs))


if __name__ == '__main__':
    main()

Measured memory_bytes: 10176
#include <stdio.h>


#define MAX 200000

int max(int a,int b) { return a>b ? a: b;}
int min(int a,int b) { return a<b ? a: b;}


int main(void) {
    int R[MAX], i, n;
    

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

    int maxv = -2000000000;
    int minv = R[0];
    

    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    

    printf("%d\n",maxv);


    return 0;
}



Measured memory_bytes: 2528
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) x.begin(),x.end()

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int x,y;
	cin>>x>>y;
	bool f =0;
	for(int i = 0; i <= x; i++){
		if(4*i + 2*(x - i) == y){
			f = 1;
			break;
		}
	}
	if(f){
		cout<<"Yes"<<nl;
	}
	else cout<<"No"<<nl;
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string A;
  string J;
	cin >> A;
  if(A[0]==A[1]&&A[1]==A[2]){
    J = "Yes";
  }
  else if(A[1]==A[2]&&A[2]==A[3]){
    J = "Yes";
  }
  else{
    J = "No";
  }
  cout << J << endl;
}

Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列


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 <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

int  N, K;

ll pow3(ll x) {
  return x*x*x;
}

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

  cin >> N >> K;
  ll ans = pow3(N/K);
  if (K%2==0) ans += pow3((N+K/2)/K);
  cout << ans << '\n';
  return 0;
}


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

int calc_tap(double a, double b) {
  double n = ceil(max(b - a, 0.0) / (a - 1.0)) + 1.0;
  return (int)n;
}

int main() {
  double a;
  double b;
  cin >> a >> b;

  int res;
  if (b == 1) {
    res = 0;
  } else {
    res = calc_tap(a, b);
  }
  cout << res << endl;
}


Measured memory_bytes: 3652
N, T = map(int, input().split())
table = [[0] * (N + 1) for _ in range(T + 1)]
dish = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda t: t[0])
for t in range(T + 1):
    for n in range(N):
        minutes_to_take, deliciousness = dish[n]
        now = table[t][n]
        if t < T:
            table[min(T, t + minutes_to_take)][n + 1] = max(table[min(T, t + minutes_to_take)][n + 1], now + deliciousness)
        if n < N:
            table[t][n + 1] = max(table[t][n + 1], now)
print(max(table[t][N] for t in range(T + 1)))

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll l;
  cin>>l;

  ld ans = pow(l/3.0, 3);
  cout<<Decimal;
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n,x; cin>>n>>x;
	vl v(n);
	ll ans;
	cin>>ans;
	ans=abs(x-ans);
	rep(i,0,n-1){
		ll b; cin>>b;
		ans=gcd(ans,abs(x-b));
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 4000
"""
https://atcoder.jp/contests/abc087/tasks/arc090_b

xR-xL = D
Mこの情報が正しいかどうかの判定
グループを作って、グループ内の拘束条件があっているか確認
重み付きunionfindを使う
https://qiita.com/drken/items/cce6fc5c579051e64fab
http://at274.hatenablog.com/entry/2018/02/03/140504


5 5
1 2 2
2 3 3
4 5 4
2 5 10
3 4 3
"""

from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(int)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])           
            self.weight[x] += self.weight[self.parent[x]]   #圧縮時にweightを更新(和)
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    # def calc_weight(self, x):
    #     self.find(x) #圧縮
    #     return self.weight[x]

    # def calc_diff(self, x, y):
    #     return self.calc_weight(y) - self.calc_weight(x)

    def weighted_union(self, x, y, w):
        # print("unite",x,y,w,self.weight)
        px = self.find(x)
        py = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        # if px == py: return 0
        if self.rank[px] < self.rank[py]:
            self.parent[px] = py
            self.weight[px] = w - self.weight[x] + self.weight[y]
        else:
            self.parent[py] = px
            self.weight[py] = - w + self.weight[x] - self.weight[y]
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1
        return 0


    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)


N,M = map(int, input().split())
uf = UnionFind(N)
for i in range(N):
    uf.find(i)

for i in range(M):
    l,r,d = map(int, input().split())
    # 初めて出てくる奴らは数直線形成に使う
    if not uf.judge(l, r):
        uf.weighted_union(l, r, d)
    # 二回目のやつらは後で拘束条件に使う
    else:
        if d == -uf.weight[r]+uf.weight[l]:
            continue
        else:
            print("No")
            exit()
print("Yes")
# for i in uf.parent.keys():
#     uf.find(i)
#     print("index:{} rank:{}, parent:{}, weight:{}".format(i,uf.rank[i],uf.parent[i],uf.weight[i]))


Measured memory_bytes: 38852
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int T,n,m,i,j,k,x,y,z,Ans,sum,cnt;
int a[N],b[N],f[N];
char c[N];

struct Data{
	int x,y;
}d[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}
IL bool cmp(const Data a,const Data b){return a.x<b.x;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

IL int Find(int x){return (x==f[x])?x:f[x]=Find(f[x]);}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();	m=read();
	for (i=1;i<=n;i++)	f[i]=i;
	for (i=1;i<=m;i++){
		x=read();	y=read();
		x=Find(x);	y=Find(y);
		if (x==y)	continue;
		f[x]=y;
	}
	for (i=1;i<=n;i++){
		x=Find(i);	b[x]++;
	}
	for (i=1;i<=n;i++)	Ans=Max(Ans,b[i]);
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 10576
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, a[3], n, m, max = 0;
  for(i = 0; i < 3; ++i) {
    scanf("%lld", &a[i]);
    if(a[i] > max) max = a[i], n = i;
  }
  printf("%lld", max * 10 + a[0] + a[1] + a[2] - a[n]);
  return 0;
}

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

#define ll long long int

int main() {
	ll n;
	cin >> n;
	
	ll length[n] = {}, total_sum = 0;;
	for (ll i = 0; i < n; i++) {
	    ll temp;
	    cin >> temp;
	    length[i] = temp;
	    total_sum += temp;
	}
	
// 	int cum_sum[n] = {};
	for(ll i = 1; i<n;i++){
	    length[i]+=length[i-1];
	}
	   
	ll min_diff = INT_MAX;
	for(ll i = 0;i < n-1;i++) {
	   
	   ll diff = abs(length[i] - (total_sum - length[i]) );
	   if(diff < min_diff)
	        min_diff = diff;
	    
	}
	
	cout << min_diff << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

constexpr long long inv(long long x, long long m) {
  return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x;
}
// Mu[1] = 1, if x = p1p2...pk, Mu[x] = (-1)^k, else 0
vector<int> mu_n(int n) {
  vector<int> Mu(n), L(n), P;
  Mu[1] = L[1] = 1;
  for (int x = 2; x < n; x++) {
    if (!L[x]) P.push_back(L[x] = x), Mu[x] = -1;
    for (auto p : P) {
      if (x * p >= n) break;
      L[x * p] = p;
      if (x % p == 0) { Mu[x * p] = 0; break; }
      else Mu[x * p] = -Mu[x];
    }
  }
  return Mu;
}

const int N = 1e6 + 5, M = 998244353;
int n;
LL sum[N], f[N];
auto mu = mu_n(N);

int main() {
  cin >> n;
  auto add = [&](int x, int y) {
    f[y] += sum[y] * x % M;
    f[y] %= M;
    sum[y] += x;
    sum[y] %= M;
  };
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    for (int y = 1; y * y <= x; ++y) {
      if (x % y == 0) {
        add(x, y);
        if (y * y != x) add(x, x / y);
      }
    }
  }
  LL ans = 0;
  for (int i = 1; i < N; ++i) {
    LL cur = 0;
    for (int j = i; j < N; j += i) {
      cur += mu[j / i] * f[j] + M;
      cur %= M;
    }
    ans = (ans + cur * inv(i, M)) % M;
  }
  cout << ans << endl;
}


Measured memory_bytes: 19968
n = int(input())
import collections
import itertools
wo = ["M","A","R","C","H"]
co = collections.Counter()
for i in range(n):
    s = input()
    if s[0] in wo:
        co[s[0]] +=1
ans = 0
for c in itertools.combinations(wo,3):
    tmp =1
    for w in c:
        tmp*=co[w]
    ans+=tmp
print(ans)


Measured memory_bytes: 3316
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n, d;

int main() {
    cin >> n >> d;
    cout << (n+2*d) / (2*d+1) << endl;
}


Measured memory_bytes: 256
N=int(input());t=[0]+[N]*N
for i in range(1,N+1):
 x,a,b=t[i-1],6,9
 while a<=i:x=min(x,t[i-a],t[i-b]if b<=i else N);a*=6;b*=9
 t[i]=x+1
print(t[N])

Measured memory_bytes: 4596
#include<stdio.h>
#define NMAX 100100
int inputi(){
	char c='0';
	int ans=0;
	signed char flg=1;
	do{
		c=getchar();
	}while(c<=32);
	if(c=='-'){
		flg=-1;
		c=getchar();
	}
	do{
		ans*=10;
		ans+=(c-'0');
		c=getchar();
	}while(c>32);
	return ans*flg;
}
int main(void){
	int n,m,a,b;
	int list[5*NMAX]={0};
	int last=NMAX;
	int node[5*NMAX]={0};
	int queue[5*NMAX]={0},qfirst=0,qlen=0;;
	int room[NMAX]={0};
	int i;
	int now,tmp;
	n=inputi();
	m=inputi();
	for(i=0;i<m;i++){
		a=inputi();
		b=inputi();
		list[last]=list[a];
		list[a]=last;
		node[last]=b;
		last++;
		list[last]=list[b];
		list[b]=last;
		node[last]=a;
		last++;
	}
	queue[0]=1;qlen=1;
	room[1]=room[0]=-1;
	while(qlen){
		now=queue[qfirst];
		qlen--;
		qfirst++;
		tmp=now;
		
		while(tmp){
			tmp=list[tmp];
			if(room[node[tmp]]==0){
				room[node[tmp]]=now;
				queue[(qfirst+qlen)%(5*NMAX)]=node[tmp];
				qlen++;
			}
		}
	}
	puts("Yes");
	for(i=2;i<=n;i++){
		printf("%d\n",room[i]);
	}
	return 0;
}


Measured memory_bytes: 7860
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/

const int MX=10e5+5;
vi v[MX];
int dp[MX];

int bfs(int x)
{
    if(dp[x]!=-1)
        return dp[x];
    else
    {
        dp[x]=0;
        for(auto u:v[x])
        {
            dp[x]=max(dp[x],bfs(u)+1);
        }
    return dp[x];
    }
}

void solve()
{
  int n,m;
  cin >> n >> m;
  f(i,m)
    {
        int x,y;
        cin >> x >> y;
        v[x].pb(y);
    }
    fp(i,1,n)
        dp[i]=-1;
    vi ans;
    fp(i,1,n)
    {
       if(dp[i]==-1)
          ans.pb(bfs(i));
    }
    cout << *max_element(all(ans)) << '\n';
} 

signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 32916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }
const int INF = 1000000000;

struct UnionFind
{
    vi par;
    vi sizes;
    UnionFind(int n) : par(n), sizes(n,1){
        rep(i,0,n) par[i] = i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return;
        if(sizes[x]<sizes[y]) swap(x,y);
        par[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sizes[find(x)];
    }
};

int main(){
   ll n,m; cin>>n>>m;
   UnionFind uf(n);
   ll a[m],b[m];
   rep(i,0,m){
       cin>>a[i]>>b[i];
       a[i]--,b[i]--;
   } 
   ll ans[m+1];
   ll rec=n*(n-1)/2;
   ans[m]=rec;
   for(int i=m-1;i>=0;i--){
       if(uf.same(a[i],b[i])) ans[i]=rec;
       else{
           rec-=uf.size(a[i])*uf.size(b[i]);
           ans[i]=rec;
           uf.unite(a[i],b[i]);
       }
   }
   rep(i,1,m+1) cout<<ans[i]<<endl;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

void warshall_floyd(int V, vector< vector<int> > &d) {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {

    int N, M, L;
    cin >> N >> M >> L;
    vector<int> A(M), B(M), C(M);
    rep(i,M) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
    }
    int Q;
    cin >> Q;
    vector<int> s(Q), t(Q);
    rep(i,Q) {
        cin >> s[i] >> t[i];
        s[i]--; t[i]--;
    }

    vector<vector<int>> distance(N, vector<int>(N, INF));
    rep(i,N) distance[i][i] = 0;
    rep(i,M) {
        distance[A[i]][B[i]] = C[i];
        distance[B[i]][A[i]] = C[i];
    }
    rep(k,N) rep(i,N) rep(j,N) distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j]);

    vector<vector<int>> reachable(N, vector<int>(N, INF));
    rep(i,N) rep(j,N) if (distance[i][j] <= L) reachable[i][j] = 1;
    
    rep(k,N) rep(i,N) rep(j,N) reachable[i][j] = min(reachable[i][j], reachable[i][k] + reachable[k][j]);

    rep(i,Q) {
        cout << (reachable[s[i]][t[i]] == INF ? -1 : reachable[s[i]][t[i]] - 1) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2432
def getN():
    return int(input())
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, Ma, Mb = getNM()
query = [getList() for i in range(N)]

# dp[i][j][l]: i個まで探索したあとで物質aをjグラム,物質bをlグラム生成する最少費用
dp = [[[float('inf')] * 501 for i in range(501)] for i in range(N + 1)]
dp[0][0][0] = 0

# 各薬品
for i in range(N):
    # 物質a
    for j in range(501):
        # 物質b
        for l in range(501):
            a, b, c = query[i]
            if j - a >= 0 and l - b >= 0:
                dp[i + 1][j][l] = min(dp[i][j][l], dp[i][j - a][l - b] + c)
            else:
                dp[i + 1][j][l] = dp[i][j][l]

ans = float('inf')
for j in range(1, 500):
    for l in range(1, 500):
        if Ma * l == Mb * j and dp[N][j][l] < 10 ** 9 + 7:
            ans = min(ans, dp[N][j][l])
if ans < 10 ** 9 + 7:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 188580
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int n;
    cin >> n;
    vector<long long> a(n), b(n), c(n);
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> b[i];
    rep(i, n)cin >> c[i];
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    long long ind[3][n];
    int pos = 0;

    rep(i, 3){
        rep(j, n){
            if(i == 0){
                ind[i][j] = 1;
            }
            else if(i == 1){
                if(j == 0){
                    ind[i][j] = 0;
                    pos = 0;
                }
                if(j != 0)ind[i][j] = ind[i][j-1];
                while(b[j] > a[pos] && pos < n)ind[i][j] += ind[i-1][pos++];
            }
            else {
                if(j == 0){
                    ind[i][j] = 0;
                    pos = 0;
                }
                if(j != 0)ind[i][j] = ind[i][j-1];
                while(c[j] > b[pos] && pos < n)ind[i][j] += ind[i-1][pos++];
            }
        }
    }
    long long ans = 0;
    rep(i, n)ans += ind[2][i];
    cout << ans << endl;



}

Measured memory_bytes: 4992
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	int r, g, b, n;

	cin >> r >> g >> b >> n;

	int ans = 0;

	for (int i = 0; i <= n; i += r){
		for (int j = 0; j <= n; j += g){
			if (i + j > n) continue;
			int k = n - (i + j);
			if (i + j + k == n && k % b == 0){
				ans++;
			}
		}
	}

	cout << ans << endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
int main(){
    ll k,s, check, ans=0;
    cin >> k >> s;
    RAP(i,k+1){
        RAP(j,k+1){
            check = s-(i+j);
            if(check>=0 && check<=k){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int n = 1;
    while(x > n * (n + 1) / 2) n++;
    cout << n << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
void file(){
    freopen("read.in","r",stdin);
    freopen("write.out","w",stdout);
}
const int N=500010;
inline int read(){
    int sym=0,res=0;char ch=0;
    while (!isdigit(ch))sym|=(ch=='-'),ch=getchar();
    while (isdigit(ch)) res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
    return sym?-res:res;
}
int n,m;
int main(){
    n=read();
    for (int i=1;i<=9;i++){
        if (n%i==0){
            m=n/i;
            if (m>=1&&m<=9){
                printf("Yes");return 0;
            }
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

static const unsigned long long int MOD = 1000000007LL;

long long int a[100001];
long long int step[100001];

long long int solve(int n)
{

    if (step[n] != -1)
    {
        return step[n];
    }

    if (n == 1 || n == 0)
    {
        return 1;
    }

    long long int r1;
    long long int r2;

    r1 = a[n - 1] ? 0 : solve(n - 1) % MOD;
    r2 = a[n - 2] ? 0 : solve(n - 2) % MOD;

    step[n] = (r1 + r2) % MOD;
    return step[n];
}

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

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

    for (int i = 0; i < m; i++)
    {
        int tmp;
        cin >> tmp;
        a[tmp] = 1;
    }

    cout << solve(n);

    return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int k;
int bit[1000010];
void add(int a,int w){
  for(int i = a; i <= k; i += i & -i)bit[i] += w;
}
int sum(int a){
  int ret = 0;
  for(int i = a; i > 0; i -= i & -i) ret += bit[i];
  return ret;
}
int main(){
  long long n,m;cin>>n>>m;
  vector<long long> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
    a[i] -= m;
  }
  vector<long long> b(n+1);
  vector<long long> c(n+1);
  b[0] = 0;
  c[0] = 0;
  for(int i = 1; n >= i; i++){
    b[i] = b[i-1]+a[i-1];
    c[i] = b[i];
  }
  sort(c.begin(),c.end());
  c.erase(unique(c.begin(),c.end()),c.end());
  vector<long long> d(c.size());
  for(int i = 0; n >= i; i++){
    auto z = lower_bound(c.begin(),c.end(),b[i]) - c.begin();
    d[z]++;
  }
  k = c.size();
  for(int i = 1; k >= i; i++){
    //cout << d[i-1] << endl;
    add(i,d[i-1]);
  }
  long long ans = 0;
  for(int i = 0; n >= i; i++){
    
    auto z = lower_bound(c.begin(),c.end(),b[i]) - c.begin();
    ans += max(0,sum(k)-sum(z)-1);
    //cout <<sum(z) << endl;
    //cout <<":" << b[i] << " " << z << endl;
    add(z+1,-1);
  }
  cout << ans << endl;

}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

const int max_n = 200050;
int buka[max_n] = {0};

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    rep(i, n-1){ int tmp; cin >> tmp; buka[--tmp]++;}

    rep(i, n){
        cout << buka[i] << endl;
    }
}



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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

ll solve(ll a,ll b,ll c){
    ll diff = 0x7fffffffffffffff;
    if (a % 2) {
        diff = min(diff, b*c);
    } else {
        diff = 0;
    }
    if (b % 2) {
        diff = min(diff, c*a);
    } else {
        diff = 0;
    }
    if (c % 2) {
        diff = min(diff, a*b);
    } else {
        diff = 0;
    }
    return diff;
}

int main() {
    int a,b,c; cin >>a>>b>>c;
    cout << solve(a,b,c) << endl;
    // cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
// AOJ 2881: Change of the Era Name
// 2018.7.11 bal4u

#include <stdio.h>

int new = (31<<9) + (5<<5) + 1;		// H31.5.1

int main()
{
	int y, m, d, date;
	char era[10], buf[50];
	
	while (fgets(buf, 50, stdin) && *buf != '#') {
		sscanf(buf, "%s%d%d%d", era, &y, &m, &d);
		date = (y<<9) + (m<<5) + d;
		if (date >= new) printf("? %d %d %d\n", y-30, m, d);
		else printf("%s %d %d %d\n", era, y, m, d);
	}
	return 0;
}



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

#define int long long

signed main(){

    int n, m;
    while(cin >> n >> m, n != 0){
        int num = 0;
        int a[30010];
        int b[30010];

        multiset<int> st;
        for(int i = 0;i < n;i++){
            cin >> a[i];
            num += a[i];
            num %= m;
            b[i] = num;
            st.insert(b[i]);
        }

        int ans = 0;

        num = 0;
        for(int i = 0;i < n;i++){
            auto itr = st.lower_bound(num);
            if(itr == st.begin()){
                itr = st.end();
                itr--;
            }else{
                itr--;
            }

            ans = max(ans, (m + (*itr) - num) % m);

            num = b[i];
            st.erase(st.lower_bound(num));
        }
        cout << ans << endl;

    }

    return 0;
}





Measured memory_bytes: 4952
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int fib[1001];

int main()
{
	fib[0] = 2, fib[1] = 3;
	FOR(i, 2, 1001) fib[i] = (fib[i - 1] + fib[i - 2]) % 1001;
	int V, d;
	while (cin >> V >> d)
	{
		vi v;
		REP(i, V) v.push_back(fib[i]);
		sort(ALL(v));
		int cnt = 1;
		REP(i, V-1)
		{
			if (v[i + 1] - v[i] >= d) cnt++;
		}
		cout << cnt << endl;
	}
}

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

using namespace std;

const int INF = numeric_limits<int>::max();
const int MAXN = 1e6 + 100;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    if(s[0] == 'S') {
        cout << "Cloudy";
    }
    else if(s[0] == 'C') {
        cout << "Rainy";
    }
    else if(s[0] == 'R') {
        cout << "Sunny";
    }
    return 0;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 101;
int g[N][N] , a[N * N] , n , H , W;

int main(){
    scanf("%d%d",&H,&W);
    scanf("%d",&n);
    rep(i,0,n) scanf("%d",a + i);
    int x=0,y=0;
    rep(i,0,n) {
        rep(j,0,a[i]) {
            g[x][y]=i+1;
            if(~x&1){
                if(y==W-1) x++;
                else y++;
            } else {
                if(y==0) x++;
                else y--;
            }
        }
    }
    rep(i,0,H) rep(j,0,W) printf("%d%c",g[i][j]," \n"[j+1==W]);
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var dn = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var d = dn[0];
            var n = dn[1];
            var a = (int)Math.Pow(100, d);

            int count = 0;
            int value = 0;

            Func<int, int> TimesOfDivisible = x=>
            {
                int res = 0;
                while(x%100 == 0)
                {
                    x/=100;
                    res++;
                }
                return res;
            };

            while(count < n)
            {
                value++;
                if(TimesOfDivisible(value) == d)
                {
                    count++;
                }
            }

            Console.WriteLine(value);
        }

    }
}


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

int main(){
  int n;
  cin>>n;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  int w=h[0],aw=1;
  for(int i=1;i<n;i++){
    w=max(w,h[i]);
    if(w==h[i]){
      aw++;
    }
  }
  cout<<aw<<endl;
}


Measured memory_bytes: 256
// 2018.09.05 1.5min 1WA

#include <iostream>
using namespace std;


int main() {

    string str;
    cin >> str;

    int opt = 0;
    for(int i=0;i<3;i++){
        if(str.at(i) =='o')opt++;
    }

    cout << 700 + opt*100 << endl;

}

Measured memory_bytes: 256
N, X = map(int, input().split())
pat = [1 for _ in range(N+1)]
mai = [1 for _ in range(N+1)]
for i in range(1, N+1):
  mai[i] = 2 * mai[i-1] + 3
  pat[i] = 2 * pat[i-1] + 1

def cnt_pat(x, n):
  if n == 0:
    return 1
  if x == 1:
    return 0
  if x <= mai[n] // 2:
    return cnt_pat(x-1, n-1)
  if x == mai[n] // 2 + 1:
    return pat[n-1] + 1
  if x < mai[n]:
    return pat[n-1] + 1 + cnt_pat(x-mai[n]//2-1, n-1)
  if x == mai[n]:
    return pat[n]
  
print(cnt_pat(X, N))

Measured memory_bytes: 3064
import java.util.*;

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

        int W = sc.nextInt();
        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        int[] a = new int[N];
        int wl = 0;
        int wr = W;
        int ht = H;
        int hb = 0;

        for(int i=0; i<N; i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            a[i] = sc.nextInt();
        }

        for(int i=0; i<N; i++){
            if(a[i]==1){
                wl = Math.max(wl, x[i]);
            }
            else if(a[i]==2){
                wr = Math.min(wr, x[i]);
            }
            else if(a[i]==3){
                hb = Math.max (hb, y[i]);
            }
            else{
                ht = Math.min(ht, y[i]);
            }
        }
        if(wl<wr && hb<ht){
            System.out.println((wr - wl) * (ht - hb));
        }
        else{
            System.out.println(0);
        }

    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 123;
int n, sz[N], par[N];
ll h[N];
vector <array <int, 2>> g[N];

void dfs(int v, int p) {
	sz[v] = 1;
	par[v] = p;
	for (auto i : g[v]) {
		int to = i[0], w = i[1];
		if (to == p) continue;
		h[to] = h[v] + w;
		dfs(to, v);
		sz[v] += sz[to];
	}
}

bool is_centroid(int v) {
	if (sz[1] - sz[v] > sz[1] / 2) return false;
	for (auto i : g[v]) {
		int to = i[0];
		if (to == par[v]) continue;
		if (sz[to] > sz[1] / 2) return false;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		g[x].pb({y, w});
		g[y].pb({x, w});
	}
	dfs(1, 1);
	int c = -1;
	for (int i = 1; i <= n; i++) {
		if (is_centroid(i)) {
			c = i;
			break;
		}
	}
	memset(& h, 0, sizeof(h));
	memset(& sz, 0, sizeof(sz));
	dfs(c, c);
	ll res = 0, mn = 1e18, flag = 0;
	for (int i = 1; i <= n; i++) {
		res += h[i];
		if (sz[i] * 2 == n)
			flag = h[i];
		if (i != c) mn = min(mn, h[i]);
	}
	if (flag) mn = flag;
	cout << res * 2 - mn;
}


Measured memory_bytes: 17308
import math

N = int(input())

num_digits = int(math.log10(N) + 1)

num = 0
if num_digits % 2 != 0:
    num += (N - (10**(num_digits-1)) + 1)

for i in range(num_digits-1):
    if (i + 1) % 2 != 0: #奇数
        num += 9*10**i
    else:
        pass

print(num)



Measured memory_bytes: 3060
x=range(int(input())-1,-1,-1)
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:_+=P[j+1][1]*P[j][0]-P[j][1]*P[j+1][0]
print(_*0.5)

Measured memory_bytes: 7712
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  vector<ll> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    ans += x[i];
  }
  sort(x.begin(), x.end());
  if (ans % 10 == 0) {
    for (int i = 0; i < N; i++) {
      if (x[i] % 10 != 0) {
        ans -= x[i];
        break;
      }
    }
  }
  if (ans % 10 == 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
	int h,w;
	while(1){
		cin>>h>>w;
		if(h==0 && w== 0) break;
		for(int i=1;i<=h;i++){
			for(int j=1; j<=w; j++){
				if(i==1 || i==h) cout<<"#";
				else if(j==1 || j==w){
					cout<<"#";
				}else{
					cout<<".";
				}
			}
			cout<<"\n";
		}
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3028
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a;
	scanf("%lld",&a);
	puts(a%1000%111==0||a/10%111==0?"Yes":"No");
}

Measured memory_bytes: 128