akhauriyash/Code-Regression huggingface dataset:
<?php
    /*
        Problem URL : http://agc008.contest.atcoder.jp/tasks/agc008_a
        Score  :
        Result :
        Time   : ms
        Memory : KB
     */
 
    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    // define('DEBUG', true);
    define('DEBUG', false);

    $arr = array();

    fscanf(STDIN, "%d %d", $x, $y);

    if ($x >= 0 && $y >= 0) {
        if ($x < $y) {
            echo ($y - $x) . PHP_EOL;
            exit;
        } elseif ($y == 0) {
            echo (($x - $y) + 1 ) . PHP_EOL;
            exit;
        } else {
            echo (($x - $y) + 2 ) . PHP_EOL;
            exit;
        }
    } elseif ($x >= 0 && $y < 0) {
        if ($x >= -$y) {
            echo ($x + $y + 1) . PHP_EOL;
            exit;
        } else {
            echo (-$y - $x + 1) . PHP_EOL;
            exit;
        }
    } elseif ($x < 0 && $y >= 0) {
        if ($x == -$y) {
            echo "1\n";
            exit;
        } elseif (-$x >= $y) {
            $w1 = -$x - $y + 1;
            $w2 = $y - $x;
            echo min($w1, $w2) . PHP_EOL;
            exit;
        } else {
            $w1 = $y - $x;
            $w2 = $y + $x + 1;
            echo min($w1, $w2) . PHP_EOL;
            exit;
        }
    } elseif ($x < 0 && $y < 0) {
        if ($x > $y) {
            echo ($x - $y + 2) . PHP_EOL;
            exit;
        } else {
            echo ($y - $x) . PHP_EOL;
            exit;
        }
    }


Measured memory_bytes: 2812
n,m=map(int,input().split())

