akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>

#define N 201000
#define ll long long
#define RG register

using namespace std;

inline int read(){
    RG int x=0,t=1;RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}

int n,top,first[N],val[N];
struct mona { int nxt,en,w; } s[N<<1];
inline void Insert(int x,int y,int w) { s[++top]=(mona) { first[x],y,w },first[x]=top; }
struct navi { int x,y; ll w; } si[N*18]; int tot;
inline bool cmp(navi x,navi y) { return x.w<y.w; }

int vis[N],siz[N],Sz,Rt,Mx,Minn; ll dis[N],Min;
inline void Getroot(int k,int fa){
	siz[k]=1; int Max=0;
	for(RG int i=first[k];i;i=s[i].nxt){
		int en=s[i].en; if(en==fa||vis[en]) continue ;
		Getroot(en,k),siz[k]+=siz[en],Max=max(Max,siz[en]);
	}   Max=max(Max,Sz-siz[k]);
	if(Max<Mx) Mx=Max,Rt=k;
}
inline void Getdis(int k,int fa,ll ds){
	dis[k]=ds; if(dis[k]+val[k]<Min) Min=dis[k]+val[k],Minn=k;
	for(RG int i=first[k];i;i=s[i].nxt){
		int en=s[i].en; if(en==fa||vis[en]) continue ;
		Getdis(en,k,ds+s[i].w);
	}   return ;
}
inline void Getsid(int k,int fa){
	si[++tot]=(navi) { k,Minn,Min+dis[k]+val[k] };
	for(RG int i=first[k];i;i=s[i].nxt){
		int en=s[i].en; if(en==fa||vis[en]) continue ;
		Getsid(en,k);
	}   return ;
}
inline void Divide(int k){
	vis[k]=1,Min=val[k],Minn=k; int Cp=Sz;
	for(RG int i=first[k];i;i=s[i].nxt)
		if(!vis[s[i].en]) Getdis(s[i].en,k,s[i].w);
	si[++tot]=(navi) { k,Minn,Min+val[k] };
	for(RG int i=first[k];i;i=s[i].nxt)
		if(!vis[s[i].en]) Getsid(s[i].en,k);
	for(RG int i=first[k];i;i=s[i].nxt){
		int en=s[i].en; if(vis[en]) continue ;
		Sz=siz[k]>siz[en]?siz[en]:Cp-siz[k];
		Mx=1e9,Getroot(en,k),Divide(Rt);
	}   return ;
}

int fa[N];
inline int Find(int x) { if(fa[x]!=x) fa[x]=Find(fa[x]); return fa[x]; }
int main(){
	n=read(); for(RG int i=1;i<=n;++i) val[i]=read(),fa[i]=i;
	for(RG int i=1;i<n;++i){
		int x=read(),y=read(),w=read();
		Insert(x,y,w),Insert(y,x,w);
	}   Sz=n,Mx=1e9,Getroot(1,0),Divide(Rt);
	sort(si+1,si+1+tot,cmp); ll ans=0;
	for(RG int i=1;i<=tot;++i){
		int fx=Find(si[i].x),fy=Find(si[i].y);
		if(fx!=fy) fa[fx]=fy,ans+=si[i].w;
	}   printf("%lld\n",ans);
}


Measured memory_bytes: 70528
h, w = map(int, input().split())
grid = [['#' for i in range(w+2)]]
for i in range(h):
  grid.append(['#'] + [s for s in str(input())] + ['#'])
grid.append(['#' for i in range(w+2)])

ud = [[0 for j in range(w+2)] for i in range(h+2)]
lr = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue

    if ud[i-1][j] > 0:
      ud[i][j] = ud[i-1][j]
    else:
      cnt = 0
      d = i
      while grid[d][j] != '#':
        cnt += 1
        d += 1
      ud[i][j] = cnt

    if lr[i][j-1] > 0:
      lr[i][j] = lr[i][j-1]
    else:
      cnt = 0
      r = j
      while grid[i][r] != '#':
        cnt += 1
        r += 1
      lr[i][j] = cnt

ans = 0
for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    cnt = ud[i][j] + lr[i][j] - 1
    ans = max(ans, cnt)
    #print(i, j, cnt)
print(ans)

Measured memory_bytes: 253064
#include <iostream>
#include <limits>
#include <algorithm>
using namespace std;

int main() {
    int n; cin >> n;
    int minv = numeric_limits<int>::max();
    int maxv = numeric_limits<int>::min();
    while (n--) {
        int r; cin >> r;
        maxv = max(maxv, r - minv);
        minv = min(minv, r);
    }
    cout << maxv << endl;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define V vector<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int s, w;  cin >> s >> w;
    if(s <= w)  cout << "unsafe" << endl;
    else        cout << "safe" << endl;
  	return 0;
}


