akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll ans=0,sum=0;
  rep(i,n) {
    ans+=sum*a[i];
    ans%=MAX;
    sum+=a[i];
    sum%=MAX;
  }
  pr(ans);

}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 5200
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 100000;
ll A[NM];

ll MOD = 1000000007;


void solve() {
    int A,B;
    cin >> A >> B;

    double tempA, tempB;
    for (double i = 0; i < 10000; i++)
    {
        if (i <= A) {
            continue;
        }
        if (i <= B) {
            continue;
        }

        tempA = i * 0.08;
        tempB = i * 0.10;
        if ((int)tempA == A && (int)tempB == B) {
            cout << (int)i;
            return;
        }
    }
    cout << -1;
    
}



int main() {
    solve();
    return 0;
}







Measured memory_bytes: 256
n,m=map(int,input().split())
s=input()
t=input()

#最大公約数
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

#最小公倍数
def lcm(x,y):
    return x*y//gcd(x,y)

l=lcm(n,m)

a=l//n
b=l//m
ln=[]
lm=[]
i=0
while i<n:
    ln.append(i)
    i+=b
i=0
while i<m:
    lm.append(i)
    i+=a

p=0
for i in range(len(ln)):
    if s[ln[i]]!=t[lm[i]]:
        p=1
if p==0:
    print(l)
else:
    print(-1)

Measured memory_bytes: 5236
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n, x, y := r.nextInt(), r.nextInt(), r.nextInt()

	x--
	y--
	if x > y {
		x, y = y, x
	}
	ans := make([]int, n)
	minInt := func(a int, vs ...int) int {
		for i := range vs {
			v := &vs[i]
			if a > *v {
				a = *v
			}
		}
		return a
	}
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			d := minInt(j-i, abs(x-i)+1+abs(j-y))
			ans[d]++
		}
	}

	for _, v := range ans[1:] {
		fmt.Fprintln(stdout, v)
	}
}


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

template<int MAX>
struct Combination {
    vector<long long> _inv, _fac, _ifac;
    const long long MOD;
    Combination(long long mod) : _inv(MAX+1), _fac(MAX+1), _ifac(MAX+1), MOD(mod) { init(); }
    inline void init(long long mod = 0) { init_inv(), init_fac(); }

    inline void init_inv() {
        _inv[0] = 0;
        for (int i = 1; i <= MAX; i++) {
            if (i == 1) _inv[i] = 1;
            else {
                _inv[i] = (MOD - (MOD / i) * _inv[MOD % i]) % MOD;
                if (_inv[i] < 0) _inv[i] += MOD;
            }
        }
    }
    inline void init_fac() {
        _fac[0] = _ifac[0] = 1;
        for (int i = 1; i <= MAX; i++) {
            _fac[i] = _fac[i-1] * i % MOD;
            _ifac[i] = _ifac[i-1] * _inv[i] % MOD;
        }
    }

    inline long long modpow(long long n, long long r) {
        n %= MOD, r %= (MOD-1);
        if (!n) return 0;
        long long ret = 1; long long tmp = n;
        while (r != 0) {
            if (r % 2) ret *= tmp;
            tmp *= tmp; tmp %= MOD; ret %= MOD;
            r /= 2;
        }
        return ret;
    }
    inline const long long invb(int i) { return (i <= MAX) ? _inv[i] : this->modpow(i, MOD-2); }
    inline const long long inv(int i) { return _inv[i]; }
    inline const long long fac(int i) { return _fac[i]; }
    inline const long long ifac(int i) { return _ifac[i]; }

