akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 貪欲法

ll f(vector<P> p) {
  int n = p.size();
  rep(i, n) p[i].first = min(p[i].first, n);
  vector<vector<int>> s(n + 1);
  rep(i, n) s[p[i].first].push_back(p[i].second);

  ll res = 0;
  priority_queue<int> q;
  for (int i = n; i >= 1; --i) {
    for (int x : s[i]) q.push(x);
    if (q.size() > 0) {
      res += q.top();
      q.pop();
    }
  }
  return res;
}

void solve() {
  int n;
  cin >> n;
  vector<P> pl, pr;
  ll ans = 0;
  rep(i, n) {
    int k, l, r;
    cin >> k >> l >> r;
    int m = min(l, r);
    ans += m;
    l -= m;
    r -= m;
    if (l > 0)
      pl.emplace_back(k, l);
    else
      pr.emplace_back(n - k, r);
  }
  ans += f(pl);
  ans += f(pr);
  cout << ans << endl;
}

int main() {
  int ts;
  cin >> ts;
  rep(ti, ts) solve();
  return 0;
}


Measured memory_bytes: 10472
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;

int n, ans = 1;

int main()
{
	scanf ("%d", &n);
	for (int i = 0; i <= n; i++){
		if (ans > n)	break;
		ans *= 2;
		//printf ("%d\n", ans);
	}
	printf ("%d\n", ans / 2);
}


Measured memory_bytes: 128
h,w,kk=list(map(int,input().split()))
s=[list(map(int,list(input()))) for i in range(h)]
l=[]
for i in range(2**(h-1)):
  ll=[0]
  for j in range(h-1):
    if i & 2**j:
      ll.append(ll[-1]+1)
    else:
      ll.append(ll[-1])
  l.append(ll)

mc=w+h
for i in l:
  c=[0 for i in range(h)]
  cc=0
  f=1
  #print(i,0)
  for j in range(w):
    #print(c)
    ff=0
    for k in range(h):
      c[i[k]]+=s[k][j]
    for k in range(h):
      if c[k]>kk:
        ff=1
        break
    if ff:
      cc+=1
      c=[0 for i in range(h)]
      for k in range(h):
        c[i[k]]+=s[k][j]
      for k in range(h):
        if c[k]>kk:
          f=1
      if f:
        cc=w+h
        #print(c)
        break
    f=0
  #print(cc)
  if mc>cc+len(set(i))-1:
    mc=cc+len(set(i))-1
print(mc)

Measured memory_bytes: 9268
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

typedef pair<int,int> pii;

struct edge{int to,cost;};
const int INF = 1000000000;
const int MAX_V = 100000;

int main(){
  int V,E,r;
  int d[MAX_V];
  vector<edge> G[MAX_V];
  priority_queue<pii,vector<pii>,greater<pii> > q;
  scanf("%d %d %d",&V,&E,&r);
  for(int i=0;i<E;i++){
    int s,t,d;
    scanf("%d %d %d",&s,&t,&d);
    edge e;
    e.cost = d; e.to = t;
    G[s].push_back(e);
  }
  fill(d,d+V,INF);
  d[r] = 0;
  q.push(pii(0,r));

  while(!q.empty()){
    pii p = q.top(); q.pop();
    int v = p.second;
    if(p.first>d[v]) continue;
    for(int i=0;i<G[v].size();i++){
      if(d[G[v][i].to]>d[v]+G[v][i].cost){
        d[G[v][i].to] = d[v] + G[v][i].cost;
        q.push(pii(d[G[v][i].to],G[v][i].to));
      }
    }
  }
  for(int i=0;i<V;i++){
    if(d[i]==INF) printf("INF\n");
    else printf("%d\n",d[i]);
  }
  return 0;
}

Measured memory_bytes: 12632
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define int ll

int fact[114514]={};

