akhauriyash/Code-Regression huggingface dataset:
// May this submission get accepted
#pragma GCC optimize ("O3")
#pragma GCC target("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    string s = inp1;
    ll n = s.size();

    vector<vector<ll>> dp(n+1, vector<ll>(2, INF));
    dp[0][0] = 0;
    REP(i, n) {
        ll d = s[i] - '0';
        RANGE(j, 0, 9) {
            ll f = (d + j) % 10;
            ll f2 = (d + j + 1) % 10;
            chmin(dp[i+1][d+j>9], dp[i][0] + j + f);
            chmin(dp[i+1][d+j+1>9], dp[i][1] + j + f2);
        }
    }
    ll ans = min(dp[n][0], dp[n][1]+1);
    say(ans);
    
    
}

Measured memory_bytes: 55964
from itertools import product
def main():
    n, m, x = map(int, input().split())
    books = []
    for _ in range(n):
        books.append(tuple(map(int, input().split())))

    books_set_all = []
    books_pattern = product((0, 1), repeat=n)
    for each_pattern in books_pattern:
        books_set = [0] * (m + 1)
        for i1 in range(n):
            if each_pattern[i1] == 1:
                for i2 in range(m + 1):
                    books_set[i2] += books[i1][i2]
        books_set_all.append(books_set)
    price_all = []
    for ebs in books_set_all:
        price = ebs[0]
        ebs[0] = x
        if len([j for j in ebs if j >= x]) == m + 1:
            price_all.append(price)
    if len(price_all) > 0:
        print(min(price_all))
    else:
        print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11328
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) 
{
	int N;
	deque<double> vs;

	cin >> N;

	for (int i = 0; i < N; i++) {
		double v;
		cin >> v;
		vs.push_back(v);
	}

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

	while (vs.size() > 1) {
		double a = vs[0];
		double b = vs[1];
		double c = (a + b) / 2.0;
		vs.pop_front();
		vs.pop_front();
		vs.push_back(c);
		sort(vs.begin(), vs.end());
	}

	printf("%.7lf\n", vs[0]);

	return 0;
}

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

int main()
{
	while(true){
		string line;
		cin>>line;
		if(!line.size()){break;}
		int joi = 0, ioi = 0;
		
		for(int i = 0; i < line.size() - 2; i++){
			if(line[i + 1] == 'O' && line[i + 2] == 'I'){
				if(line[i] == 'J'){
					joi++;
				}
				else if(line[i] == 'I'){
					ioi++;
				}
			}
		}
		cout<<joi<<endl<<ioi<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, a, b, c, d, e;
    cin>>n>>a>>b>>c>>d>>e;

    ll m = min({a, b, c, d, e});
    ll cnt = (n + m - 1) / m;
    cout<<cnt + 4<<endl;
}

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

int main(){
	char c;
	cin >> c;
	int flag =0;

	if(c == 'a') flag=1;
	if(c == 'i') flag=1;
	if(c == 'u') flag=1;
	if(c == 'e') flag=1;
	if(c == 'o') flag=1;

	if(flag == 1)cout << "vowel"<<endl;
	else cout<<"consonant"<<endl;
}

Measured memory_bytes: 256
def solve(string):
    ins = string.split("\n")
    if len(set(ins[1:])) < int(ins[0]):
        return "No"
    for _p, _n in zip(ins[1:], ins[2:]):
        if _p[-1] != _n[0]:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    tmp = [str(n)]
    for _ in range(n):
        tmp.append(input())
    print(solve("\n".join(tmp)))


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &v : a)
    cin >> v;

  int vmax = *max_element(a.begin(), a.end());

  vector<int> vec(vmax + 1, -1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++vec[a[i]];
    for (int j = 2 * a[i]; j <= vmax; j += a[i])
      if (vec[j] < 0)
        vec[j] = 1;
      else
        ++vec[j];
  }

  int cnt = 0;
  for (auto &v : a)
    cnt += vec[v] <= 0;
  cout << cnt << endl;
}