    const long long operator()(int n, int r) {
        if (n < r) return 0;
        return fac(n) * ifac(r) % MOD * ifac(n-r) % MOD;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    constexpr int MAX = 600000;
    constexpr int mod = 1000000007;
    Combination<MAX> C(mod);
    int n, m, l, r; cin >> n >> m >> l >> r;
    vector<long long> x(r+1, 0);
    vector<long long> y(r+1, 0);
    for (int a = 1; a <= r; a++) {
        for (int i = 0; i <= n-m; i++) {
            if ((long long) (m+i) * a > r) break;
            if (i & 1) x[(m+i)*a] -= C(n-m, i);
            else x[(m+i)*a] += C(n-m, i);
            x[(m+i)*a] = (x[(m+i)*a] + mod) % mod;
        }
    }
    for (int i = r; i >= m; i--) {
        x[i] = (x[i] - x[i-m] + mod) % mod;
    }
    for (int i = 0; i <= r; i++) y[i] = C(n+i, i);
    auto calc = [&](int l) {
        long long ret = 0;
        for (int i = 0; i <= l; i++) {
            ret += x[i] * y[l-i] % mod;
        }
        return ret % mod;
    };
    long long sub = (calc(r) - calc(l-1) + mod) % mod * C(n, m) % mod;
    long long all = 0;
    for (int i = l; i <= r; i++) all += C(i+n-1, i);
    cout << (all - sub + mod) % mod << "\n";
    return 0;
}

Measured memory_bytes: 19072
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=500;
char ch[M];
int dis[M][M];
int c[M];
int n;
bool dfs(int x,int col){
	if (!c[x]) c[x]=col; 
	else if (c[x]!=col) {
//		cout<<x<<" "<<c[x]<<" "<<col<<"\n";
		return 0;
	}
		else return 1;
	bool flag=1;
	F(i,1,n){
		if (dis[x][i]==1){
			flag&=dfs(i,3-col);
		} 
	}
	return flag;
}
int main(){
	n=read();
	F(i,1,n){
		scanf("%s",ch+1);
		F(j,1,n){
			if (i==j){
				dis[i][j]=0;
				continue;
			}
			if (ch[j]=='1'){
				dis[i][j]=1;
			}
			else dis[i][j]=1e9;
		}
	}
	if (!dfs(1,1)) {
		puts("-1");
		return 0;
	}
	F(k,1,n){
		F(i,1,n){
			F(j,1,n){
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	int ans=0;
	F(i,1,n){
		F(j,1,n){
			if (dis[i][j]!=1e9) ans=max(ans,dis[i][j]);
		}
	}
//	cout<<dis[3][5]<<"\n";
	cout<<ans+1<<"\n"; 
	return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pll pair<long long int, long long int>
#define great (long long int)(1e9+7)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fst first
#define scd second

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

   sort(a,a+n);
ll ans=0;
   for(ll k=1;k<=n-1;k++)
   {
       ans+=a[n-1-(k/2)];

   }
   cout<<ans<<endl;return;

}
int main()
{
    //fastio;
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


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

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

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

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

  for (int i = 1; i < n; i++) {
    if(i != 1)
      dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i]);
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i]);
  }

  printf("%d\n", dp[n-1]);

  return 0;
}

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

typedef vector< long long > vi;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define ll long long

ll dp[200000];
ll cost(ll n, ll h[]);

int main(void)
{
    fill_n(dp, 200000, -1);
    ll n;
    cin >> n;
    ll h[n];
    for (int i = 0; i < n; i++)
        cin >> h[i];
    dp[2] = abs(h[1] - h[0]);
    dp[1] = 0;
    cout << cost(n, h) << "\n";
}

