akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string t;
    cin>>t;

    rep(i , t.length()){
        if(t[i] =='?')t[i] = 'D';
    }
    
    /*
    if(t[0]=='D')ans++;
    rep1(i,1,t.length()){
        if(t[i-1]=='P'&&t[i-1]=='D')ans++;
        if(t[i]=='D')ans++;
    }
    */

    cout<<t<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int main (){
  int i,a,b,c;
  cin>>a>>b;
  if(a*b==2)
  cout<<3;
  if(a*b==3)
  cout<<2;
  if(a*b==6)
  cout<<1;
  return 0;
}

Measured memory_bytes: 256
s = input()
tmp = ""
for i in range(len(s)):
  if s[i] == "1":
    tmp = tmp + "1"
  elif s[i] == "0":
    tmp = tmp + "0"
  elif s[i] == "B" and tmp =="":
    pass
  else:
    tmp = tmp[:-1]
print(tmp)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
#define Graph vector<vector<int>>
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
#define inf 1000000321
#pragma GCC optimize("Ofast")
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll D,T,S;
    cin >> D>>T>>S;
    if(S*T >= D){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}   

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n; 
    cin >> n;
    v_int h(n);
    cin >> h;
    
    sort(h.begin(), h.end());
    
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            int a = h[i], b = h[j];
            int c1 = a+b;
            int c2 = b-a+1;

            auto dist1 = lower_bound(h.begin()+j+1, h.end(), c1);
            auto dist2 = lower_bound(h.begin()+j+1, h.end(), c2);
            ans += dist1 - dist2;
        }
    }
    cout << ans << endl;

    return 0;
} /*atcoder*/



Measured memory_bytes: 3612
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
#define tc int t;cin>>t;while(t--)
#define get cin>>
#define geta ll a[n];for (int i = 0; i < n; ++i){cin>>a[i];}
#define puta for (int i = 0; i < n; ++i){cout<<a[i];}
#define put cout<<
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
vector<int> adj[100001];
ll dp[100001][2];
ll ans=1;
ll fun(int i,int par,int col)
{
	if (dp[i][col]!=-1)
	{
		return dp[i][col];
	}
	ll ans=1;
	for (int j = 0; j < adj[i].size() ; ++j)
	{
		if(adj[i][j]!=par)
		{
		ll t=0;
		if (col==0)
		{
			t+=fun(adj[i][j],i,0);
			t%=MOD;
			t+=fun(adj[i][j],i,1);
			t%=MOD;
		}
		else
		{
			t+=fun(adj[i][j],i,0);
			t%=MOD;
		}
		ans*=t;ans%=MOD;
	    }
	}
	dp[i][col]=ans;
	return dp[i][col];
}
int main() 
{
   fast();
   memset(dp,-1,sizeof(dp));
   int n;cin>>n;
   for (int i = 0; i < n-1; ++i)
   {
   	int a,b;cin>>a>>b;
   	adj[a].pb(b);
   	adj[b].pb(a);
   }
   ll ans;
   ans=fun(1,-1,0);
   ans%=MOD;
   ans+=fun(1,-1,1);
   ans%=MOD;
   cout<<ans;
   return 0;
}

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

vector<ll> a(51);  //レベルNバーガーの層
vector<ll> b(51);  //レベルNバーガーのパティ

ll f(ll l,ll x) {
	if (l == 0) return b[0];
	else if (x == 1) return 0;
	else if (2 <= x && x <= a[l-1]+1) return f(l-1,x-1);
	else if (x == a[l-1]+2) return b[l-1]+1;
	else if (a[l-1]+3 <= x && x <= a[l]-1) return b[l-1]+1+f(l-1,x-a[l-1]-2);
	else return b[l];
}