Measured memory_bytes: 7984
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<long long> x(n); REP(i, n) cin >> x[i];
  vector<long long> diff(n - 1);
  REP(i, n - 1) diff[i] = x[i + 1] - x[i];
  int m; long long k; cin >> m >> k;
  vector<vector<int> > pos(61, vector<int>(n - 1));
  REP(i, n - 1) pos[0][i] = i;
  while (m--) {
    int a; cin >> a; --a;
    swap(pos[0][a - 1], pos[0][a]);
  }
  REP(i, 60) REP(j, n - 1) pos[i + 1][j] = pos[i][pos[i][j]];
  vector<int> rabbit(n - 1);
  REP(i, n - 1) rabbit[i] = i;
  REP(i, n - 1) {
    REP(j, 61) if (k >> j & 1) rabbit[i] = pos[j][rabbit[i]];
  }
  vector<double> ans(n);
  ans[0] = x[0];
  REP(i, n - 1) ans[i + 1] = ans[i] + diff[rabbit[i]];
  REP(i, n) printf("%.11f\n", ans[i]);
  return 0;
}


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

#define FOR(i,s,e) for(int i=s;i<e;i++)
#define RFOR(i,s,e) for(int i=s;i>=e;i--)

// vector<int> vec(N,0) →長さN,0初期化
// vec[i]→ iにアクセス、vec.push_back(x)　→末尾にxを追加
// vec.size()サイズ取得
// vec2d[20][10] == vector< vector<int> > v2d(N, vector<int>(3,0))
#define SORT(vec) sort(vec.begin(),vec.end())
#define MAX(vec) *max_element(vec.begin(),vec.end())
#define MAXID(vec) distance(vec.begin(),max_element(vec.begin(),vec.end()))
#define MIN(vec) *min_element(vec.begin(),vec.end())
#define MINID(vec) distance(vec.begin(),min_element(vec.begin(),vec.end()))
#define NID(vec,n) distance(vec.begin(),find(vec.begin(),vec.end(),n))



int N,M;




int main(){
	cin >> N;
	vector< vector<int> > v2d(N, vector<int>(4,0));
	vector< vector<int> > bucket(201,vector<int>(3,0));
	FOR(i,0,N){
		FOR(j,0,3) cin >> v2d[i][j];
	}
	// FOR(i,0,N) cout << v2d[i][0] << " "  << v2d[i][1] << " " << v2d[i][2] << v2d[i][3] << endl;

	FOR(j,0,3){
		FOR(i,0,N){
			bucket[v2d[i][j]][j]++;
		}
	}

	// FOR(i,0,201) cout << i << " "<< bucket[i][0] << bucket[i][1] << bucket[i][2] << endl;
	FOR(j,0,3){
		FOR(i,0,N){
			if (bucket[v2d[i][j]][j] == 1) v2d[i][3] += v2d[i][j];
		}
	}
	FOR(i,0,N) cout << v2d[i][3] << endl;
	return 0;
}



Measured memory_bytes: 3176
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  long[] a; readA(n, a);

  auto b = cumulativeSum(a), m = 10L^^18;
  foreach (i; 1..n)
    m = min(m, (b[0..i] - b[i..$]).abs);

  writeln(m);
}

class CumulativeSum(T)
{
  size_t n;
  T[] s;

  this(T[] a)
  {
    n = a.length;
    s = new T[](n+1);
    s[0] = T(0);
    foreach (i; 0..n) s[i+1] = s[i] + a[i];
  }

  T opSlice(size_t l, size_t r) { return s[r]-s[l]; }
  size_t opDollar() { return n; }
}
auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }


Measured memory_bytes: 6784
#include<stdio.h>

int main(void)
{
  char b;

  scanf("%c",&b);


  if(b=='A')
    b='T';
  else if(b=='T')
    b='A';
  else if(b=='C')
    b='G';
  else if(b=='G')
    b='C';


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

  return 0;
}