Measured memory_bytes: 3648
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	/* inline operator ll () { ll x; return scanf("%lld", &x), x; } */
	/* template<class T> inline void operator () (T &x) { x = *this; } */
	/* template<class T, class ...A> inline void operator () (T &x, A &...a) */
	/* { x = *this; this -> operator () (a...); } */
} read;

const int maxn = 2000005, mod = 1000000007;
ll fac[maxn], ifac[maxn];

inline void __d (ll &x) { if (x < 0) x += mod; }

inline ll power (ll x, int k) {
	if (k < 0) k += mod - 1;
	ll res = 1;
	while (k) {
		if (k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

inline ll C (int n, int m) {
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

void combinator_init (int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i ++)
		fac[i] = fac[i - 1] * i % mod;
	ifac[n] = power(fac[n], -1);
	for (int i = n; i; i --)
		ifac[i - 1] = ifac[i] * i % mod;
}

ll F (int n, int m) {
	if (n < 0 or m < 0) return 0;
	return C(n + m + 2, m + 1) - 1;
}

ll G (int x1, int x2, int y1, int y2) {
	/* if (x1 > x2 or y1 > y2) debug("ERROR\n"); */
	/* if (x1 < 0 or y1 < 0) debug("ERROR\n"); */
	-- x1, -- y1;
	return (F(x2, y2) - F(x1, y2) - F(x2, y1) + F(x1, y1) + mod * 2) % mod;
}

int main () {
	combinator_init(2000002);
	int x1 = read, x2 = read, x3 = read, x4 = read, x5 = read, x6 = read;
	int y1 = read, y2 = read, y3 = read, y4 = read, y5 = read, y6 = read;

	ll ans = 0;

	for (int i = x3; i <= x4; i ++)
		(ans += G(x5 - i, x6 - i, y5 - y4 - 1, y6 - y4 - 1) *
		 G(i - x2, i - x1, y4 - y2, y4 - y1) % mod *
		 (1 + i + y4)) %= mod;

	for (int i = y3; i <= y4; i ++)
		(ans += G(x5 - x4 - 1, x6 - x4 - 1, y5 - i, y6 - i) *
		 G(x4 - x2, x4 - x1, i - y2, i - y1) % mod *
		 (1 + i + x4)) %= mod;

	for (int i = x3; i <= x4; i ++)
		(ans += G(i - x2, i - x1, y3 - y2 - 1, y3 - y1 - 1) *
		 G(x5 - i, x6 - i, y5 - y3, y6 - y3) % mod *
		 (mod - i - y3)) %= mod;

	for (int i = y3; i <= y4; i ++)
		(ans += G(x3 - x2 - 1, x3 - x1 - 1, i - y2, i - y1) *
		 G(x5 - x3, x6 - x3, y5 - i, y6 - i) % mod *
		 (mod - i - x3)) %= mod;

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


Measured memory_bytes: 31360
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = long.Parse(spl[0]);
        var k     = long.Parse(spl[1]);


        long min = long.MaxValue;
        var x = n % k;
        var z = n / k;
        min = Math.Min(min, Math.Abs(x));
        min = Math.Min(min, Math.Abs(k*(z+1)-n));
        min = Math.Min(min, Math.Abs(k - n));

        return min;
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int h[110];
    rep(i, n) cin >> h[i];
    int ans = 0;
    rep(i, n) {
        bool ok = true;
        REP(j, 0, i - 1) {
            if(h[j] > h[i]) ok = false;
        }
        ans += ok;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7
 
int main(){
  string a,b;
  cin>>a>>b;
  int x=stoi(a+b);
  VE xx;
  rep(i,1,320){
    xx.push_back(i*i);
  }
  auto itr = find(xx.begin(),xx.end(),x);
  if(itr!=xx.end()){
    print("Yes");
  }else{
    print("No");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int k,s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++)
  {
    for (int j = 0; j <= k;j++){
      int x = s - i - j;
      if(0 <= x && x <= k)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,a[5];
int main()
{
	cin>>n;
	for(int i=1;i<=4;i++)
	{
		a[i]=n%10;
		n/=10;
	}
	
	for(int i=2;i<=4;i++)
	{
		if(a[i]==a[i-1])m++;
		else m=0;
		if(m>=2)
		{cout<<"Yes";
		return 0;
		}
	
	}
	cout<<"No";
	
	
	
	
	
	return 0;
}

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

using namespace std;

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

    char c1 = S[2], c2 = S[3], c3 = S[4], c4 = S[5];
    if (c1 == c2 && c3 == c4) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << endl;
        return 0;
    }

}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int ans = n;
    if(n == 100)
        ++ ans;
    while(--d >= 0)
        ans *= 100;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
"""
解説と提出 #5739708をもとに作成
"""

import sys
sys.setrecursionlimit(10 ** 6)


def solve():
    N = int(input())
    result = [-1] * N
    uvw_map = [[] for _ in range(N)]
    '''枝毎の距離相関図を作る'''
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        uvw_map[u].append([v, w])
        uvw_map[v].append([u, w])
    # 木の頂点を求める
    # -> 任意の場所で良い. 1 とする.
    # 頂点から順に塗っていく
    result[0] = False
    result = paint(uvw_map, 0, result)
    for i in result:
        print(int(i))


def paint(uvw_map, num, result):
    # num に紐づくノードの一覧を取得する
    num_map = uvw_map[num]
    # num との距離に応じて色を決定する
    nums = []
    for v, w in num_map:
        if result[v] != -1:
            continue
        result[v] = result[num] if w % 2 == 0 else not(result[num])
        # # 色分けを行ったものについてのみ記録しておく(num')
        nums.append(v)
    # num' すべてに対して同様の操作を行う
    for n in nums:
        result = paint(uvw_map, n, result)
    return result


if __name__ == '__main__':
    solve()


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

int main () {
  int K, X;
  cin >> K >> X;
  
  for (int i = 0; i < K; i++) {
    cout << X - K + i + 1<< " ";
  }
  for (int i = 0; i < K; i++) {
    if (i == 0) {
      continue;
    }
    cout << X + i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
n=int(input())
a=input()
ans=0

import collections as co
d=co.defaultdict(list)
for x,i in enumerate(a):
    d[i].append(x)

se=set()
for i in d.keys():
    se.add(i)

for pin in range(1000):
    pin=str(pin)
    pin=pin.zfill(3)
    now=-1
    cnt=0
    flag=True
    
    for num in pin:
        if num not in se:
            flag=False
    
        for i in d[num]:
            if i>now:
                now=i
                cnt+=1
                break

    if cnt==3 and flag==True:
        ans+=1
print(ans)


Measured memory_bytes: 4724
def main():
    import collections
    import sys
    input = sys.stdin.buffer.readline
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    input = sys.stdin.readline
    S = [input() for i in range(H)]

    q = collections.deque()
    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1

    flag = True

    r = set()
    ss = []
    start = -1
    goal = -1
    # D = collections.defaultdict(int)
    D = dict()
    for i in range(H):
        for j in range(W):
            if (i, j) in r or S[i][j] == '#':
                continue
            q.append((i, j))
            ss.append(set([(i, j)]))
            r.add((i, j))
            L = len(ss)
            D[(i, j)] = L-1
            while(q):
                x, y = q.popleft()
                for k, l in ((x-1, y), (x+1, y), (x, y-1), (x, y+1)):
                    if 0 <= k <= H-1 and 0 <= l <= W-1 and S[k][l] != '#' and (k, l) not in r:
                        r.add((k, l))
                        D[(k, l)] = L - 1
                        q.append((k, l))
                        ss[-1].add((k, l))
            if start == -1 and (Ch, Cw) in ss[-1]:
                start = L - 1
            if goal == -1 and (Dh, Dw) in ss[-1]:
                goal = L - 1

    if D[Ch, Cw] == D[(Dh, Dw)]:
        print(0)
        exit(0)

    G = [set() for i in range(len(ss))]
    for id, X in enumerate(ss):
        for x, y in X:
            for i in range(x-2, x+3):
                if 0 <= i <= H-1:
                    for j in range(y-2, y+3):
                        if 0 <= j <= W-1:
                            if S[i][j] != '#' and D[(i, j)] != id:
                                G[id].add(D[(i, j)])

    r = set()
    r.add(start)
    q.append((start, 0))
    while(q):
        x, c = q.popleft()
        if x == goal:
            print(c)
            flag = False
            break
        for y in G[x]:
            if y in r:
                continue
            else:
                r.add(y)
                q.append((y, c+1))
    # print(G)
    if flag:
        print(-1)


main()


Measured memory_bytes: 271728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <deque>
#include <map>

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define LEN(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int a[200001],p[2020];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s; cin >>s;
	reverse(ALL(s));
	int i,tmp=1,ans=0;
	for (i=0;i<s.size();i++) {
		a[i]=(tmp*(s[i]-'0'))%2019;
		tmp=(tmp*10)%2019;
	}
	tmp=0;
	for (i=0;i<s.size();i++) {
		tmp=(tmp+a[i])%2019;
		p[tmp]++;
	}
	for (i=0;i<2019;i++) {
		ans+=p[i]*(p[i]-1)/2;
	}
	ans+=p[0];
	cout <<ans;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 4504
#include<stdio.h>
#define MAX 100

int adj[MAX][MAX];
int d[MAX];
int f[MAX];
int flg[MAX];
int time=0;

void dfs(int u,int n){
	
	flg[u]=1;
	d[u]=++time;
	
	for(int i=0;i<n;i++){
		if(adj[u][i]==1 && flg[i]==0){
			dfs(i,n);
		}
	}
	f[u]=++time;
	
	return;
	
}

int main(){
	int n,i,j;
	int x,y,z;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		flg[i]=0;
		for(j=0;j<n;j++)
			adj[i][j]=0;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		for(j=0;j<y;j++){
			scanf("%d",&z);
			adj[x-1][z-1]=1;
		}
	}
	
	for(i=0;i<n;i++){
		if(!flg[i])
			dfs(i,n);
	}
	
	for(i=0;i<n;i++)
		printf("%d %d %d\n",i+1,d[i],f[i]);
	
	return 0;
	
}


Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;
int a[201010];
vector<int> T[201010];
int dp[201010];
using P = pair<int, int>;
stack<P> S;
int ans[201010];
bool used[201010];

void dfs(int cur)
{
    int n = a[cur];
    auto lb = lower_bound(dp, dp + N, n);

    int idx = lb - dp;

    int prev_value = *lb;
    S.push(make_pair(idx, prev_value));
    *lb = n;

    auto lb_inf = lower_bound(dp, dp + N, inf);
    int inf_idx = lb_inf - dp;
    ans[cur] = inf_idx;

    used[cur] = true;

    auto node = T[cur];
    for (int i = 0; i < node.size(); i++) {
        if (used[node[i]]) {
            continue;
        }

        dfs(node[i]);
        P last_op = S.top();
        S.pop();
        dp[last_op.first] = last_op.second;
    }

    used[cur] = false;
}

int main()
{
    rep(i, 0, 201000)
    {
        dp[i] = inf;
    }

    cin >> N;
    rep(i, 0, N)
    {
        cin >> a[i];
    }
    rep(i, 0, N - 1)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        T[u].push_back(v);
        T[v].push_back(u);
    }

    dfs(0);

    rep(i, 0, N)
    {
        cout << ans[i] << endl;
    }
}


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

N, K, *H = map(int, read().split())

H = sorted(H)[::-1]
cnt = 0
for i in range(min(K, N), N, 1):
    cnt += H[i]

print(cnt)

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int main(){
    ll n;
    cin >> n;
    vl p;
    lrep(i,2,n){
        ll cnt=0;
        if(i==2){
            p.pb(2);
            continue;
        }
        lrep(j,2,i-1){
            if(i%j){
                cnt++;
            }
            if(cnt==i-2){
                p.pb(i);
            }
        }
    }
    vl fac;
    lrp(i,p.size()){
        ll m=n;
        fac.pb(0);
        while(m){
            fac.at(i)+=m/p.at(i);
            m /= p.at(i);
        }
    }
    ll ans=1;
    lrp(i,fac.size()){
        ans *= (fac.at(i)+1);
        ans %= 1000000007;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

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

		while (true) {
			final int n = sc.nextInt();
			final int k = sc.nextInt();
			
			if(n == 0 && k == 0){
				break;
			}
			
			ArrayList<Integer> array = new ArrayList<Integer>(k);
			
			boolean white = false;
			for(int i = 0; i < k; i++){
				final int in = sc.nextInt();
				
				if(in == 0){
					white = true;
				}else{
					array.add(in);
				}
			}
			
			Collections.sort(array);
			
			int cur_len = 1;
			int connected_len = 1;
			int max = 1;
			for(int i = 1; i < array.size(); i++){
				//System.out.println(array.get(i) + " <-> " + array.get(i-1) + " => " +cur_len + " " + connected_len);
				
				if(array.get(i) - array.get(i-1) == 1){
					cur_len++;
					if(white){
						connected_len++;
					}
				}else if(array.get(i) - array.get(i-1) == 2){
					if(white){
						max = Math.max(connected_len, max);
						connected_len = cur_len + 2;
					}else{
						max = Math.max(cur_len, max);
					}
					cur_len = 1;
				}else{
					if(white){
						max = Math.max(connected_len, max);
						connected_len = 1;
					}else{
						max = Math.max(cur_len, max);
					}
					cur_len = 1;
				}
			}
			
			if(white){
				max = Math.max(connected_len, max);
			}else{
				max = Math.max(cur_len, max);
			}
			
			System.out.println(max);
		}

	}

}

Measured memory_bytes: 14000
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;

int main(void)
{
	int a;
	cin >> a;
	int bi = a+1, res = 0;
	for (int i = 0; i < a; i++) {
		int c;
		cin >> c;
		bi = min(bi, c);
		if (bi == c)
			++res;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, a[100005];

int abs(int x) {
  return x < 0 ? -x : x;
}

int ans;

int main() {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if(n <= 2) {
    for(int i = 1; i < n; i++)
      printf("%d ", a[i]);
    printf("%d\n", a[n]);
    return 0;
  }
  sort(a + 1, a + n + 1);
  for(int i = n - 1; i > 1; i--) {
    if(abs(a[i] * 2 - a[n]) < abs(a[i - 1] * 2 - a[n])) {
      ans = a[i]; break;
    } else ans = a[i - 1];
  }
  printf("%d %d\n", a[n], ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9

using namespace std;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

int h[1000000];
int N;

int main () {
  cin >> N;
  Rep(i, N) cin >> h[i];

  int ans = 0;
  int tmp = 0;
  bool iscontinued = false;

  Rep(i, N-1) {
    if (h[i] >= h[i+1]) {
      if (iscontinued) {
        tmp++;
        ans = max(ans, tmp);
      } else {
        tmp = 1;
        ans = max(ans, tmp);
        iscontinued = true;
      }
    } else {
      tmp = 0;
      iscontinued = false;
    }
  }

  cout << ans << "\n";
}

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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int q = scanner.nextInt();
		char[][] array = new char[q * 2][1000];
		for (int i = 0; i < q * 2; i++) {
			array[i] = scanner.next().toCharArray();
		}

		for (int l = 0; l < q * 2; l += 2) {
			int n = array[l].length;
			int m = array[l + 1].length;
			int[][] dp = new int[n + 1][m + 1];
			boolean flag = false;
			char[] a = Arrays.copyOf(array[l],n);
			char[] b = Arrays.copyOf(array[l+1], m);
			for (int i = 1; i < n + 1; i++) {
				for (int j = 1; j < m + 1; j++) {
					//System.out.println(array[0][i - 1] + ":" +array[1][j - 1]);
					if (a[i - 1] == b[j - 1]) {
						dp[i][j] += dp[i - 1][j - 1] + 1;
					} else {
						dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
					}
				}
			}
//			for (int i = 0; i < n + 1; i++) {
//				for (int j = 0; j < m + 1; j++) {
//					System.out.print(dp[i][j]);
//				}
//				System.out.println();
//			}

			System.out.println(dp[n][m]);
		}
	}
}

Measured memory_bytes: 64108
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=0;
	fo(i,0,3030) fo(j,0,3030) if(d-a*i-b*j>=0&&(d-a*i-b*j)%c==0)ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


template<class T>
bool chmax(T &a, const T &b) {
    if (a < b)
    {
        return b;
    }
    return a; 
}

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

int main() {
    ll n; cin >> n;
    vector<ll> t(n); ll same_direction = 0;
    cin >> same_direction;
    REP(i, 1, n) {
        cin >> t[i];
        same_direction = lcm(same_direction, t[i]);
        // cout << same_direction << endl;
    }
    cout << same_direction << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    int cn;
    cin >> s;
    cin >> cn;
    for (int i=0;i<cn;i++){
        string c;
        cin >> c;
        if (c=="print"){
            int a,b;
            cin >> a >> b;
            for (int i=a;i<=b;i++)
                cout << s[i];
            cout << endl;
        }
        if (c=="reverse"){
            int a,b;
            cin >> a >> b;
            char t;
            for (int i=0;i<=(b-a)/2;i++){
                t=s[a+i];
                s[a+i]=s[b-i];
                s[b-i]=t;
            }
        }
        if (c=="replace"){
            int a,b;
            string r;
            cin >> a >> b >> r;
            s.replace(a,b-a+1,r);
        }
    }
}


Measured memory_bytes: 3220
s=input()
i=0
flag=1
for c in s:
    i+=1
    if i%2:
        if not(c=='R' or c=='U' or c=='D'):
            print("No")
            flag=0
            break
    else:
        if not(c=='L' or c=='U' or c=='D'):
            print("No")
            flag=0
            break
if flag: print("Yes")
            

Measured memory_bytes: 3060
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

//DEBUG_OUT("----\n");

void func(void)
{
    int N, n;
    cin >> N;
    n = N;

    int f = 0;
    for(int i=0; i<10; i++){
        f += N % 10;
        N /= 10;
    }
    DEBUG_OUT("f = %d\n", f);
    if(n%f == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <string>
#include <cmath>

int main() {
    std::array<int, 7> cnt_rank{};
    int n;

    std::cin >> n;

    for (; n--;) {
        double height;
        std::cin >> height;
        
        height -= 165.;
        
        if (height < 0) {
            ++cnt_rank[0];
        }
        else {
            int rank;
            rank = std::min((int)(height / 5 + 1), 6);

            ++cnt_rank[rank];
        }
    }
    
    for (int i = 0; i < 6; ++i) {
        std::cout << i + 1 << ":" << std::string(cnt_rank[i], '*')
                  << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 1244
import sys
input = sys.stdin.readline
from collections import deque
R,C,N=map(int,input().split())
table=[]
def f(i,j):
    if i==0:
        return j
    if j==C:
        return C+i
    if i==R:
        return R+C+C-j
    if j==0:
        return R+R+C+C-i
for i in range(N):
    a,b,c,d=map(int,input().split())
    if (0<a<R and 0<b<C) or (0<c<R and 0<d<C):
        continue
    table.append((f(a,b),i))
    table.append((f(c, d), i))
table.sort()
H=deque()
for i in range(len(table)):
    if len(H)!=0 and H[-1]==table[i][1]:
        H.pop()
    else:
        H.append(table[i][1])
#print(H,table)
while len(H)!=0 and H[0]==H[-1]:
    H.popleft()
    H.pop()
if len(H)==0:
    print('YES')
else:
    print('NO')

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

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').ToArray();
            var S = input[0];
            var T = input[1];

            var result = string.Empty;
            for (int i = 0; i < N; i++)
            {
                result += S[i].ToString() + T[i].ToString();
            }
            Console.WriteLine(result);
        }
    }
}

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

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

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

  if(S.at(0)==S.at(1)&&S.at(2)==S.at(3)&&S.at(0)!=S.at(2))
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	int res = 0;
	for (int i = 0; i < n; i++) {
		a[i] = ri();
		for (int j = 0; j < i; j++) res += a[i] * a[j];
	}
	std::cout << res << std::endl;
	return 0;
}



Measured memory_bytes: 256
#agc008-a
x,y=map(int,input().split())
ans=float('inf')

#反転させるかどうか決めた後のx,yの上下関係を考える
#0,0
if y-x>0:
    ans=min(ans,y-x)
#1,0
if -x<=y:
    ans=min(ans,1+y+x)
#0,1
if x<=-y:
    ans=min(ans,1+-y-x)
#1,1
if -x<=-y:
    ans=min(ans,2+-y+x)
print(ans)

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

using namespace std;

int main(void){
    string s, t;
    cin >> s >> t;
    t[t.length() - 1] =  ' ';
    s += ' ';
    if(s == t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3600
import sys

def match(a,b):
    return a == '?' or b== '?' or a == b


def solve(a, b, c):
    a = list(a)
    b = list(b)
    c = list(c)
    ab = [False] * 100000
    ac = [False] * 100000
    bc = [False] * 100000
    for i in range(len(a)):
        for j in range(len(b)):
            if not match(a[i],b[j]):
                ab[i-j+50000] = True
    for i in range(len(b)):
        for j in range(len(c)):
            if not match(b[i],c[j]):
                bc[i-j+50000] = True
    for i in range(len(a)):
        for j in range(len(c)):
            if not match(a[i],c[j]):
                ac[i-j+50000] = True
    M = max(len(a),len(b),len(c))
    ans = M*3
    for i in range(-M*2,M*2+1):
        for j in range(-M*2,M*2+1):
            if not ab[i + 50000] and not ac[j + 50000] and not bc[j-i + 50000]:
                L = min(i,j,0)
                R = max(len(a),len(b)+i,len(c)+j)
                ans = min(ans,R-L)
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = next(tokens)  # type: str
    b = next(tokens)  # type: str
    c = next(tokens)  # type: str
    solve(a, b, c)

if __name__ == '__main__':
    main()



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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

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

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(){
  int n, m;

  while(cin >> n >> m, n and m){
    vector<bool> hatake(8000000, false);
    int cnt = 0;
    vector<int> v;

    for(int i = n;;i++){
      bool jud = false;

      if(cnt == m and !hatake[i]){
        cout << i << endl;
        break;
      }

      if(!hatake[i] and cnt < m){
        v.pb(i);
        int a = 1;
        while(i * a < 8000000){
          hatake[a*i] = true;
          a++;
        }
        cnt ++;
      }

    }
  }
  return 0;

}


Measured memory_bytes: 7728
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

main()
{   FAST;
    int t,n,c=0,k;
    cin>>t;
    map<int,int>mp;
    for(int i=0;i<t;i++){
        cin>>k;
        mp[k]++;
    }
    for(auto it:mp){
        if(it.second &1) c++;
    }
    cout<<c;
}

Measured memory_bytes: 8320
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iterator>

using namespace std;

void dfs(vector <set <int>>& g, int v, int c, vector <int>& colors) {
	colors[v] = c;
	for (auto to : g[v]) {
		if (colors[to] == -1)
			dfs(g, to, c, colors);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	vector <set <int> > g(n);
	vector <set <int> > a(n);
	vector <set <int> > b(n);
	vector <int> colors(n, -1);
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		a[u].insert(v);
		a[v].insert(u);
		g[u].insert(v);
		g[v].insert(u);
	}
	for (int i = 0; i < k; ++i) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		b[u].insert(v);
		b[v].insert(u);
		g[u].insert(v);
		g[v].insert(u);
	}
	int color = 0;
	vector <int> ans(n);
	for (int i = 0; i < n; ++i) {
		if (colors[i] == -1)
			dfs(a, i, color, colors);
		
		/*int cnt = 0;
		for (auto to : b[i]) {
				if (colors[to] == colors[i])
					++cnt;
				
			}
		ans[i] = comp.size() - a[v].size() - cnt;*/
		
		color++;
	}
	vector <int> sizes(color);
	for (int i = 0; i < n; ++i) {
		sizes[colors[i]]++;
	}
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		for (auto to : b[i]) {
			if (colors[to] == colors[i])
				++cnt;

		}
		cout << sizes[colors[i]] - a[i].size() - cnt - 1 << ' ';
	}
	return 0;
}

Measured memory_bytes: 55168
#include<stdio.h>
int binsearch(int, int [], int);

int main(){
  int n, i, q, c = 0;
  scanf("%d", &n);
  int S[n];
  for(i = 0; i < n; i++) scanf("%d", &S[i]);
  
  scanf("%d", &q);
  int T[q];
  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
    if(binsearch(n, S, T[i]) == 1) c += 1;
  }

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

  return 0;
}

int binsearch(int n, int A[], int key){
  int left = 0, right = n;
  int mid;

  while(left < right){
    mid = (left + right) / 2;

    if(A[mid] > key) right = mid;
    if(A[mid] < key) left = mid + 1;
    if(A[mid] == key) return 1;

  }
  return 0;
}
				       


  



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

char buf[512][512];
char dat[5] = "RYGB";
set<pair<int, int> > vis;
int r, c, D;

int foo(int x)
{
	if (x <= 0) return -x;
	return x-1;
}

void dfs(int cx, int cy, int typ)
{
	auto it = vis.lower_bound(make_pair(cx, cy));
	if (it == vis.end() || *it != make_pair(cx, cy))
		vis.insert(it, make_pair(cx, cy));
	else
		return;
	bool did = false;
	int d = (D+1)/2;
	if (D&1)
	{
		for (int i = -d+1;i <= d-1;i++) for (int j = abs(i)-d+1;j <= d-abs(i)-1;j++)
		{
			if (cx+i >= 0 && cx+i < r && cy+j >= 0 && cy+j < c)
			{
				buf[cx+i][cy+j] = dat[typ];
				did = true;
			}
		}
		if (did)
		{
			dfs(cx+d, cy+d-1, typ^1);
			dfs(cx-d, cy-d+1, typ^1);
			dfs(cx+d-1, cy-d, typ^2);
			dfs(cx-d+1, cy+d, typ^2);
		}
	} else
	{
		for (int i = -d+1;i <= d-1;i++) for (int j = abs(i)-d+1;j <= d-abs(i);j++)
		{
			if (cx+i >= 0 && cx+i < r && cy+j >= 0 && cy+j < c)
			{
				buf[cx+i][cy+j] = dat[typ];
				did = true;
			}
		}
		if (did)
		{
			dfs(cx, cy+d+d, typ^1);
			dfs(cx, cy-d-d, typ^1);
			dfs(cx+d, cy+d, typ^2);
			dfs(cx-d, cy-d, typ^2);
		}
	}
}

int main()
{
	scanf("%d%d%d", &r, &c, &D);
	dfs(0, 0, 0);
	for (int i = 0;i < r;i++)
	{
		for (int j = 0;j < c;j++)
		{
#ifdef DEBUG
			if (buf[i][j] == 'R') printf("\x1b[31m");
			else if (buf[i][j] == 'G') printf("\x1b[32m");
			else if (buf[i][j] == 'Y') printf("\x1b[33m");
			else if (buf[i][j] == 'B') printf("\x1b[34m");
			if (buf[i][j] == 0) buf[i][j] = ' ';
#endif
			printf("%c", buf[i][j]);
#ifdef DEBUG
			printf("\x1b[0m");
#endif
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 35968
#include<bits/stdc++.h>
using namespace std;
const long long int mod=1e9+7;
typedef long long ll;
long long int wy(long long int a,long long int b)
 {
 	long long int res=1;
 	while (b)
 	{
 		if (b&1) res=res*a%mod;
 		a=a*a%mod;
 		b>>=1;
	 }
	 return res;
  } 
  int main()
  {
  	long long int n,m;
  	scanf("%lld",&n);
  	if (n==2) {
  		printf("%lld\n",n); return 0;
	  }
	  else if (n<2) {
	  	printf("%lld\n",0); return 0;
	  }
  	m=(wy(10,n)-wy(9,n)-wy(9,n)+wy(8,n))%mod; 	
  	if (m<0) m+=mod;
  	printf("%lld\n",m);
  	return 0;
  }

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,W;
    cin>>n>>W;
    vint w(n+1);
    vint v(n+1);
    REP(i,1,n+1){
	cin>>w[i]>>v[i];
    }
    vector<vector<ll> > dp(n+1,vector<ll>(W+1));
    REP(i,1,n+1){
	rep(j,W+1){
	    if(j-w[i]>=0){
		dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
	    }
	    else{
		dp[i][j]=dp[i-1][j];
	    }
	}
    }
    cout<<dp[n][W]<<'\n';
    return(0);
}


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

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

inline int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

const int INF=1e9+9;

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

    int n;
    cin >> n;
    vector<ll> A(n);

    for(auto &i: A)
        cin >> i;
    sort(A.begin(),A.end());
    ll res=A[0];

    FOR(i,1,n){
        res=gcd(res,A[i]);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, ans = 0; cin >> n;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        while(1) {
            if(a % 2 == 0) {
                ans++;
                a /= 2;
            } else {
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// Problem : C - One Quadrillion and One Dalmatians
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	vlli ans;
	int n;
	cin>>n;
	int k=n;
	
	while(k){
		k--;
		ans.pb(k%26);
		k/=26;
	}	
	reverse(all(ans));
	string A="";
	FOR(i,ans.size()){
		// if(ans[i]==0)
		// {
			// A[A.size()-1]='z';
			// continue;
		// }
		A+=('a'+ans[i]);
	}
	cout<<A;
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


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

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


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        readonly static long mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = s[0];
            int m = s[1];

            if (Abs(n - m)>=2)
            {
                WriteLine(0);
                return;
            }
            long tmp = 1;
            int i = Max(n,m);
            while (i > 0)
            {
                tmp *= i;
                tmp %= mod;
                i--;
            }

            long hoge = 1;
            int j = Min(n,m);
            while (j > 0)
            {
                hoge *= j;
                hoge %= mod;
                j--;
            }

            WriteLine(
                Abs(n-m) == 1 ? ((tmp% mod) * hoge) % mod: (((tmp * 2) % mod) * hoge) % mod
                );
        }

    }

}


Measured memory_bytes: 13396
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
  	int[] al=new int[n];
    for(int a=0;a<n;a++){
    int b=sc.nextInt();
    al[a]=b;
    b=0;
    }
    int total=0;
    for(int c=0;c<n;c++){
      for(int d=0;d<n;d++){
        if(d!=c){
    total+=al[c]*al[d];}}
    }
    System.out.println(total/2);
    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int n, m;
    cin >> n >> m;
    vector<bool> is_possible(n, false);
    vector<int> num(n, 1);
    is_possible[0] = true;

    rep(i, m){
        int x, y;
        cin >> x >> y;
        --x;
        --y;

        --num[x];
        ++num[y];
        if(is_possible[x]){
            is_possible[y] = true;
            if(num[x]==0) is_possible[x] = false;
        }
    }

    int res = 0;
    rep(i, n){
        res += is_possible[i];
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, x: int, a: "List[int]"):
    ans = sum(a)

    if a[0] > x:
        a[0] = x

    for i in range(N-1):
        if a[i]+a[i+1] > x:
            a[i+1] -= (a[i]+a[i+1]-x)

    print(ans-sum(a))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15496