akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define ALL(n) begin(n), end(n)

int main()
{
  int N;
  cin >> N;
  vector<int> n(N + 1);
  rep2(i, 1, N + 1) cin >> n.at(i);
  int cnt = 1, i = 1;
  while (true)
  {
    if (n.at(i) == i || cnt > N)
    {
      cout << -1 << endl;
      break;
    }
    else if (n.at(i) == 2)
    {
      cout << cnt << endl;
      break;
    }
    else
    {
      cnt++;
      i = n.at(i);
    }
  }
}

Measured memory_bytes: 640
def ABC_50_B():
    N = int(input())
    T = input().split()
    M = int(input())

    for i in range(len(T)):
        T[i] = int(T[i])

    for i in range(M):
        P,X = map(int,input().split())

        Y = T[P-1]
        T[P-1] = X

        print(sum(T))

        T[P-1] = Y




if __name__ == '__main__':

    ABC_50_B()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
	int k;
	scanf("%d",&k);
	if(k%2==0) {
		int a= k/2;
		cout<<pow(a,2);
	}
	else {
		int a= k/2;
		cout<<a*(a+1);
	}
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1111;
char s[N];
int n,m,k;
int main(){
	scanf("%s",s+1);
	printf("%c%c%c",s[1],s[2],s[3]);
    return 0;
}

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

bool compare(string x, string y)
{
	for (int i = 0; i < x.size(); i++)
	{
		if(x[i] != '?' && x[i] != y[i])
		{
			return false;
		}
	}
	return true;
}

int main()
{
	string s, t;
	getline(cin, s);
	getline(cin, t);
	
	char ans[s.size()];
	
	for (int i = s.size() - t.size(); i >= 0; i--) 
	{
		string sub = s.substr(i, t.size());
		if (compare(sub, t))
		{
			int k = 0;
			for (int j = 0; j < s.size(); j++)
			{
				
				if (j >= i && j < i + t.size())
				{
					ans[j] = t[k++];
				}
				else
				{
					ans[j] = (s[j] == '?') ? 'a': s[j];
				}
			}
			for (int n = 0; n < s.size(); n++)
			{
				cout << ans[n];
			}
			cout << endl;
			return 0;
		}
	}
	
	cout << "UNRESTORABLE" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }
        int count = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                long c = 0;
                for (int k = 0; k < d; k++) {
                    c += Math.abs(x[i][k] - x[j][k]) * Math.abs(x[i][k] - x[j][k]);
                }
                if (Math.sqrt(c) % 1 == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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 (a>b) { a=b; return 1; } return 0; }

bool cmp(const pair<int,int> &a, const pair<int,int> &b){
    return (ll)a.first*(ll)1e10-a.second < (ll)b.first*(ll)1e10-b.second;

}