Measured memory_bytes: 128
/*
Looking from a window above
It's like a story of love
Can you hear me?
Came back only yesterday
I'm moving further away
Want you near me
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you
Sometimes when I think of her name
When it's only a game
And I need you
Listen to the words that you say
It's getting harder to stay
When I see you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you
Uh uh uh only you, only you
Only you, only you, only you
This is going to take a long time
And I wonder what's mine
Can't take no more
Wonder if you'll understand
It's just the touch of your hand
Behind a closed door
And all I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
Only you
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) ((int)(x.size()))
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 3e18;
const int N = 5e5 + 100;




int32_t main(){ 
   FAST;
   int a, b, h;
   cin >> a >> b >> h;
   int ans = (a + b) * h;
   ans >>= 1;
   cout << ans << endl;   
}

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

int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  for(int i=0; i<n-1; i++) cin >> b[i];
  
  int ans = b[0];
  for(int i=1; i<n-1; i++){
  	ans += min(b[i-1], b[i]);
  }
  ans += b[n-2];
  
  cout << ans << endl;
}

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

using namespace std;

const int N = 2e5 + 5;

struct query {
    int type , side;
    char c;
} info[N];

string s;

void go (int i , bool rev) {
    if (i == -1) {
        if (rev)
            reverse(s.begin() , s.end());
        cout << s;
        return;
    }

    if (info[i].type == 1) {
        rev ^= 1;
        go(i - 1 , rev);
    } else {
        info[i].side ^= rev;
        if (info[i].side) {
            go(i - 1 , rev);
            cout << info[i].c;
        } else {
            cout << info[i].c;
            go(i - 1 , rev);
        }
    }
}

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#ifdef LOCAL
    freopen("input.in" , "r" , stdin);
#endif
    int q;
    cin >> s >> q;

    for (int i = 0 ;i < q ;i++) {
        cin >> info[i].type;
        if (info[i].type == 2) {
            cin >> info[i].side >> info[i].c;
            info[i].side--;
        }
    }

    go(q - 1 , 0);
}


Measured memory_bytes: 15440
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int N;
bool E[22][22];
ll cache[1 << 21];
const ll MOD = 1000000007;

ll dfs(int mask, int i) {
  if (cache[mask] != -1) {
    return cache[mask];
  }

  if (mask == (1 << N) - 1) {
    return 1;
  }

  ll cnt = 0;

  for (int j = 0; j < N; ++j) {
    if (!E[i][j]) continue;
    if ((mask >> j) & 1) continue;

    cnt += dfs(mask | (1 << j), i + 1);
    cnt %= MOD;
  }

  return cache[mask] = cnt;
}

int main() {
  memset(cache, -1, sizeof(cache));
  memset(E, false, sizeof(E));
  cin >> N;

  bool e;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> e;
      E[i][j] = e;
    }
  }

  dfs(0, 0);

  cout << cache[0] << endl;

  return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
int a,b,ans=0;
cin>>a>>b;
string left,right,s;
for (int i = a; i <=b; i++)
{
  /* code */
  s=to_string(i);
  if (s[0]==s[4]&&s[1]==s[3])
  {
    ans++;
  }
  
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	while(true){
		int pos[10] = {0} , t , ans[2] = {0};
		rep(i,4) if(cin >> t) pos[t] = i+1; else return 0;
		rep(i,4){
			cin >> t;
			if(pos[t]) ans[pos[t]==i+1]++;
		}
		cout << ans[1] << " " << ans[0] << endl;
	}	
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**9)
N, K = map(int, input().split())
mod = 10**9 + 7
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def p(n, k):
    x = 1
    for i in range(k):
        x *= n - i
        x %= mod
    return x
def f(x, par):
    L = len(G[x])
    if x == par:
        if L <= K-1:
            ans = K*p(K-1,L) % mod
        else:
            return 0
    elif x != par:
        if L-1 <= K-2:
            ans = p(K-2,L-1)
        else:
            return 0
    for i in G[x]:
        if i != par:
            ans *= f(i, x)
            ans %= mod
    return ans
print(f(0, 0))

Measured memory_bytes: 87340
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld\n",x)
#define print2(x) printf("%lld ",x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 333333



