akhauriyash/Code-Regression huggingface dataset:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
import functools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
k = inp()
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += functools.reduce(euclid,[a,b,c])

print(ans)

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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}



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

int ans = 100;

for (int i = 1; i < n; i++)
{
  int x = findSumOfDigits(i);
  int y = findSumOfDigits(n-i);

  if(x + y < ans){
    ans = x + y;
  }
}

cout << ans << endl;
}

Measured memory_bytes: 256
def values(s):
    maxv = int(''.join(sorted(s)[::-1]))
    minv = int(''.join(sorted(s)))
    return maxv - minv

while True:
    a0, L = map(int, input().split())
    if L == 0:
        break
    a = [-1]*1000001
    a[a0] = 0
    i = 1
    ai = values(str(a0).zfill(L))
    while True:
        if a[ai] != -1:
            j = a[ai]
            break
        else:
            a[ai] = i
        ai = values(str(ai).zfill(L))
        i += 1
    print(j, ai, i-j)

Measured memory_bytes: 23304
#include <bits/stdc++.h>
#define ll             long long
#define Max(a,b)       ((a)>(b)?(a):(b))
#define Min(a,b)       ((a)<(b)?(a):(b))
#define si(a)          scanf("%d",&a)
#define pii            pair <int, int>
#define mp             make_pair
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define mem(a,v)       memset(a,v,sizeof(a))
#define MAX 2007
#define MOD 100000007
#define LG  16
using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    if(a.length()>b.length()){
        cout<<"GREATER";
    }
    else if(a.length()<b.length()){
        cout<<"LESS";
    }
    else{
        int i;
        for(i=0;i<a.length();i++){
            if(a[i]>b[i]){
                cout<<"GREATER";
                break;
            }
            else if(a[i]<b[i]){
                cout<<"LESS";
                break;
            }
        }
        if(i>=a.length()){
            cout<<"EQUAL";
        }
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();

    System.out.println((H * W) - (h * W + H * w - h * w));

  }
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll S = 0;
    REP(i, N) {
        cin >> A[i];
        S += A[i];
    }

    ll ans = INF;
    ll s = A[0];
    FOR(i, N, 1) {
        ll t = S - s;
        ans = std::min(ans, abs(t - s));
        s += A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
l,r = map(int,input().split())
mod = 2019

if r+1-l >= mod:
    print(0)
else:
    if r%mod > l%mod:
        ans = mod
        for i in range(l%mod,r%mod+1):
            for j in range(i+1,r%mod+1):
                ans = min(ans,(i*j)%mod)
        print(ans)
    else:
        print(0)

Measured memory_bytes: 40940
#include<stdio.h>
#include<string.h>
 
void print(char str[1000], int a, int b) {
    char substr[1000];
    strncpy(substr, str + a, b - a + 1);
    substr[b - a + 1] = '\0';
    printf("%s\n", substr);
}
 
void reverse(char str[1000], int a, int b) {
    int i;
    char revstr[1000];
    strcpy(revstr, str);
    for (i = a;i <= b;i++) {
        revstr[i] = str[b + a - i];
    }
    strcpy(str, revstr);
}
 
void replace(char str[1000], int a, int b, char p[1000]) {
    int i;
    for (i = a;i <= b;i++) {
        str[i] = p[i - a];
    }
}
 
int main() {
    int i;
    int a, b, n;
    char str[1000], p[1000];
    char op[10];
     
    scanf("%s", str);
    scanf("%d", &n);
 
    for (i = 0;i < n;i++) {
        scanf("%s", op);
 
        if (strcmp(op, "print") == 0) {
            scanf("%d %d", &a, &b);
            print(str, a, b);
        }
        else if (strcmp(op, "reverse") == 0) {
            scanf("%d %d", &a, &b);
            reverse(str, a, b);
        }
        else if (strcmp(op, "replace") == 0) {
            scanf("%d %d %s", &a, &b, p);
            replace(str, a, b, p);
        }
    }
 
    return 0;
}

Measured memory_bytes: 600
<?php
$length = fgets(STDIN);
$numbers = explode(" " , trim(fgets(STDIN)));

echo implode(" " , $numbers) . PHP_EOL;

for($i = 1 ; $i < $length ; $i++){
  $key = $numbers[$i];
  for($y = $i - 1 ; $y >= 0 and $numbers[$y] > $key ; $y--){
		$numbers[$y + 1] = $numbers[$y];
  }
  $numbers[$y + 1] = $key;
  echo implode(" " , $numbers) . PHP_EOL;
}


Measured memory_bytes: 9264
#include <stdio.h>
#include <string.h>

int lower(char *a, char *b){ return *a - *b; }
int upper(char *a, char *b){ return *b - *a; }

int main(void)
{
	char num[8];
	char lnum[8];
	char unum[8];
	int c;

	while (scanf("%s", num), atoi(num)){
		c = 0;
		while (atoi(num) != 6174){
			if (atoi(num) % 1111 == 0){
				c = -1;
				break;
			}
			strcpy(lnum, num);
			qsort(lnum, 4, 1, lower);
			strcpy(unum, num);
			qsort(unum, 4, 1, upper);
			sprintf(num, "%04d", atoi(unum) - atoi(lnum));
			c++;
		}
		printf(~c ? "%d\n" : "NA\n", c);
	}

	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		if(size[x]>size[y])swap(x,y);
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};

int main(){
	
	long long N,M,Q;
	cin>>N>>M>>Q;
	
	vector<pair<int,int>> P0,P1;
	
	for(int i=0;i<Q;i++){
		int a,b,c;
		cin>>a>>b>>c;
		
		if(c==0)P0.emplace_back(a,b);
		else P1.emplace_back(a,b);
	}
	
	unionfind uf(N);
	
	for(int i=0;i<P0.size();i++)uf.unite(P0[i].first,P0[i].second);
	
	for(int i=0;i<P1.size();i++){
		if(uf.check(P1[i].first,P1[i].second)){
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	set<int> S;
	long long single = 0;
	
	for(int i=0;i<N;i++){
		if(uf.find(i)==i)single++;
	}
	
	if(single<=2&&P1.size()!=0){
		cout<<"No"<<endl;
		return 0;
	}
	
	long long maxi = N-single;
	long long mini = N-single;

	mini = N-1;
	if(P1.size()!=0)mini ++;
	
	maxi += single * (single-1) / 2;
	
	if(clamp(M,mini,maxi)==M)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 5360
/// 11:57 AM 02/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);
void sol(ll i, ll prev, ll n, ll m, vector<ll> v, vector<vector<ll> > &total) {
    if(i==n) {
        total.pb(v);
        return;
    }
    for(ll j=prev;j<=m;j++) {
        vector<ll> temp = v;
        temp.pb(j);
        sol(i+1, j, n, m, temp, total);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, m, q;
    cin >> n >> m >> q;
    vector<vector<ll> > query(q, vector<ll>(4,0));
    for(auto &x:query) {
        cin >> x[0] >> x[1] >> x[2] >> x[3];
    }
    vector<ll> temp;
    vector<vector<ll> > v;
    sol(0, 1, n, m, temp, v);
    ll score = -1;
    for(auto &vv:v) {
        ll t = 0;
        for(auto &y:query) {
            if(vv[y[1]-1] - vv[y[0]-1] == y[2]) {
                t += y[3];
            }
        }
        score = max(score, t);
    }
    cout<<score;
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

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



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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> Dep, Des;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 1) Dep.push_back(b);
		if (b == N) Des.push_back(a);
	}
	sort(Dep.begin(), Dep.end());
	sort(Des.begin(), Des.end());
	if (Dep.empty() || Des.empty()) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	int i = 0, j = 0;
	while (Dep[i] != Des[j]) {
		if (Dep[i] < Des[j]) {
			if (i < Dep.size() - 1) i++;
			else break;
		}
		else {
			if (j < Des.size() - 1) j++;
			else break;
		}
	}
	cout << (Dep[i] == Des[j] ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 1276
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
    print("No")
    quit()
else:
    print("Yes")
m=-10**9
p=(-m-1)//(h*w-1)  
ans=[[m if i%h==0 and j%w==0 else p for j in range(1,W+1)] for i in range(1,H+1)]
for i in ans:
    print(" ".join(map(str,i)))

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

typedef long long ll;
typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define REP1(i, N) for (int i = 1; i < N; i++)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ANS(a) cout << a << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())
#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

int N;
vector<int> A;

int
main()
{
  cin >> N;
  int max = 0;
  int max2 = 0;
  REP(i, N) { int a; cin >> a; A.push_back(a); 
    if (max < a) { max = a; }
    else if (max2 < a) { max2 = a; }
  }

  REP(i, N) {
    if (A[i] == max) {
      printf("%d\n", max2);
    } else {
      printf("%d\n", max);
    }
  }
}


Measured memory_bytes: 4240
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int n,m;
  cin >> n >> m;

  cout << n*(n-1)/2+m*(m-1)/2 << endl;

  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    ll ma = a[0];
    REP(i, n-1){
        if(a[i] < ma){
            ans += ma - a[i];
        }else{
            ma = a[i];
        }
    }
    cout << ans << endl;
}   

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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB(x) push_back(x);
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); 
   string s,t;
   cin>>s>>t;
   
   ll n = s.length();
   ll ans =0;
   fo(i,n) 
   {
       if(s[i] != t[i])
       {
           ans++;
       }
   }

   cout<< ans << endl;
}





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


int main() {
int h,w;
cin>>h>>w;
string s[h];
for(int i=0;i<h;i++){
    cin>>s[i];
}
int m[h+2][w+2] ={0};

for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        if(s[i][j]=='#'){
            for(int k=i;k<i+3;k++){
                for(int l=j;l<j+3;l++){
                    m[k][l]+=1;
                }
            }
        }
    }
}
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        if(s[i][j]=='#'){
            cout<<'#';
        }else{
            cout<<m[i+1][j+1];
        }
    }
    cout<<endl;
}
	return 0;
}