void f(){
    fact[0] = fact[1] = 1;
    for(int i=2;i<114514;i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

signed main(){
    int n,m;
    scanf("%lld%lld",&n,&m);
    if(abs(n-m)>=2){
        printf("0\n");
        return 0;
    }

    f();
    int ans = fact[n] * fact[m] % MOD;

    if(n==m) ans = ans*2%MOD;

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

Measured memory_bytes: 1152
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
		new Main().run();
	}
 
	void run() {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long n = S.length();
		long[][] cnt = new long[S.length()][26];
		for (int i = 0; i < S.length(); ++i) {
			cnt[i][S.charAt(i) - 'a']++;
			for (int j = 0; j < 26 && i > 0; ++j) {
				cnt[i][j] += cnt[i - 1][j];
			}
		}
		long ans = n * (n - 1) / 2 + 1;
		for (long i = n - 1; i >= 0; --i) {
			ans -= cnt[(int)n - 1][S.charAt((int)i) - 'a'] - cnt[(int)i][S.charAt((int)i) - 'a'];
		}
		// for (int i = 0; i + 1 < n; ++i) {
		// for (int j = 0; j < 2; ++j) {
		// int l, r;
		// if (j == 0) {
		// l = i - 1;
		// r = i + 1;
		// } else {
		// l = i;
		// r = i + 1;
		// }
		// while (l >= 0 && r < n) {
		// if (S.charAt(l) != S.charAt(r)) {
		// ++ans;
		// }
		// --l;
		// ++r;
		// }
		// }
		// }
		System.out.println(ans);
	}
 
	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    int a[n];
    long double sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sum=round(sum/n);
    long long cost=0;
    for(int i=0;i<n;i++){
        cost+=((sum-a[i])*(sum-a[i]));
    }
    cout<<cost;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<b+min(c,a+b+1)<<endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[110];
int main () {
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i=1;i<=n;i++) {
		if (s[i]=='L'&&i%2) {printf("No\n");return 0;}
		if (s[i]=='R'&&(!(i%2))) {printf("No\n");return 0;}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define sc1(n) scanf("%lld",&n)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MX 100000
using namespace std;

typedef long long int ll;
typedef unsigned long long ul;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
char A[3005];
char B[3005];
string ans;
ll dp[3005][3005];
ll lcs(ll i,ll j)
{
    if(A[i]=='\0'||B[j]=='\0')
    {
        return 0;
    }
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll ret=0;
    if(A[i]==B[j])
    {
        ret=1+lcs(i+1,j+1);
    }
    else
    {
        ll v1=lcs(i+1,j);
        ll v2=lcs(i,j+1);
        ret=max(v1,v2);
    }
    return dp[i][j]=ret;
}
void printlcs(ll i,ll j)
{
    if(A[i]=='\0'||B[j]=='\0')
    {
        return;
    }
    if(A[i]==B[j])
    {
        printf("%c",A[i]);
        printlcs(i+1,j+1);
    }
    else
    {
        if(dp[i+1][j]>dp[i][j+1])
        printlcs(i+1,j);
        else
        printlcs(i,j+1);
    }
    return ;
}
int main()
{
    memset(dp,-1,sizeof dp);
    scanf("%s%s",A,B);
    lcs(0,0);
    printlcs(0,0);
    printf("\n");
    return 0;
}


Measured memory_bytes: 71040
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 200000
using namespace std;
int n,a[N+5],s[N+5],nxt[N+5],fir[N+5],lst[N+5];long long k;
class FastIO
{
	private:
		#define FS 100000
		#define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
		#define pc(c) (C==E&&(clear(),0),*C++=c)
		#define tn (x<<3)+(x<<1)
		#define D isdigit(c=tc())
		int T;char c,*A,*B,*C,*E,FI[FS],FO[FS],S[FS];
	public:
		I FastIO() {A=B=FI,C=FO,E=FO+FS;}
		Tp I void read(Ty& x) {x=0;W(!D);W(x=tn+(c&15),D);}
		Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);}
		Tp I void write(Ty x) {W(S[++T]=x%10+48,x/=10);W(T) pc(S[T--]);}
		Tp I void write(Con Ty& x,Con char& y) {write(x),pc(y);}
		I void clear() {fwrite(FO,1,C-FO,stdout),C=FO;}
}F;
int main()
{
	RI i,p=1,t=1,cnt=0;for(F.read(n,k),i=1;i<=n;++i) F.read(a[i]),!fir[a[i]]&&(fir[a[i]]=i);
	for(i=n;i;--i) !lst[a[i]]?(nxt[i]=fir[a[i]]):(nxt[i]=lst[a[i]]),lst[a[i]]=i;
	W(true) if(nxt[p]<=p&&++t,p=nxt[p],p^n) ++p;else break;k%=t,p=t=1;
	W(t<k) nxt[p]<=p&&++t,p=nxt[p],p^n?++p:(p=1,++t);
	W(p<=n) nxt[p]<=p?(F.write(a[p],' '),0):p=nxt[p],++p;return F.clear(),0;
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 200005;

i64 a[MAXN];

i64 n, k;

i64 merge(vector<i64>& arr, const vector<i64>& left, const vector<i64>& right) {
    i64 i = 0, j = 0, count = 0;
    while (i < left.size() || j < right.size()) {
        if (i == left.size()) {
            arr[i + j] = right[j];
            j++;
        }
        else if (j == right.size()) {
            arr[i + j] = left[i];
            i++;
        }
        else if (left[i] <= right[j]) {
            arr[i + j] = left[i];
            i++;
        }
        else {
            arr[i + j] = right[j];
            count += left.size() - i;
            j++;
        }
    }
    return count;
}

i64 invCount(vector<i64>& arr) {
    if (arr.size() < 2) {
        return 0;
    }

    i64 m = (arr.size() + 1) / 2;
    vector<i64> left;
    left.resize(m);
    memcpy(left.data(), arr.data(), sizeof(i64) * m);

    i64 n = arr.size() - m;
    vector<i64> right;
    right.resize(n);
    memcpy(right.data(), arr.data() + m, sizeof(i64) * n);
    
    return invCount(left) + invCount(right) + merge(arr, left, right);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> k;

    vector<i64> a;
    a.resize(n);

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

    i64 R = 1;
    set<i64> q;

    i64 TR = 0;
    i64 t = 0;
    for (i64 i = 0; i < k; i++) {
        q.insert(a[i]);
        if (i > 0) {
            if (a[i] < a[i - 1]) {
                t = 0;
            }
            else {
                t++;
            }
        }
    }

    if (t == k - 1) {
        TR++;
    }

    for (i64 j = 0; j + k < n; j++) {
        q.insert(a[j + k]);

        if (a[j + k] < a[j + k - 1]) {
            t = 0;
        }
        else {
            t++;
        }
        if (t == k - 1) {
            TR++;
        }

        if (!(*q.begin() == a[j] && *q.rbegin() == a[j + k])) {
            R++;
        }
        q.erase(a[j]);
    }

    cout << R - max(0ll, TR - 1) << endl;

    return 0;
}


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long N, long long A) {
  cout << N * N - A << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  solve(N, A);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int selectionSort(int A[], int N){
    int i, j, t, sw = 0, minj;
    for(i = 0; i < N; i++){
        minj = i;
        for(j = i; j < N; j++){
            if(A[j] < A[minj]) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if(i != minj) sw++;
    }
    return sw;
}

int main(void){
    int A[100], N, i, sw;
    
    scanf("%d", &N);
    for(i = 0; i < N; i++) scanf("%d", &A[i]);
    
    sw = selectionSort(A, N);
    
    for(i = 0; i < N; i++){
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    
    return 0;
}

Measured memory_bytes: 604
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	cout << min({ a,b,c }) << " " << max({ a,b,c }) << endl;
}


Measured memory_bytes: 3100
// https://atcoder.jp/contests/abc159/tasks/abc159_b

#include <iostream>
#include <string>

using namespace std;

bool is_palindrome(string s) {
    const int N = s.size();
    for (int i = 0; i < N / 2; ++i) {
        if (s[i] != s[N - 1 - i]) return false;
    }
    return true;
}

bool solve(string s) {
    const int N = s.size();
    auto s1 = s.substr(0, (N-1)/2);
    auto s2 = s.substr((N+3)/2 - 1);
    return
        is_palindrome(s) &&
        is_palindrome(s1) &&
        is_palindrome(s2);
}

int main() {
    string S;
    cin >> S;
    auto ans = solve(S);
    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/b.in", "r", stdin);
//  freopen("../IO/b.in", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n, m;
  in >> n >> m;
  int sum = 0;
  for (int i = 0, x; i < m; ++i) {
    in >> x;
    sum += x;
  }
  n -= sum;
  out << max(-1, n) << '\n';
}


Measured memory_bytes: 3672
program C086
    implicit none
    integer(8) :: N
    integer(8), allocatable, dimension(:) :: t, x, y
    integer(8) :: i, d, ju, dt 

    read(5,*) N
    allocate(t(N))
    allocate(x(N))
    allocate(y(N))
    do i = 1, N
        read(5,*) t(i), x(i), y(i)
    end do

    ju = 0
    d = x(1) + y(1)
    if (d<=t(1)) then
        if (mod(t(1)-d,2)/=0) then
            ju = ju + 1
        end if
    else
        ju = ju + 1
    end if

    do i = 2, N
        d = abs(x(i)-x(i-1)) + abs(y(i)-y(i-1))
        dt = t(i) - t(i-1)
        if (d<=dt) then
            if (mod(dt-d,2)/=0) then
                ju = ju + 1
            end if
        else
            ju = ju + 1
        end if


    end do

    if (ju == 0) then
        write(6,*) "Yes"
    else
        write(6,*) "No"
    end if

    





    
end program C086

Measured memory_bytes: 5144
s = input()
n = len(s)-1

bins= []

for i in range(2**n):
    bins.append(list(str(format(i,'b')).zfill(n)))

ans = 0
for i in range(2**n):
    sum = 0
    temp = str(s[0])
    for j in range(n):
        if bins[i][j] == '0':
            sum += int(temp)
            temp = ''
            temp += str(s[j+1])
        
        else:
            temp += str(s[j+1])
    sum += int(temp)
    

    ans += sum

print(ans)

Measured memory_bytes: 39664
class node:
    def __init__(self):
        self.number = 0
        self.in_time    = 0
        self.out_time   = 0
        self.link_node  = []
        self.is_serched = False

def dfs_visit(node, timer):
    node.in_time    = timer
    node.is_serched = True
    temp            = timer + 1

    for item in node.link_node:
        if item.is_serched == False:
            temp = dfs_visit(item, temp)
    node.out_time = temp
    return node.out_time + 1

n = input()
node_list = [None] * (n + 1)

for i in xrange(1, n + 1):
    node_list[i] = node()
    node_list[i].number = int(i)

for i in xrange(1, n + 1):
    line = raw_input().split()
    for node_num in line[2 : ]:
        node_list[i].link_node.append(node_list[int(node_num)])

temp = 1
for item in node_list[1 : ]:
    if item.is_serched == False:
        temp = dfs_visit(item, temp)

for item in node_list[1 : ]:
    print '%s %s %s' % (str(item.number), str(item.in_time), str(item.out_time))
    

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string a, b;
	cin >> a >> b;
	if (a>b) {
		cout << ">" << endl;
	}
	else if(a<b){
		cout << "<" << endl;
	}
	else {
		cout << "=" << endl;
	}
	return 0;
}



Measured memory_bytes: 3572
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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



  ll N;
  cin >> N;

  ll arr[N];
  for (ll i = 0; i < N; i++) {
    cin >> arr[i];
  }

  ll dp[N];
  dp[0] = 0;
  dp[1] = abs(arr[1] - arr[0]);

  for (int i = 2; i < N; i++) {
    dp[i] = min(dp[i - 2] + abs(arr[i] - arr[i - 2]),
                dp[i - 1] + abs(arr[i] - arr[i - 1]));
  }

  cout << dp[N - 1];
}

Measured memory_bytes: 1792
import numpy as np

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

srtX = sorted(X)

low = srtX[int(N / 2) - 1]
high = srtX[int(N / 2)]

ans = []
for x in X:
    if x < high:
        ans.append(high)
    else:
        ans.append(low)

for a in ans:
    print(a, end=' ')


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

// macros
#define overload_rep(va_0, va_1, va_2, name, ...) name
#define rep_0(i, n) for(int i = 0; i < (n); ++i)
#define rep_1(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations
int N, M, Q;
int cnt[2001][2001];
int vert[2000][2001], side[2001][2000];
bool grid[2000][2000];

// solve
int main(){

    cin >> N >> M >> Q;
    rep(i, N)rep(j, M){
        char c;
        cin >> c;
        grid[i][j] = (c == '1');
        cnt[i + 1][j + 1] = int(grid[i][j]) + cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j];
    }

    rep(i, N - 1)rep(j, M)vert[i + 1][j + 1] += int(grid[i][j] && grid[i + 1][j]) + vert[i + 1][j] + vert[i][j + 1] - vert[i][j];
    rep(i, N)rep(j, M - 1)side[i + 1][j + 1] += int(grid[i][j] && grid[i][j + 1]) + side[i + 1][j] + side[i][j + 1] - side[i][j];

    while(Q--){
        int x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << (cnt[x2][y2] - cnt[x1 - 1][y2] - cnt[x2][y1 - 1] + cnt[x1 - 1][y1 - 1]) - ((vert[x2 - 1][y2] - vert[x1 - 1][y2] - vert[x2 - 1][y1 - 1] + vert[x1 - 1][y1 - 1]) + (side[x2][y2 - 1] - side[x1 - 1][y2 - 1] - side[x2][y1 - 1] + side[x1 - 1][y1 - 1])) << '\n';
    }

}