int main(void) {
  ll a, b, c;
  cin >> a >> b >> c;
  ma = max(a, b);
  ma = max(ma, c);
  cout << ma * 9 + a + b + c << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int H, W, D;
  cin >> H >> W >> D;
  VEC<int> X(H * W + 1), Y(H * W + 1);
  REP(i, 0, H) {
    REP(j, 0, W) {
      int A;
      cin >> A;
      X[A] = i;
      Y[A] = j;
    }
  }
  VEC<LL> dist(H * W + 1, 0);
  REP(i, D + 1, H * W + 1) {
    dist[i] = dist[i - D] + abs(X[i] - X[i - D]) + abs(Y[i] - Y[i - D]);
    //DUMP(i, dist);
  }
  int Q;
  cin >> Q;
  REP(i, 0, Q) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%lld\n", dist[b] - dist[a]);
  }

  return 0;
}


Measured memory_bytes: 2560
/*
	Distrubute candies to children, given they can get [0 - a[i]] candies, such that
	no candies remain after distribution 
*/

#include <bits/stdc++.h>
 
using namespace std;
int mod=1e9+7; 
 
int main()
{
    int n,k;				// k - candies,  n- children 
    cin >> n >> k;		
    int a[n+1];				// a[i] = maximum candies one can get

    for(int i=1;i<=n;i++)    
        cin >> a[i];

    int dp[n+1][k+1];		// dp[i][j] - denotes no of ways to distribute j candies in 1....i children


    dp[0][0]=1;				// 0 candy - 0 children

    for(int i=1;i<=k;i++)  // 0 children - k candies	- candies remain spare so 0 ways
        dp[0][i]=0;
    
    for(int i=1;i<=n;i++)
    {
        int sums[k+1];		
        sums[0]=dp[i-1][0];
        for(int j=1;j<=k;j++)		// prefix sum - Sum of dp[i-1][0...j] - ways i-1 candies can be distrubuted among j children
        {
            sums[j]=(sums[j-1]+dp[i-1][j])%mod;  
        }

        for(int j=0;j<=k;j++)
        {
            int tr = sums[j];  				//Sum of dp[i-1][0...j]
            int unreachable = j-a[i]-1;  		// We need to subtract the sum of the first "unreachable" elements (dp[i-1][0...unreachable])
            if(unreachable >= 0)
            {
                tr=(tr-sums[unreachable]+mod)%mod;  ///Add mod to make sure that "tr-sums[unreachable]" is not negative.
            }
            dp[i][j]=tr;
        }
    }
  	cout << dp[n][k] << endl;
    return 0;
}

Measured memory_bytes: 40064
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200006;
const int INF = (int)1e9;
int e_num = 1, S, T;
int hed[maxn], dep[maxn];
struct Edge {
  int from, to, nxt, c;
} edge[maxn * 4];
void addedge(int from, int to, int c) {
  edge[++e_num] = (Edge){from, to, hed[from], c};
  hed[from] = e_num;
}
void adde(int from, int to, int c) {
  addedge(from, to, c);
  addedge(to, from, 0);
}
int que[maxn + 5], head = 0, tail = 0;
bool bfs() {
  head = tail = 0;
  que[tail++] = S;
  memset(dep, 0, sizeof dep);
  dep[S] = 1;
  while (head != tail) {
    int cur = que[head++]; head %= maxn;
    for (int i = hed[cur]; i; i = edge[i].nxt) {
      int to = edge[i].to;
      if (!dep[to] && edge[i].c) {
        dep[to] = dep[cur] + 1;
        que[tail++] = to; tail %= maxn;
      }
    }
  }
  return dep[T];
}
int hed2[maxn];
int dfs(int x, int flow) {
  if (x == T) return flow;
  int ret = 0;
  for (int &i = hed2[x]; i; i = edge[i].nxt) {
    int to = edge[i].to;
    if (dep[to] == dep[x] + 1 && edge[i].c) {
      int tmp = dfs(to, min(flow, edge[i].c));
      edge[i].c -= tmp;
      edge[i ^ 1].c += tmp;
      flow -= tmp;
      ret += tmp;
      if (!flow) {
        break;
      }
    }
  }
  if (!ret) dep[x] = 0;
  return ret;
}
int dinic() {
  int ret = 0;
  while (bfs()) {
    memcpy(hed2, hed, sizeof hed);
    ret += dfs(S, INF);
  }
  return ret;
}