ans=0

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(1,a):
    if m%i==0:
      if i*n<=m:
        ans=max(ans,i)
      if (m//i)*n<=m:
        ans=max(ans,m//i)
  print(ans)

Measured memory_bytes: 3064
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-17 15:42
# @url:https://atcoder.jp/contests/abc056/tasks/arc070_a
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    x=int(input())
    ans=math.ceil((math.sqrt(8*x+1)-1)/2)
    print (ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 72792
import sys
from collections import defaultdict
MOD=10**9+7
N=int(input())
alist=list(map(int,input().split()))

adic=defaultdict(int)
for a in alist:
  adic[a]+=1
#print(adic)

answer=1
if N%2==1:  
  for a,v in adic.items():
    #print(a,v)
    if a==0:
      if v!=1:
        print(0)
        sys.exit(0)
    elif a%2==0:
      if v!=2:
        print(0)
        sys.exit(0)
      else:
        answer*=2
        answer%=MOD
    else:
      print(0)
      sys.exit(0)
  print(answer)
else:
  for a,v in adic.items():
    #print(a,v)
    if a%2==0:
      print(0)
      sys.exit(0)
    else:
      if v==2:
        answer*=2
        answer%=MOD
      else:
        print(0)
        sys.exit(0)
  print(answer)

Measured memory_bytes: 14820
// C - GCD on Blackboard
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b){
	if(a<b) swap(a,b);
	while(b){int r =a%b; a=b; b=r;}
	return a;
}

int main(){
	int N; cin>>N;
	vector<int> A(N), L(N), R(N), M(N);

	for(int n=0; n<N; ++n) cin>>A[n];
	for(int n=0; n<=N-1-1; ++n) L[n+1] = gcd(L[n], A[n]);
	for(int n=N-1-1; n>=0; --n) R[n] = gcd(R[n+1], A[n+1]);
	for(int n=0; n<N; ++n) M[n] = gcd(L[n], R[n]);

	int maxi = 0;
	for(int n=0; n<N; ++n) maxi = max(maxi,M[n]);
	cout<< maxi <<endl;
}

Measured memory_bytes: 1792
from collections import deque
H, W = map(int, input().split())
m = [[-1] * (W + 1) for _ in range(H + 1)]
white = 0
for h in range(H):
    for w, c in enumerate(input()):
        if c == ".":
            m[h][w] = 0
            white += 1

gh = H - 1
gw = W - 1
mincount = 0
todo = deque()
todo.append((0, 0))
m[0][0] = 1
while todo:
    h, w = todo.popleft()
    ncount = m[h][w] + 1
    for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        nh = h + dh
        nw = w + dw
        if nh == gh and nw == gw:
            mincount = ncount
            todo.clear()
            break
        if m[nh][nw] == 0:
            m[nh][nw] = ncount
            todo.append((nh, nw))

if mincount > 0:
    print(white - mincount)
else:
    print(-1)


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

const int N = 2e5 + 5;
int l = ( int )ceil( log2( N ) );
vector< long long > segtree( ( 1 << ( l + 1 ) ) + 10, 0 );
int n;
vector< int > height( N ), beauty( N );
long long res, ans = 0;

long long query( int v, int tl, int tr, int l, int r )
{
	if( tl == l && tr == r )
	{
		return segtree[ v ];
	}
	int tm = ( tl + tr ) >> 1;
	if( r <= tm )
	{
		return query( 2 * v, tl, tm, l, r );
	}
	else if( l > tm )
	{
		return query( 2 * v + 1, tm + 1, tr, l, r );
	}
	else
	{
		return max( query( 2 * v, tl, tm, l, tm ), query( 2 * v + 1, tm + 1, tr, tm + 1, r ) );
	}
}

void update( int v, int tl, int tr, int pos, long long val )
{
	if( tl == tr )
	{
		segtree[ v ] = val;
		return;
	}
	int tm = ( tl + tr ) >> 1;
	if( pos <= tm )
	{
		update( 2 * v, tl, tm, pos, val );
	}
	else
	{
		update( 2 * v + 1, tm + 1, tr, pos, val );
	}
	segtree[ v ] = max( segtree[ 2 * v ], segtree[ 2 * v + 1 ] );
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> n;
	for( int i = 1; i <= n; ++i )
	{
		cin >> height[ i ];
	}
	for( int i = 1; i <= n; ++i )
	{
		cin >> beauty[ i ];		
	}
	for( int i = 1; i <= n; ++i )
	{
		res = 0;
		if( height[ i ] != 1 )
		{
			res = query( 1, 1, n, 1, height[ i ] - 1 );
		}
		res += beauty[ i ];
		update( 1, 1, n, height[ i ], res );
		ans = max( ans, res );
	}
	cout << ans << "\n";
	return 0;
}

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


int main() {
  int n,m;
  cin>>m>>n;
  int c[m+2];
  int d[n];
  for(int i=0;i<m+1;i++)
  {
    c[i]=100000000;
  }
  for(int i=0;i<n;i++)
  {
    cin>>d[i];
  }
  c[0]=0;
  for(int i=0;i<m+1;i++)
  {
    for(int j=0;j<n;j++)
    {
      if(i-d[j]>=0)
      {
        c[i]=min(c[i],c[i-d[j]]+1);
      }
    }
  }
  cout<<c[m]<<endl;
}




Measured memory_bytes: 3284
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 //     String[] nyu=sc.nextLine().split("");
     String nyu=sc.nextLine();


int num=Integer.parseInt(nyu);
   String  sen=sc.nextLine();

//int num2=Integer.parseInt(sn[1]);

int count=0;

if(num>3199){
System.out.println(sen);
}else{
System.out.println("red");
}




//System.out.println(count);

//System.out.println(a/b);


	}
}

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