int main() {

	a[0] = 1;
	b[0] = 1;

	for (ll i=1;i<=50;i++) {
		a[i] = 2*a[i-1]+3;
		b[i] = 2*b[i-1]+1;
	}

	ll n,x;
	cin >> n >> x;
	ll ans = f(n,x);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int A, B, C;
    cin >> A >> B >> C;
    for(int i=1; i<=B; i++) {
        if((A*i)%B == C) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        ans += B[A[i]-1]
        if i != 0 and A[i-1]+1 == A[i]:
            ans += C[A[i]-2]
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    string s;
    getline(cin,s);
    bool c=false,f=false;
    int k1=0,k2=0;
    for(int i=0;i<=s.size()-1;i++)
    {
        if(s[i]=='C')
        {
            c=true;
            k1=i;
        }
        if(s[i]=='F')
        {
            f=true;
            k2=i;
        }
    }
    if(c&&f&&k2>k1)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 29.12.2019 21:02:36       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int t = 0; t < 4; t++) {
    vector<int> a(n + 2);
    a[0] = t & 1;
    a[1] = (t & 2) >> 1;
    for (int i = 2; i < n + 2; i++) {
      char c = s[(i - 1) % n];
      if (c == 'o') a[i] = a[i - 1] ^ a[i - 2];
      else a[i] = a[i - 1] ^ a[i - 2] ^ 1;
    }
    if (a[0] == a[n] && a[1] == a[n + 1]) {
      for (int i = 0; i < n; i++) cout << (!a[i] ? 'S' : 'W');
      cout << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 924
#include<bits/stdc++.h>
using namespace std;
int a[2010],mn[2010],nxt[2010];
int main(){
	int n,x;
	long long ans=1LL<<60;
	scanf("%d%d",&n,&x);
	for(int i=0;i<n;i++) scanf("%d",&a[i]),mn[i]=a[i];
	for(int i=0;i<n;i++){
		long long tmp=1LL*x*i;
		for(int j=0;j<n;j++){
			tmp+=mn[j];
		}
		if(tmp<ans) ans=tmp;
		for(int j=0;j<n;j++){
			nxt[(j+1)%n]=min(mn[j],mn[(j+1)%n]);
		}
		for(int j=0;j<n;j++) mn[j]=nxt[j];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL 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;}

//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) LL((a).size())
#define EACH(i,c) for(auto 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(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

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

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

#define PUTS(x) cout << (x) << endl;

LL dp[100005][3] = {{0}};

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

    LL n;
    cin>>n;
    VL a(n),b(n),c(n);
    REP(i,n)cin>>a[i]>>b[i]>>c[i];

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    FOR(i,1,n){
        dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
        dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
        dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
    }
    PUTS(max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])));
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace arc_068_A
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong a = ulong.Parse(Console.ReadLine());
            ulong ans = (a / (int)11) * 2;
            ulong s = a % 11;
            if (s > 6) { ans += 2; }
            else if (s > 0) { ans += 1; }
            Console.WriteLine(ans);Console.ReadLine();
           
        }
    }
}

Measured memory_bytes: 13140
import math

a, b, c, d = map(int, input().split())

def lcm(x,y):
    return (x*y) // math.gcd(x,y)