int n, p[maxn], q[maxn], bp[maxn], bq[maxn], cnt;
void solve(int *p, int *bel) {
  for (int i = 1; i <= n; i++) if (!bel[i]) {
    int x = i;
    ++cnt;
    do {
      bel[x] = cnt;
      x = p[x];
    } while (x != i);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    ++p[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &q[i]);
    ++q[i];
  }
  solve(p, bp);
  solve(q, bq);
  S = 0, T = ++cnt;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i] == i && q[i] == i) {
      ans++;
    } else if (q[i] == i) {
      adde(S, bp[i], 1);
    } else if (p[i] == i) {
      adde(bq[i], T, 1);
    } else {
      addedge(bq[i], bp[i], 1);
      addedge(bp[i], bq[i], p[i] == q[i]);
    }
  }
  ans += dinic();
  printf("%d\n", n - ans);
  return 0;
}

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

int main(){
	int n,m,ret,c;
	while(cin >> n && n){
		cin >> m;
		ret = 0;
		for(int i=n;i<=m;i++){
			c = i;
			while(c%2==0){
				c/=2;
			}
			while(c%3==0){
				c/=3;
			}
			while(c%5==0){
				c/=5;
			}
			if(c==1)ret++;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
#define mod 1e9+7
typedef long long ll;

void Main()
{
	string O, E;	
  	cin >> O >> E;
  	string ans;
  	int i = 0;
  	while(1){
      	if(i == (int)O.size()){break;}
    	ans += O.at(i);
      	if(i == (int)E.size()){break;}
      	ans += E.at(i);
      	i++;
    }
  
  	cout << ans;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(s) s.begin(),s.end()
#define ld long double

using namespace std;

const int maxn = 1e5 + 7;
const ld eps = 1e-6;
const ll inf = 1e9 + 7;

int n;
ll a[maxn],ans;
map<ll,int>m;

int main () {

cin >> n;

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

for (int i = 1; i <= n; i ++) {
	if (m[a[i]] != a[i] && m[a[i]] != 0) {
		if (m[a[i]] < a[i])ans += m[a[i]], m[a[i]] = 0;
		else ans += (m[a[i]] - a[i]), m[a[i]] = a[i];
	}
}

cout << ans;

return 0;
}

Measured memory_bytes: 7040
#include <iostream>
using namespace std;
int main(){
	double v;
	while(cin>>v){
		int n;
		double t = v/9.8;
		double y = 4.9*t*t;
		for(int i=0;;i++){
			if(5*i-5>y){
				n=i;
				break;
			}
		}
		cout<<n<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<cstdio>
#include<cstring>

const int N=30000;

struct saver
{
	int s[N];
	void push(int x){s[++s[0]]=x;}
	int get(){return s[s[0]--];}
}s20,s21,s3,s6;

int n;

int main()
{
	scanf("%d",&n);

	if(n==3)
	{
		puts("2 5 63");
		return 0;
	}

	for(int i=1;i<=N;i++)
		if(i%2==0 && i%3==0)s6.push(i);
		else if(i%3==0)s3.push(i);
		else if(i%2==0 && i%3==1)s20.push(i);
		else if(i%2==0 && i%3==2)s21.push(i);

	printf("%d %d %d %d ",s20.get(),s21.get(),s3.get(),s3.get());
	n-=4;

	while(n>s6.s[0])
	{
		if(s20.s[0]>0 && s21.s[0]>0)printf("%d %d ",s20.get(),s21.get()),n-=2;
		else printf("%d %d ",s3.get(),s3.get()),n-=2;
	}
	while(n--)printf("%d ",s6.get());
	printf("\n");

	return 0;
}


Measured memory_bytes: 384
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define bug() cout << "BUG" << endl ;
#define X first
#define Y second
#define sz(x) (int)x.size()
#define per(how) cout << fixed << setprecision(how)
#define bit(a , b) (a >> b) & 1
#define all(v) v.begin() , v.end()
#define LB(x) (x & -x)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 , MOD = 1e9 + 7 , SQRT = 350 ;
inline void smin(ll &x , ll y) { x = min(x , y) ; }
inline void smax(ll &x , ll y) { x = max(x , y) ; }

const ll MAXN = 1e5 + 100 ; 
ll n ;
vector < ll > adj[MAXN] ;
ll d[MAXN] , h[MAXN];
ll par[MAXN];

void dfs(ll v = 1 , ll p = -1)
{
	par[v] = p;
	if(p != -1)		h[v] = h[p]+1;
	d[v] = 1; 
	for(auto u : adj[v])
	{
		if(u == p)	continue ; 
		dfs(u , v);
		d[v] += d[u];
	}
}

ll f(ll x , ll k)
{
	if(x % k == 0)	return x / k ; 
	else	return (x / k) + 1;
}

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ; 
	for(ll i = 0 ; i < n - 1 ; i++)
	{
		ll u , v ; 
		cin >> u >> v ; 
		adj[u].pb(v) , adj[v].pb(u);
	}
//	h[1]=1;
	dfs();
	h[n]-- ; 
	h[n] /= 2 ;ll x= n;
	while(h[n]--)	x= par[x];
	if(d[x] >= n - d[x])	cout << "Snuke";
	else 	cout << "Fennec";
	cout << endl ;
	return 0 ; 
}


Measured memory_bytes: 12800
import itertools

def warshall_floyd(D, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                D[i][j] = min(D[i][j], D[i][k]+D[k][j])


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
D = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    D[a-1][b-1] = c
    D[b-1][a-1] = c

warshall_floyd(D, N)

ans = float('inf')
for P in itertools.permutations(r):
    cost = 0
    for i in range(R-1):
        cost += D[P[i]-1][P[i+1]-1]
    ans = min(ans, cost)

print(ans)

Measured memory_bytes: 59480
#include<bits/stdc++.h>
using namespace std;
int n,k;
double ans=0.0;

int main() {
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++) {
        long long now=i,cnt=0;
        while(now<k) now*=2,cnt++;
        ans+=1.0/(double)(1LL<<cnt);
    }
    ans/=(double) n;
    printf("%.10f\n",ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

int main() {
   int a, b, c;
   cin >> a >> b >> c;
   if (a + c == b ||
       a + b == c ||
       b + c == a ) {
    cout << "Yes" << endl;
   } else {
    cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    int d[n];
    for(int i = 0;i < n;++i)
    {
        cin >> d[i];
    }

    int max_d=0;
    for(int i = 1;i < n;++i)
    {
        if(d[i]-d[i-1]>max_d)
        {
            max_d = d[i] - d[i-1];
        }
    }

    if(k-d[n-1]+d[0]>max_d)
    {
        max_d = k-d[n-1]+d[0];
    }

    cout << k - max_d << endl;
    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  unordered_map<int,char> aTon = {{'M',0},{'A',1},{'R',2},{'C',3},{'H',4}};
  int N;cin >> N;
  const int M = 5;
  vector<ll> v(5,0);
  string S;
  rep(i,N){
    cin >> S;
    if(aTon.count(S[0])) ++v[aTon[S[0]]];
  }
  ll count = 0;
  rep(i,M)repp(j,i+1,M)repp(k,j+1,M){
    count += v[i]*v[j]*v[k];
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > miti(n);
    rep(i, m) {
        int ai, bi;
        cin >> ai >> bi;
        ai--; bi--;
        miti[ai].emplace_back(bi);
        miti[bi].emplace_back(ai);
    }

    queue<int> room;
    vector<int> ans(n, -1);
    room.push(0);
    while (!room.empty()) {
        int c = room.front(); room.pop();
        for (int i : miti[c]) {
            if (ans[i] != -1) continue;
            ans[i] = c;
            room.push(i);
        }
    }

    cout << "Yes" << endl;
    rep(i, n) {
        if (i == 0) continue;
        cout << ans[i] + 1 << endl;
    }
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 10020
/*input
314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int dp[maxn][2];
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    string s;
    cin>>s;
    dp[0][0]=2;
    REP1(i,sz(s)){
        dp[i][0]=min(dp[i-1][1]+min('9'-s[i-1]+2,s[i-1]-'0'+2),dp[i-1][0]+'9'-s[i-1]);
        dp[i][1]=min(dp[i-1][1],dp[i-1][0])+s[i-1]-'0';
        //cout<<dp[i][0]<<' '<<dp[i][1]<<'\n';
    }
    cout<<min(dp[sz(s)][0],dp[sz(s)][1]);
}

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1e9+7
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

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

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}


int read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

int main(){
	string s;
	cin >> s;
	if(s.size() <= 3) {
		cout << "No\n";
	}
	else {
		if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
			cout << "Yes\n";
		}
		else cout << "No\n";
	}
}



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

int main()
{
	int N,n;
    int x,y;

    scanf("%d",&N);

    x = 8 * N;

    n = N - (N % 15);
    y = 2 * n/15;
    printf("%d00\n",(x-y));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
int INF = 1LL<<60;
int MOD = 998244353;
 
string to_string(char &c) {string x(1, c); return x;}
string to_string(string &s) {return s;}
string to_string(const char s[]) {return (string)s;}
template <class C> string to_string(C &v) {
    string res;
    for (auto &x : v) res += to_string(x) + ' ';
    return res;
}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {
    for (auto &x : v) is >> x;
    return is;
}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {
    os << '(' << pr.first << ", " << pr.second << ')';
    return os;
}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
template <class Container> ostream &operator<<(ostream &os, Container &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ',' << ' ';
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}
 
main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int R, C;
    cin >> R >> C;
    vvb grid(R, vb(C));
    REP(i, 0, R) REP(j, 0, C) {
        char x;
        cin >> x;
        grid[i][j] = x=='#';
    }
    
    int res=0;
    REP(sr, 0, R) REP(sc, 0, C) if (!grid[sr][sc]) {
        queue<pii> q; q.push({sr, sc});
        vvi dist(R, vi(C, -1));
        dist[sr][sc] = 0;
        while (!q.empty()) {
            int r,c; tie(r,c) = q.front(); q.pop();
            res = max(res, dist[r][c]);
            for (pii pr : vector<pii>{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}) {
                int dr,dc; tie(dr,dc) = pr;
                int nr=r+dr, nc=c+dc;
                if (0<=nr&&nr<R && 0<=nc&&nc<C && !grid[nr][nc] && dist[nr][nc] == -1) {
                    q.push({nr, nc});
                    dist[nr][nc] = dist[r][c]+1;
                }
            }
        }
    }
    print(res);
}

Measured memory_bytes: 256
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<functional>
#include<climits>

//  scan & print

#define sf scanf
#define pf printf
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c);


#define pro printf("1\n")
#define pcase(kase) printf("Case %d: ",kase)

// constants

#define infinity 9999999

using namespace std;

int kase=1;

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

int ddx[]={1,1,0,-1,-1,-1,0,1};
int ddy[]={0,1,1,1,0,-1,-1,-1};

int GCD(int A,int B)
{
    if(!B)
        return A;
    return GCD(B,A%B);
}

int main()
{
    int  n;
    sf1(n);
    int ara[n+5];
    for(int i=0;i<n;i++)
    {
        sf1(ara[i]);
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        for(int j=n-1;j>=(i+1);j--)
        {
            if(ara[j]<ara[j-1])
            {
                int t;
                t=ara[j];
                ara[j]=ara[j-1];
                ara[j-1]=t;
                cnt++;
            }
        }
    }
    pf("%d",ara[0]);
    for(int i=1;i<n;i++)
    {
        pf(" %d",ara[i]);
    }
    pf("\n");
    pf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
#define MAX 100001

typedef struct {
  int parent,leftchild,rightsibling;
} Node;

Node t[MAX];
int depth[MAX];
int child[MAX];

int main() {
  int i,j,n,id,k;
  
  scanf("%d",&n);
  for(i=0; i<n; i++){ 
    t[i].parent=t[i].leftchild=t[i].rightsibling=-1;
    depth[i]=0;
  }
  for(i=0; i<n; i++) {
    scanf("%d%d",&id,&k);
    if(k) {
      for(j=0; j<k; j++) {
	scanf("%d",&child[j]);
	t[child[j]].parent = id;
	if(j==0) t[id].leftchild = child[j];
	else t[child[j-1]].rightsibling = child[j];
      }
    }
  }
  for(i=0; i<n; i++) {
    j=i;
    while(t[j].parent!=-1) {
      j=t[j].parent;
      depth[i]++;
    }
  }

  for(i=0; i<n; i++) {
    printf("node %d: parent = %d, depth = %d, ",i,t[i].parent,depth[i]);
    if(t[i].parent==-1) printf("root, [");
    else if(t[i].leftchild!=-1) printf("internal node, [");
    else printf("leaf, [");
    id=t[i].leftchild;
    j=0;
    while(id!=-1) {
      if(j) printf(", ");
      printf("%d",id);
      id = t[id].rightsibling;
      j++;
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 2560
def culc_factrial(n):
    factrial = [1] * (n+1)
    for i in range(1, n+1):
        factrial[i] = factrial[i-1] * i
    return factrial


N, K = map(int, input().split())

factrial = culc_factrial(2000)

for i in range(1, K+1):
    hoge = factrial[N-K+1] // (factrial[i]*factrial[N-K+1-i])
    fuga = factrial[K-1] // (factrial[i-1]*factrial[K-i])
    print(hoge*fuga % (1000000007))


Measured memory_bytes: 5748
N, M , X = list(map(int,input().split()))

c = [[]]*N
a = [[[]]*M]*N

for n in range(N):
    temp = list(map(int,input().split()))
    c[n] = temp[0]
    a[n] = temp[1:M+1]


ans = 10**7

for i in range(2 ** N):
    price = 0
    intelligence = [0 for _ in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            price += c[j]
            for k in range(M):
                intelligence[k] += a[j][k]
    flag = 1
    for k in range(M):
        if intelligence[k] < X:
            flag = 0
    if flag == 1:
        ans = min(ans,price)

if ans == 10**7:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,a[N]; 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	ll s=0,ans=1e18,p=a[1];
	if(a[1]<=0){
	s+=abs(a[1])+1;
	p=1;
	}
	for(int i=2;i<=n;i++){
		if(i%2==0){
			if(p+a[i]>=0){
				s+=abs(a[i]+p)+1;
				p=-1;
			}
			else p+=a[i];
		}
		else {
			if(p+a[i]<=0){
				s+=abs(a[i]+p)+1;
				p=1;
			}
			else p+=a[i];
		}
	}
	ans=min(ans,s),s=0,p=a[1];
	if(a[1]>=0){
	s+=abs(a[1])+1;
	p=-1;	
	}
	for(int i=2;i<=n;i++){
		if(i&1){
			if(p+a[i]>=0){
				s+=abs(a[i]+p)+1;
				p=-1;
			}
			else p+=a[i];
		}
		else {
			if(p+a[i]<=0){
				s+=abs(a[i]+p)+1;
				p=1;
			}
			else p+=a[i];
		}
	}
	printf("%lld\n",min(ans,s));
	return 0;
}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  map<int, int>A;
  REP(i,0,3){
    int a;cin>>a;
    A[a]++;
  }
  for(auto v:A){
    if(v.second==2){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  
  

  return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

for _ in range(n):
    s = input()
    if s[0] in 'MARCH' :
        names[s[0]] += 1

ans = 0
for (x,y,z) in list(itertools.combinations('MARCH',3)) :
    ans += names[x]*names[y]*names[z]

print(ans)


Measured memory_bytes: 3060
n, m = map(int,input().split())
lst = []

for i in range(m):
  l = list(map(int,input().split()))
  lst.append(l)

ans=[0]*n
for i in range(m):
  ans[lst[i][0]-1] += 1
  ans[lst[i][1]-1] += 1
for i in range(n):
  print(ans[i])

Measured memory_bytes: 3060