int main() {
  int r,g,b;
  cin >> r >> g >> b;

  int x = r * 100 + g * 10 + b;
  if(x % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 3532
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from operator import add

N,M,X = map(int, input().split())		# 5 7 2
CA = [list(map(int, input().split())) for _ in range(N)]		#=> [[1, 0], [2, 10], [3, 210], [4, 3210]]

A=[]
C=[]
for n in range(N):
	C.append(CA[n][0])
	A.append(CA[n][1:])


ans = sum(C)+1
for i in range(1 << N):

	tmpA = [0]*M
	c = 0
	
	for j in range(N):
		if ((i >> j) & 1) == 0: continue

		tmpA = map(add, tmpA, A[j])
		c += C[j]
	
	if min(tmpA) < X: continue
	
	ans = min(ans, c)


print( ans if ans <= sum(C) else -1)



Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    a=a-1;
    b=b-1;
    cout<<a*b<<endl;
    //cout<<endl;
    //printf("In this case, the area is %d square yards.\n",a*b);
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int h, w;
string c[50];
int d[50][50];

int main() {
    std::ios::sync_with_stdio(false);
    cin >> h >> w;
    int ans = h*w;
    inc(i, 0, h){
        cin >> c[i];
        inc(j, 0, w){
            if(c[i][j] == '#') ans--;
            d[i][j] = INF;
        }
    }

    queue<pair<int, int>> q;
    q.push({0, 0});
    d[0][0] = 0;
    while(!q.empty()){
        auto n = q.front();q.pop();
        int i = n.fi;
        int j = n.se;

        inc(k, 0, 4){
            int ni = i + di[k];
            int nj = j + dj[k];
            if(ni >= 0 && ni < h && nj >= 0 && nj < w){
                if(c[ni][nj] == '#') continue;
                if(d[ni][nj] != INF) continue;
                q.push({ni, nj});
                d[ni][nj] = d[i][j] + 1;
            }
        }
    }

    if(d[h-1][w-1] == INF){
        cout << -1 << endl;
        return 0;
    }

    cout << ans - d[h-1][w-1] -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n,q,com,b,e;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cin>>q;
	for(int j=0;j<q;j++){
		cin>>com>>b>>e;
		if(com==0) cout<<*min_element(a.begin()+b,a.begin()+e)<<endl;
		else cout<<*max_element(a.begin()+b,a.begin()+e)<<endl; 
	}

	return 0;
}


Measured memory_bytes: 3116
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N,K;
    int[] h;
    private void solve() {
        N = nextInt();
        K = nextInt();
        h = new int[N];
        for(int i = 0;i < N;i++) {
            h[i] = nextInt();
        }

        Arrays.sort(h);

        int ans = Integer.MAX_VALUE;
        for(int i = 0;i < N - K + 1;i++) {
            int min = h[i];
            int max = h[i + K - 1];
            ans = Math.min(ans, max - min);
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxn = 10;

string s[mxn];

int main(){
	setIO();
	int r, c, k, ctr = 0;
	cin >> r >> c >> k;
	for (int i = 0; i < r; i++)
		cin >> s[i];
	for (int row = 0; row < (1<<r); row++){
		for (int col = 0; col < (1<<c); col++){
			int ct = 0;
			for (int i = 0; i < r; i++){
				for (int j = 0; j < c; j++){
					if (row&(1<<i) || col&(1<<j)) continue;
					if (s[i][j] == '#') ct++;
				}
			}
			// cout << ct << endl;
			if (ct == k) ctr++;
		}
	}
	cout << ctr << endl;
}

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

using ll = long long;

constexpr int mod = 1e9 + 7;

int main() {
    int N, X, Y, Z;
    cin >> N >> X >> Y >> Z;
    int const M = 1 << (X + Y + Z);
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1));
    int const mask = (1 << (Z - 1)) | (1 << (Z + Y - 1)) | (1 << (Z + Y + X - 1));
    dp[0][0] = 1;

    for(int i = 0; i < N; ++i) {
        for(int S = 0; S < M; ++S) {
            if(dp[i][S] == 0) {
                continue;
            }
            for(int j = 1; j <= 10; ++j) {
                int nS = ((S << j) | (1 << (j - 1))) & (M - 1);
                if((nS & mask) == mask) {
                    (dp[i + 1][M] += dp[i][S]) %= mod;
                } else {
                    (dp[i + 1][nS] += dp[i][S]) %= mod;
                }
            }
        }
        (dp[i + 1][M] += dp[i][M] * 10) %= mod;
    }
    cout << dp[N].back() << endl;
}


Measured memory_bytes: 43392
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

template<const long long mod = 1000000007>
struct mint{ //modint
    long long x;
    mint(long long x = 0): x((x %= mod) < 0 ? x + mod : x) {}
    friend istream& operator >> (istream &s, mint& m){ return s >> m.x; }
    friend ostream& operator << (ostream &s, mint m){ return s << m.x; }
    inline mint& operator += (mint a){ if((x += a.x) >= mod)x -= mod; return *this; }
    inline mint& operator -= (mint a){ if((x += mod - a.x) >= mod)x -= mod; return *this; }
    inline mint& operator *= (mint a){ (x *= a.x) %= mod; return *this; }
    inline mint& operator /= (mint a){ return (*this) *= a.inv(); }
    inline mint operator + (mint a){ mint res(*this); return res += a; }
    inline mint operator - (mint a){ mint res(*this); return res -= a; }
    inline mint operator * (mint a){ mint res(*this); return res *= a; }
    inline mint operator / (mint a){ mint res(*this); return res /= a; }
    inline void takemod(){ x = ((x % mod) + mod) % mod; }
    inline mint inv(){
        long long a = x, b = mod, u = 1, v = 0, t;
        while(b){
            t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    inline mint pow(long long p){
        mint res(1), tmp(x);
        for(; p; p >>= 1){ if(p & 1)res *= tmp; tmp *= tmp; }
        return res;
    }
};

// jsc2019-qual
int main(){

    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n)cin >> a[i];

    mint<> ans(0);
    rep(i, n){
        rep(j, i){
            if(a[i] < a[j]){
                ans += mint<>(k) * mint<>(k + 1) / mint<>(2);
            } else if(a[i] > a[j]){
                ans += mint<>(k) * mint<>(k - 1) / mint<>(2);
            }
        }
    }

    cout << ans << endl;
    return 0;

}

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

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

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


ll sum[MAX];

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

  ll x;
  cin >> n >> x;
  vll a(n);
  rep(i, n) cin >> a[i];
  sort(rall(a));
  ans = n * x;
  FOR(i, 1, n + 1) sum[i] += sum[i - 1] + a[i - 1];
  FOR(i, 1, n + 1) {
	tmp = 5 * sum[i];
	cnt = (n + i - 1) / i;
	FOR(j, 2, cnt + 1) {
	  tmp += (sum[min(i*j, n)] - sum[i*(j - 1)])*(2 * j + 1);
	  if (tmp < 0) break;
	}
	tmp += x * i;
	if (tmp > 0) mi = min(mi, tmp);
  }

  cout << ans + mi << endl;


  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int buf = (a + b) % 2;
  if (buf == 0) {
    cout << (a + b) / 2 << endl;
  }
  else {
    cout << ((a + b) / 2) + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{

int one[10000], min, max, two, thee;
long long sum = 0;
scanf("%d", &two);//1以上が入力されるものとします
for(thee = 0; thee < two; thee++){
scanf("%d", &one[thee]);
sum += one[thee];
}
max = min = one[0];//とりあえず最初の要素をセットしておく
for(thee = 1; thee < two; thee++){//2番目以降の要素と比較
if(one[thee] > max)max = one[thee];
if(one[thee] < min)min = one[thee];
}
printf("%d %d %lld\n", min, max, sum);

return 0;
}


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

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

  if(n % 2 == 1) {
    cout << 0 << '\n';
    return 0;
  }

  ll cnt = 0;
  ll five = 5;
  while(five * 2LL <= n) {
    cnt += (n / (five * 2));
    five *= 5;
  }
  cout << cnt << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;
const ld pi = (acos(-1));


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n;cin >> n;
  vector<pair<ll,ll>>p;
  rep(i,0,n){
      ll a,b;
      cin >> a >> b;
      p.push_back(make_pair(b,a));
  }
  sort(ALL(p));
  ll t=0;
  bool flag=false;
  rep(i,0,n){
    t+=p[i].second;
    if(t>p[i].first) flag=true;
  }
  if(flag) cout << "No" << endl;
  else cout << "Yes" << endl;
  
 }

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int fact[N];
int inv[N];
int h, wi, n;
vector<pair<int, int>> vec;

int mul(int a, int b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return ((ll)a * b) % mod;
}

int add(ll a, ll b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}

int fastpow(int base, int power)
{
    if(!power)
        return 1;
    int ret = fastpow(base, power / 2);
    ret = mul(ret, ret);
    if(power & 1)
        ret = mul(ret, base);
    return ret;
}

void pre()
{
    fact[0] = fact[1] = 1;
    for(int i = 2; i < N; i++)
    {
        fact[i] = mul(fact[i - 1], i);
    }
    inv[1] = inv[0] = 1;
    for(int i = 2; i < N; ++i)
        inv[i] = fastpow(fact[i], mod - 2);
}

ll ncr(int n, int r)
{
    return mul(fact[n], mul(inv[n - r], inv[r]));
}

ll w(int r1, int c1, int r2, int c2)
{
    int w1 = (r2 - r1);
    int w2 = (c2 - c1);
    return ncr(w1 + w2, w1);
}

int dp[3005][3005][2];

int solve(int idx, int prev, int odd)
{
    if(idx == n)
    {
        if(odd)
            return (-w(vec[prev].first, vec[prev].second, wi, h) + mod) % mod;
        else
            return w(vec[prev].first, vec[prev].second, wi, h);
    }
    int &ret = dp[idx][prev][odd];
    if(ret != -1)
        return ret;
    ret = solve(idx + 1, prev, odd);
    if(vec[idx].second >= vec[prev].second)
        ret = add(ret, mul(solve(idx + 1, idx, (odd + 1) % 2),
            w(vec[prev].first, vec[prev].second, vec[idx].first, vec[idx].second)));
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    pre();
    cin >> wi >> h >> n;
    for(int i = 1; i <= n; i++)
    {
        int r, c;
        cin >> r >> c;
        vec.push_back({r, c});
    }
    sort(vec.begin(), vec.end());
    int ans = w(1, 1, wi, h);
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < n; i++)
    {
        ans = add(ans, mul(w(1, 1, vec[i].first, vec[i].second), solve(i + 1, i, 1)));
    }
    cout << ans;
}


Measured memory_bytes: 72704
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;

inline LL gcd(LL a, LL b){return b ? gcd(b, a % b) : a;}
bool judge(LL a, LL b, LL c, LL d){
	if(a < b || d < b) return false;
	a -= b;
	if(a <= c){
		if(b == d) return true;
		a += ((c - a) / (d - b) + 1) * (d - b);
	} // now a > c
	a %= b;
	if(a > c) return false;
	LL g = gcd(b, d - b);
	if(g == b) return true;
	return a + (b - a - 1) / g * g <= c;
}
int main(){
	int testcase; LL a, b, c, d;
	cin >> testcase;
	while(testcase --){
		cin >> a >> b >> c >> d;
		cout << (judge(a, b, c, d) ? "Yes" : "No") << endl;
	} return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int res = (int)Math.ceil((double)n / (d * 2 + 1));
        System.out.println(res);
    }
}


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

#define ll long long
#define MOD 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define INF (ll)1e9
#define fora(i,a,b) for(ll i=a;i<b;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp(x,y) make_pair(x,y)
#define mli map<ll,int>
#define mll map<ll,ll>

using namespace std;

int main()
{   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    if(n%1000==0)
    {
        cout<<0;
    }
    else
    {
        cout<<(n/1000+1)*1000-n<<endl;
    }
    
    
    return 0;
}




Measured memory_bytes: 3648
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)
	var maxMatch int
	for i := 0; i <= len(s)-len(t); i++ {
		matched := matchCount(t, s[i:i+len(t)]) 
		if matched > maxMatch{
			maxMatch = matched
		}
	}
	fmt.Println(len(t) - maxMatch)
}