int main() {
    int N; cin>>N;
    vector<pair<int,int>> q(N);
    int l,r;
    int lmax=-MOD,rmin=MOD;
    for (int i = 0; i < N; ++i) {
        cin>>l>>r;
        chmax(lmax,l);
        chmin(rmin,r);
        q[i]=make_pair(l,r);
    }

    sort(q.begin(),q.end(),cmp);
    int ans=-1;
    for(auto a:q){
        //cout<<a.first<<" "<<a.second<<endl;
        chmax(ans,max(0,rmin-lmax+1)+a.second-a.first+1);
    }

    vector<int>left(N),right(N);
    //left set
    int llmax=q[0].first,lrmin=q[0].second;
    left[0]=lrmin-llmax+1;
    for (int i = 1; i < N-1; ++i) {
        chmax(llmax,q[i].first);
        chmin(lrmin,q[i].second);
        left[i]=lrmin-llmax+1;
    }

    //right set
    llmax=q[N-1].first,lrmin=q[N-1].second;
    right[N-2]=lrmin-llmax+1;
    for (int i = N-3; i >=0; --i) {
        chmax(llmax,q[i+1].first);
        chmin(lrmin,q[i+1].second);
        right[i]=lrmin-llmax+1;
    }

    for (int i = 0; i < N - 1; ++i) {
        //cout<<left[i]<<" "<<right[i]<<endl;
        chmax(ans,left[i]+right[i]);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long n,m,a,r,c,h;
long long w;
int main()
{
    string s;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(s[0]=='M')m++;
        else if(s[0]=='A')a++;
        else if(s[0]=='R')r++;
        else if(s[0]=='C')c++;
        else if(s[0]=='H')h++;
    }

    w+=m*a*r;
    w+=m*a*c;
    w+=m*a*h;
    w+=m*r*c;
    w+=m*r*h;
    w+=m*c*h;
    w+=a*r*c;
    w+=a*r*h;
    w+=a*c*h;
    w+=r*c*h;


    cout<<w<<endl;

   return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

N,M=list(map(int, input().split()))
evaluation=[]
for i in range(N):
    evaluation.append(list(map(int, input().split())))

# points=[[0 for i in range(N)] for j in range(N)]
cake_points=[[] for j in range(N)]

for list_index in range(N):
    for bits in range(1<<3):
        point_sum = 0
        for i in range(3):
            if (bits & 1<<i):
                point_sum += evaluation[list_index][i]
            else:
                point_sum += -evaluation[list_index][i]
        cake_points[list_index].append(point_sum)

answer_candidates=[]
for j in range(8):
    cake_points.sort(key=itemgetter(j))
    candidate_sum = 0
    for i in range(M):
        candidate_sum += cake_points[i][j]
    answer_candidates.append(candidate_sum)

abs_answer_candidates=[]
for point in answer_candidates:
    abs_answer_candidates.append(abs(point))

print(max(abs_answer_candidates))

Measured memory_bytes: 3700
H, W = map(int, input().split())
grid = [input() for _ in range(H)]

graph_1 = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            if j != 0 and grid[i][j - 1] == '.':
                graph_1[i][j] = graph_1[i][j - 1] + 1
            else:
                graph_1[i][j] = 1

for i in range(H):
    for j in reversed(range(W - 1)):
        if grid[i][j + 1] == '.' and grid[i][j] == '.':
            graph_1[i][j] = graph_1[i][j + 1]

graph_2 = [[0] * W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if grid[i][j] == '.':
            if i != 0 and grid[i - 1][j] == '.':
                graph_2[i][j] = graph_2[i - 1][j] + 1
            else:
                graph_2[i][j] = 1

for j in range(W):
    for i in reversed(range(H - 1)):
        if grid[i + 1][j] == '.' and grid[i][j] == '.':
            graph_2[i][j] = graph_2[i + 1][j]

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, graph_1[i][j] + graph_2[i][j] - 1)
        
print(ans)


Measured memory_bytes: 126168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) csp max(0,a+b-n) << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<pll> v;
  rep(i, a)
  {
    ll p;
    cin >> p;
    v.push_back(MP(p, 1));
  }
  rep(i, b)
  {
    ll p;
    cin >> p;
    v.push_back(MP(p, 2));
  }
  rep(i, c)
  {
    ll p;
    cin >> p;
    v.push_back(MP(p, 3));
  }
  sort(all(v), greater<pll>());

  ll sum = 0;
  int noth = 0;
  int cnt_x = 0, cnt_y = 0;
  for (auto p : v)
  {
    if (p.second == 1 && cnt_x < x)
    {
      sum += p.first;
      cnt_x++;
    }
    else if (p.second == 2 && cnt_y < y)
    {
      sum += p.first;
      cnt_y++;
    }
    else if (p.second == 3)
    {
      sum += p.first;
      noth++;
    }

    if (cnt_x + cnt_y + noth == x + y)
      break;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 10476
import math

k = int(input())
sum = 0
gcds = [[0 for i in range(k)] for i in range(k)]
for p in range(1,k+1):
    for q in range(1,k+1):   
        gcds[p-1][q-1] = math.gcd(p,q)          
        for r in range(1,k+1):
            sum += math.gcd(gcds[p-1][q-1], r)
            


print(sum)

Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    string S,T;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;
    string U;
    cin >> U;
    if(U == S) {
        A--;
    }
    else {
        B--;
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string s;
    bool flag = false;

    cin >> s;

    if (s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi")
    {
        flag = true;
    }

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


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;
using Edge = vector<vector<pair<int, int>>>; // src -> dst, weight

bool graph_dfs(int                      vertex,
               const Edge&              edge,
               vector<pair<int, bool>>& vertex_label) {

    bool ret = true;
    REP(i, edge[vertex].size()) {
        int dst    = edge[vertex][i].first;
        int weight = edge[vertex][i].second;

        if(!vertex_label[dst].second) {
            vertex_label[dst].first  = vertex_label[vertex].first + weight;
            vertex_label[dst].second = true;

            ret = graph_dfs(dst, edge, vertex_label);
            if(!ret) {
                break;
            }
        }
        else if(vertex_label[dst].first != vertex_label[vertex].first + weight) {
            return false;
        }
    }

    return ret;
}

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

    int N, M;
    std::cin >> N >> M;

    Edge        edge(N);
    vector<pair<int, bool>> vertex_label(N, make_pair(0, false));

    REP(i, M) {
        int l, r, d;
        std::cin >> l >> r >> d;
        edge[l - 1].emplace_back(r - 1,  d);
        edge[r - 1].emplace_back(l - 1, -d);
    }

    string ans = "Yes";
    REP(i, edge.size()) {
        if(edge[i].size() == 0 || vertex_label[i].second) {
            continue;
        }

        vertex_label[i].second = true;
        if(!graph_dfs(i, edge, vertex_label)) {
            ans = "No";
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}



Measured memory_bytes: 12416
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

long int combination(long int n, long int r);

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

long int combination(long int n, long int r)
{
	if(r>n-r) r = n-r;
	if(r == 0) return 1;
	else if(r == 1) return n;
	return (combination(n-1, r) + combination(n-1, r-1));
	//大きくなるとき
	/*
	long int tmp1, tmp2, tmp3;
	tmp1 = combination(n-1, r);
	if(tmp1>=MOD) tmp1 = tmp1%MOD;
	tmp2 = combination(n-1, r-1);
	if(tmp2>=MOD) tmp2 = tmp2%MOD;
	tmp3 = tmp1+tmp2;
	if(tmp3>=MOD) tmp3 = tmp3%MOD;
	return (tmp3);
	*/
}


int main(){
	int array[32], k;
	scanf("%d", &k);
	array[0] = 1;
	array[1] = 1;
	array[2] = 1;
	array[3] = 2;
	array[4] = 1;
	array[5] = 2;
	array[6] = 1;
	array[7] = 5;
	array[8] = 2;
	array[9] = 2;
	array[10] = 1;
	array[11] = 5;
	array[12] = 1;
	array[13] = 2;
	array[14] = 1;
	array[15] = 14;
	array[16] = 1;
	array[17] = 5;
	array[18] = 1;
	array[19] = 5;
	array[20] = 2;
	array[21] = 2;
	array[22] = 1;
	array[23] = 15;
	array[24] = 2;
	array[25] = 2;
	array[26] = 5;
	array[27] = 4;
	array[28] = 1;
	array[29] = 4;
	array[30] = 1;
	array[31] = 51;
	printf("%d\n", array[k-1]);
	
	return 0;
}

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

class UnionFind {
  public:
  vector < ll > par; // 各元の親を表す配列
  vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

  // Constructor
  UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }

  // Member Function
  // Find
  ll root(ll x) { // 根の検索
    while (par[x] != x) {
      x = par[x] = par[par[x]]; // x の親の親を x の親とする
    }
    return x;
  }

  // Union(Unite, Merge)
  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    // merge technique（データ構造をマージするテク．小を大にくっつける）
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) { // 連結判定
    return root(x) == root(y);
  }

  ll size(ll x) { // 素集合のサイズ
    return siz[root(x)];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.merge(a, b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ans < uf.size(i)) ans = uf.size(i);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6372
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func max32(a, b int32) int32 {
	if a > b {
		return a
	}
	return b
}

var dp [][]int32
var maxL int

func makeTbl(N int, v, w []int) {
	N = min(N, len(v))
	dp = make([][]int32, N+1)
	for n := 0; n <= N; n++ {
		dp[n] = make([]int32, maxL+1)
	}
	// out(v, w, N)

	for n := 1; n < N; n++ {
		prev := n / 2
		// out("cur", n, "prev", prev)
		for i := 0; i <= maxL; i++ {
			if w[n] <= i {
				dp[n][i] = max32(dp[prev][i], dp[prev][i-w[n]]+int32(v[n]))
			} else {
				dp[n][i] = dp[prev][i]
			}
		}
		// out(n, dp[n][:10])
	}
}

var v []int
var w []int

func calc(s, L int, idx []int) int {
	N := len(idx)
	n := 1 << uint(N)
	ret := 0
L0:
	for i := 0; i < n; i++ {
		sumw := 0
		sumv := 0
		for j := 0; j < N; j++ {
			x := idx[j]
			if (i>>j)%2 == 1 {
				sumw += w[x]
				sumv += v[x]
			}
			if sumw > L {
				continue L0
			}
		}
		// out(strconv.FormatInt(int64(i), 2), sumw, sumv, L)
		rest := L - sumw
		sumv += int(dp[s][rest])
		ret = max(ret, sumv)
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	v = make([]int, N+1)
	w = make([]int, N+1)
	for i := 1; i <= N; i++ {
		v[i], w[i] = getInt(), getInt()
	}

	Q := getInt()
	AV := make([]int, Q)
	AL := make([]int, Q)

	for i := 0; i < Q; i++ {
		AV[i], AL[i] = getInt(), getInt()
		maxL = max(maxL, AL[i])
	}

	const lv = 2048
	makeTbl(lv, v, w)

	wb := bufio.NewWriter(os.Stdout)
	defer wb.Flush()
	for i := 0; i < Q; i++ {
		L := AL[i]
		V := AV[i]
		// out(V, L, dp[V][:L])
		if V < lv {
			fmt.Fprintln(wb, dp[V][L])
			continue
		}
		idx := make([]int, 0, 16)
		for V >= lv {
			idx = append(idx, V)
			V /= 2
		}
		// out(val, weight, V, L)
		ret := calc(V, L, idx)
		fmt.Fprintln(wb, ret)
	}
}


Measured memory_bytes: 839364
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int N, Q;
  cin >> N >> Q;
  vector<int> v[N];
  int q, a, b;

  rep(i, Q) {
    cin >> q;
    if(q == 0) {
      cin >> a >> b;
      v[a].push_back(b);
    }
    if(q == 1) {
      cin >> a;
      rep(i, v[a].size()) {
        if(!i) cout << v[a][i];
        else cout << " " << v[a][i];
      }
      cout << endl;
    }
    if(q == 2) {
      cin >> a;
      v[a].clear();
    }
  }
  return 0;
}



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

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

  for(int i = 1; i<10; i++){    
      for(int j = 1; j<10; j++){
         
          int a;
          a = i*j;

          if (N == a){
          cout << "Yes" << endl;
          return 0;     

          }
        
          
       
         
        }   
          
          
      }
      cout << "No" << endl;
      return 0;
  
 
  

}

Measured memory_bytes: 256
n = int(input())
c = 0
c_dict = {}
l = []
for i in range(n):
    s_listed = sorted(list(input()))
    s = ''.join(s_listed)
    if s in c_dict.keys():
        c_dict[s] += 1
        c += c_dict[s] - 1
    else:
        c_dict[s] = 1
print(int(c))


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

#define ll long long int
#define pi pair<ll,ll>

void solve(){
    ll a, b;    cin >> a >> b;
    ll g = __gcd(a, b);
    if (g == b)
        cout << 0 << '\n';
    else if (g == a)
        cout << a << '\n';
    else if (b < a) {
        b /= g;
        a /= g;
        cout << g*min(b-a%b, a%b) << '\n';
    }
    else {
        b /= g;
        a /= g;
        cout << g*min({a,b-a}) << '\n';
    }
}

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

    int test = 1;
    // cin >> test;
    while(test--)
        solve();
    return 0;
}

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

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector <int> a(n);
	long sum = 0;
	int count = 0;
	for(int &i : a){
		cin >> i;
		sum += i;
	}
	for(int &i : a){
		if(i*1.0 >= (sum*1.0)/(4*m))
			++count;
	}
	if(count >= m)
		cout << "Yes\n";
	else 
		cout << "No\n";	
}

Measured memory_bytes: 256
from sys import stdin 
n = int(stdin.readline())
a = stdin.readline().strip()
x = 0
fir = 0 
sec = 0
for i in a:
    if i=='(':
        fir+=1
    else:
        if fir > 0:
            fir-=1
        else:
            sec+=1
            fir = 0

print sec*'(' + a + ')'*fir

Measured memory_bytes: 2568
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int _=2005,yl=998244353;
string s;
ll f[_<<1][_<<1],n,ans;
int main(){
	cin>>s;n=s.length();s='0'+s;f[0][0]=1;
	for(int i=1,cnt=0,t=0;i<=n*2;++i){
		if(i<=n)cnt+=s[i]-'0',t+=2;
		for(int j=max(0,i-(t-cnt));j<=cnt;++j){
			if(j==0)f[i][j]=f[i-1][j];
			else f[i][j]=(f[i-1][j]+f[i-1][j-1])%yl;
			if(i==n*2)ans+=f[i][j];
		}
	}
	cout<<ans%yl<<endl;
}


Measured memory_bytes: 123520
import java.util.Scanner;
public class Main{
    public static boolean search(long a[], long b){
        int start = 0;
        int end = a.length-1;
        while(true){
            if(a[start] == b || a[end] == b)
                return true;
            else{
                int mid = (start + end)/2;
                if(a[mid] == b)
                    return true;
                else if(a[mid] < b)
                    start = mid;
                else
                    end = mid;
            }
            if(start + 1 >= end)
                return false;
        }
    }
    public static boolean include(long a[], long b[]){
        for(int i = 0 ; i < b.length ; i++){
            if(!(search(a,b[i])))
                return false;
        }
        return true;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        for(int i = 0 ; i < n ; i++)
            a[i] = sc.nextLong();
        int m = sc.nextInt();
        long b[] = new long[m];
        for(int i = 0 ; i < m ; i++)
            b[i] = sc.nextLong();
        if(include(a,b))
            System.out.println(1);
        else
            System.out.println(0);
    }
}


Measured memory_bytes: 124484
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
vector<ll>v;
ll l, r, ans;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> l >> r;
    for(int i = l; i <= min(l + 2019, r); i++){
        v.push_back(i);
    }
    ans = 2e18;
    for(int i = 0; i < v.size(); i++){
        ll rem = v[i] % 2019;
        for(int j = 0; j < v.size(); j++){
            if(i == j) continue;
            ans = min(ans, (rem * v[j]) % 2019);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int X;
    cin >> X;
    if (X>=30){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }

    return 0;
}


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

int main()
{
    string s, t, u;
    int a, b;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if (s == u) cout << a-1 << " " << b << endl;
    else if (t == u) cout << a << " " << b-1 << endl;
    else cout << a << " " << b << endl;
    
    return 0;
}

Measured memory_bytes: 256
inf = 1000
h,w = map(int,input().split())

dp = []
for i in range(10):
    c = list(map(int,input().split()))
    dp.append(c)

for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])

ans = 0
A = [list(map(int, input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if A[i][j] not in [-1,1]:
            ans += dp[A[i][j]][1]

print(ans)

Measured memory_bytes: 3444
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    
    int N,M;
    cin >> N >> M;
    int p = 0;
    string S = "";
    int a[N];
    bool b[N];
    for(int i=0;i<N;i++){
        a[i] = 0;
        b[i] = false;
    }
    int AC = 0;
    int WA = 0;
    for(int i=0;i<M;i++){
        cin >> p >> S;
        if(b[p-1] == false){
            if(S == "AC"){
                AC++;
                WA += a[p-1];
                b[p-1] = true;
            }else{
                a[p-1]++;
            }
        }
    }
    cout << AC << " " << WA << endl;
    return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}


signed main()
{
    string s; cin >> s;
    sort(ALL(s));

    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[3]) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<complex>
using namespace std;
#define EPS 1e-10
double area2( double a, double b, double c){
  double s = ( a + b + c ) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}

int main(){
  int a, l, x;
  while(cin >> a >> l >> x){
    double h = (l + x) / 2.0; // たぶん真ん中でしょ
    cout << fixed << setprecision(6) << area2(a,l,l) + area2(h,h,l)*2 + EPS << endl;
  }
}

Measured memory_bytes: 1236
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

int cand[11][43210];
int db[61][61][61];

void setcand(int h, int m, int s, int i){
	REP(j, 60){
		if(db[h][m][s] >= 0) cand[i][db[h][m][s]] = db[h][m][s];
		(h += 1) %= 60;
		(m += 1) %= 60;
		(s += 1) %= 60;
	}
}

int prints(int s){
	printf("%02d:%02d:%02d", s/3600, (s/60)%60, s%60);
}

main(){
	int i,j;
	memset(db, -1, sizeof(db));
	REP(s, 43200){
		int h = s/720;
		int m = (s/60)%60;
		int ss = s%60;
		db[h][m][ss] = s;
	}

	while(cin >> n, n){
		memset(cand, 63, sizeof(cand));
		REP(i, n){
			int h, m, s;
			cin >> h >> m >> s;
			setcand(h, m, s, i);
			setcand(h, s, m, i);
			setcand(m, h, s, i);
			setcand(m, s, h, i);
			setcand(s, h, m, i);
			setcand(s, m, h, i);
		}
		REP(i, n){
			RREP(j, 43200) cand[i][j] = min(cand[i][j], cand[i][j+1]);
		}
		pii ans(43200, 0);
		REP(i, 43200){
			int mx = 0;
			REP(j, n) mx = max(mx, cand[j][i]-i);
			ans = min(ans, pii(mx, i));
		}
		prints(ans.second);
		putchar(' ');
		prints(ans.first+ans.second);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3912
#include <iostream>

using namespace std;
long long dp[51][51][8000] = {},mod = 1000000007;
int main(){
	int i,j,l,n,k;
	cin >> n >> k;
	dp[0][0][n*(n + 1)] = 1;
	for(i=1;i<=n;i++){
		for(j=1;j<=i;j++){
			for(l=0;l<=2*n*(n + 1);l++){
				if(j>=2) (dp[i][j - 2][l + 2*i] += (j - 1)*(j - 1)*dp[i - 1][j - 1][l]) %= mod;//両方前と結ぶ
				(dp[i][j - 1][l] += (2*j - 1)*dp[i - 1][j - 1][l]) %= mod;//片方だけ前と結ぶor i番目どうし結ぶ
				(dp[i][j][l - 2*i] += dp[i - 1][j - 1][l]) %= mod;//どちらも結ばない
			}
		}
	}
	cout << dp[n][0][k + n*(n + 1)] << endl;
}


Measured memory_bytes: 148224
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int N, M, X;
    cin >> N >> M >> X;

    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M, 0));

    for (int i = 0; i < N; ++i) {
        cin >> C[i];
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
        }
    }

    ll ans = -1;

    for (int x = 0; x < (1 << N); ++x) {
        ll c = 0;
        vector<ll> r(M);

        for (int i = 0; i < N; ++i) {
            if (x & (1 << i)) {
                c += C[i];

                for (int j = 0; j < M; ++j) {
                    r[j] += A[i][j];
                }
            }
        }

        bool ok = all_of(begin(r), end(r), [X](auto ri){ return ri >= X; });
        if (ok) {
            if (ans == -1) {
                ans = c;
                continue;
            }

            ans = min(ans, c);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <math.h>
int main (void)
{
	double x1, y1, x2, y2;
	scanf("%lf %lf %lf %lf",&x1, &y1, &x2, &y2);

	double kyori = pow((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1),0.5);
	printf("%.8f\n",kyori);

	return 0;


}

Measured memory_bytes: 696
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N = int(readline())

G = [None]*N
W = 0
for i in range(N):
    j, k, *V = map(int, readline().split())
    G[i] = [(v, c) for v, c in zip(V[::2], V[1::2])]
    if V:
        W = max(W, max(V[1::2]))

def dial(N, G, W, s):
    B = [-1]*(N*W + 1)
    L = [-1]*(N*W + 1)
    *prv, = range(-1, N-1)
    *nxt, = range(1, N+1)
    nxt[-1] = -1
    prv[s+1] = s-1
    nxt[s-1] = (s+1 if s < N-1 else -1)
    prv[s] = nxt[s] = -1
    B[0] = L[0] = s
    B[N*W] = +(s == 0)
    L[N*W] = (N-1 if s < N-1 else N-2)

    dist = [N*W] * N
    dist[s] = 0
    for w in range(N*W):
        v = B[w]
        while v != -1:
            for x, c in G[v]:
                e = w + c
                if e < dist[x]:
                    d = dist[x]
                    dist[x] = e

                    p = prv[x]; n = nxt[x]
                    if p != -1:
                        nxt[p] = n
                    else:
                        B[d] = n
                    if n != -1:
                        prv[n] = p
                    else:
                        L[d] = p

                    l = L[e]
                    if l != -1:
                        nxt[l] = x
                    else:
                        B[e] = x
                    prv[x] = l; nxt[x] = -1
                    L[e] = x
            v = nxt[v]
    return dist
dist = dial(N, G, W, 0)
ans = []
for i in range(N):
    ans.append("%d %d\n" % (i, dist[i]))
sys.stdout.writelines(ans)


Measured memory_bytes: 21228
def main():
    a, b, k = map(int, input().split())
    
    s = set()

    for i in range(a, a+k):
        s.add(i)

    for i in range(b-k+1, b+1):
        s.add(i)

    for i in sorted(s):
        if a <= i and i <= b:
            print(i)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535;

int main()
{
    int r;
    cin >> r;
    cout << 2 * r * PI << endl;
    return 0;
}

Measured memory_bytes: 3780
#include <stdio.h>
int main(void){
  int n,m,t,a[100],i,cnt=0;
  scanf("%d %d %d",&n,&m,&t);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  cnt=m;
  int mode=1;
  for(i=0;i<n;i++){
    if(mode==0){
      cnt+=m;
      mode=1;
    }
    if(i<n-1){
      if(a[i+1]-a[i]<2*m)
	cnt+=a[i+1]-a[i];
      else{
	cnt+=m;
	mode=0;
      }
    }
  }
  if(mode==1)
    cnt+=m<(t-a[n-1])?m:(t-a[n-1]);
  printf("%d\n",t-cnt);
  return 0;
}

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

int main()
{
        ll N;
        cin >> N;
        vector<ll> a(N, 0);
        ll total = 0;
        for (int i = 0; i < N; ++i) {
                cin >> a[i];
                total += a[i];
        }
        ll S = 0;
        ll A = 0;
        ll ans = 0;
        for (int i = 0; i < N-1; ++i) {

                A += a[i];

                S = total - A;

                ll dif = abs(S-A);
                if (i == 0) ans = dif;
                else if (dif < ans) ans = dif;
        }

        cout << ans << endl;





}


Measured memory_bytes: 1792
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let x: u64 = sc.read();
    let v: Vec<u64> = sc.vec(n);

    let mut sum = vec![0; n + 1];
    for i in 0..n {
        sum[i + 1] = sum[i] + v[i];
    }

    let mut min = 1e18 as u64;
    for k in 1..(n + 1) {
        let mut ans = x * ((n + k) as u64);
        for a in 0.. {
            if n < a * k {
                break;
            }
            let sum = if n >= (a + 1) * k {
                sum[n - a * k] - sum[n - (a + 1) * k]
            } else {
                sum[n - a * k]
            };
            let m = if a == 0 { 5 } else { 2 * (a + 2) - 1 };
            ans += sum * (m as u64);
        }
        min = cmp::min(min, ans);
    }
    println!("{}", min);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



  //二分探索(最小値を出す問題は疑う)


// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < N; ++i){
// 		res += max(0ll, A[i]-x/F[i]);
//     }
//     return res <= K;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }



int main(){
  int a, b;
  cin >> a >> b;
  if(a > 0 && b > 0) print("Positive");
  else if(a <= 0 && b >= 0) print("Zero");
  else if(a < 0 && b < 0) {
    if((b - a + 1) % 2 == 0) print("Positive");
    else if ((b - a + 1) % 2 == 1) print("Negative");
  }
}

Measured memory_bytes: 256
n = int(input())
s = input()

# assume [0 is S, -1 is S]

for ans0, ans_last in [ ('S','S'),('S','W'),('W','S'),('W','W') ]:
    ans = ['tbd']*n
    ans[0] = ans0
    ans[-1] = ans_last
        
    for i in range(n-2):
        if (s[i] == 'o' and ans[i] == 'S') or (s[i] == 'x' and ans[i] == 'W'):
            ans[i+1] = ans[i-1]
        else:
            ans[i+1] = 'S' if ans[i-1] == 'W' else 'W'

    last_two_flag = False
    last_one_flag = False

    if (s[n-2] == 'o' and ans[n-2] == 'S') or (s[n-2] == 'x' and ans[n-2] == 'W'):
        if ans[n-3] == ans[n-1]:
            last_two_flag = True
    else:
        if ans[n-3] != ans[n-1]:
            last_two_flag = True


    if (s[n-1] == 'o' and ans[n-1] == 'S') or (s[n-1] == 'x' and ans[n-1] == 'W'):
        if ans[n-2] == ans[0]:
            last_one_flag = True
    else:
        if ans[n-2] != ans[0]:
            last_one_flag = True

    if last_one_flag and last_two_flag:
        print(''.join(ans))
        exit()

print(-1)

Measured memory_bytes: 4852
#include<stdio.h>
int main()
{
	int a,b;
	
	do{
		scanf("%d %d",&a,&b);
		if(a==0 && b==0)
		break;
		for(int i=0;i<a;i++)
		{
			for(int j=0;j<b;j++)
			{
				if(i==0 || j==0 || i==a-1 || j==b-1 )
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}while(a!=0 && b!=0);
}


Measured memory_bytes: 1844
h, w = map(int, input().split()) 
sy, sx = map(int, input().split()) 
gy, gx = map(int, input().split()) 
sy-=1
sx-=1
gy-=1
gx-=1
s = [input() for i in range(h)]

from collections import deque

q = deque([])
q.append([sy, sx, 0])

mx=[0,0,1,-1]
my=[1,-1,0,0]

vis = [[-1]*w for i in range(h)]
vis[sy][sx]=0

while len(q)>0:
  y, x, c = q.popleft()

  for i in range(4):
    nx=x+mx[i]
    ny=y+my[i]
    if 0<=nx<w and 0<=ny<h and s[ny][nx]=="." and (vis[ny][nx]>c or vis[ny][nx]==-1):
      vis[ny][nx]=c
      q.appendleft([ny,nx,c])
  
  for xi in range(5):
    for yi in range(5):
      nx=x+xi-2
      ny=y+yi-2    
      if 0<=nx<w and 0<=ny<h and s[ny][nx]=="." and vis[ny][nx]==-1:
        vis[ny][nx]=c+1
        q.append([ny,nx,c+1])
print(vis[gy][gx])
      
  
  
  
  

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  for (int i = 0; i < M; i++){
    cin >> p.at(i) >> S.at(i);
  }
  vector<int> result(N+1);
  int WA = 0;
  int AC = 0;
  for (int i = 0; i < M; i++){
    if (S.at(i) == "WA"){
      if (result.at(p.at(i)) != 1){
        result.at(p.at(i))--;
      }
    }
    else if (S.at(i) == "AC"){
      if (result.at(p.at(i)) != 1){
        WA -= result.at(p.at(i));
        result.at(p.at(i)) = 1;
        AC++;
      }
    }
  }
  cout << AC << " " << WA << endl;
}



Measured memory_bytes: 6528
A, B, C = map(int, input().split())
K = int(input())

for k in range(K):
    if A >= B:
        B = 2*B
        continue
    elif B >= C:
        C = 2*C
        continue
    elif A >= C:
        C = 2*C
        continue
        
if A < B and B < C:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9116
#include <cstdio>

#include <array>
#include <algorithm>

#include <iostream>

using namespace std;

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

	array<int, 3> N{};

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

	sort( begin( N ), end( N ), greater<int>{} );

	cout << N[0] * 10 + N[1] + N[2] << "\n";
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int H, W, K;
	cin >> H >> W >> K;

	pii sp, gp;
	cin >> sp.second >> sp.first >> gp.second >> gp.first;
	sp.first--, sp.second--, gp.first--, gp.second--;

	vector<string> SMAP(H);
	rep(i, 0, H)cin >> SMAP[i];
	vector<vector<int>> D(H, vector<int>(W, INF));

	queue<pair<pii,int>> q;
	D[sp.second][sp.first] = 0;
	q.push(mp(sp, 0));
	while (!q.empty())
	{
		auto p = q.front();
		q.pop();
		auto pos = p.first;
		int v = p.second + 1;
		rep(i, 1, K + 1)
		{
			int nx = pos.first + i, ny = pos.second;
			if (!(0 <= nx && nx < W && 0 <= ny && ny < H))break;
			if (SMAP[ny][nx] == '@' || D[ny][nx] < v)break;
			if (chmin(D[ny][nx],v))
			{
				q.push(mp(mp(nx, ny), v));
			}
		}
		rep(i, 1, K + 1)
		{
			int nx = pos.first - i, ny = pos.second;
			if (!(0 <= nx && nx < W && 0 <= ny && ny < H))break;
			if (SMAP[ny][nx] == '@' || D[ny][nx] < v)break;
			if (chmin(D[ny][nx], v))
			{
				q.push(mp(mp(nx, ny), v));
			}
		}
		rep(i, 1, K + 1)
		{
			int nx = pos.first, ny = pos.second + i;
			if (!(0 <= nx && nx < W && 0 <= ny && ny < H))break;
			if (SMAP[ny][nx] == '@' || D[ny][nx] < v)break;
			if (chmin(D[ny][nx], v))
			{
				q.push(mp(mp(nx, ny), v));
			}
		}
		rep(i, 1, K + 1)
		{
			int nx = pos.first, ny = pos.second - i;
			if (!(0 <= nx && nx < W && 0 <= ny && ny < H))break;
			if (SMAP[ny][nx] == '@' || D[ny][nx] < v)break;
			if (chmin(D[ny][nx], v))
			{
				q.push(mp(mp(nx, ny), v));
			}
		}
	}

	if (D[gp.second][gp.first] == INF)cout << -1 << endl;
	else cout<<D[gp.second][gp.first] << endl;

	return 0;
}

Measured memory_bytes: 19844
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;
 
#define mod 1000000007
long long modexpo(long long x, long long p){
    int res = 1;x = x%mod;
    while(p){
        if(p%2)res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

int32_t main(){
    IOS
    int n;
    cin >> n;
    int a = modexpo(9,n);
    int b = modexpo(8,n);
    int c = modexpo(10,n);
    int ans = c - 2*a + b;
    ans %= mod;
    if(ans < 0){
        ans += mod;
    }
    cout << ans << "\n";
} 

Measured memory_bytes: 3648
n = int(input())
cnt = 0
a = []
for i in range(1,n+1,2):
    for j in range(1,i+1):
        if i % j == 0:
            cnt += 1
        else:
            continue
    if cnt == 8:
        a.append(j)
        cnt = 0
    else:
        cnt = 0
print(len(a))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll mn = min({a, b, c, d, e});
  ll m = (n+mn-1)/mn;
  ll ans = m + 4;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596