akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> L(M), R(M), D(M);
    vector<vector<Pll>> G(N);
    rep(i,M){
        cin >> L[i] >> R[i] >> D[i];
        L[i]--;R[i]--;
        G[L[i]].push_back(Pll(D[i], R[i]));
        G[R[i]].push_back(Pll(-D[i], L[i]));
    }
    vector<ll> dist(N,1e18);
    rep(i,N){
        if(dist[i] != 1e18) continue;
        queue<Pll> que;
        que.push(Pll(0,i));
        while(!que.empty()){
            ll cost = que.front().fi;
            ll v = que.front().se;
            que.pop();
            if(dist[v] != 1e18) continue;
            dist[v] = cost;
            for(auto& p:G[v]){
                ll dost = p.fi;
                ll u = p.se;
                que.push(Pll(cost+dost,u));
            }
        }
    }
    rep(i,M){
        if(dist[R[i]] - dist[L[i]] != D[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 25204
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N);
    cout<<a[N-1]-a[0]<<endl;
    
    return 0;
    
}


Measured memory_bytes: 256
def calc(x,y)
  d = 0.0
  x.length.times do |i|
    d += (x[i]-y[i])**2
  end
  return (d**0.5).to_i**2 == d
end

n,d = gets.split.map(&:to_i)
x = []
n.times do 
  x << gets.split.map(&:to_i)
end

ans = 0
n.times do |i|
  (i+1).upto(n-1) do |j|
    ans += 1 if calc(x[i],x[j])
  end
end
p ans

Measured memory_bytes: 1916
#include <iostream>

using namespace std;

int main()
{
    long long  S;

    cin >> S;

    long k = 1000000000;
    long x3, y3;

//    y3 = S / 1000000000 + 1;
//    x3 = y3 * 1000000000 - S;
    x3 = (k - S%k)%k;
    y3 = (x3+S)/k;

    cout << "0 0 1000000000 1 " << x3 << " " << y3 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
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; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

int N;
int A[214514];
 
int TSsolve(int f){
    int sum=0;
    REP(i,N){
        sum+=abs(A[i]-f);
    }
   return sum;
}

int TernarySearch(int m,int M){
    int L=min(m,M),R=max(m,M);
    L--;
    int mid1,mid2;
    while(abs(R-L)>2){
       mid1=(2*L+R)/3;
       mid2=(L+2*R)/3;
       
        if(TSsolve(mid1)<TSsolve(mid2)){
            R=mid2;
        }else{
            L=mid1;
        } 
    }
    int r=INF;
    for(int i=L;i<=R;i++){
        r=min(r,TSsolve(i));
    }
    return r;
}
 
signed main(void){
   cin >> N;
   REP(i,N){
       cin >> A[i];
       A[i]-=(i+1);
   }
   sort(A,A+N);
   cout << TernarySearch(A[0],A[N-1]) << endl;
  return 0;
}



Measured memory_bytes: 1792
/**
 *    author:  zjsdut
 *    created: 2020/03/10 11:40:20
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define rep(n)                                                                 \
  for (int _iter_##n = 0, _num_##n = (int)n; _iter_##n < _num_##n; ++_iter_##n)
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

int main() {
#if defined LOCAL
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  int n, k;
  scan(n, k);
  vi p(n); scan(p);
  rng (i, 1, n) {
    p[i] += p[i - 1];
  }
  int ma = p[k - 1];
  rng (i, k, n) {
    chkmax(ma, p[i] - p[i - k]);
  }
  println((ma + k) / 2.);
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<functional>
#include <iomanip>

using namespace std;

int main() {
   int N;
   cin >> N;
   double p[ N ];
   for( int i = 0; i < N; i++ ) {
      cin >> p[ i ];
   }

   int half = N/2 + 1;
   double** dp = ( double ** ) malloc( sizeof( double * ) * N );
   for( int i = 0; i < N; i++ )  {
      dp[ i ] = ( double * ) malloc( sizeof( double ) * ( N + 1 ) );
   }
   for( int i = 0; i < N; i++ ) {
      for( int j = 0; j <= N; j++ ) {
         dp[ i ][ j ] = -1;
      }
   }

   function< double ( int, int )> getDp;
   getDp = [ & ] ( int i, int h ) -> double {
      if( i == 0 ) {
         if( h == 0 ) {
            return 1 - p[ 0 ];
         } else if( h == 1 ) {
            return p[ 0 ];
         } else {
            // Everything else is impossible
            return 0;
         }
      }

      if( dp[ i ][ h ] != -1 ) {
         return dp[ i ][ h ];
      }
      if( h == 0 ) {
        dp[ i ][ h ] = ( 1 - p[ i ] ) * getDp( i - 1, h );
      } else {
        dp[ i ][ h ] = ( 1 - p[ i ] ) * getDp( i - 1, h )
                       + p[ i ] * getDp( i - 1, h - 1 );
      }
      return dp[ i ][ h ];
   };

   double output = 0;
   for( int i = half; i <= N; i++ ) {
      output += getDp( N-1, i );
   }
   cout << fixed << setprecision( 20 ) << output;
   return 0;
}


Measured memory_bytes: 71700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] count = new int[100000];
		for(int i=0;i<n;i++) {
			count[in.nextInt()]++;
		}
		int max = -1;
		for(int i=2;i<100000;i++) {
			int num = count[i-2]+count[i-1]+count[i];
			if(num>max) max = num;
		}
		System.out.println(max);
		in.close();
	}

}


Measured memory_bytes: 53964
S=list(input())
n=len(S)
for i in range(n):
  S[i]=int(S[i])
k=int(input())
dp0=[[0]*(n+1) for i in range(k+1)]
dp0[0][0]=1
s=0
for i in range(n):
  if S[i]!=0:
    s=s+1
    if s==k+1:
      break
    dp0[s][i+1]=1
  else:
    dp0[s][i+1]=1
dp1=[[0]*(n+1) for i in range(k+1)]
for i in range(1,n+1):
  if dp0[0][i]==0:
    dp1[0][i]=1
for i in range(1,k+1):
  for j in range(1,n+1):
    if S[j-1]==0:
      dp1[i][j]=dp0[i-1][j-1]*0+dp0[i][j-1]*0+dp1[i-1][j-1]*9+dp1[i][j-1]
    else:
      dp1[i][j]=dp0[i-1][j-1]*(S[j-1]-1)+dp0[i][j-1]+dp1[i-1][j-1]*9+dp1[i][j-1]
print(dp0[-1][-1]+dp1[-1][-1])

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

namespace _20180305_AOJ
{
    class ALDS1_3A
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                string[] elements = line.Split(' ');

                Console.WriteLine(RPN(elements));
            }
        }

        static int RPN(string[] arr)
        {
            Stack<int> stack = new Stack<int>();
            foreach(var v in arr)
            {
                int d;
                if (int.TryParse(v, out d))
                {
                    stack.Push(d);
                }
                else
                {
                    int op2 = stack.Pop();
                    int op1 = stack.Pop();
                    switch (v)
                    {
                        case "+":
                            stack.Push(op1 + op2);
                            break;
                        case "-":
                            stack.Push(op1 - op2);
                            break;
                        case "*":
                            stack.Push(op1 * op2);
                            break;
                    }
                }
            }

            return stack.Pop();
        }
    }
}



Measured memory_bytes: 10156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc =new Scanner(System.in);
		
		int k=sc.nextInt();
		int x=sc.nextInt();
		
		for(int i=1-k;i<=k-1;i++) {
	        System.out.print(x+i + " ");
		}
        System.out.println();
	}
	
}





Measured memory_bytes: 23252
def selectionSort(A, N):
	for i in range(N):
		minj = i
		for j in range(i, N):
			if A[j][1:] < A[minj][1:]:
				minj = j
		if i != minj:
			tmp = A[i]
			A[i] = A[minj]
			A[minj] = tmp

	return A

def bubbleSort(A, N):
	for i in range(N):
		for j in range(N - 1, i, -1):
			if A[j][1:] < A[j - 1][1:]:
				tmp = A[j]
				A[j] = A[j - 1]
				A[j - 1] = tmp

	return A

if __name__ == '__main__':
	n = int(input())
	R = list(map(str, input().split()))
	C = R[:]
	SR = selectionSort(R, n)
	BR = bubbleSort(C, n)

	fStable = SR == BR

	print(" ".join(map(str, BR)))
	print("Stable")
	print(" ".join(map(str, SR)))
	if (fStable == True):
		print("Stable")
	else:
		print("Not stable")

Measured memory_bytes: 7812
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll cnt[26]; string s;
  cin>>s;
  for(int i=0;i<26;i++)cnt[i]=0;
  for(int i=0;i<s.size();i++)cnt[s[i]-'a']++;
  ll ans=s.size()*(s.size()-1)/2;
  for(int i=0;i<26;i++){
      ans-=cnt[i]*(cnt[i]-1)/2;
  }
  cout<<ans+1<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;cin>>n;
    int x;cin>>x;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int ans=0;
    while(x>=a[ans]&&ans<n){
        x-=a[ans];
        ans++;
    }
    if(ans==n&&x!=0)--ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=100005;

vi adj[N];

void solve()
{
    int n,m;
    cin>>n>>m;
    int u,v;int in[n+1]={0};
    queue<int>q;
    for(int i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[u].pb(v);
        in[v]++;
    }
    for(int i=1;i<=n;i++)
        if(!in[i])
            q.push(i);
    vi topo;int dp[n+1]={0};
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        topo.pb(u);
       // cout<<u<<endl;
        for(int v:adj[u])
        {
            in[v]--;
            if(!in[v])
                q.push(v);
        }
    }
    int ans=1;
    for(int i=n-1;i>=0;i--)
    {
        u=topo[i];
        dp[u]=1;
        for(int v:adj[u])
            dp[u]=max(dp[u],1+dp[v]);
        ans=max(ans,dp[u]);
    }
    cout<<ans-1<<endl;
    
    
    
    
}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 8440
#include<cstdio>
using namespace std;

int main() {
  int n, m, d;
  char s[100][101];
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int counter = 0;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        counter++;
        if (counter >= d) ans++;
      } else counter = 0;
    }
  }
  for (int j = 0; j < m; j++) {
    int counter = 0;
    for (int i = 0; i < n; i++) {
      if (s[i][j] == '.') {
        counter++;
        if (counter >= d) ans++;
      } else counter = 0;
    }
  }
  printf("%d\n", ans);
}



Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int h[N];
  const int INF = 1e9;
  for(int i=0; i<N; i++) cin >> h[i];
  int dp[N];
  for(int i=0; i<N; i++) dp[i] = INF;
  dp[0] = 0;

  for(int i=0; i<N-1; i++){
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
    if(i <= N-2) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]));    
  }
  cout << dp[N-1] << endl;                  
  return 0;
}

Measured memory_bytes: 1024
import numpy as np
from collections import Counter
N,M = list(map(int,input().split()))

a = []

for i in range(M):
    a.append(list(map(int,input().split())))
a = np.array(a)
a = a.flatten()

count = Counter(a)
for i in range(N):
    print (count[i+1])

Measured memory_bytes: 21508
/*ex2_1*/
/*moriai ryo*/
#include <stdio.h>
 
int main(){
  int size,white;/*変数用意*/
  scanf("%d",&size);
  scanf("%d",&white);/*入力*/
  printf("%d\n",size*size-white);/*一辺^2-白いマスの数*/
  return 0;
}


Measured memory_bytes: 128
import heapq

N=int(input())
arr=list(map(int,input().split()))
hq=[]

for i in range(N):
    heapq.heappush(hq,arr[i])
    
while len(hq)>1:
    a=heapq.heappop(hq)
    b=heapq.heappop(hq)
    heapq.heappush(hq,(a+b)/2)

print(*hq)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){ans = ans*base;}
        base *= base;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

int cnt[101][101];

int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);
    int n, m;
    cin >> n >> m;
    vector <string> vec(n);

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

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(vec[i][j] == '#') continue;
            int c = 0;
            //cout << i <<" " << j << endl;
             if(i > 0){
               c += (vec[i-1][j] == '#');
            }
            if(j > 0){
               c += (vec[i][j-1] == '#');
            }
            if(i > 0 && j > 0){
                c += (vec[i-1][j-1] == '#');
            }
            if(i > 0 && j < m-1){
                c += (vec[i-1][j+1] == '#');
            }
            if(j < m-1){
                c += (vec[i][j+1] == '#');
            }
            if(i < n-1){
                c += (vec[i+1][j] == '#');
            }
            if(i < n-1 && j < m-1){
                c += (vec[i+1][j+1] == '#');
            }
            if(i < n-1 && j > 0){
               c += (vec[i+1][j-1] == '#');
            }
            vec[i][j] = c+'0';
        }
    }
    for(int i = 0; i < n; i++) cout << vec[i] << endl;
}