func matchCount(a, b string) int {
	count := 0
	for i, v := range a {
		if byte(v) == b[i] {
			count ++
		}
	}
	return count
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N;
  cin>>N;
  string str;
  cin>>str;
  for(ll i=0;i<(ll)str.size();i++){
    for(ll j=0;j<N;j++){
      if(str.at(i)=='Z'){str.at(i)='A';}
      else{str.at(i)++;}
    }
  }
  cout<<str<<endl;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n && n;){
		vi a(n),b(n);
		rep(i,n) cin>>a[i];
		rep(i,n) cin>>b[i];

		vi amin(n),amax(n);
		amin[0]=amax[0]=a[0];
		repi(i,1,n){
			if(a[i-1]<a[i])
				amin[i]=amax[i]=a[i];
			else{
				amin[i]=1;
				amax[i]=amax[i-1];
			}
		}
		vi bmin(n),bmax(n);
		bmin[n-1]=bmax[n-1]=b[n-1];
		per(i,n-1){
			if(b[i]>b[i+1])
				bmin[i]=bmax[i]=b[i];
			else{
				bmin[i]=1;
				bmax[i]=bmax[i+1];
			}
		}

		ll res=1;
		rep(i,n){
			int mn=max(amin[i],bmin[i]),mx=min(amax[i],bmax[i]);
			if(mn>mx){
				res=0;
				break;
			}
			(res*=mx-mn+1)%=MOD;
		}

		cout<<res<<endl;
	}
}