Measured memory_bytes: 52608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    
    vector<ll> a(n),c(n+1);

    for(int i = 0; i < n;i++){
        cin >> a[i];
        c[a[i]]++;
    }

    ll ans=0;

    for(int i = 1; i < n+1;i++){
        ans += (ll)(c[i]*(c[i]-1)/2);
    }

    for(int i = 0; i < n;i++){
        cout << ans - (ll)(c[a[i]]-1) << endl;
    }



}

Measured memory_bytes: 5760
N, P = map(int, input().split())
A = list(map(int, input().split()))
ev = 0
od = 0
for a in A:
    if a % 2 == 0:
        ev += 1
    else:
        od += 1
if P == 0 and od == 0:
    print(2**ev)
else:
    print(2**ev * (2**od//2))


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define l1 long
#define ld long double
#define lld long long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x) cout<<"$ "<<x<<" $"<<endl
#define bug(x) cout<<"& "<<x<<" &"<<endl
#define all(v) v.begin(),v.end()
#define lop1(i,j,n) for(int i=j; i<n; ++i)
#define lop2(i,j,n) for(int i=j; i<=n; ++i)
#define lop3(i,n,j) for(int i=n; i>j; --i)
#define lop4(i,n,j) for(int i=n; i>=j; --i)
#define view(v) for(auto i: v) cout<<i<<" "
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
const ll M=1e9+7;
const ld PI=3.1415926536;
//int p[N];
//int find(int k){ return p[k]==k ? k : p[k]=find(p[k]); }
using namespace std;

void solve()
{
    int a[5];
    lop1(i,0,5) cin>>a[i];
    lop1(i,0,5) if(!a[i]) cout<<i+1;
    return;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    fast
    ll t=1;
	//cin>>t;
    while(t--) solve();
	return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i,ans=0;cin>>N;ll A[N];bool x=true;
  REP(i,N)cin>>A[i];sort(A,A+N);
  REP(i,N)if((N%2==0&&A[i]!=1+i/2*2)||(N%2==1&&A[i]!=(i+1)/2*2))x=false;
  if(x){
    ans=1;
    REP(i,N/2){
      ans*=2;ans%=1000000007;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

// a^n mod を計算する                                                                                                 
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する                                                                                              
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

int main(){
  int N, M, K;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &K);
  long long mod = 998244353;
  long long ans = 0;
  long long nCk = 1;
  std::vector<long long > multiple(N, 0);
  multiple[0]=1;
  for (int i=1; i<N; i++){
    multiple[i]=multiple[i-1]*(M-1);
    multiple[i] %= mod;
  }

  for (int k=0; k<=K; k++){
    ans += ((nCk*M)%mod)*multiple[N-k-1];
    ans%=mod;
    nCk *= ((N-1-k)*modinv(k+1, mod))%mod;
    nCk %= mod;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 4448
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;
const double INF = DBL_MAX / 1000;

class Edge
{
public:
    int to, cost, experience;
    Edge(){};
    Edge(int to0, int cost0, int experience0){
        to = to0;
        cost = cost0;
        experience = experience0;
    }
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, -1);
}

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

    while(--c >= 0){
        int n, m;
        cin >> n >> m;

        int start, goal;
        cin >> start >> goal;

        vector<vector<Edge> > edges(n);
        for(int i=0; i<m; ++i){
            int u, v, e, t;
            cin >> u >> v >> e >> t;
            edges[u].push_back(Edge(v, t, e));
            edges[v].push_back(Edge(u, t, e));
        }

        vector<int> dist; // ゴールまでの距離
        shortestPath(edges, goal, dist);
        vector<pair<int, int> > d(n);
        for(int i=0; i<n; ++i)
            d[i] = make_pair(dist[i], i);
        sort(d.rbegin(), d.rend());

        // 効率の値effを2分探索
        // Σexp/Σcost >= eff ⇔ Σexp >= eff*Σcost ⇔ Σ(exp - eff*cost) >= 0

        double left = 0.0;
        double right = 1000000.0;
        while(left < right - EPS){
            double eff = (left + right) / 2.0;

            vector<double> dp(n, -INF);
            dp[start] = 0.0;
            for(int i=0; i<n; ++i){
                int a = d[i].second;
                for(unsigned j=0; j<edges[a].size(); ++j){
                    int b = edges[a][j].to;
                    if(dist[b] < dist[a])
                        dp[b] = max(dp[b], dp[a] + (edges[a][j].experience - eff * edges[a][j].cost));
                }
            }

            if(dp[goal] >= 0.0)
                left = eff;
            else
                right = eff;
        }

        printf("%.10f\n", (left + right) / 2.0);
    }

    return 0;
}

Measured memory_bytes: 1296
# C - Guess The Number

N, M = map(int, input().split())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)

mi = 0
if N > 1:
    mi = 10**(N-1) 

ans = -1
for i in range(mi, 10**N):
    for m in range(M):
        if str(i)[S[m]-1]!=str(C[m]):
            break
    else:
        ans = i
        break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n;cin>>n;
  string s,t;cin>>s>>t;

  REP(i,n){
    cout<<s[i];
    cout<<t[i];
  }
  cout<<endl;
 

  return 0;
}

Measured memory_bytes: 256
def BubbleSort(N ,A): # バブルソート
   count = 0
   for i in range(N): # 未ソート部分列は一つずつ減っていく
      for j in range(N-1, i, -1): # 一番後ろ(配列的にはN-1番目)から未ソート部分列の先頭(i+1)まで
         if A[j] < A[j-1]: # 後ろより前の方が大きかったら交換
            A[j], A[j-1] = A[j-1], A[j]
            count+=1 # 交換回数をカウント
   return A, count

N = int(input())
A = list(map(int, input().split())) # 「1 2 3…」のような配列入力
ans, count = BubbleSort(N, A)
print(*ans)
print(count)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int n;
    cin >> n;
    set<string> ans;
    rep(i, n) {
        string s;
        cin >> s;
        ans.insert(s);
    }
    cout << ans.size() << endl;
}

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

#define all(x) (x).begin(), (x).end()

vector<long long> direction[2];
long long X[100005];
int W[100005];
long long posVal[100005];
long long pos[100005];

int findIndx(int i, int val){
    return lower_bound(all(direction[i]), val) - direction[i].begin();
}

int main(){
    int N; long long L, T;
    scanf("%d%lld%lld", &N, &L, &T);
    //assert(T < L);

    for(int i = 0; i < N; i ++){
        scanf("%lld%d", &X[i], &W[i]);
        W[i] --;
        direction[W[i]].push_back(X[i]);

        if(W[i]){
            posVal[i] = ((X[i]-T)%L + L)%L;
        }else{
            posVal[i] = (X[i]+T)%L;
        }
        pos[i] = i;
    }

    sort(all(direction[0]));
    sort(all(direction[1]));

    long long rem = 2*T%L;
    long long quo = 2*T/L;
    //printf("rem=%lld quo=%lld\n", rem, quo);
    for(int i = 0; i < N; i ++){
        long long cnt = quo*(long long)direction[W[i]^1].size();

        /*
        printf("i=%d W[%d]=%d X[%d]=%lld opposite_direction_size=%d posVal[%d]=%lld\n",
               i, i, W[i], i, X[i], (int)direction[W[i]^1].size(), i, posVal[i]);
               */


        /*long long cutoff3 = X[i];
        if(W[i]){
            cutoff3 = (X[i]+rem)%L;
        }else{
            cutoff3 = (X[i]-rem)%L;
        }*/

        long long cutoff1, cutoff2;
        if(W[i] == 0){
            cutoff1 = X[i]+rem;
            cutoff2 = -1;
            if(cutoff1 >= L){
                cutoff2 = cutoff1 - L;
                cutoff1 = L;
            }
            long long case1 = max(findIndx(1, cutoff1) - findIndx(1, X[i]), 0);
            long long case2 = max(findIndx(1, cutoff2+1), 0);
            cnt += case1 + case2;
        }else{
            cutoff1 = X[i]-rem;
            cutoff2 = L;
            if(cutoff1 < 0){
                cutoff2 = L + cutoff1;
                cutoff1 = -1;
            }
            long long case1 = max(findIndx(0, L) - findIndx(0, cutoff2), 0);
            long long case2 = max(findIndx(0, X[i])-findIndx(0, cutoff1+1), 0);
            cnt += case1 + case2;
        }

        int temp;
        if(W[i]){
            temp = ((i-cnt)%N + N)%N;
        }else{
            temp = ((i+cnt)%N + N)%N;
        }
        pos[temp] = i;

        //printf("i=%d cnt=%lld temp=%d cutoff1=%lld cutoff2=%lld\n", i, cnt, temp, cutoff1, cutoff2);
    }

    for(int i = 0; i < N; i ++){
        printf("%lld\n", posVal[pos[i]]);
    }

    return 0;
}


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

int main()
{
	int n,x;
	int i,j,k;
	int cnt = 0;
	
	while(1)
	{
		cin >> n >> x;
		if((n == 0) && (x == 0))
		break;
		
		for(i = 1; i <= n; i++)
		{
			for(j = i + 1; j <= n; j++)
			{
				for(k = j + 1; k <= n; k++)
				{
					if(i + j + k == x)
					{
						cnt++;
					}
				}
			}
		}
	cout << cnt << endl;
	cnt = 0;
	}
}


Measured memory_bytes: 3076
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int imos[4][2005][2005];
char field[2005][2005];

long long dp[100005];

int main(void) {
    string L; cin >> L;
    long long ans = 1;
    for (int i = L.length()-1; i >= 1; i--) {
        ans *= 3LL;
        ans %= MOD;
        dp[i] = ans;
    }
    dp[L.length()] = 1;
    long long ans2 = 2;
    long long ans3 = 0;
    for (int i = 1; i < L.length(); i++) {
        if (L[i] == '1') {
            if (i+1 <= L.length()){
                ans3 += ans2 * dp[i+1];
                ans3 %= MOD;                
            }
            ans2 *= 2LL;
            ans2 %= MOD;
        }
    }
    long long fa = (ans + ans2) % MOD;
    fa += ans3;
    fa %= MOD;
    cout << fa << endl;
}   


Measured memory_bytes: 1280
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var odd float64
	if n % 2 == 0 {
		odd = float64(n / 2) / float64(n)
	} else {
		odd = float64(n / 2 + 1) / float64(n)
	}
	fmt.Println(odd)
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int cnt = 0;
    if (b <= c || d <= a) {
        cnt = 0;
    }
    else if (a <= c && b <= d) {
        cnt = b - c;
    }
    else if (a >= c && b <= d) {
        cnt = b - a;
    }
    else if (a <= c && d <= b) {
        cnt = d - c;
    }
    else if (c <= a && d <= b) {
        cnt = d - a;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int H,W,i,j,seki,sho;
		;
	for(;;){
		cin>>H>>W;
		if(H==0 && W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				seki=i+j;
				sho=seki/2*2;
				if(seki==sho){
					cout<<"#";
				}else{
					cout<<".";
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
N = int(input())
end_A_only = 0
start_B_only = 0
both = 0
count = 0
for i in range(N):
    s = input()
    count += s.count("AB")
    if s[-1] == "A" and s[0] == "B":
        both += 1
    elif s[-1] == "A":
        end_A_only += 1
    elif s[0] == "B":
        start_B_only += 1
    else:
        pass

if both == 0:
    count += min(end_A_only, start_B_only)

else:
    if end_A_only == 0 and start_B_only == 0:
        count += both - 1
    elif end_A_only == 0 or start_B_only == 0:
        count += both
    else:
        count += both + 1
        count += min(end_A_only - 1, start_B_only - 1)


print(count)

Measured memory_bytes: 3064
n, m, c = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
count = 0
for _ in range(n):
    a = [int(i) for i in input().split()]
    _sum = 0
    for i in range(len(a)):
        _sum += a[i] * b[i]
    if _sum + c > 0:
        count += 1
print(count)

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

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

using namespace std;

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

	int ans=0,cnt1=0,cnt2=0,cnt3=0;
	rep(i,n){
		string s; cin>>s;
		int len=s.length();
		rep(j,len-1) if(s[j]=='A' && s[j+1]=='B') ans++;
		if(s[0]=='B' && s[len-1]=='A') cnt1++;
		else if(s[  0  ]=='B') cnt2++;
		else if(s[len-1]=='A') cnt3++;
	}

	ans+=min(cnt2,cnt3);
	if(cnt2+cnt3>0) ans+=cnt1;
	else            ans+=max(cnt1-1,0);

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

	return 0;
}


Measured memory_bytes: 3716
H, W = map(int, input().split())
S = []
for i in range(H):
    s = list(input())
    for j in range(W):
        if s[j] == '.':
            s[j] = 0
    S.append(s)

dx = [0,1,1,1,0,-1,-1,-1]
dy = [1,1,0,-1,-1,-1,0,1]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        for k in range(8):
            nx = j + dx[k]
            ny = i + dy[k]
            if nx >= 0 and ny >= 0 and ny < H and nx < W :
                if S[ny][nx] == "#":
                    S[i][j] += 1
for i in range(H):
    l = map(str,S[i])
    ans = "".join(l)
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

vector<vector<int>> tree;
int n,m,sum=0;

int dfs(int s,vector<int> used){
  bool flag=true;
  rep(i,n)if(used[i]==0)flag=false;
  if(flag)sum++;
  rep(i,tree[s].size()){
    int u=tree[s][i];
    if(used[u]==1)continue;
    used[u]=1;
    dfs(u,used);
    used[u]=0;
  }
  return sum;
}

signed main(){
  cin>>n>>m;
  tree=vector<vector<int>>(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    tree[a].pb(b);
    tree[b].pb(a);
  }
  vector<int> used(n);
  used[0]=1;
  cout<<dfs(0,used)<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    pii p[100001];
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first;
        p[i].second = i + 1;
    }
    sort(p, p + n);
    for (int i = 0; i < n; i++) {
        cout << p[i].second << ' ';
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 1664
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var turn = int.Parse(Console.ReadLine());
            var pointTaro = 0;
            var pointHanako = 0;
            for (int i = 0; i < turn; i++)
            {
                var animals = Console.ReadLine().Split();
                var judge = animals[0].CompareTo(animals[1]);
                if (judge > 0) 
                {
                    pointTaro += 3;
                }
                else if (judge < 0)
                {
                    pointHanako += 3;
                }
                else
                {
                    pointTaro++;
                    pointHanako++;
                }
            }

            Console.WriteLine("{0} {1}", pointTaro, pointHanako);
        }
    }
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, p, ans = 0;
    cin >> n;
    bool read = true;
    for (int i = 1; i <= n; i++) {
        cin >> p;
        if (!read) { read = true; continue; }
        if (read && i == p) { ans++; read = false; }
    }
    cout << ans << endl;
}


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

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;

                double[] dArr = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray();
                double mean = dArr.Sum() / n;
                double deviation = dArr.Sum(d => Math.Pow(d - mean, 2)) / n;
                double sigma = Math.Sqrt(deviation);

                Console.WriteLine(sigma);
            }

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10008
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<complex>
using namespace std;

int main() {
    int n,m,a,d,tmp;
    int b[30][10];
    char s[10];
    bool f;

    for (;;) {
        scanf("%d",&n);
        if (n==0) break;
        scanf("%d",&m);
        scanf("%d",&a);
        scanf("%d",&d);

        for (int i=0;i<d;++i) {
            scanf("%s",&s);
            for (int j=0;j<n-1;++j) {
                b[i][j]=s[j]-'0';
            }
        }

        tmp=m;
        for(int i=0;i<d;++i) {
            if(tmp<n && b[i][tmp-1]) tmp++;
            else if (tmp>1 && b[i][tmp-2]) tmp--;
        }
        if(tmp==a) {
            printf("0\n");
        } else {
            f=0;
            for (int i=0;i<d;++i) {
                for (int j=0;j<n-1;++j) {
                    if (!b[i][j] && (!j || !b[i][j-1]) && (j==n-2 || !b[i][j+1])) {
                        b[i][j]=1;
                        tmp=m;
                        for (int k=0;k<d;++k) {
                            if (tmp<n && b[k][tmp-1]) tmp++;
                            else if (tmp>1 && b[k][tmp-2]) tmp--;
                        }

                        if (tmp==a) {
                            f=1;
                            printf("%d %d\n",i+1,j+1);
                        }
                        b[i][j]=0;
                    }
                    if (f) break;
                }
                if (f) break;
            } 
            if (!f) printf("1\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3180
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
 
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int gcd(int a, int b){
  if(b==0) return a;
  return gcd(b, a%b);
}
 
int main(void) {
    int A, B, K;
    scanf("%d %d %d", &A, &B, &K);
 
    int D = gcd(A, B);
    int C = 0;
 
    for(int i = D; i >= 1; i--) {
        if(D%i != 0) continue;
        C++;
        if(K == C) {
            printf("%d", i);
        }
    }
 
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a[55];
int main(){
	int H,W;
	cin>>H>>W;
	for(int i=0;i<H;i++)
		cin >> a[i];
			
//	for(int i=0;i<H;i++){
//		cout << a[i];
//		cout << endl;
//	}			
			
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++){
			if(a[i][j]=='#'){
				if(i!=0){if(a[i-1][j]=='#') continue;}//shang
				if(i!=H-1){if(a[i+1][j]=='#') continue;}//xia
				if(j!=0){if(a[i][j-1]=='#') continue;}//zuo
				if(j!=W-1){if(a[i][j+1]=='#') continue;}//you
//				cout << endl;
//				cout << i << " " << j << endl;
				cout<<"No";return 0;
			}
		}
	cout<<"Yes";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
int x,y;
for(int a=1;a<=10000;a++)
{cin >> x >> y;
if(x!=0)
{
for(int b=1;b<=x;b++)
{
for(int c=1;c<=y;c++)
{cout << "#";}
cout << endl;
}
cout << endl;
}
}
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

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

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    cout << pow(n, 3) << endl;
    return 0;
}

Measured memory_bytes: 384