Measured memory_bytes: 256
/**
 *  author: said_v15
 *  created with web_programmer
**/
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    int ans=0;
    bool TrOrNot;
    for(int i=0;i<n;i++)
    {
        TrOrNot=true;
        for(int j=0;j<i;j++)
        {
            if(arr[j]>arr[i]) {TrOrNot=false; break;}
        }
        if(TrOrNot) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int c[4][4];
  cin>>c[1][1]>>c[1][2]>>c[1][3];
  cin>>c[2][1]>>c[2][2]>>c[2][3];
  cin>>c[3][1]>>c[3][2]>>c[3][3];
  int a[4]={0};
  int b[4]={0};
  b[1]=c[1][1]-a[1];
  b[2]=c[1][2]-a[1];
  b[3]=c[1][3]-a[1];
  a[2]=c[2][1]-b[1];
  a[3]=c[3][1]-b[1];
  for (int i(1);i<=3;i++){
    for (int j(1);j<=3;j++){
      if (a[i]+b[j]!=c[i][j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    vector<int> ans(3);
    ans[0] = a + b;
    ans[1] = a - b;
    ans[2] = a * b;

    printf("%d\n", *max_element(ans.begin(), ans.end()));

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    char s[200];
    scanf("%s",s);
    if(s[6]=='5'||s[6]=='6'||s[6]=='7'||s[6]=='8'||s[6]=='9'||s[5]=='1'){printf("TBD");}
    else{printf("Heisei");}
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_H = (int)(1e2 + 5);
const int MAX_W = (int)(1e1 + 5);
const ll MOD = (ll)(1e9 + 7);

int h, w, k;

ll dp[MAX_H][MAX_W];

ll ans;

bool check(vector<bool>& arr) {
  for (int l = 1; l <= w - 1; ++l) {
    if (arr[l] && arr[l + 1]) {
      return false;
    }
  }

  return true;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d", &h, &w, &k);

  dp[0][1] = 1LL;

  for (int i = 0; i < h; ++i) {
    for (int j = 1; j <= w; ++j) {
      for (int k = 0; k < 1 << (w - 1); ++k) {
        vector<bool> arr;

        arr.push_back(false);  // guard

        for (int l = 0; l < w - 1; ++l) {
          arr.push_back(k >> l & 1);
        }

        if (!check(arr)) continue;  // in-valid pattern

        if (arr[j]) {
          dp[i + 1][j + 1] += dp[i][j];
          dp[i + 1][j + 1] %= MOD;
        } else if (arr[j - 1]) {
          dp[i + 1][j - 1] += dp[i][j];
          dp[i + 1][j - 1] %= MOD;
        } else {
          dp[i + 1][j] += dp[i][j];
          dp[i + 1][j] %= MOD;
        }
      }
    }
  }

  ans = dp[h][k];

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

  return 0;
}


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

using namespace std;
int main() {
  int n;
  int k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = k; i <= n - 1; i++) {
    if (a.at(i) > a.at(i - k)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3952
from collections import deque
import sys

input = sys.stdin.readline

n,m = map(int,input().split())

dis = [10**10] * n
edges = [[] for _ in range(n)]

for _ in range(m):
    l,r,d = map(int,input().split())
    edges[l-1].append((r-1, d))
    edges[r-1].append((l-1, -d))

for i in range(n):
    if dis[i] == 10**10:
        dis[i] = 0
        q = [i]
        while q:
            l = q.pop()
            for r,d in edges[l]:
                if dis[r] == 10**10:
                    dis[r] = dis[l] + d
                    q.append(r)
                else:
                    if dis[r] - dis[l] != d:
                        print('No')
                        exit()

print('Yes')


Measured memory_bytes: 78112
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
print(n*(n-1)//2)

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()

int main() {
    string s;
    string hi = "hi";
    cin >> s;
    if (s.size() % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0; i < s.size(); i+=2) {
        if(s[i]==hi[0] && s[i+1]==hi[1]) {
            continue;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(){
    int h,w;
    cin>>h>>w;
    string s[2*h];
    for(int i=0;i<2*h;i=i+2){
        cin>>s[i];
        s[i+1]=s[i];
    }
    for (int i=0;i<2*h;i++){
        cout<<s[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>

int main() {
        int n, a;

        while (true) {
                scanf("%d", &n);
                if (!n) {
                        break;
                }

                long long sum = 0, max = -100000;
                for (int i = 0; i < n; i++) {
                        scanf("%d", &a);
                        sum += a;
                        if (sum > max) {
                                max = sum;
                        }
                        if (sum < 0) {
                                sum = 0;
                        }
                }
                printf("%lld\n", max);
        }

        return 0;
}

Measured memory_bytes: 2740
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        // 入力
        Scanner sc = new Scanner(System.in);
        int[] x = new int[5];
        x[0] = sc.nextInt();
        x[1] = sc.nextInt();
        x[2] = sc.nextInt();
        x[3] = sc.nextInt();
        x[4] = sc.nextInt();
        int k = sc.nextInt();

        for (int i=0;i<5-1;i++) {
            for (int j=i+1;j<5;j++) {
                if (Math.abs(x[i]-x[j]) > k) {
                    System.out.println(":(");
                    return;
                }
            }
        }
        System.out.println("Yay!");
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<iostream>
const int MAXN=3010;
const int MOD=1e9+7;
int n,f[MAXN][MAXN];
int sum1[MAXN][MAXN],sum2[MAXN][MAXN];

inline bool getc(){
	char ch;std::cin>>ch;
	return ch=='<';
}
int main(){
	scanf("%d",&n);
	f[1][1]=sum1[1][1]=sum2[1][1]=1;
	for(int i=2;i<=n;i++){
		if(getc())
			for(int j=1;j<=i;j++)
				f[i][j]=sum1[i-1][j-1];
		else
			for(int j=1;j<=i;j++)
				f[i][j]=sum2[i-1][j];
		for(int j=1;j<=i;j++)
			sum1[i][j]=(sum1[i][j-1]+f[i][j])%MOD;
		for(int j=i;j>=1;j--)
			sum2[i][j]=(sum2[i][j+1]+f[i][j])%MOD;
	}
	printf("%d\n",sum1[n][n]);
	return 0;
}

Measured memory_bytes: 105088
#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
int main()
{
    int N, C;
    int D[33][33];
    int c[505][505];

    cin >> N >> C;
    for ( int i = 0; i < C; i++ ) {
        for ( int j = 0; j < C; j++ ) {
            cin >> D[i][j];
        }
    }

    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            cin >> c[i][j]; --c[i][j];
        }
    }
    vector < pair < int , int >  > iwa[3];
    for ( int g = 0; g < 3; g++ ) {
        for ( int p = 0; p < C; p++ ) {
            int sum = 0;
            for ( int i = 0; i < N; i++ ) {
                for ( int j = (g - i + 999999999) % 3; j < N; j += 3 ) {
                    sum += D[c[i][j]][p];
                }
            }
            iwa[g].emplace_back(sum, p);
        }
        sort(begin(iwa[g]), end(iwa[g]));
    }

    vector < int > p = { 0, 1, 2 };
    int minv = INF;
    do {
        int sum = 0;
        bool flag[33] = {};
        for ( int pos : p ) {
            for ( auto &x : iwa[pos] ) {
                if ( !flag[x.second] ) {
                    sum += x.first;
                    flag[x.second] = true;
                    break;
                }
            }
        }
        minv = min(minv, sum);
    } while ( next_permutation(begin(p), end(p)) );

    cout << minv << endl;
    return ( 0 );
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >>n;
    if(n%10==7 || (n/10)%10==7 || (n/100)==7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;
    lint W; cin >> W;

    vector<lint> w(N);
    vector<lint> v(N);

    REP(i, N) {
      lint x;
      cin >> x; w[i] = x;
      cin >> x; v[i] = x;
    }

    lint M=100001;

    vector<lint> dp(M, 0);

    REP(i, N) {
      lint idx;
      for(lint j=M-1-v[i];j>=1;j--) {
        if(dp[j] == 0) continue;
        idx = j + v[i];
        
        if(dp[idx] == 0) {
          dp[idx] = w[i] + dp[j];
        } else {
          dp[idx] = min(dp[idx], w[i]+dp[j]);
        }
      }
      idx = v[i];
      if(dp[idx] == 0) {
        dp[idx] = w[i];
      } else {
        dp[idx] = min(dp[idx], w[i]);
      }

      
    }

    lint res =0;

    REP(j, M) {
      if(dp[j] != 0 && dp[j] <= W) res = j;
    }

    PRINT(res);
    return 0;
}


Measured memory_bytes: 1024
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		for(int i = 0; i < adjMatrix.length; i++) {
			for(int j = 0; j < totalVertex ; j++) {
				adjMatrix[i][j] = 0;
			}
		}		
		int a = 0;		
		for(LinkedList<Integer> S: this.adjList) {
			for(Integer i : S) {
				adjMatrix[a][i] = 1;
			}
			a++;
		}	
		for(int m = 0; m < adjMatrix.length; m++) {
			for(int n = 0; n < totalVertex; n++) {
				if(n == totalVertex - 1) {
					System.out.println(adjMatrix[m][n]);
				}
				else {
					System.out.print(adjMatrix[m][n] + " ");
				}
			}
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


Measured memory_bytes: 33312
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S;
    cin>>S;
    int ans=0;
    for(int i=0;i<3;i++){
        if(S[i]=='R')ans++;
    }
    if(S=="RSR")ans=1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
using namespace std;
int A[2][100];
int sum[2][100];
int main()
{
  int N;
  cin >> N;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  sum[0][0] = A[0][0];
  sum[1][0] = sum[0][0] + A[1][0];
  for (int i = 1; i < N; i++) {
    sum[0][i] = sum[0][i-1] + A[0][i];
  }
  for (int i = 1; i < N; i++) {
    sum[1][i] = max(sum[1][i-1], sum[0][i]) + A[1][i];
  }
  cout << sum[1][N-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
struct edge
{
    long long from, to, cost;
};
vector<long long> dijkstra(long long s, vector<edge> G[], long long V)
{
    vector<long long> d(V + 1);
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> que;
    for (long long i = 0; i < V; i++)
    {
        d[i] = 1e18;
    }
    d[s] = 0;
    que.push(pair<long long, long long>(0, s));
    while (!que.empty())
    {
        pair<long long, long long> p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first)
            continue;
        for (long long i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(pair<long long, long long>(d[e.to], e.to));
            }
        }
    }
    return d;
}
int main()
{
    ll n, x, y;
    cin >> n >> x >> y;
    vector<edge> G[n];
    edge eee;
    eee.cost = 1;

    rp(i, 0, n - 1)
    {
        eee.to = i;
        G[i + 1].push_back(eee);
        eee.to = i + 1;
        G[i].push_back(eee);
    }
    eee.to = y - 1;
    G[x - 1].push_back(eee);
    eee.to = x - 1;
    G[y - 1].push_back(eee);
    vl dx = dijkstra(x - 1, G, n);

    vl dy = dijkstra(y - 1, G, n);
    //ca(n, dy);
    ll ans[n];
    za(n, ans);
    rp(i, 0, n)
    {
        rp(j, i + 1, n)
        {
            ll dd = min({dx[i] + dx[j], dy[i] + dy[j], ll(j - i)});
            ans[dd - 1]++;
        }
    }
    rp(i, 0, n - 1) cout << ans[i] << endl;
}

Measured memory_bytes: 512
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let _n: usize = read()[0];
    let a: Vec<usize> = read();
    let mut v = vec![0_usize; 100_002];
    for &i in a.iter() {
        v[i] += 1;
    }
    let ans: usize = v.windows(3).map(|w| w.iter().sum()).max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 6396
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
#define int ll
void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    if (a > b) swap(a, b);
    if ((b - a) % 2 == 0) {
        cout << (b-a) / 2LL << endl;
        return;
    }
    if (a < n - b + 1) {
        int hoge = a - 1;
        a -= hoge;
        b -= hoge;
        b--;
        cout << (b - a) / 2LL + hoge + 1LL << endl;
        return;
    }
    else {
        a = n - a + 1LL;
        b = n - b + 1LL;
        swap(a, b);
        int hoge = a - 1;
        a -= hoge;
        b -= hoge;
        b--;
        cout << (b - a) / 2LL + hoge + 1LL << endl;
        return;
    }
}
#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
ll dis2[100005];
bool vis[100005];
vector <pair<ll,ll>> vec[100005];
void can1(int st,int n)
{
    for(int j=0;j<=n;j++)
    {
        vis[j]=false;
        dis2[j]=INT_MAX;
    }
    dis2[st]=0;
    multiset <pair <int,int>> s;
    s.insert({0,st});
    while(!s.empty())
    {
        pair <int,int> p=*s.begin();
        s.erase((s.begin()));
        int x,w;
        x=p.se;
        if(vis[x])
        {
            continue;
        }
        vis[x]=true;
        int size=vec[x].size();
        for(int i=0;i<size;i++)
        {
            int y=vec[x][i].se;
            w=vec[x][i].fr;
            if(dis2[x]+w<dis2[y])
            {
                dis2[y]=dis2[x]+w;
                s.insert({dis2[y],y});
            }
        }
    }
}
signed main()
{   


      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll n,x,y;
         cin>>n>>x>>y;
    vec[x].pb({1,y});
    vec[y].pb({1,x});
    for(int i=1;i<n;i++)
    {
        vec[i].pb({1,i+1});
        vec[i+1].pb({1,i});
    }
    int res[n+5];
    for(int i=0;i<=n;i++) res[i]=0;
    for(int i=1;i<=n;i++)
    {
        can1(i,n);
        for(int j=1;j<=n;j++)
        {
            res[dis2[j]]++;
        }
    }
    for(int i=1;i<n;i++)
    {
        cout<<res[i]/2<<endl;
    }

      }
      






}



























Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N + 1), y(M + 1);
    x[0] = X, y[0] = Y;
    for(int i = 1; i <= N; ++i)
        cin >> x[i];
    for(int i = 1; i <= M; ++i)
        cin >> y[i];
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    cout << (x[N] + 1 > y[0] ? "War" : "No War") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

const int maxN=9;
bool isused[maxN]={false};
int N,M;
map<int ,VI> road;
int a,b;

bool isallsearched(){
    bool isall=true;
    FOR(i,1,N+1){
        if(isused[i]==false){isall=false;} 
    }
    return isall;
}

int numpath=0;
void dfs(int node){
    
    if(isallsearched()){
        numpath++;
        return;
    }
    FOR(i,0,road[node].size()){
        if(isused[road[node][i] ]==false){
        cerr<<"from"<<node<<" to"<<road[node][i]<<endl;
            isused[road[node][i]]=true;
            dfs(road[node][i] );
            isused[road[node][i]]=false;
        }
    }
}


int main(){
    cin>>N>>M;
    REP(i,M){
        cin>>a>>b;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    cerr<<"path"<<endl;;
    for (auto& x:road) {
        std::cerr <<"node:"<< x.first<<endl; 
        REP(i,x.second.size()){cerr<<x.second[i];}
        cerr<<endl;
    }
    cerr<<endl;
    isused[1]=true;
    dfs(1);
    cout<<numpath<<endl;
}


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

int ha[25], hb[25], h[25];
int main() {
	while(1) {
		int w,d;
		cin >> w >> d;
		if(w==0) break;
		for(int i=0;i<25;i++) h[i] = ha[i] = hb[i]= 0;
		for(int i=0;i<w;i++) {
			int tmp;
			cin >> tmp;
			ha[tmp]++;
		}
		for(int i=0;i<d;i++) {
			int tmp;
			cin >> tmp;
			hb[tmp]++;
		}
		int ans = 0;
		for(int i=1;i<=20;i++) {
			h[i] = max(ha[i],hb[i]);
			ans += h[i]*i;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main(){
int H=1,W=1;
while ((H!=0)&&(W!=0)){
	cin>>H>>W;
	if ((H==0)&&(W==0)){
		break;
	}
	for (int i=0;i<H;i++){
		if ((i==0)||(i==H-1)){
				for (int j=0;j<W;j++){
			cout<<'#';
			}
		cout<<endl;	
		}
		else {
			for (int j=0;j<W;j++){
		if ((j==0)||(j==W-1))
		cout<<'#';
		else {
			cout<<'.';
		}
		}
		cout<<endl;	
		}
		}
	cout<<endl;
	}
}


Measured memory_bytes: 3052
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long int;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 373;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> init_vector2(size_t n0, size_t n1, T e = T()) {
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> init_vector3(size_t n0, size_t n1, size_t n2, T e = T()) {
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

template <typename T>
void dump(int n, const vector2<T>& a) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << a[i][j];
        }
        cout << endl;
    }
    cout << endl;
}

vector2<int> count_table(int n, const vector2<int>& a) {
    vector2<int> ans = init_vector2(n + 1, n + 1, 0);
    for (int y = 1; y <= n; y++) {
        for (int x = 1; x <= n; x++) {
            ans[y][x] = ans[y - 1][x] + ans[y][x - 1] - ans[y - 1][x - 1] +
                        a[y - 1][x - 1];
        }
    }
    return ans;
}

int access_table(const vector2<int>& a, int sy, int sx, int ty, int tx) {
    return a[ty][tx] - a[ty][sx] - a[sy][tx] + a[sy][sx];
}

int eval(int k, const vector2<int>& btab, const vector2<int>& wtab, int cy,
         int cx) {
    int ans = 0;
    ans += access_table(btab, cy, cx, cy + k, cx + k);
    ans += access_table(btab, cy + k, cx + k, cy + 2 * k, cx + 2 * k);
    ans += access_table(wtab, cy + k, cx, cy + 2 * k, cx + k);
    ans += access_table(wtab, cy, cx + k, cy + k, cx + 2 * k);
    return ans;
}

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

    vector2<int> b = init_vector2(4 * k, 4 * k, 0);
    vector2<int> w = init_vector2(4 * k, 4 * k, 0);

    rep(i, n) {
        int x, y;
        char c;
        cin >> x >> y >> c;

        x %= 2 * k;
        y %= 2 * k;

        if (c == 'B') {
            b[y][x]++;
            b[y + 2 * k][x]++;
            b[y][x + 2 * k]++;
            b[y + 2 * k][x + 2 * k]++;
        } else {
            w[y][x]++;
            w[y + 2 * k][x]++;
            w[y][x + 2 * k]++;
            w[y + 2 * k][x + 2 * k]++;
        }
    }

    // dump(4 * k, a);

    vector2<int> btab = count_table(4 * k, b);
    vector2<int> wtab = count_table(4 * k, w);

    // dump(4 * k + 1, btab);
    // dump(4 * k + 1, wtab);

    int ans = 0;
    for (int cy = 0; cy < 2 * k; cy++) {
        for (int cx = 0; cx < 2 * k; cx++) {
            ans = max(ans, eval(k, btab, wtab, cy, cx));
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 250880
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
hash = {}
a.each do |i|
  hash[i-1] ? hash[i-1] += 1 : hash[i-1] = 1
  hash[i] ? hash[i] += 1 : hash[i] = 1
  hash[i+1] ? hash[i+1] += 1 : hash[i+1] = 1
end
puts hash.sort{|a,b| a[1]<=>b[1]}[-1][1]

Measured memory_bytes: 21144
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "10 30 20" => "Yes",
    "30 30 100" => "No",
    "56 25 31" => "Yes",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: u8,
        b: u8,
        c: u8,
    }

    if a + b == c || a + c == b || b + c == a {
        return String::from("Yes");
    } else {
        return String::from("No");
    }
}

Measured memory_bytes: 4352