Measured memory_bytes: 2688
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long ll;
inline ll read() {
	char ch = getchar(); ll x = 0; int op = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') op = -1;
	for(; isdigit(ch); ch = getchar()) x = x*10+ch-'0';
	return x*op;
}
inline void write(ll a) {
	if(a < 0) putchar('-'), a = -a;
	if(a >= 10) write(a/10); putchar('0'+a%10);
}
int main() {
	ll m, n, x, len; m = 0; n = read(), x, len = 0;
	while(n) { x = n%10; n /= 10; len ++; m += x; }
	write(max(x-1+(len-1)*9, m));
	return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)
a=0
t=1
d=[1]+[0]*2018

for i in range(n):
    a+=int(s[n-1-i])*t
    a%=2019
    t*=10
    t%=2019
    d[a]+=1

ans=0
for i in d:
    ans+=i*(i-1)//2

print(ans)


Measured memory_bytes: 9224
#include <iostream>
#include <vector>
using namespace std;
const int num = 19;
int sx[5]={2, 1, 0, 0, 0};
int ex[5]={4, 4, 4, 3, 2};
int nsx[3]={2, 1, 1};
int nex[3]={3, 3, 2};
int dx[7]={0, 1, -1, 0, 1, -1, 0};
int dy[7]={-1, -1, 0, 0, 0, 1, 1};