ll cost(ll n, ll h[])
{
    if (n == 2)
        return dp[2];
    if (n == 1)
        return dp[1];

    if (dp[n] == -1)
        dp[n] = min(cost(n - 1, h) + abs(h[n - 1] - h[n - 2]), cost(n - 2, h) + abs(h[n - 1] - h[n - 3]));

    return dp[n];
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N;cin>>N;
    int ans=INF;
    for(int i=0;i<=N;i++){
        int preans=0;
        int M=i,M2=N-i;
        while(M>0){
            preans+=M%6;
            M/=6;
        }
        while(M2>0){
            preans+=M2%9;
            M2/=9;
        }
        ans=min(ans,preans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        v: [(i64, i64); n],
    }

    let mut sumed = v.iter().map(|&(x, y)| x + y).collect::<Vec<i64>>();
    sumed.sort();
    sumed.reverse();

    let ans: i64 =
        (0..n).step_by(2).map(|i| sumed[i]).sum::<i64>() - v.iter().map(|&(x, y)| y).sum::<i64>();
    println!("{}", ans);
}


Measured memory_bytes: 6720
# AtCoder Beginner Contest 175
# C - Walking Takahashi

X,K,D =map(int,input().split())

X=abs(X)

A=X//D
M=X%D

if K<=A:
    print(X-K*D)
    exit()

else :
    if A%2==K%2:
        print(M)
    else :
        print(min(abs(M+D),abs(M-D)))

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,k;cin>>n>>m>>k;
  vi A(n),B(m);
  for(auto &a:A)cin>>a;
  for(auto &a:B)cin>>a;
  vi rui(n+10),rui2(m+1);
  for(int i=0;i<n;i++){
    rui[i+1] = rui[i] + A[i];
  }
   for(int i=0;i<m;i++){
    rui2[i+1] = rui2[i] + B[i];
  }
  rui2.pb(llINF);
  ll ans = 0;
  for(ll i=0;i<=n;i++){
    ll sum = rui[i];
    if(sum > k)continue;
    auto ub = upper_bound(ALL(rui2),k-sum);
    ans = max(ans,i + (ub-rui2.begin())-1);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
  }
  vector<vector<int>> aa(100010);
  for (int i = 0; i < m; ++i) {
    aa[a[i]].push_back(b[i]);
    aa[b[i]].push_back(a[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    bool ok = true;
    for (int j = 0; j < aa[i].size(); ++j) {
      // cout << i << " " << aa[i][j] << " " <<  h[i] << " " << h[aa[i][j]] << endl;
      if (h[i] <= h[aa[i][j]]) {
        // cout << "NO" << endl;
        ok = false;
      }
    }
    if (ok) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 9772
#include <stdio.h>

int main(void)
{
	int a, b;
	int digit;

	while ((scanf("%d %d", &a, &b)) != EOF){
		int sum = a + b;
		for (digit = 1; sum >= 10; sum /= 10){
			digit++;
		}

		printf("%d\n", digit);
	}

	return 0;
}


Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
char a;
int main()
{
	cin>>a;
	if(a=='a') cout<<"vowel"<<endl;
	if(a=='e') cout<<"vowel"<<endl;
	if(a=='i') cout<<"vowel"<<endl;
	if(a=='o') cout<<"vowel"<<endl;
	if(a=='u') cout<<"vowel"<<endl;
	
	if(a!='a'&&a!='e'&&a!='i'&&a!='o'&&a!='u')cout<<"consonant"<<endl;
	return 0;
 } 

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

using namespace __gnu_pbds;
using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll i = 0; i < n; i++)
#define FORN(i, a, b) for (ll i = a; i < b; i++)
#define FORE(i, l) for (auto i : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) n.begin(), n.end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    FOR(i, n) cin >> a[i];
    queue<ll> q;
    q.emp(0); q.emp(0);
    vector<bool> visited(n);
    while (!q.empty())
    {
        ll cur = q.front(); q.pop();
        ll s = q.front(); q.pop();
        if (visited[cur]) break;
        if (cur == 1) cout << s << '\n';
        visited[cur] = 1;
        q.emp(a[cur] - 1); q.emp(s + 1);
    }
    if (!visited[1]) cout << -1 << '\n';
}



Measured memory_bytes: 1024
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const a = arg[1].split(" ").map(n=>parseInt(n));
    const list = [...Array(200000)].fill(0);
    
    for(let i in a) {
        list[a[i]]++;
    }
    
    list.sort((a,b)=>b-a);
    
    console.log(N - list.slice(0, K).reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 50172
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, int(xs.size()) - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

vector<int> solve(int n, int m, vector<vector<int> > const & g, vector<vector<int> > const & g_rev) {
    queue<int> que;
    vector<int> outdegree(n);
    REP (i, n) {
        outdegree[i] = g[i].size();
        if (outdegree[i] == 0) {
            que.push(i);
//cerr << "push* " << i+1 << endl;
        }
    }
    vector<int> parent(n, -1);
    while (not que.empty()) {
        int i = que.front();
        que.pop();
//cerr << "pop " << i+1 << endl;
        for (int j : g[i]) {
            if (parent[j] == -1) {
                parent[j] = i;
            }
        }
        for (int j : g_rev[i]) {
            -- outdegree[j];
            if (outdegree[j] == 0) {
//cerr << "push " << j+1 << endl;
                que.push(j);
            }
        }
    }
    return parent;
}

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > g(n), g_rev(n);
    REP (i, n - 1 + m) {
        int a, b; cin >> a >> b;
        -- a;
        -- b;
        g[a].push_back(b);
        g_rev[b].push_back(a);
    }
    auto parent = solve(n, m, g, g_rev);
    REP (i, n) {
        cout << parent[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 12152
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }
  sort(vec.rbegin(), vec.rend());

  int ans = vec[0] / 2;
  for (int i = 1; i < N; i++) {
    ans += vec[i];
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;

void merge (int *first1, int *last1, int *first2, int *last2){
    int size1 = last1 - first1;
    int size2 = last2 - first2;
    int *result = new int[size1+size2];
    int i = 0;
    int j = 0;
    int index = 0;
    while (true){
        if (i < size1 && (first1[i] <= first2[j] || j >= size2)){
            result[index] = first1[i];
            ++i; ++index;
        }
        if (j < size2 && (first1[i] > first2[j] || i >= size1)){
            result[index] = first2[j];
            ++j; ++index;
        }
        if (i==size1 && j==size2){
            for (i=0; i<size1; ++i) first1[i] = result[i];
            for (j=0; j<size2; ++j) first2[j] = result[j+size1];
            delete[] result;
            return;
        }
    }
}
void MergeSort (int *first, int *last){
    int size = last - first;
    if(size <= 1) return;
    MergeSort(first, first+size/2);
    MergeSort(first+size/2, last);
    merge(first, first+size/2, first+size/2, last);
}


int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

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

  int H, W;

  string s;
  cin >> H >> W;
  REP(i, H){
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

#define MAX_N 100000

struct uftree {
    int par[MAX_N], rank[MAX_N];
    uftree(int N) {
        for (int i=0; i<N; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y]) par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    int p, x, y, pinv[N];
    for (int i=0; i<N; i++) {
        scanf("%d", &p);
        pinv[p-1] = i;
    }
    uftree T(N);
    for (int i=0; i<M; i++) {
        scanf("%d %d", &x, &y);
        T.unite(x-1, y-1);
    }
    int ans=0;
    for (int i=0; i<N; i++) if (T.same(i, pinv[i])) ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1280
#include<algorithm>
#include<cstdio>
#define N 200002
#define p 1000000007
#define ll long long
using namespace std;
inline int mod(int x){return x>=p?x-p:x;}
inline int calc(int x,int y)
{
	int z=1;
	for(;y;x=(ll)x*x%p,y>>=1)if(y&1)z=(ll)x*z%p;
	return z;
}
int a[N],b[N],c[N],d[N],e[N],f[N],g[N],i,j,n,o[N],s,x;
inline bool cmp(int u,int v){return a[u]==a[v]?u<v:a[u]<a[v];}
inline void add(int u,int v){while(u<=n)o[u]=mod(o[u]+v),u+=u&-u;}
inline int sum(int u)
{
	int v=0;
	while(u)v=mod(o[u]+v),u-=u&-u;
	return v;
}
int main()
{
	scanf("%d",&n),c[n+1]=*d=d[1]=*e=*f=s=1;
	for(i=2;i<=n;i++)d[i]=(ll)(p-p/i)*d[p%i]%p;
	for(i=1;i<=n;i++)scanf("%d",a+i),c[a[b[i]=i]]++;
	for(i=n;i;i--)c[i]=c[i+1]+c[i]-1,s=(ll)c[i]*s%p;
	if(sort(b+1,b+n+1,cmp),!s)return 0*puts("0");
	for(i=1;i<=n;i++)e[i]=(ll)e[i-1]*d[c[i]]%p*(c[i]==1?g[i]=1:c[i]-1)%p,f[i]=(ll)f[i-1]*c[i]%p*d[c[i]-1]%p,g[i]+=g[i-1];
	for(i=j=1;i<=n;x=(x+(ll)sum(b[i])*e[a[b[i]]])%p,add(b[i],f[a[b[i]]]),i++)if(g[a[b[i]]]!=g[a[b[j]]])while(j<i)add(b[j],mod(p-f[a[b[j]]])),j++;
	for(i=1;i<=n;i++)o[i]=0;
	for(i=j=n;i;x=(x+(ll)sum(b[i])*f[a[b[i]]])%p,add(b[i],mod(p-e[a[b[i]]])),i--)if(g[a[b[i]]]!=g[a[b[j]]])while(i<j)add(b[j],e[a[b[j]]]),j--;
	for(i=1;i<=n;i++)o[i]=0;
	for(i=j=n;i;x=mod(x+sum(b[i])),add(b[i],2),i--);
	return 0*printf("%lld\n",500000004ll*x%p*s%p);
}

Measured memory_bytes: 6400
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> P;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    P.resize(N);
    for (auto &val : P)
    {
        cin >> val;
    }
    vector<int> ord(N);
    for (int i = 0; i < N; i++)
    {
        ord[i] = i;
    }
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        return P[i] > P[j];
    });
    multiset<int> s;
    ll ans = 0;
    s.insert(N);
    s.insert(N);
    s.insert(-1);
    s.insert(-1);
    ll result = 0;
    for (auto i : ord)
    {
        auto iter = s.lower_bound(i);
        ll idx1 = *iter;
        ++iter;
        ll idx2 = *iter;
        --iter;
        --iter;
        ll idx3 = *iter;
        --iter;
        ll idx4 = *iter;
        result += P[i] * (idx2 - idx1) * (i - idx3);
        result += P[i] * (idx3 - idx4) * (idx1 - i);
        s.insert(i);
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 5760
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B;
  ci(A, B);
  if(A == B){
    co("Draw");
  }
  else if(A == 1){
    co("Alice");
  }
  else if(B == 1){
    co("Bob");
  }
  else if(A > B){
    co("Alice");
  }
  else{
    co("Bob");
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		if(M % 2 == 1) {
			int l = 1, r = N/2;
			if(N % 2 == 0)
				r--;
			for(int i = 0; i < M/2; i++) {
				System.out.println(l + " " + r);
				l++;
				r--;
			}
			l = N/2+1;
			r = N;
			if(N % 2 == 0) {
				l--;
				r--;
			}
			for(int i = 0; i < (M+1)/2; i++) {
				System.out.println(l + " " + r);
				l++;
				r--;
			}
		}
		else {
			int l = 1, r = N/2;
			if(N % 2 == 0)
				r--;
			for(int i = 0; i < M/2; i++) {
				System.out.println(l + " " + r);
				l++;
				r--;
			}
			l = N/2+1;
			r = N;
			if(N % 2 == 0) {
				l--;
				r--;
			}
			for(int i = 0; i < M/2; i++) {
				System.out.println(l + " " + r);
				l++;
				r--;
			}
		}

	}

}

Measured memory_bytes: 54060
' Imports System.Collections.Generic
' Imports System.Globalization
' Imports System.IO
' Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim K, X As Integer
        Dim arr() As String
        arr = Split(Console.ReadLine())
        K = arr(0) : X = arr(1)
        Dim ans = new List(Of Integer)()
        For i As Integer = X - K + 1 To X + K - 1
            ans.Add(i)
        Next
        Console.WriteLine(String.join(" ", ans))
        Return
    End Sub
End Class

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

int main() {
	int first,end,flagf=0,flage=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'&&flagf==0&&flage==0){
			first=i;
			flagf=1;
		}
		if(s[i]=='Z'&&flagf==1){
			end=i;
			flage=1;
		}
	}
	//cout<<end<<" "<<first<<endl;
	cout<<end-first+1<<endl;
	return 0;
}

Measured memory_bytes: 640
/**
 *    author:  math2do
 *    created: 31.05.2020 17:44:53
**/

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(const char &ch) {
  return "'" + string(1, ch) + "'";
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  reverse(res.begin(), res.end());
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ld = long double;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(17);
  cerr << fixed << setprecision(17);
  long long a;
  ld b;
  cin >> a >> b;
  ld res = b * a;
  cout << (unsigned long long) res << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <stdio.h>

int main(){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	
	int i, j;
	for( i = 1; i < 10; i++)
		for( j = 1; j < 10; j++)
			printf("%dx%d=%d\n", i, j, i * j);

	//while(1){}
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 5e3 + 10, INF = 1e9 + 7;
int a[N], b[N][210], l[N], r[N];
LL sum[N], f[N][N];

void add(int x1, int y1, int x2, int y2, int x) {
    f[x1][y1] += x;
    f[x2+1][y2+1] += x;
    f[x1][y2+1] -= x;
    f[x2+1][y1] -= x;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i < n; i++) scanf("%d", a + i);
    for (int i = 1; i < n; i++) sum[i+1] = sum[i] + a[i];
    for (int i = 1; i <= n; i++) 
        for (int j = 1; j <= m; j++) scanf("%d", &b[i][j]);
    for (int j = 1; j <= m; j++) {
        vector<pair<int, int> > q;
        q.push_back(make_pair(INF, 0));
        for (int i = 1; i <= n; i++) {
            while (q.back().first < b[i][j]) q.pop_back();
            l[i] = q.back().second + 1;
            q.push_back(make_pair(b[i][j], i));
        }
        q.clear();
        q.push_back(make_pair(INF, n+1));
        for (int i = n; i >= 1; i--) {
            while (q.back().first <= b[i][j]) q.pop_back();
            r[i] = q.back().second - 1;
            q.push_back(make_pair(b[i][j], i));
        }
        for (int i = 1; i <= n; i++) add(l[i], i, i, r[i], b[i][j]);
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) f[i][j] += f[i][j-1];
    LL ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            f[i][j] += f[i-1][j];
            if (i <= j) ans = max(ans, f[i][j] - (sum[j] - sum[i]));
        }
    printf("%lld\n", ans);
    return 0;
}


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

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        int answer = 0;
        for (int i = 0; i < n; i++)
        {
            int l = sc.NextInt();
            int r = sc.NextInt();
            answer += (r - l + 1);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

void swap(int *, int *);

int main(){
  int i,j,count=0,n;
  int *arr;

  // input and allocation
  scanf("%d",&n);
  arr = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++) scanf("%d",&arr[i]);

  // sorting
  for(i=0; i<n; i++){
    for(j=n-1; j>i; j--){
      if(arr[j] < arr[j-1]){
	swap(&arr[j],&arr[j-1]);
	count++;
      }
    }
  }

  // output
  for(i=0; i<n; i++){
    printf("%d",arr[i]);
    if(i == n-1) break;
    printf(" ");
  }
  printf("\n%d\n",count);

  free(arr);

  return 0;
}

void swap(int *p1, int *p2){
  int tmp;

  tmp = *p1;
  *p1 = *p2;
  *p2 = tmp;

}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

const ll MOD = 1000003;

ll X, Y;
ll fact[2000015], revfact[2000015];

ll nod(ll a, ll b, ll x)
{
    if (a == 0)
    {
        X = 0, Y = -x;
        return 1;
    }
    if (b == 0)
    {
        X = x, Y = 0;
        return 1;
    }
    if (a < b)
    {
        ll d = nod(a, b % a, x);
        X += (b / a) * Y;
    }
    else
    {
        ll d = nod(a % b, b, x);
        Y += (a / b) * X;
    }
    return 1;
}

ll binpow(ll x, ll step)
{
    if (step == 0) return 1;
    if (step % 2 == 0)
    {
        ll a = binpow(x, step / 2);
        return a * a % MOD;
    }
    else return x * binpow(x, step - 1) % MOD;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    fact[0] = 1;
    for (int i = 1; i <= 2 * MOD; i++) fact[i] = fact[i - 1] * (ll) i % MOD;
    revfact[MOD - 1] = MOD - 1;
    for (int i = MOD - 2; i >= 0; i--) revfact[i] = revfact[i + 1] * (ll) (i + 1) % MOD;

    int quer;
    cin >> quer;
    for (int rep = 1; rep <= quer; rep++)
    {
        ll x, d, n;
        cin >> x >> d >> n;
        if (d == 0) {cout << binpow(x, n) << '\n'; continue;}
        if (n >= MOD) {cout << "0\n"; continue;}

        ll p = nod(d, MOD, x);
        if (Y < 0) Y += (abs(Y) / d + 1) * d;
        Y %= d;
        ll val = (x + Y * MOD) / d;
        ll ans = fact[val + n - 1] * revfact[val - 1] % MOD * binpow(d, n) % MOD;
        cout << ans << '\n';
    }
    return 0;
}



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

int main() {
  char b;
  cin >> b;
  
  if (b == 'A') cout << "T" << endl;
  if (b == 'T') cout << "A" << endl;
  if (b == 'G') cout << "C" << endl;
  if (b == 'C') cout << "G" << endl;

}

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

bool judge(int s){
  for(int i=2;i*i<=s;i++){
    if(s%i!=0 && (i+1)*(i+1)>s){return true;}
    if(s%i==0){return false; break;}
    }
}


int main(){

  int n,l;
  cin>>n;
  l=n;
  int b[1000]={};

  if(judge(n)){cout<<l<<": "<<n<<endl;}

  else{int count=0;
  for(int m=2;m<=n;){
    if(n==1){break;}
    if(n%m==0 && judge(m)){n=n/m; b[count]=m; count++; continue;}
    m++;
  }


  cout<<l<<":";
  for(int i=0;;i++){
    if(b[i]==0){cout<<endl; break;}
    cout<<" "<<b[i];
  }}

 
  return 0;
}



Measured memory_bytes: 3100
import java.util.*;
import java.text.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int h = sc.nextInt();
    int w = sc.nextInt();
    char[][] arr = new char[h][w];
    int[][] d = new int[h][w];
    int[] dx = {1, 0, -1, 0};
    int[] dy = {0, 1, 0, -1};

    public static void main(String[] args){
        new Main().run();
    }

    void run() {

        for (int i=0; i<h; i++) {
            arr[i] = sc.next().toCharArray();
        }

        int wallCnt = 0;

        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                d[i][j] = Integer.MAX_VALUE;
                if (arr[i][j] == '#') wallCnt++;
            }
        }
        d[0][0] = 0;

        dfs(new Pair(0, 0));

        if (d[h-1][w-1] == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(h * w - wallCnt - d[h-1][w-1] - 1);
        }
    }

    void dfs(Pair pair) {

        Queue<Pair> queue = new ArrayDeque<>();
        queue.add(pair);
        while (!queue.isEmpty()) {
            Pair tmp = queue.peek();
            for (int i=0; i<4; i++) {
                int ny = tmp.y + dy[i];
                int nx = tmp.x + dx[i];
                if (ny<0 || h<=ny || nx<0 || w<=nx) continue;
                if (arr[ny][nx] == '#') continue;
                if (d[ny][nx] != Integer.MAX_VALUE) continue;
                d[ny][nx] = Math.min(d[ny][nx], d[tmp.y][tmp.x]+1);
                queue.add(new Pair(ny, nx));
            }
            queue.poll();
        }

    }

    class Pair {
        int y;
        int x;
        public Pair(int y, int x) {
            this.y = y;
            this.x = x;
        }
    }

}