Measured memory_bytes: 256
using System;

class Atcoder53
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int x = int.Parse(input[0]);
        int a = int.Parse(input[1]);
        int b = int.Parse(input[2]);

        if (b <= a)
            Console.WriteLine("delicious");
        else if (b > a && b <= x + a)
            Console.WriteLine("safe");
        else
            Console.WriteLine("dangerous");
    }
}

Measured memory_bytes: 11092
#include <cassert>
#include <cctype>
#include <cerrno> 
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main() {
 vector<int> vec(5);
 int ans;
for (int i = 0; i < 5; i++) {
  cin >> vec.at(i);
  if(vec.at(i)==0)
  {
  	ans=i;
  }
}

    cout << ans+1<<endl;
       }


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll X;
        cin>>X;
        for(ll a=-1000;a<=1000;a++)
        {
            for(ll b=-1000;b<=1000;b++)
            {
                ll sum=a*a*a*a*a-b*b*b*b*b;
                if(sum==X)
                {
                    cout<<a<<" "<<b<<endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

int main(){
    int h, w, k;
    std::cin >> h >> w >> k;

    std::vector<std::vector<std::string>> c(h, std::vector<std::string>(w));
    for (int i = 0; i < h; i++)
    {
        std::string s;
        std::cin >> s;
        for (int j = 0; j < w; j++)
        {
            c[i][j] = s[j];
        }
    }
    
    int ans = 0;
    for (int i = 0; i < (1 << h); i++)
    {
        for (int j = 0; j < (1 << w); j++)
        {
            int black = 0;
            for (int ii = 0; ii < h; ii++)
            {
                for (int jj = 0; jj < w; jj++)
                {
                    if ((((i >> ii) & 1) == 0) && (((j >> jj) & 1) == 0) && (c[ii][jj] == "#"))
                    {
                        black++;
                    }
                }
            }
            
            if (black == k)
            {
                ans++;
            }
        }
    }
    
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include <math.h>
double distance(int, int, int, int);

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

  int x[N+1], y[N+1];
  int m, n;
  for(int i=0; i<N; i++){
    scanf("%d %d", &m, &n);
    x[i]=m;
    y[i]=n;
    // printf("%d %d\n", x[i], y[i]);

  }
    // scanf("%d", &y[i]);
    double sum_distance=0;
    for(int i=0; i<N; i++){
      for(int j=i+1; j<N; j++){
        sum_distance+=distance(x[i], x[j], y[i], y[j]);
      }
    }

    printf("%lf", 2.0*sum_distance/(double)N);

}

double distance(int x1, int x2, int y1, int y2){
  return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}


Measured memory_bytes: 128
n = int(raw_input())
t = 1
a = 1
for i in range(n):
    x, y = map(int, raw_input().split())
    tmp = max(
        t / x if t % x == 0 else t / x + 1,
        a / y if a % y == 0 else a / y + 1
    )
    t = x * tmp
    a = y * tmp
print t+a


Measured memory_bytes: 2568
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

int my_abs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    int count = 0;
    int ans = 0;
    if (H >= W && N % H == 0) {
        cout << N / H << endl;
    }
    else if(H >= W && N % H != 0){
        cout << N / H + 1 << endl;
    }
    else if(H < W && N % W != 0){
        cout << N / W + 1 << endl;
    }
    else {
        cout << N / W << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,ans = 0;
  char x[1001] = { 0 };
  while(1){
	scanf("%s",x);
	if(x[0] == '0') break;
	for(i = 0; x[i] != '\0'; i++){
	  ans += x[i] - '0';
	}
	printf("%d\n",ans);
	ans = 0;
  }
  return 0;
}

Measured memory_bytes: 536
from collections import Counter
from itertools import combinations

N = int(input())
R = [[int(i) for i in input().split()] for _ in range(N)]

if N == 1:
    print(1)
    quit()

L = []
for (x1, y1), (x2, y2) in combinations(R, 2):
    L.append((x1 - x2, y1 - y2))
    L.append((-x1 + x2, -y1 + y2))

C = Counter(L)
print(N - C.most_common(1)[0][1])


Measured memory_bytes: 3828
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, -1, 0 };
const int MAX_N = 100000;

int main() {
	int N, M, x, y, ans=0;
	int balls[MAX_N];
	int p[MAX_N] = {1};
	cin >> N >> M;
	for(int i=0;i<N;i++) balls[i] = 1;
	for(int i=0;i<M;i++) {
		cin >> x >> y;
		x--; y--;
		balls[x]--; balls[y]++;
		if(p[x]) p[y]=1;
		if(balls[x]==0) p[x]=0;
	}
	for(int i=0;i<N;i++) ans+=p[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import sys
a = sys.stdin.readline().rstrip()

L1 =[2,4,5,7,9]
L2 = [0,1,6,8]
L3=[3]

if int(a[-1]) in L1:
    print('hon')
elif int(a[-1]) in L2:
    print('pon')
elif int(a[-1]) in L3:
    print('bon')

Measured memory_bytes: 9192
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin
 
def main():
    S = input()
    ans = 0
    for s in S:
        if s == "1":
            ans += 1
    print(ans)
 
input = lambda: stdin.readline().rstrip()
main()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(double A, double B, double H, double M) {
  double pi = 3.14159265359;

  double rad1 = (double)(H + M / 60) / 12 * 2 * pi;
  double rad2 = (double)M / 60 * 2 * pi;
  using P = complex<double>;
  P p1(cos(rad1) * A, sin(rad1) * A);
  //  cout << p1 << endl;
  P p2(cos(rad2) * B, sin(rad2) * B);
  // cout << p2 << endl;
  // cout << norm(p1 - p2) << endl;
  printf("%.10f\n", abs(p1 - p2));
}

signed main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long H;
  scanf("%lld", &H);
  long long M;
  scanf("%lld", &M);
  solve(A, B, H, M);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


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

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

string S;

int main() {
    cin >> S;
    if (S[0] == 'A' && S[1] == 'A' && S[2] == 'A') {
        cout << "No" << endl;
        return 0;
    }
    if (S[0] == 'B' && S[1] == 'B' && S[2] == 'B') {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin>>a;
if (a=="A"){
cout<<"T"<<endl;
}else if(a=="T"){
cout<<"A"<<endl;
}else if(a=="C"){
cout<<"G"<<endl;
}else if(a=="G"){
cout<<"C"<<endl;
}

     }

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    string a, b;
    cin >> a >> b;

    int anum = a.size();
    int bnum = b.size();

    if(anum > bnum){
        cout << "GREATER" << endl;
        return 0;
    }
    else if(bnum > anum){
        cout << "LESS" << endl;
        return 0;
    }

    if(a > b || anum > bnum) cout << "GREATER" << endl;
    else if(b > a || anum < bnum) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int years = sc.nextInt();
	int fee = sc.nextInt();
	if(years < 6){
		fee = 0;
	}else if(years < 13 && years >= 6){
		fee = fee/2;
	}
	System.out.println(fee);
}
}


Measured memory_bytes: 21844
import scala.io.StdIn

object Main extends App {
  val nLen = StdIn.readInt()
  val ns = StdIn.readLine().split(" ").map(_.toInt)
  val qLen = StdIn.readInt()
  val qs = StdIn.readLine().split(" ").map(_.toInt)

  println(
    qs.count(q => BinarySearch.binarySearch(ns, q))
  )
}

object BinarySearch {
  def binarySearch(xs: Array[Int], x: Int): Boolean = binarySearch(xs, x, 0, xs.length - 1)

  private def binarySearch(xs: Array[Int], x: Int, lSide: Int, rSide: Int): Boolean = {
    if (rSide < lSide) false
    else {
      val mid = lSide + (rSide - lSide) / 2
      if (xs(mid) < x) binarySearch(xs, x, mid + 1, rSide)
      else if (x < xs(mid)) binarySearch(xs, x, lSide, mid - 1)
      else xs(mid) == x
    }
  }
}



Measured memory_bytes: 76196
#include <stdio.h>
int main(void){
    int N, T, i, ans = 0;
    int t[200000];
    
    scanf("%d %d", &N, &T);
    
    for(i = 0; i < N; i++){
        scanf("%d", &t[i]);
    }
    
    for(i = 0; i < N; i++){
        if(N - 1 == i){
            ans = ans + T;
        }else if(T > t[i + 1] - t[i]){
            ans = ans + (t[i + 1] - t[i]);
        }else if(T <= t[i + 1] - t[i]){
            ans = ans + T;
        }
    }
    printf("%d\n", ans);
    
}


Measured memory_bytes: 2432
m, k = map(int, input().split())
v = []
if k == 0:
  for i in range(0, 2**m):
    v.append(i)
    v.append(i)
elif k < 2**m and m > 1:
  for i in range(0, 2**m):
    if i != k:
      v.append(i)
  v.append(k)
  for i in range(2**m-1, -1, -1):
    if i != k:
      v.append(i)
  v.append(k)
if len(v) == 0:
  print(-1)
else:
  for i in range(0, len(v)):
    print(v[i])
    if i == len(v)-1:
      print("\n")
    else:
      print(" ")

Measured memory_bytes: 15864
def main():
    l, r = map(int, input().split())
    q, ll = l // 2019, l % 2019
    rr = r % 2019
    rng = [*range(ll, rr+1)] if r - l < (2019 * q - ll) % 2019 else [*range(ll, 2019)] + [*range(rr+1)]
    lenrng = len(rng)
    ans = 2020
    for i in range(lenrng-1):
        for j in range(i+1, lenrng):
            tmp = rng[i] * rng[j] % 2019
            if tmp < ans:
                ans = tmp
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9220
import java.util.Scanner;

class Main{
	public static void main(String[] arg){
	
		
		Scanner sc = new Scanner(System.in);

		String str=sc.next();
		int m=sc.nextInt();
		int a,b;
		
		for(int i=0;i<m;i++){
			
			String go=sc.next();
			a=sc.nextInt();
		        b=sc.nextInt();

			if(go.equals("reverse")){
				
				
				String o =str.substring(0,a);
				String s=str.substring(a, b+1);
				String n= str.substring(b+1);
				String q="";
				
				for(int y=s.length()-1;y>=0;y--){
					q+=s.charAt(y);
				}
				
			str=o+q+n;
			}
			else if(go.equals("replace")){
				//a=sc.nextInt();
				//b=sc.nextInt();
				String str2=sc.next();
				str=str.substring(0,a)+str2+str.substring(b+1,str.length());
				
			}else if(go.equals("print")){
				//a=sc.nextInt();
				//b=sc.nextInt();
				String str2=str.substring(a,b+1);
			    System.out.println(str2);
			}
			
		}
		
		
		
		
		
		}
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template

int n,b[200],sum;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    for(int i=1;i<n;i++){
        cin>>b[i];
        if(i==1)sum+=b[i];
        else{
            sum += min(b[i],b[i-1]);
        }
    }
    sum+=b[n-1];
    cout<<sum<<newl;
}


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

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


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

int main(){
	int n;
	while(true){
		cin >> n;
		int arr[50];
		if(n == 0){
			break;
		}

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

		bool flag = false;
		for(int i=0;i<n-1;i++){
			if(flag){
				if(arr[i]+1 == arr[i+1]){
					continue;
				}else{
					cout << arr[i] << " ";
					flag = false;
					continue;
				}
			}
			if(arr[i]+1 == arr[i+1]){
				cout << arr[i] << "-";
				flag = true;
				continue;
			}else{
				cout << arr[i] << " ";
			}
		}
		cout << arr[n-1] << endl;
	}
}

Measured memory_bytes: 0
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

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;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	int ans = 0;
	REP(i, n)
	{
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	print(ans > 100000 ? 100000 : ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
/*  ex9_1
    kento_titech*/
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define SIZE 11
typedef struct {
    int size;
    int count;
    char data[SIZE];
    char *tail;
    char *head;
} stack;

void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk, char x);
void pop(stack *stk);

stack stk;

int main(void){
    initialize_stack(&stk);
    char input[SIZE];
    int i;
    scanf("%s",input);
    for(i=0;i<strlen(input);i++){
        if(input[i]=='1'||input[i]=='0'){
            push(&stk,input[i]);
        }
        else
            pop(&stk);
    }
    print_stack(&stk);
    printf("\n");
    return 0;
}

void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->head=&(stk->data[0]);
    stk->tail=&(stk->data[0]);
}

void push(stack *stk,  char x){    
    *(stk->tail) = x;
    stk->tail++;
    stk->count++;
}

void pop(stack *stk){
    if(stk->count > 0){
        stk->tail--;
        stk->count--;
    }
}

void print_stack(stack *stk){
    char *p;
    int i;    
    p = stk->head;
    for(i=0;i< stk->count;i++)
        printf("%c",*p++);
}

Measured memory_bytes: 1644
x, k, d = gets.chomp.split(' ').map(&:to_i)

i = 1

pk = x.abs / d
if pk > k
  dd = k * d
  i = k
else
  dd = pk * d
  i = pk
end

if x > 0
  x -= dd
else
  x += dd
end

while i < k
  if x.abs <= d
    if (k - i) % 2 == 1
      if x > 0
        x -= d
      else
        x += d
      end
    end
    break
  end

  if x > 0
    x -= dd
  else
    x += dd
  end
  i += 1
end

puts x.abs

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define FOR(i, x, n) for (int i = x; i < (int)(n); ++i)
#define ALL(n) begin(n), end(n)
#define ll long long
#define INF 1e9
int main() {
    int k;
    cin >> k;
    ll ans = -1;
    ll seven = 0;
    ll order = 1;
    ll a;

    // REP(i, 1000000) {
    //     a = k * i;
    //     REP(j, 12) {
    //         seven += order * 7;
    //         if (a == seven) {
    //             ans = j;
    //             break;
    //         } else
    //             order *= 10;
    //     }
    //     if (ans != -1) break;
    // }

    int mod = 0;
    REP(i, k + 1) {
        mod += 7;
        if (mod % k == 0) {
            ans = i + 1;
            break;
        } else {
            mod %= k;
            mod *= 10;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  rep(i,N) {
    if (A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int N,S=0,tmp;
    cin >> N;

    tmp = N;

    while(tmp>=1){
        S += (tmp%10);
        tmp = tmp / 10;
    }

    if((N%S)==0){
        cout <<"Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }

    return 0;
}

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

typedef pair <int, int> ii;
typedef pair <ii, int> iii;

const int Maxn = 20;

int L;
vector <iii> E;

void Add(int a, int b, int c)
{
    a = Maxn - a;
    b = Maxn - b;
    E.push_back(iii(ii(a, b), c));
}

int main()
{
    scanf("%d", &L); L--;
    Add(1, 0, 0);
    Add(1, 0, 1);
    Add(1, 0, 2);
    Add(1, 0, 3);
    for (int i = 2; i < 19; i++) {
        Add(i, i - 1, 0);
        Add(i, i - 1, 1 << i);
    }
    int cur = 0;
    for (int i = 19; i > 1; i--)
        if (L & 1 << i) {
            Add(19, i - 1, cur);
            cur |= 1 << i;
        }
    if (L & 1 << 1) {
        Add(19, 0, cur);
        Add(19, 0, cur + 1);
        cur |= 1 << 1;
    }
    if (L & 1 << 0) {
        Add(19, 0, cur);
        cur |= 1 << 0;
    }
    Add(19, 0, cur);
    printf("%d %d\n", Maxn, int(E.size()));
    for (int i = 0; i < E.size(); i++)
        printf("%d %d %d\n", E[i].first.first, E[i].first.second, E[i].second);
    return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
h,w=map(int,input().split())
nx,ny=map(int,input().split())
gx,gy=map(int,input().split())
maze=[input()for i in range(h)]
#. 46 # 35
nx-=1;ny-=1;gx-=1;gy-=1
from collections import deque
dq=deque([(nx,ny)])
dq2=deque([])
T=[[float('inf')]*w for  a in range(h)]
T[nx][ny]=0
moves=((1,0),(-1,0),(0,1),(0,-1))
from itertools import product as pr
Mmoves=tuple(i for i in pr((-2,-1,0,1,2),repeat=2)if i!=(0,0) )

while dq:
    while dq:
        x,y=dq.popleft()
        for i,j in moves:
            nex,ney=x+i,y+j
            if not(0<=nex<h and 0<=ney<w) or maze[nex][ney]==35:continue
            if T[x][y]<T[nex][ney]:
                T[nex][ney]=T[x][y]
                dq.append((nex,ney))
        for i,j in Mmoves:
            nex,ney=x+i,y+j
            if not(0<=nex<h and 0<=ney<w) or maze[nex][ney]==35:continue
            if T[x][y]+1<T[nex][ney]:
                T[nex][ney]=T[x][y]+1
                dq2.append((nex,ney))
    dq,dq2=dq2,dq
if T[gx][gy]==float('inf'):print(-1)
else:print(T[gx][gy])

Measured memory_bytes: 99356
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-24 18:15:16
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int n; cin >> n;
  string s; cin >> s;

  auto ok = [&](string t) -> bool {
    while (t.size() < 3) {
      t.insert(t.begin(), '0');
    }
    bool f1 = false, f2 = false, f3 = false;
    char c1 = t[0], c2 = t[1], c3 = t[2];
    for (char e : s) {
      if (!f1) {
        f1 = (e == c1);
      } else if (!f2) {
        f2 = (e == c2);
      } else if (!f3) {
        f3 = (e == c3);
      }
    }
    return f3;
  };

  int ans = 0;

  for (int i = 0; i <= 999; ++i) {
    ans += ok(to_string(i));
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    int N,T;
    cin >> N >>T;
    int min_cost = 1001;
    vector<vector<int>> time_cost(N,vector<int>(2));
    for (int i=0;i<N;i++){
        for(int j=0;j<2;j++){
            cin >>time_cost.at(i).at(j);
        }
    }
    for(int i=0;i<N;i++){
        if(time_cost.at(i).at(1)<=T){
            min_cost =min(min_cost,time_cost.at(i).at(0));
            }
    }
    if(min_cost==1001){
        cout << "TLE" << endl;
    }
    else{
        cout << min_cost <<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n,k;
  cin >> n >> k;
  vl num(100007,0);
  rep(i,n){
    ll a, b;
    cin >> a >> b;
    num[a] += b;
  }
  ll total = 0;
  for (ll i = 1; i < 100007; i++){
    total += num[i];
    if(total>=k){
      print(i);
      break;
    }
  }
}

Measured memory_bytes: 4024
a,b,k = gets.split(" ").map { |e| e.to_i }
if 2*k < b-a+2
  num = a
  for i in 0..k-1 do
    puts num+i
  end
  num = b-k+1
  for i in 0..k-1 do
    puts num+i
  end
else
  for i in a..b do
    puts i
  end
end

Measured memory_bytes: 1788
a = [int(input()) for _ in range(5)]
if all(i % 10 == 0 for i in a):
    print(sum(a))
else:
    b = sum(i // 10 for i in a) * 10
    c = [i % 10 for i in a if i % 10 != 0]
    print(b + len(c) * 10 - (10 - min(c)))

Measured memory_bytes: 9060
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
maxa = A[0]
ans= 0
for i in range(1,N):
    if A[i] < maxa:
        ans += maxa - A[i]
    else:
        maxa = A[i]
print(ans)

Measured memory_bytes: 32000
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  ll n;
  cin >> n;
  ll ans = 1;
  for (int i = 1; i < n; i++) {
    if (i * i > n) break;
    else ans = i * i;
  }
  cout << ans << endl;
}


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

long long md(pair<long long,long long> x,pair<long long,long long> y){
    return max(x.first,y.first)-min(x.first,y.first)+max(x.second,y.second)-min(x.second,y.second);
}

int GCD(int x,int y){
    int temp;
    if(x<y){
        temp=x,x=y,y=temp;
    }
    if(y<1){
        return -1;
    }
    if(x%y==0){
        return y;
    }
    return GCD(x,x%y);
}

int main(){
    int A,B;
    cin >> A >> B;
    if(A>2*B)
    cout << A-2*B << endl;
    else
    cout << 0 << endl;
}

Measured memory_bytes: 256
# ITP1_5_C: Print a Chessboard

def make_line(width, is_even)
  ('#.' * width)[ is_even ? 0 : 1, width ]
end

while true
  height, width = gets.split.map &:to_i
  break if height == 0 && width == 0

  even_line = make_line width, true
  odd_line  = make_line width, false

  height.times do |n|
    puts( n.even? ? even_line : odd_line )
  end
  puts
end

Measured memory_bytes: 8628
#include<iostream>
using std::cout;
using std::endl;

int main()
{
	for (int x = 1; x <= 9; x++)
	{
		for (int y = 1; y <= 9; y++)
		{
			cout << x << "x" << y << "=" << x*y << endl;
		}
	}
		return 0;
}

Measured memory_bytes: 1116