int filter(int x, int y, vector<vector<int> > &hex){
	int ret=0;
	for(int i=0; i<7; i++){
		ret |= hex[x+dx[i]][y+dy[i]]<<i;
	}
	return ret;
}

int main(){
	while(1){
		string str;
		cin >> str;
		if(str=="#") break;
		for(int i=0; i<(int)str.length(); i++){
			str[i] -= '0';
		}
		
		vector<vector<int> > hex(5, vector<int>(5));
		vector<vector<int> > nhex(5, vector<int>(5));
		bool success = true;
		for(int i=0; i<(1<<num); i++){
			int pt=0;
			for(int y=0; y<5; y++){
				for(int x=0; x<5; x++){
					if(x<sx[y] || ex[y]<x) continue;
					hex[x][y] = ((i&(1<<pt))==0)? 0: 1;
					pt++;
				}
			}
			for(int y=0; y<3; y++){
				for(int x=0; x<3; x++){
					if(x+1<nsx[y] || nex[y]<x+1) continue;
					nhex[x+1][y+1] = str[filter(x+1,y+1,hex)];
				}
			}
			if(str[filter(2,2,nhex)] != nhex[2][2]){
				success = false;
				break;
			}
		}
		
		if(success){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3056
#include <cstdio>

int main()
{
  int a, b, c;
  while ( scanf("%d %d %d", &a, &b, &c) != EOF )
  {
    int health = a+b+1;
    int ans;
    if ( c <= health ) ans = b+c;
    else ans = b+health;
    
    printf("%d", ans);
  }
  return 0;
}


Measured memory_bytes: 128
use strict;
#use warnings;

my $in = <>;
chomp $in;
my $mod = (10 ** 9) + 7;
my @result;

sub func{
	my $n = shift;
	
	if (defined $result[$n]){
		return $result[$n];
	}

	my $ret = func($n - 1) + func($n - 3);
	$ret %= $mod;
	$result[$n] = $ret;
	return $ret;
}

$result[1] = 0;
$result[2] = 0;
$result[3] = 1;
print func($in);

exit;

Measured memory_bytes: 5892
#include <iostream>

using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a * b > c * d) cout << a * b;
	else if (c * d > a * b) cout << c * d;
	else cout << a * b;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    string s;
    cin>>s;
    int n = s.size();

    vector<int> div;
    rep(i, n - 1) {
        if (s[i] != s[i + 1]) div.push_back(i);
    }
    div.push_back(n);
    vector<int> ans(n);
    bool r = true;
    int d = 0;
    rep(i, n) {
        if (i > div[d]) {
            d++;
            r = !r;
        }
        if (r) ans[div[d] + (div[d] + i) % 2]++;
        else ans[div[d - 1] + (i + div[d - 1]) % 2]++;
    }
    rep(i, n) cout<<ans[i]<<endl;
}

Measured memory_bytes: 1480
#include <iostream>
using namespace std;
const int NICO = 1000000 + 10;
int n, a[NICO];
char s[NICO];
int main()
{
    scanf("%d %s", &n, s+1);
    s[n+1] = s[1];s[n+2] = s[2];
    for(int i=0;i<4;i++)
    {
        a[1] = i/2;//0为羊，1为狼
        a[2] = i%2;//1,2,3,4,...,n,(n+1)
        for(int j=2;j<=n+1;j++)
        {
            int same = (((s[j]=='o')+a[j]) == 1);
            a[j+1] = same?a[j-1]:(1-a[j-1]);
        }
        if(a[1] == a[n+1] && a[2] == a[n+2])
        {
            for(int j=1;j<=n;j++)
            {
                printf("%c", a[j]?'W':'S');
            }
            printf("\n");
            return 0;
        }
    }
    printf("-1\n");
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define endl '\n'
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	ll sum = 0;
	ll n = s.size();
	for (int i = 0; i < n; i++) {
		sum += (s[i] - '0');
		sum %= 9;
	}
	if (sum % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=15,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn];
int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) cin >> d[i];
  sort(d,d+n);
  ll sum = 0;
  REP (i,n-1) sum += d[i];

  if (sum > d[n-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

table1 = [[0 for j in range(m)]for i in range(n)]
table2 = [[0 for k in range(l)]for j in range(m)]
table3 = [[0 for k in range(l)]for i in range(n)]

for i in range(n):
    a = list(map(int,input().split()))

    for j in range(m):
        table1[i][j] = a[j]
#print(table1)

for j in range(m):
    b = list(map(int,input().split()))

    for k in range(l):
        table2[j][k] = b[k]
#print(table2)

for i in range(n):
    for k in range(l):
        for j in range(m):
            table3[i][k] += table1[i][j]*table2[j][k]
        if k == l-1:
            print(table3[i][k])
        else:
            print(table3[i][k],"",end="")


Measured memory_bytes: 7148
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////
ll f[300], upper, a, b, c, k;

int main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    // f[0] = 0;
    // FOR(i, 1, 20) {
    // 	if(i & 1) f[i] = 2*f[i-1]+1;
    // 	else f[i] = 2*f[i-1]-1;
    // 	if(f[i] < 0) {
    // 		upper = i, break;
    // 	}
    // }
    cin >> a >> b >> c >> k;
    if(k & 1) cout << b-a << endl;
    else cout << a-b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
char s[105][15],a[105][15];
int vis[105];
int main(){
    int n,m;
    memset(vis,0,sizeof(vis));
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf("%s",s[i]);
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    scanf("%s",a[i]);
    char cmp[15];
    int num,res=0;
    for(int i=0;i<n;i++)
    if(!vis[i]){
        strcpy(cmp,s[i]);
        vis[i]=1;
        num=1;
        for(int j=i+1;j<n;j++){
            if(strcmp(cmp,s[j])==0){
                num++;
                vis[j]=1;
            }
        }
        for(int j=0;j<m;j++)
        if(strcmp(cmp,a[j])==0)
        num--;
        res=max(num,res);
    }
    printf("%d",res);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    char x;
    cin>>x;
    if(x<='Z')cout << "A" << endl;
    else cout << "a" << endl;
}

Measured memory_bytes: 3616
package main

import (
	"fmt"
)

func main() {

	var N, A, B int
	fmt.Scan(&N, &A, &B)
	ans := A * (N / (A + B))
	if (N%(A+B)) < A {
		ans += N % (A + B)
	} else {
		ans += A
	}
	fmt.Println(ans)
}


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

int h, w;
std::string s;
std::vector<std::vector<char>> vec;
std::vector<std::vector<int>> o;
std::queue<std::pair<int, int>> q;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};

int main() {
    std::cin >> h >> w;
    vec.assign(h, std::vector<char>(w, 'A'));
    o.assign(h, std::vector<int>(w, -1));
    for (int i = 0; i < h; i++) {
        std::cin >> s;
        for (int p = 0; p < w; p++) {
            vec[i][p] = s[p];
            if (vec[i][p] == '#') {
                q.push(std::make_pair(i, p));
                o[i][p] = 0;
            }
        }
    }
    while (!q.empty()) {
        auto e = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int x = e.second + dx[i];
            int y = e.first + dy[i];
            if (x < 0 || x >= w || y < 0 || y >= h) {
                continue;
            }
            if (o[y][x] == -1) {
                o[y][x] = o[e.first][e.second] + 1;
                q.push(std::make_pair(y, x));
            }
        }
    }
    int ans = 0;
    for (int j = 0; j < h; j++) {
        for (int k = 0; k < w; k++) {
            if (o[j][k] > ans) {
                ans = o[j][k];
            }
        }
    }
    std::cout << ans << std::endl;
}


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

struct UnionFind
{
    vector<int> par; //自身の親を格納

    UnionFind(int n) : par(n)
    { //記法がよくわからんコンストラクタ？/すべてを根として初期化
        rep(i, n) par[i] = i;
    }

    int root(int x)
    { //xの根を再帰で得る関数
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind tree(n);
    vector<set<int>> dame(n); //友達関係、ブロック関係をせｔで管理
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        dame[a].insert(b);
        dame[b].insert(a);
        tree.unite(a, b);
    }
    rep(i, k)
    {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        if (!tree.same(c, d))
            continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }

    vector<int> root(n); //自身の根を記録
    map<int, int> group; //根とそこに含まれる個数
    rep(i, n)
    {
        root[i] = tree.root(i);
        group[root[i]]++;
    }

    rep(i, n)
    {
        cout << group[root[i]] - dame[i].size() - 1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 29312
/***** author : CodingPhenomena *****/

    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        string T;
        
        
        
            string s2="AAA";
            string s1= "BBB";
            cin>>T;
            if(T==s1 or T==s2)
                cout<<"No";
            else
                cout<<"Yes";

       
        return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int K; cin >> K; 
	if(K % 2 == 0 || K % 5 == 0){
		cout << -1  << "\n"; return 0; 
	}
	int rem = 7 % K; 
	for(int i = 1; i <= 1145141919; i++){
		if(rem == 0){
			cout << i << "\n"; return 0; 
		}
		rem *= 10; rem += 7; 
		rem %= K; 
	}
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int n; cin >> n;
    vector<int> A[n];
    int q; cin >> q;
    rep(i,q){
        int query; cin >> query;
        if(query == 0){
            int t, x; cin >> t >> x;
            A[t].push_back(x);
        }else if(query == 1){
            int t; cin >> t;
            rep(j,A[t].size()){
                cout << A[t][j];
                if(j != A[t].size()-1) cout << " ";
            }
            cout << endl;
        }else{
            int t; cin >> t;
            A[t].clear();
        } 
    }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int n;
  cin >> n;
  vector<int> p(n);

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

  int cnt = 0, cmin = 1e9;
  for (int i = 0; i < n; ++i) {
    cmin = min(cmin, p[i]);
    if (cmin == p[i]) {
      ++cnt;
    }
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int fa[N];
int num[N];

int getfa(int x)
{
    return fa[x]==x?x:(fa[x]=getfa(fa[x]));
}
int main()
{
    int n,m,x,y,fx,fy,res=1;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)fa[i]=i,num[i]=1;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        fx=getfa(x),fy=getfa(y);
        if(fx!=fy)
        {
            num[fx]+=num[fy];
            res=max(res,num[fx]);
            fa[fy]=fx;
        }
    }
    printf("%d\n",res);
    return 0;
}


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

int main(){
  int N, X, L;
  cin >> N >> X;
  int Ans=1;
  int x=0;
  for(int i=0; i<N; i++){
    cin >> L;
    x+=L;
    if(x<=X){
      Ans++;
    }
    else{
      break;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
n,x=map(int, input().split())
xlist=list(map(int, input().split()))
ylist=[]
for i in range(n):
  ylist.append(xlist[i]-x)
import math
ans=ylist[0]
for i in range(n):
  ans=math.gcd(ans,ylist[i])
print(ans)

Measured memory_bytes: 20004
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n;
    cin >> n;
    int tcount = 0;
    int hcount = 0;
    for(int i = 0; i < n; i++){
        string taro;
        string hanako;
        cin >> taro >> hanako;
        for(int j = 0; j < taro.size(); j++){
            if(taro[j] >= 'A' && taro[j] <= 'Z')
                taro[j] += 'a' - 'A';
        }
        for(int j = 0; j < hanako.size(); j++){
            if(hanako[i] >= 'A' && hanako[i] <= 'Z')
                hanako[i] += 'a' - 'A';
        }
        if(taro > hanako){
            tcount += 3;
        }else if(taro < hanako){
            hcount += 3;
        }else{
            tcount++;
            hcount++;
        }
    }
    cout << tcount << " " << hcount << endl;
}


Measured memory_bytes: 3216
#include<iostream>
#include<vector>

int main(){
	int n;
	std::cin >> n;
	std::vector<int> A(n);
	for (int i = 0; i < n; ++i) std::cin >> A[i];
	for (int i = 1; i < n; ++i){
		for (int k = 0; k < n; ++k){
			if (k != n - 1)std::cout << A[k] << ' ';
			else std::cout << A[k] << std::endl;
		}
		int key = A[i];
		int j = i - 1;
		while (j >= 0 && A[j]>key){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = key;
	}
	for (int k = 0; k < n; ++k){
		if (k != n - 1)std::cout << A[k] << ' ';
		else std::cout << A[k] << std::endl;
	}
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int cou[111111];

int main(){
	
	int n;cin >> n;
	vector<pair<ll,ll>> v;
	map<ll,ll> mp;
	REP(i,n){
		ll d;cin >> d;
		v.PB(MP(d,i+1));
		mp[d] = i+1;
	}
	
	sort(ALL(v),greater<pair<ll,ll>>());
	
	vector<pair<int,int>> ans;
	ll sum = 0;
	
	REP(i,n-1){
		ll mai = n - 2*(cou[v[i].SE]+1);
		//cout << v[i].FI << ' ' << mai << endl;
		if(!mp[v[i].FI - mai]){
			cout << -1 << endl;
			return 0;
		}
		ans.PB(MP(v[i].SE,mp[v[i].FI - mai]));
		cou[mp[v[i].FI - mai]] += cou[v[i].SE] + 1;
		sum += cou[v[i].SE] + 1;
	}
	
	if(sum != v[n-1].FI){
		cout << -1 << endl;
		return 0;
	}
	
	REP(i,ans.size()){
		cout << ans[i].FI << ' ' << ans[i].SE << endl;
	}
	return 0;
}


Measured memory_bytes: 11376