Measured memory_bytes: 35876
#include <stdio.h>
#include<stdlib.h>
int main()
{
	int x,y;
	scanf("%d%d", &x, &y);
	int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	if (days[x - 1] == days[y - 1])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	system("pause");
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <sstream>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int n;
    cin >> n;
    cout << n/3 << endl;
    return 0;
}

Measured memory_bytes: 256
import math


def main():
    while True:
        n = int(input())
        if n == 0:
            break

        nums = list(map(int, input().split()))
        mean = sum(nums) / n
        var = sum((s - mean) ** 2 for s in nums) / n
        sd = math.sqrt(var)

        print(sd)

if __name__ == "__main__":
    main()

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

#define REP(x, y) for (x = 1; x < y; x++)

int combination (int n);

int main(void) {
	int N;

	while (cin >> N, N) cout << combination(N) << endl;

	return 0;
}

int combination (int n) {
	int count = 0, i, j, k;

	REP(i, n) REP(j, n) if ((i * (j + 1) + (j * (j - 1) / 2 + j) == n)) count++;
	return count;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }

int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
vector<int>v;
bool isPresent(int n){
    for(int i=0;i<v.size();i++){
        if(v[i]==n) return true;
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    int sum=0;
    while(t--){
        int n;
        double t,a;
        cin>>n>>t>>a;
        double h[n];
        for(int i=0;i<n;i++){
            double x;
            cin>>x;
            h[i]=abs((t-x*(0.006))-a);
        }
        int index;
        double min=1e9;
        for(int i=0;i<n;i++){
            if(min>h[i]) {min=h[i];index=i;}
        }
        cout<<index+1;
        
        
    }
}
    

Measured memory_bytes: 256
(_,K),*T=[map(int,t.split())for t in open(0)]
A,B=map(sorted,T)
m,M,i=0,2**40,1
exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K else((i+M)//2,M,i);"*41)
print(M)

Measured memory_bytes: 120608
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    long long A;
    float B;
    string B_s;
    
    cin >> A >> B;
    
//    int B_int = B*100;
    int B_int = round(B*100);
//    int B_int = stoi(B_s.substr(0, B_s.length()-2))*100 + stoi(B_s.substr(B_s.length()-2));
    long long result = A*B_int;
    
    string S = to_string(result);
    
//    cout << S << endl;
    if (S.length()<=2) {
        cout << 0 << endl;
    }
    else {
        cout << S.substr(0, S.length()-2) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3792
import sys
from collections import Counter
from math import factorial
import numpy as np
from scipy.misc import comb
def main():
    input = sys.stdin.readline
    N = int(input())
    S = ["".join(sorted(list(input()))).strip() for _ in range(N)]
    #print(S)
    c = Counter(S)
    mosc = c.most_common()
    
    ans = np.int64(0)
    for i in range(len(mosc)):
        elem = mosc[i]
        if elem[1] > 1:
          n = elem[1]
          r = 2
          #ans += np.int64(factorial(n) / factorial(r) / factorial(n - r))
          ans +=  comb(n, r, exact=True)
    print(ans)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 34288
#include <iostream>

using namespace std;

int main()
{
	char c[2][4];
	cin >> c[0] >> c[1];
	if (c[0][1] == c[1][1] && c[0][0] == c[1][2] && c[0][2] == c[1][0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
s=[]
for i in range(n):
    s.append(input())
m = int(input())
t=[]
for i in range(m):
    t.append(input())
cmax=0
for i in range(n):
    cnt=0
    for j in range(n):
        if s[i]==s[j]:
            cnt+=1
    for j in range(m):
        if s[i]==t[j]:
            cnt-=1
    cmax = max(cnt,cmax)
print(cmax)
        

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
long long int n,m,jud;
int main(){
	ios::sync_with_stdio(0);
    cin>>n>>m;
    jud=2*n;
    if(jud>m) cout<<m/2<<endl;
    else if(jud==m) cout<<n<<endl;
    else m-=jud,m/=4,cout<<n+m<<endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
s = s[::-1]
i = 0
check = True
while i < len(s):
  if s[i:i+5] == "maerd" or s[i:i+5] =="esare":
    i += 5
  elif s[i:i+6] == "resare":
    i += 6
  elif s[i:i+7] == "remaerd":
    i += 7
  else:
    check = False
    break
    
if check == True:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 40432
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int a, b;
  double t;
  cin >> a >> b >> t;
  t += 0.5;
  cout << b * (int)(t / a) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        
        int[] p = new int[n];
        for(int i=0;i<n;i++)
        {
            p[i] = scan.nextInt();
        }
        
        int x = Count_down_A(p,a);
        int y = Count_bw_AB(p,a,b);
        int z = Count_up_B(p,b);
        
        int ans = ThreeMin(x,y,z);
        System.out.println(ans);
    }
    
    static int Count_down_A(int[] p,int a){
        int count = 0;
        for(int i=0;i<p.length;i++)
        {
            if(p[i]<=a)
            {
                count++;
            }
        }
        return count;
    }
    
    static int Count_bw_AB(int[] p,int a,int b){
        int count = 0;
        for(int i=0;i<p.length;i++)
        {
            if(p[i]>a && p[i]<=b)
            {
                count++;
            }
        }
        return count;
    }
    
    static int Count_up_B(int[] p,int b){
        int count = 0;
        for(int i=0;i<p.length;i++)
        {
            if(p[i]>b)
            {
                count++;
            }
        }
        return count;
    }
    
    static int ThreeMin(int a,int b,int c){
        int min = a;
        if(b<min){  min = b;  }
        if(c<min){  min = c;  }
        
        return min;
    }
}

Measured memory_bytes: 22996