print((b- b//c - b//d + (b // lcm(c,d))) - ((a-1)- (a-1)//c - (a-1)//d +( (a-1) // lcm(c,d))))

Measured memory_bytes: 9052
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray
import           Data.Array.IO
import           Data.Array.MArray
import           Data.Maybe

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

(!?) :: IOUArray Int Int -> Int -> IO (Maybe Int)
a !? i = do
    (_, t) <- getBounds a
    if i < 1 || t < i
        then return Nothing
        else Just <$> readArray a i

printHeap :: IOUArray Int Int -> IO ()
printHeap a = do
    (_, e) <- getBounds a
    forM_ [1 .. e] $ \i -> do
        key <- readArray a i
        mparent <- a !? (i `div` 2)
        mleft   <- a !? (i * 2)
        mright  <- a !? (i * 2 + 1)
        putStr $ "node "  ++ show i   ++ ": "
        putStr $ "key = " ++ show key ++ ", "
        when (isJust mparent) $ do
            putStr $ "parent key = " ++ show (fromJust mparent) ++ ", "
        when (isJust mleft) $ do
            putStr $ "left key = "   ++ show (fromJust mleft)   ++ ", "
        when (isJust mright) $ do
            putStr $ "right key = "  ++ show (fromJust mright)  ++ ", "
        putStrLn ""

main :: IO ()
main = do
    n <- readLn
    xs <- (-1 :) . fmap readi . B.words <$> B.getLine
    ary <- newListArray (0, n) xs :: IO (IOUArray Int Int)
    printHeap ary



Measured memory_bytes: 4128
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

void Output(bool ok) {
  cout << (ok ? "YES" : "NO") << endl;
  exit(0);
}

int main()
{
  ll n;
  cin >> n;
  ll a, b, C, D;
  cin >> a >> b >> C >> D;
  b = abs(a - b);
  a = 0;

  n--;
  for (ll x = 0; x <= n; ++x) {
    ll y = n - x;
    ll l, r;
    l = x * C - y * D;
    r = x * D - y * C;
    if (l <= b && b <= r) Output(true);
  }
  Output(false);

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
A = [int(i) for i in input().split()]

ans = []
for i in range(N):
    count = 0
    while True:
        if A[i] % 2 != 0:
            ans.append(count)
            break
        else:
            A[i] /= 2
            count += 1
print(min(ans))


Measured memory_bytes: 3060
func gcd(_ a: Int, _ b: Int) -> Int {
    guard b != 0 else { return a }

    let r = a % b
    if r > b - r {
        return gcd(b, b - r)
    } else {
        return gcd(b, r)
    }
}

func gcd(_ a: Int, _ b: Int, _ c: Int) -> Int {
    gcd(gcd(a, b), c)
}

let N = Int(readLine()!)!

var sum0 = 0
for i in 1 ... N {
    guard i + 1 <= N else { continue }
    for j in i + 1 ... N {
        guard j + 1 <= N else { continue }
        for k in j + 1 ... N {
            sum0 += gcd(i, j, k)
        }
    }
}

var sum1 = 0
for i in 1 ... N {
    guard i + 1 <= N else { continue }
    for j in i + 1 ... N {
        sum1 += gcd(i, i, j)
        sum1 += gcd(i, j, j)
    }
}

var sum2 = 0
for i in 1 ... N {
    sum2 += gcd(i, i, i)
}

print(sum0 * 6 + sum1 * 3 + sum2)


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

using namespace std;

int main() {

	int n, m, qq;
	cin >> n >> m >> qq;

	vector<vector<int>> lr(n + 1,vector<int> (n+1));

	int l, r;
	for (int i = 1; i <= m; i++) {

		cin >> l >> r;
		lr[l][r]++;

	}

	vector<vector<int>> lrsum(n + 1, vector<int>(n + 1));

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {

			lrsum[i][j] = lrsum[i - 1][j] + lrsum[i][j - 1] - lrsum[i - 1][j - 1] + lr[i][j];

		}
	}

	int p, q;
	for (int i = 0; i < qq; i++) {
		cin >> p >> q;
		
		cout << lrsum[q][q] - lrsum[p - 1][q] - lrsum[q][p - 1] + lrsum[p - 1][p - 1] << endl;;

	}

	return 0;
}

Measured memory_bytes: 5556
import collections
N,M=map(int,input().split())

ki=[]
k_sw=[] #Li -> s1 ~ ski
for i in range(M):
    terms = input().split()
    ki.append(int(terms[0]))
    k_sw.append([])
    for j in range(1,len(terms)):
        k_sw[i].append(int(terms[j]))
P=list(map(int,input().split()))

def is_all_on(swb):
    all_on = True
    for i in range(M):
        #for Light
        sws = k_sw[i]
        total = 0
        for s in sws:
            total += swb[s-1]
        if total % 2 != P[i]:
            all_on = False
            break
    return all_on

on_num = 0
for swp in range(0,2**N):
    binary_pattern = format(swp,'0'+str(N)+'b')
    blist = []
    for b in binary_pattern:
        blist.append(int(b))
    if is_all_on(blist):
        on_num += 1
print(on_num)

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test


constexpr int mod = 1e9 + 7;

struct M {
    unsigned v;
    M(long long a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    M& operator+=(M r) { if ((v += r.v) >= mod) v -= mod; return *this; }
    M& operator-=(M r) { if ((v += mod - r.v) >= mod) v -= mod; return *this; }
    M& operator*=(M r) { v = (uint64_t)v * r.v % mod; return *this; }
};

uint32_t add(M a, M b) { return (a += b).v; }
uint32_t mul(M a, M b) { return (a *= b).v; }
uint32_t sub(M a, M b) { return (a -= b).v; }

uint32_t po(M x, int n) {
    M res(1);
    while (n > 0) {
        res *= (n & 1 ? x : 1);
        x *= x; n /= 2;
    }
    return res.v;
}

const int N = 2e5 + 4;

int a[N], post[N];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = n; i > 0; --i) {
        post[i] = add(post[i+1], a[i]);
    }
    int ans = 0;
    for (int i = 1; i < n; ++i) {
        ans = add(ans, mul(a[i], post[i+1]));
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 6740
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int a[16],b[20000],c[20001][256],n,m;
int fi(int p,int q){
  int i;
  if(c[p][q]>=0)
    return c[p][q];  
  int mn=1<<30;
  for(i=0;i<m;++i){
    int r=min(max(0,q+a[i]),255);
    mn=min(mn,fi(p+1,r)+(b[p]-r)*(b[p]-r));
  }
  return c[p][q]=mn;
}
int main(){
  int i;
  //int n,m;
  while(cin>>n>>m,n||m){
    //int a[16],b[20000];
    for(i=0;i<m;++i)
      cin>>a[i];
    for(i=0;i<n;++i)
      cin>>b[i];
    memset(c,-1,n*256*sizeof(int));
    memset(c[n],0,256*sizeof(int));
    cout<<fi(0,128)<<endl;
  }
  return 0;
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  
int n;
vector<int> num;

int dp[10][10];
void f(int index, int first_dig, int last_dig, int tight)
{
    if(index == num.size())
    {
        if(first_dig == -1 || first_dig == 0) first_dig = last_dig;
        if(last_dig)
            dp[first_dig][last_dig]++;
        return;
    }
    int lim = 9;
    if(tight) lim = num[index];
    for(int i=0;i<=lim;i++)
    {
        int tmp = first_dig;
        if(first_dig == -1 || first_dig == 0) tmp = i;
        int tmp_tight = tight;
        if(i < lim) tmp_tight = 0;
        f(index+1, tmp, i, tmp_tight);
    }
}

int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    cin >> n;
    int tmp = n;
    while(tmp > 0)
    {
        num.pb(tmp%10);
        tmp /= 10;
    }
    reverse(all(num));
    f(0, -1, -1, 1);

    int ans =0;
    for(int i=1;i<=9;i++)
    {
        for(int j=0;j<=9;j++)
        {
            ans += dp[i][j]*dp[j][i];
        }
    }
    
    cout << ans << "\n";
    return 0;
}



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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define foru(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define endl "\n"
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define com(a, b) a ## b
#define scv(a, b, c) #a#b#c
#define db(x) cerr << "[" << #x << ": " << (x) << "] " << endl;
#define run cerr << 1 << endl; 
template<class T> void printvec(vector<T>& x, int a, int b) {foru (i, a, b) cout << x[i] << " "; cout << endl;}

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<pll> v2l;
typedef pair<char, int> pci;
typedef vector<pci> vci;

const ld PI = acos((ld) -1);
const ld EPS = 1e-6;
const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const ll MOD = 1e9 + 7;
const ll oo = 1e18 + 7;
const int BASE = 10000;

void solve() {
    double R;
    cin >> R;
    cout << R * 2 * PI;
}

int main() {
    #ifdef DEBUG
        com(fre, open) (scv(solve, ., inp), "r", stdin);
        com(fre, open) (scv(solve, ., out), "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
} 

Measured memory_bytes: 3792
#include <iostream>



using namespace std;



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



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n,a,b,sum=0;
	cin>>n>>a;
	for(int i=0;i<n;i++)
	{
		cin>>b;
		if(a<=b)sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  vector<vector<int>> num(2,vector<int>(n));
  for(int i = 0;i <= 1;i++){
    for(int j = 0;j <= n - 1;j++){
      cin >> num[i][j];
    }
  }
  //cout<<1<<endl;
  int res = 0;
  res = INT_MIN;
  for(int i = 0;i <= n - 1;i++){
    int nowi = 0;
    int nowj = 0;
    int count = 0;
    //cout<<2<<endl;
    while(1){
      count += num[nowi][nowj];
      if(nowi == 1 && nowj == n - 1)break;
      if(nowj == i && nowi == 0)nowi++;
      else nowj++;
      //cout<<3<<endl;
    }
    res = max(res,count);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,n,total=0,temp;cin>>h>>n;
    for(int i=0;i<n;i++){
        cin>>temp;
        total+=temp;
    }
    if(total<h)cout<<"No\n";
    else cout<<"Yes\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int N, S, G, D;

bool check(vector<string> &v){
  //cout <<"==========" <<endl;
  //REP(i, v.size()) cout <<v[i] <<endl;
  int now = S;
  REP(i, v.size()){
    if(now != 0 && v[i][now - 1] == '1') --now;
    else if(now != N - 1 && v[i][now] == '1') ++now;
  }
  return now == G;
}

bool solve(vector<string> &v){
  REP(i, v.size()){
    REP(j, v[i].size()){
      if(v[i][j] == '1') continue;
      if(j != 0 && v[i][j - 1] == '1') continue;
      if(j + 1 != N - 1 && v[i][j + 1] == '1') continue;
      v[i][j] = '1';
      if(check(v)){
        cout <<i + 1 <<" " <<j + 1 <<endl;
        return 1;
      }
      v[i][j] = '0';
    }
  }
  return false;
}

int main(){
  while(cin >>N && N){
    cin >>S >>G >>D;
    --S; --G;
    vector<string> v(D);
    REP(i, D) cin >>v[i];
    if(check(v)) cout <<0 <<endl;
    else if(!solve(v)) cout <<1 <<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,p[200010],a[200010],ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		a[p[i]]=i;
	}
	int now=1;
	ans=1;
	for (int i=2;i<=n;i++)
	{
		if (a[i]>a[i-1])
		{
			now++;
		}
		else
		{
			now=1;
		}
		ans=max(ans,now);
	}
	printf("%d\n",n-ans);
    return 0;
}

Measured memory_bytes: 1792
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val length = StdIn.readInt
    val array = StdIn.readLine().split(" ").map(_.toInt)

    trace(array)
    insertionSort(array)
  }

  def insertionSort(array: Array[Int]): Unit = {
    val length = array.length
    for (i <- 1 to length - 1) {
      val v = array(i)
      var j = i - 1
      while (j >= 0 && array(j) > v) {
        array(j + 1) = array(j)
        j -= 1
      }
      array(j + 1) = v
      trace(array)
    }
  }

  def trace(array: Array[Int]): Unit = {
    val result = for (i <- array.toList) yield i
    println(result.mkString(" "))
  }
}

Measured memory_bytes: 47408
//2018.10.24

#include <iostream>
using namespace std;

int main() {

    string n;
    cin >> n;
    for(int i=0;i<3;i++) {
        if (n[i] == '1') n[i] = '9';
        else { n[i] = '1'; }
    }

    cout << n << endl;

}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(0, a + 1):
    for j in range(0, b + 1):
        for k in range(0, c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)

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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                char[] input = Console.ReadLine().ToCharArray();
                int[] numbers = (Array.ConvertAll(input, new Converter<char, int>(s => int.Parse(s.ToString()))));

                if (input[0] != '0')
                {
                    Console.WriteLine(numbers.Sum());
                }
                else
                {
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 9524
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const long long M = 1000000007;
map<pair<long long,long long>,long long> m;

long long solve(long long s, long long x){
	if(s == 0) return 1;
	if(m.count(make_pair(s,x))) return m[make_pair(s,x)] % M;

	long long res = solve(s / 2, x / 2) % M;
	(res += solve((s - 1) / 2, (x - 1) / 2)) %= M;
	if(s >= 2) (res += solve((s - 2) / 2, x / 2)) %= M;
	return m[make_pair(s,x)] = res;
}

int main(){
    long long n;
    cin >> n;
	cout << solve(n,n) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* Binary Indexed Tree(0-index) */

struct BIT{
  typedef int Type;
  int bit_size;
  vector<Type> data;
  
  BIT(int n){
    bit_size = n;
    data.assign(n+1,0);
  }
  
  //add x to kth value
  void add(int k,Type x){
    k += 1;
    
    while(k<=bit_size){
      data[k]+=x;
      k+= k&(-k); }
  }
  
  //sum of [1,k]
  Type query(int k){
    k += 1;
    
    Type rec=0;
    while(k>0){
      rec+=data[k];
      k-= k&(-k);
    }
    return rec;
  }
};


int main(){
  int n;
  int a[SIZE],t[SIZE];
  
  scanf("%d",&n);
  
  for(int i=0;i<n;i++){
    scanf("%d",a+i);
    t[a[i]] = i;
  }

  BIT bit(n+1);
  BIT bit2(n+1);

  ll ans = 0;
  
  for(int i=1;i<=n;i++){
    int x,y;
    int p = t[i];

    int l,r,mid,u;
    
    l = p; r = n-1, u = bit.query(p);
    while(l<r){
      mid = (l+r+1)/2;

      if(bit.query(mid) > u){
        r = mid-1;
      }else{
        l = mid;
      }
    }
    y = l - p;

    l = 0; r = p, u = bit2.query(n-p);
    while(l<r){
      mid = (l+r)/2;

      if(bit2.query(n-mid) > u){
        l = mid+1;
      }else{
        r = mid;
      }
    }
    x = p - l;
    

    ans += (ll)(x+1) * (y+1) * i;


    bit.add(p,1);
    bit2.add(n-p,1);
  }

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


Measured memory_bytes: 3328
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
BC = M.times.map { gets.split.map(&:to_i) }
B = 0
C = 1

cnt = Hash.new(0)
A.each do |a|
  cnt[a] += 1
end

BC.each do |bc|
  cnt[bc[C]] += bc[B]
end

rest = N
ans = 0
cnt.sort.reverse_each do |c|
  ans += c[0] * [c[1], rest].min
  rest -= c[1]
  break if rest <= 0
end

puts ans

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

// why am I so weak

int n;
int a[100055];

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

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	int res = 0;
	int mode = -1;
	int last = -1;

	for (int i = 0; i < n; i++) {
		if (mode == -1) {
			res++;
			last = a[i];
			mode = 3;
			continue;
		}

		if (mode == 0) {
			if (a[i] < last) {
				res++;
				mode = 3;
			}
		} else if (mode == 1) {
			if (a[i] > last) {
				res++;
				mode = 3;
			} 
		} else {
			if (last < a[i]) mode = 0;
			else if (last > a[i]) mode = 1;
		}

		last = a[i];
	}

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

	return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int A[3];

	cin >> A[0] >> A[1] >> A[2];

	sort(A, A+3);

	cout << A[2] - A[0] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define sort(v) sort(v.begin(), v.end())
#define sortr(v) sort(v.rbegin(), v.rend())
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int n;string s;
    cin >> n >> s;
    bool dp[30003][4][1009];
    dp[0][0][0] = true;
    for(int i = 0 ; i <= n ; i++){
        for(int j = 0 ; j <= 3 ;j++){
            for(int k = 0 ; k < 1000 ; k++){
                if(!dp[i][j][k]) continue;

                dp[i+1][j][k] = true;

                if(j <= 2){
                    dp[i+1][j+1][k*10+(s[i]-'0')] = true;
                }
            }
        }

    }

    int ans = 0;

    for(int i = 0 ; i < 1000 ; i++){
        if(dp[n][3][i]) ans++;
    }

    cout << ans;
}



Measured memory_bytes: 118528
N = int(input())
x = [[0,0,0]]
for i in range(N):
    num = [int(i) for i in input().split()]
    x.append(num)

count = 0    
for i in range(1,len(x)):
    dist = 0
    dist = dist + x[i][1]-x[i-1][1] + x[i][2]-x[i-1][2]
    
    if dist == 0:
        (x[i][0]-x[i-1][0])%2==0
        count += 1
        continue
        
    if dist <= x[i][0]-x[i-1][0]:
        if (x[i][0]-x[i-1][0])-dist==0:
            count += 1
            continue

        if ((x[i][0]-x[i-1][0])-dist)%2==0:
            count += 1

if count == (len(x)-1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61016
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int n; cin>>n;
  if(n%1000==0) out(0);
  else out(1000-n%1000);
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    vector<int> X(N);
    for (ll i = 0; i < N; i++) {
        cin >> X[i];
    }
    ll tmp;
    ll ans = INF;
    for (ll i = 1; i < 101; i++) {
        tmp = 0;
        for (ll j = 0; j < N; j++) {
            tmp += (X[j] - i) * (X[j] - i);
        }
        ans = min(ans, tmp);
    }

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

}

Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String[] params = in.nextLine().split(" ");
        int r = Integer.parseInt(params[0]);
        int D = Integer.parseInt(params[1]);
        int x = Integer.parseInt(params[2]);

        int result = x;
        for( int i = 1 ; i <= 10 ; i++ ){
            result = r * result - D;
            System.out.println(result);
        }

    }

}


Measured memory_bytes: 21716
<?php
fscanf(STDIN, "%d %d", $N, $X);
$L = explode(" ", trim(fgets(STDIN)));
$ans = 0;
for ($i = 0; $i <= $N; $i++) {
    if ($i === 0) {
        $t = 0;
    } else {
        $t += $L[$i - 1];
    }
    if ($t <= $X) $ans++;
}
echo $ans;

Measured memory_bytes: 4728
from collections import deque
import sys


H, W = [int(_) for _ in input().split()]

M = []
w_count = 0
for i in range(H):
    s = input()
    w_count += s.count('.')
    M.append(s)

visited = [[False for _ in range(W)] for _ in range(H)]

q = deque([[0, 0, 1]])
while len(q) != 0:
    p = q.popleft()
    x = p[0]
    y = p[1]
    count = p[2]
    if x == W - 1 and y == H - 1:
        print(w_count - count)
        sys.exit(0)
    cands = []
    if x - 1 >= 0:
        cands.append([x-1, y])
    if x + 1 < W:
        cands.append([x+1, y])
    if y - 1 >= 0:
        cands.append([x, y-1])
    if y + 1 < H:
        cands.append([x, y+1])
    for cx, cy in cands:
        if M[cy][cx] == '.' and not visited[cy][cx]:
            q.append([cx, cy, count+1])
            visited[cy][cx] = True
print(-1)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstdint>
#include <vector>

constexpr intmax_t mod = 1e9+7;

template <typename Tp>
Tp gcd(Tp a, Tp b, Tp& x, Tp& y) {
  x = Tp(0);
  y = Tp(1);
  for (Tp u = y, v = x; a;) {
    Tp q = b/a;
    std::swap(x -= q*u, u);
    std::swap(y -= q*v, v);
    std::swap(b -= q*a, a);
  }
  return b;
}

template <typename Tp>
Tp modinv(Tp a, Tp mod) {
  Tp x, y;
  gcd(a, mod, x, y);
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

template <typename Tp>
Tp modadd(Tp a, Tp b, Tp mod) {
  a += b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <typename Tp>
Tp modadd(std::initializer_list<Tp> const& adds, Tp mod) {
  Tp res = 0;
  for (auto const& add: adds) {
    res += add % mod;
    if (res < 0) res += mod;
    if (res >= mod) res -= mod;
  }
  return res;
}

template <typename Tp>
Tp modsub(Tp a, Tp b, Tp mod) {
  a -= b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <typename Tp>
Tp modmul(std::initializer_list<Tp> const& muls, Tp mod) {
  Tp res = 1;
  for (auto const& mul: muls) (res *= mul) %= mod;
  return res;
}

template <typename Tp>
Tp modpow(Tp base, intmax_t iexp, Tp mod) {
  Tp res = 1;
  for (Tp dbl = base; iexp; iexp >>= 1) {
    if (iexp & 1) res = res * dbl % mod;
    dbl = dbl * dbl % mod;
  }
  return res;
}

class modchoose {
  std::vector<intmax_t> fact, fact_inv;
  const intmax_t mod;

public:
  modchoose(intmax_t N, intmax_t mod): mod(mod) {
    fact.resize(N+1);
    fact_inv.resize(N+1);
    fact[0] = 1;
    for (intmax_t i = 1; i <= N; ++i)
      fact[i] = fact[i-1] * i % mod;

    fact_inv[N] = modinv(fact[N], mod);
    for (intmax_t i = N; i--;)
      fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
  }

  intmax_t operator ()(intmax_t n, intmax_t r) const {
    intmax_t res = fact[n] * fact_inv[r] % mod;
    (res *= fact_inv[n-r]) %= mod;
    return res;
  }
};

class modfactorial {
  std::vector<intmax_t> fact, fact_inv;
  intmax_t mod;

public:
  modfactorial(intmax_t N, intmax_t mod): mod(mod) {
    fact.resize(N+1);
    fact_inv.resize(N+1);
    fact[0] = 1;
    for (intmax_t i = 1; i <= N; ++i)
      fact[i] = fact[i-1] * i % mod;

    fact_inv[N] = modinv(fact[N], mod);
    for (intmax_t i = N; i--;)
      fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
  }

  intmax_t operator ()(intmax_t k) const {
    return fact[k];
  }

  intmax_t inverse(intmax_t k) const {
    return fact_inv[k];
  }
};

int main() {
  intmax_t n, k;
  scanf("%jd %jd", &n, &k);

  modchoose mc(k, mod);
  modfactorial mf(k, mod);
  intmax_t res = 0;
  for (intmax_t i = 1; i <= k; ++i) {
    intmax_t cur = mc(k, i);
    if ((i-1) % 2) cur = (mod-cur) % mod;
    (cur *= modpow(k-i, n, mod)) %= mod;
    (res += cur) %= mod;
  }
  res = modsub(modpow(k, n, mod), res, mod) * mf.inverse(k) % mod;
  printf("%jd\n", res);
}



Measured memory_bytes: 2764
#include<stdio.h>
int main(void){
    int n,u,k,v;
    int i,j;
    int M[100][100]={0};
    
    scanf("%d",&n);

    for(i=0;i<n;i++){
	scanf("%d%d",&u,&k);
	for(j=0;j<k;j++){
	    scanf("%d",&v);
	    v--;
	    M[i][v]=1;
	}
    }

    for(i=0;i<n;i++){
	for(j=0;j<n;j++){
	    if(j) printf(" ");
	    printf("%d",M[i][j]);
	}
	printf("\n");
    }

    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPe(i, n) for(int i = 0; i <= (int)(n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,x;
    int cnt = 0;
    cin >> a >> b >> c >> x;
    REPe(i, a) {
        REPe(j, b) {
            REPe(k, c) {
                int sum = i*500 + j*100 + k*50;
                if(sum == x) ++cnt;
            }
        }
    }

    cout << cnt << endl;

}



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

int main()
{
    int h,w;
    std::cin >> h >> w;
    std::vector<std::vector<int>> dist(10,std::vector<int>(10));
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            std::cin >> dist[i][j];
        }
    }
    for(int k = 0; k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    int res = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int t;
            std::cin >> t;
            if(t == -1 || t == 1)continue;
            res += dist[t][1];
        }
    }
    std::cout << res << std::endl;

}


Measured memory_bytes: 256
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
int N, R, C;

bool IsBorder(int r, int c) {
    return !r || !c || r == R || c == C;
}

int GetID(int r, int c) {
    if (r == 0)
        return c;
    else if (c == C)
        return C + r;
    else if (r == R)
        return C + R + C - c;
    else if (c == 0)
        return C + R + C + R - r;
    while(true);
}

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

    cin >> R >> C >> N;

    vector<pair<int, int>> points;

    for (int i = 0; i < N; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        if (IsBorder(x1, y1) && IsBorder(x2, y2)) {
            int id1 = GetID(x1, y1);
            int id2 = GetID(x2, y2);

            points.emplace_back(id1, i);
            points.emplace_back(id2, i);
        }
    }

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

    stack<int> st;

    for (auto p : points) {
        if (st.empty() || st.top() != p.second)
            st.push(p.second);
        else
            st.pop();
    }

    cout << (st.empty() ? "YES\n" : "NO\n");

    return 0;
}


Measured memory_bytes: 2420
#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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

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();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//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())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


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

int c[111][111];

int main(){
	int n,w,h,s,t;
	while(1){
		cin>>n;
		int ret = 0;
		if(n==0)return 0;
		cin>>w>>h;
		memset(c, 0, sizeof(c));
		REP(i,n){
			int x,y;
			cin>>x>>y;
			c[x][y]=1;
		}
		cin>>s>>t;
		FOR(i,1,w+1){
			FOR(j,1,h+1){
				c[i][j] = c[i-1][j]+c[i][j-1]-c[i-1][j-1]+c[i][j];
			}
		}
		FOR(i,1,w-s+2){
			FOR(j,1,h-t+2){
				ret = max(ret, c[i+s-1][j+t-1]-c[i-1][j+t-1]-c[i+s-1][j-1]+c[i-1][j-1]);
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 1216