akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	ll n;
	cin >> n;

	ll sn = (sqrt(n) + 1);

	ll ans = 0;
	for(ll i = sn; i >= 1; i--){
		if (n % i == 0){
			// cout << i << 
			ans += i-1;
			ans += (n/i) - 1;
			break;
		}
	}
	cout << ans << endl;

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


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

int n;
string str;
int number(int& i);
int term(int& i);
int expression(int& i);
int factor(int& i);

int number(int& i)
{
	int ret = 0;
	while ('0' <= str[i] && str[i] <= '9')
	{
		ret *= 10;
		ret += str[i] - '0';
		i++;
	}
	return ret;
}

int term(int& i)
{
	int ret = factor(i);
	while (true)
	{
		if (str[i] == '*')
		{
			i++;
			ret *= factor(i);
		}
		else if (str[i] == '/')
		{
			i++;
			ret /= factor(i);
		}
		else
		{
			break;
		}
	}
	return ret;
}

int expression(int& i)
{
	int ret = term(i);
	while (true)
	{
		if (str[i] == '+')
		{
			i++;
			ret += term(i);
		}
		else if (str[i] == '-')
		{
			i++;
			ret -= term(i);
		}
		else
		{
			break;
		}
	}
	return ret;
}

int factor(int& i)
{
	int ret = 0;
	if (str[i] == '(')
	{
		i++;
		ret = expression(i);
		i++;
	}
	else
	{
		ret = number(i);
	}
	return ret;
}

int main()
{
	cin >> n;
	while (n--)
	{
		cin >> str;
		int i = 0;
		cout << expression(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringJoiner;

import java.util.List;

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

    void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        HashSet<Integer> set = new HashSet<>(k * 2);
        for (int i = 0; i < k; i++) {
            if (a + i > b) {
                break;
            }
            set.add(a + i);
        }
        for (int i = 0; i < k; i++) {
            if (b - i < a) {
                break;
            }
            set.add(b - i);
        }
        List<Integer> list = new ArrayList<>(set);
        Collections.sort(list);
        for (Integer i : list) {
            System.out.println(i);
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  string N_str = to_string(N);

  int fX = 0;
  for (int i = 0; i < N_str.length(); i++) {
    fX += (int) N_str[i] - 48;
  }
  
  if (N % fX == 0) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3692
#!/usr/bin/ruby
class TLLI
	def initialize
		@trianies=[nil,[0,0,0]]
	end
	def root_triany
		1
	end
	def allocate_triany
		siz=@trianies.size
		@trianies[siz]=[0,0,0]
		return siz
	end
	def set_a(id,value)
		return if !@trianies[id]
		@trianies[id][0]=value
	end
	def set_b(id,value)
		return if !@trianies[id]
		@trianies[id][1]=value
	end
	def set_c(id,value)
		return if !@trianies[id]
		@trianies[id][2]=value
	end
	def get_a(id)
		return if !@trianies[id]
		@trianies[id][0]
	end
	def get_b(id)
		return if !@trianies[id]
		@trianies[id][1]
	end
	def get_c(id)
		return if !@trianies[id]
		@trianies[id][2]
	end
end

$black={}
class SETI <TLLI # a=>key, b=>left, c=>right
	def set_entry(key)
		if $black[key]
			$black.delete(key)
			return
		end
		x=root_triany
		y=0
		while x!=0&&!(x==root_triany&&get_a(x)==0) #fixme
			y=x
			if key<get_a(x)
				x=get_b(x)
			else
				x=get_c(x)
			end
		end
		if y==0
			set_a(root_triany,key)
		else
			leaf=allocate_triany
			set_a(leaf,key)
			if key<get_a(y)
				set_b(y,leaf)
			else
				set_c(y,leaf)
			end
		end
	end
	def find_entry(key)
		return false if $black[key]
		t=root_triany
		loop{
			return true if key==get_a(t)
			if key<get_a(t)
				t=get_b(t)
				return false if t==0
			else
				t=get_c(t)
				return false if t==0
			end
		}
	end
	def print_preorder(t)
		return if t==0
		unless $black.has_key?(get_a(t))
			Kernel.print(' ')
			Kernel.print(get_a(t))
		end
		print_preorder(get_b(t))
		print_preorder(get_c(t))
	end
	def print_inorder(t)
		return if t==0
		print_inorder(get_b(t))
		unless $black.has_key?(get_a(t))
			Kernel.print(' ')
			Kernel.print(get_a(t))
		end
		print_inorder(get_c(t))
	end
	def print_postorder(t)
		return if t==0
		print_postorder(get_b(t))
		print_postorder(get_c(t))
		unless $black.has_key?(get_a(t))
			Kernel.print(' ')
			Kernel.print(get_a(t))
		end
	end
	def print
		print_inorder(root_triany)
		Kernel.puts
		print_preorder(root_triany)
		Kernel.puts
	end
end

seti=SETI.new
$<.drop(1).each{|l|
	a=l.chomp.split
	if a[0]=='insert'
		seti.set_entry(a[1].to_i)
	elsif a[0]=='find'
		puts seti.find_entry(a[1].to_i) ? :yes : :no
	elsif a[0]=='delete'
		$black[a[1].to_i]=1
	elsif a[0]=='print'
		seti.print
	end
}

Measured memory_bytes: 267832
//author:emre yazicioglu
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define pb push_back
const int N = 2e5 + 7;
ll n,m,ans,arr[N];
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);

	ll a=0,b=0;
	cin >> n;
	fori(i,1,n+1)
		cin >> arr[i];
	// ll a;
	fori(i,1,n+1){
		if(arr[i]!=i){a++;}
		if(arr[i]!=n-i){b++;}
	}
	if(a<=2 or b<=2){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}

}

Measured memory_bytes: 256
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
#include "deque"
#include "cmath"
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	int L[109];
	for (int i = 1; i <= N; i++) {
		cin >> L[i];
	}
	int cnt = 0;
	for (int i = 1; i <= N - 2; i++) {
		for (int j = i + 1; j <= N - 1; j++) {
			for (int k = j + 1; k <= N; k++) {
				if ((L[i] - L[j])*(L[j] - L[k])*(L[k] - L[i]) == 0) {
					continue;
				}
				else if (abs(L[i] - L[j]) < L[k] && L[k] < L[i] + L[j]) {
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==1) a=14;
	if(b==1) b=14;
	if(a>b) printf("Alice\n");
	if(a<b) printf("Bob\n");
	if(a==b) printf("Draw\n");
	return 0;
}

Measured memory_bytes: 128
from itertools import combinations
from math import sqrt, floor

N, D = map(int, input().split())
X = []
for _ in range(N):
  X.append(list(map(int, input().split())))

res = 0
for x1, x2 in combinations(X, 2):
  d2 = 0
  for x1_, x2_ in zip(x1, x2):
    d2 += (x1_-x2_)*(x1_-x2_)
  if sqrt(d2) - floor(sqrt(d2)) < 1e-6:
    res += 1
print(res)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

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

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


/////////////////////////////////////////////////////////////////////////////////////////

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

    int k,n;
    cin >> k >> n;
    ll ma = 0,sum = 0;

    vector<ll> a(n);
    for (int i = 0;i < n;i++){
        cin >> a[i];
        if (i == 0) continue;
        ma = max(ma,abs(a[i] - a[i-1]));
    }
    ma = max(ma,abs(a[0] + k - a[n-1]));

    cout << k - ma << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
 
int main(){
    int a, b, c, d, e, tmp; 
    int x[5], i, j;
    scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);

    x[0] = a;
    x[1] = b;
    x[2] = c;
    x[3] = d;
    x[4] = e;

    for(i=0; i<4; i++){
        for(j=4; j>i; j--){
            if(x[i] < x[j]){
            tmp = x[i];
            x[i] = x[j];
            x[j] = tmp;
            }
        }
    }
    for(i=0;i<5;i++){
        printf("%d",x[i]);
        if(i==4){
            printf("\n");
        }else{
            printf(" ");
        }
    }
    return 0;
}

Measured memory_bytes: 600
import queue
def reverse(s):
  ret = ''
  len_ = len(s) - 1
  for i in range(len(s)):
    ret += s[len_ - i]
  return ret

S = input()
N = int(input())


p_a = queue.LifoQueue()
rp_a = queue.Queue()
p_b = queue.Queue()
rp_b = queue.LifoQueue()
flag = False
for i in range(N):
  s = input()
  if s[0] == '1':
    flag = not flag   
  else:
    if (s[2] == '2' and not flag) or (s[2] == '1' and flag) :
      p_b.put(s[4])
    elif (s[2] == '2' and flag) or (s[2] == '1' and not flag) :
  	  p_a.put(s[4])
s_a = ''
s_b = ''
while not p_a.empty():
  s_a += p_a.get()
while not p_b.empty():
  s_b += p_b.get()
ret = s_a + S + s_b
if flag:
  ret = reverse(ret)

print(ret)

Measured memory_bytes: 5748
lst = [int(s) for s in input().split()]
x = lst[2]
y = lst[3]
a = max([int(s) for s in input().split()])
b = min([int(s) for s in input().split()])

if a < b and x < b and b <= y:
    print("No War")
else:
    print("War")   

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

using namespace std;

using ll = unsigned long long int;
using pii = pair<int, int>;

ll arr[100010] = {};


int main() {

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

	sort(arr,arr+n);

	ll a = 0;

	for (int i = n - 1; i > 0; i--) {
		if (arr[i] == arr[i - 1]) {
			i--;
			if(a == 0)
				a = arr[i];
			else {
				cout << arr[i] * a << endl;
				return 0;
			}
				
		}
	}

	cout << 0 << endl;

}



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

int main(){
  string s;
  cin >> s;

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

  cout << s << endl;
  return 0;
}


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

typedef long long ll;
const int INF = 1 << 28;

struct Point
{
  int x, y;
  Point() {}
  Point(int x, int y) : x(x), y(y) {}
  void input() { scanf("%d %d", &x, &y); }
};

struct Maxminp
{
  Point maxv, minv;
  Maxminp() {}
  Maxminp(Point maxv, Point minv) : maxv(maxv), minv(minv) {}
  ll area() { return ((ll)(maxv.x - minv.x) * (ll)(maxv.y  - minv.y)); }
  void chmaxmin(Maxminp d)
  {
    maxv = Point(max(maxv.x, d.maxv.x), max(maxv.y, d.maxv.y)); 
    minv = Point(min(minv.x, d.minv.x), min(minv.y, d.minv.y));
  }
};

const Maxminp reset = Maxminp(Point(-INF, -INF), Point(INF, INF));

struct Segtree
{
  vector < Maxminp > data;
  int size;

  Segtree() {}
  
  Segtree(int sz)
  {
    int g = 1;
    while(g < sz) g *= 2;
    size = g;
    data.assign(size * 4, reset);
  }

  void update(Point val, int p)
  {
    int pos = p + size - 1;
    data[pos] = Maxminp(val, val);
    while(pos != 0) {
      pos = (pos - 1) >> 1;
      data[pos].chmaxmin(data[pos * 2 + 1]);
      data[pos].chmaxmin(data[pos * 2 + 2]);
    }
  }

  Maxminp query(int a, int b) { return (query(a, b, 0, 0, size - 1)); }
  Maxminp query(int a, int b, int k, int l, int r)
  {
    Maxminp ret = reset;
    if(r < a || b < l) return (ret);
    if(a <= l && r <= b) return (data[k]);
    ret.chmaxmin(query(a, b, k * 2 + 1, l, (l + r) / 2));
    ret.chmaxmin(query(a, b, k * 2 + 2, (l + r) / 2 + 1, r));
    return (ret);
  }
};

struct Star
{
  Point p;
  int b;
  Star() {}
  Star(Point p, int b) : p(p), b(b) {}
  void input() { p.input(); scanf("%d", &b); }
  bool operator < (const Star d) const { return (b < d.b); }
};

int main()
{
  int N, D;
  Segtree tree;
  Star data[200005];
  ll maxv = 0;
  int k = 0;
  
  cin >> N >> D;
  tree = Segtree(N);
  
  for(int i = 0; i < N; i++) data[i].input();
  sort(data, data + N);
  
  for(int i = 0; i < N; i++) {
    tree.update(data[i].p, i);
    while(k < i && data[k].b + D < data[i].b) k++;
    maxv = max(tree.query(k, i).area(), maxv);
  }

  cout << maxv << endl;

  return (0);
}

Measured memory_bytes: 35572
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> pl;
const int INF=100000001;

int main(){
  int n,k; cin>>n>>k;
  string s; cin>>s;

  int cnt=0;
  int ans=0;
  rep(i,n-1){
    if(s[i]==s[i+1]) ans++;
  }
  ans=min(n-1,ans+2*k);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 512
S=list(input())
K=int(input())
cnt=cnt2=0
s=S*2
if len(set(S))==1:
    print(len(S)*K//2);exit()
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        cnt+=1
        S[i+1]="#"
for i in range(len(s)-1):
    if s[i+1]==s[i]:
        cnt2+=1
        s[i+1]="#"
print(cnt+(cnt2-cnt)*(K-1))

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;cin>>a>>b;
  ll ans = 0;
  ll now = 1;
  while(now < b){
    ans++;
    now += a-1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    ll cnt0 = 0;
    rep(i, n) {
        if(s[i] == '0') {
            cnt0++;
        }
    }

    out(2*min(cnt0, n-cnt0));
    re0;
}

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())


void solve(ll N, ll K, vector<ll> h){
    vector<ll> dp(N);
    fill(dp.begin(), dp.end(), ll(1e9));
    dp[N-1] = 0;
    for(int i = N - 2; i >= 0; i--) {
        ll c = min(N - i - 1, K);
        ll mn = ll(1e9);
        rep(p, c) {
            mn = min(mn, dp[i + p + 1] + abs(h[i + p + 1] - h[i]));
        }
        dp[i] = mn;
    }
    cout << dp[0] << endl;
}

int main() {
    ll N;
    scanf("%lld",&N);
    ll K;
    scanf("%lld",&K);
    vector<ll> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, move(h));
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  int a, b, c, kind = 3, i;
  scanf("%d %d %d", &a, &b, &c);
  if(a == b) kind --;
  if(a == c) kind --;
  else if(b == c) kind --;
  printf("%d\n", kind);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;


int main() 
{
	int n, k, happy = 0;
	string s;
	cin >> n >> k >> s;

	for (int i = 0; i < n - 1; i++)
		if (s[i] == s[i + 1])
			happy++;
	cout << min(happy + k * 2, n - 1) << endl;

	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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;
}

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

	int k;
	cin >> k;

	vector<bool> m = vector<bool>(k,false);
	int target = 7 % k;
	m[target] = true;
	int ans = 1;
	while (!m[0]) {
		ans++;
		target = (target * 10 + 7) % k;
		if (m[target]) {
			cout << "-1" << endl;
			return 0;
		}
		m[target] = true;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3756
import java.util.*
import java.math.*
fun main(args: Array<String>) {

    val N = readLine()!!.toLong()
    //val S = readLine()!!
    val size = 9
    var ans = 0


    fun f(l:Long, i: Int, ch:Int){
        if (i == 0) {
            return
        }
        f(10*l+7L, i-1, ch or 1)
        f(10*l+5L, i-1 ,ch or 2)
        f(10*l+3L, i-1 ,ch or 4)
        if (N >= l && ch == 7) ans++
    }

    f(0, 10, 0)

    println(ans);
}


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

int main(){
  int N;
  cin >> N;
  vector<int> board(N);
  for(int i = 0; i < N; i++){
    int a = 0;
    int count = 0;
  	cin >> a;
    for(int b = 1; b < 30; b++){
      if(a % (1 << b) == 0) count++;
      else break;
    }
    board.at(i) = count;
  }
  sort(board.begin(), board.end());
  cout << board.at(0);
  return 0;
}

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

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

  if (N % 2 == 0) {
    cout << N << endl;
    return 0;
  }

  cout << N * 2 << endl;
  
  return 0;
}

Measured memory_bytes: 3580
H,W = map(int,input().split())
L = ['']*H
for i in range(H):
  L[i] = input()
row = [False]*H
col = [False]*W
for i in range(H):
  for j in range(W):
    if L[i][j] == '#':
      row[i] = True
      col[j] = True
for i in range(H):
  if row[i] == True:
    for j in range(W):
      if col[j] == True:
        print(L[i][j],end = '')
    print()

Measured memory_bytes: 4468
n = gets.to_i
t,a = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
tag = 0
min = 10 ** 9
arr.each_with_index do |h,id|
  dif = (a - (t - h * 0.006)).abs
  if dif < min
    min = dif
    tag = id
  end
end
puts tag + 1

Measured memory_bytes: 14252
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
 
def dfs(v, p):
    for u in link[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
 
N, Q = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)
 
ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x
 
dfs(0, -1)
 
print(*ans)

Measured memory_bytes: 230960
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T[] = new int[N];
        for (int i = 0; i < N; i++) {
            T[i] = sc.nextInt();
        }
        int M = sc.nextInt();
        int P[] = new int[M];
        int X[] = new int[M];
        for (int j = 0; j < M; j++) {
            P[j] = sc.nextInt();
            X[j] = sc.nextInt();
        }

        for (int j = 0; j < M; j++) {
            int tmp = T[P[j] - 1];
            T[P[j] - 1] = X[j];
            System.out.println(timeSumUp(T));
            T[P[j] - 1] = tmp;
        }

    }

    public static int timeSumUp(int A[]) {
        int sum = 0;
        for (int i = 0; i < A.length; i++) {
            sum += A[i];
        }
        return sum;
    }
}

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

int main() {
	int n;
	cin >> n;
	int ans[n] = { };
	int c[n], s[n], f[n];
	for(int i = 0; i < n - 1; i++){
		cin >> c[i] >> s[i] >> f[i];
	}
	for(int i = 0; i < n; i++){
		for(int j = i; j < n - 1; j++){
			if(s[j] < ans[i]){
				ans[i] = ans[i] + f[j] - (ans[i] % f[j]) - (f[j] * (ans[i] % f[j] == 0)) + c[j];
			}
			else{
				ans[i] = s[j] + c[j];
			}
		}
	}
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

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

int main() {
    string conv = "01235789";
    int N;
    while(cin >> N, N) {
        string ret = "";
        for(; N>0; N/=8) {
            ret += conv[N%8];
        }
        reverse(ret.begin(), ret.end());
        cout << ret << endl;
    }
}


Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>

using namespace std;

static const int MMAX = 20;
static const int NMAX = 50000;
static const int INFTY = (1 << 29);

main() {
    int n, m;
    int C[MMAX + 1];
    int T[NMAX + 1];

    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        cin >> C[i];
    }

    for (int i = 0; i <= NMAX; i++) T[i] = INFTY;
    T[0] = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 0;j + C[i] <= n; j++) {
            T[j + C[i]] = min(T[j + C[i]], T[j] + 1);
        }
    }

    cout << T[n] << endl;

    return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
int main(void)
{
    char s[100];
    char t[100];

    cin >> s;
    cin >> t;

    sort(s, s+strlen(s));
    sort(t, t+strlen(t), greater<char>());

    if (strcmp(s, t) < 0) {
        cout << "Yes" <<endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2 = list(map(int,input().split(" ")))

x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x3 - (x2-x1)
y4 = y3 - (y2-y1)
print(str(x3) + " "  + str(y3) + " "  + str(x4) + " "  + str(y4))


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

using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
using namespace std;

int main(){
  ll N; cin>>N;
  vi A(N); REP(i,N) cin>>A[i];
  bitset<2000*2000+1> bs(1);
  REP(i,N){
    bs|=(bs<<A[i]);
  }
  ll sum=0; REP(i,N) sum+=A[i];
  for(ll i=(sum+1)/2;true;i++){
    if(bs[i]){
      cout<<i<<endl;
      return 0;
    }
  }
}


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

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

    string s;
    cin >> s;
    if (s == "A") {
        cout << 'T' << endl;
        return 0;
    }
    if (s == "T") {
        cout << 'A' << endl;
        return 0;
    }
    if (s == "C") {
        cout << 'G' << endl;
        return 0;
    }
    if (s == "G") cout << 'C' << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache
from numba import jit

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	sx, sy, tx, ty = LI()
	print("R"*(tx-sx)+"U"*(ty-sy)+"L"*(tx-sx)+"D"*(ty-sy+1)+"R"*(tx-sx+1)+"U"*(ty-sy+1)+"L"+"U"+"L"*(tx-sx+1)+"D"*(ty-sy+1)+"R")



if __name__ == '__main__':
    main()

Measured memory_bytes: 88392
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a;
  cin >> a ;
    multiset<int> b;
  int g;
  for(int     i=0; i<a-1; i++)
  {
    cin >> g ;
                        b.insert  (g);
  }
  for(int i=1; i<=a; i++)
  {
       cout << b.count(i) << "\n" ;
  }
 
    
    
    
    
    
    
 
}

Measured memory_bytes: 13008
H,W = gets.split.map(&:to_i)

grid = Array.new(H){Array.new(W)}
dp =  Array.new(H){Array.new(W, -1)}

search_range =[]

H.times do |i|
  grid[i] = gets.chomp
  for j in 0..grid[i].length-1 do
    if grid[i][j] == "#"
      dp[i][j] = 0
      search_range << [i,j]
    end
  end
end

max = 0

while !search_range.empty? do
  tmp = []
  search_range.each do |x,y|

    if x != 0 && dp[x-1][y] == -1
      dp[x-1][y] = dp[x][y] + 1
      max = dp[x-1][y] if max < dp[x-1][y]
      tmp << [x-1,y]
    end

    if x != H-1 && dp[x+1][y] == -1
      dp[x+1][y] = dp[x][y] + 1
      max = dp[x+1][y] if max < dp[x+1][y]
      tmp << [x+1,y]
    end

    if y != 0 && dp[x][y-1] == -1
      dp[x][y-1] = dp[x][y] + 1
      max = dp[x][y-1] if max < dp[x][y-1]
      tmp << [x,y-1]
    end

    if y != W-1 && dp[x][y+1] == -1
      dp[x][y+1] = dp[x][y] + 1
      max = dp[x][y+1] if max < dp[x][y+1]
      tmp << [x,y+1]
    end

  end
  search_range = tmp
end

puts max


Measured memory_bytes: 89468
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    long long a[n + 1];
    for(int i = 1; i <= n; i++)
        scanf("%lld",&a[i]);
    long long ans = 1000;
    for(int i = 1; i <= n - 1; i++){
        long long s = 0;
        if(a[i] < a[i + 1])
            s = ans / a[i];
        ans += (a[i + 1] - a[i]) * s;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

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

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

struct dice {
    int men1, men2, men3, men4, men5, men6;
    // コンストラクタ：構造体をオブジェクト化する時に引数をとった場合される処理
    dice(int men1_, int men2_, int men3_, int men4_, int men5_, int men6_){
        men1 = men1_; men2 = men2_; men3 = men3_;
        men4 = men4_; men5 = men5_; men6 = men6_;
    }

    void roll(char di){
        int ori_men1 = men1; int ori_men2 = men2;
        int ori_men3 = men3; int ori_men4 = men4;
        int ori_men5 = men5; int ori_men6 = men6;
        if(di == 'N'){
            men1 = ori_men2; men5 = ori_men1;
            men6 = ori_men5; men2 = ori_men6;
        }else if(di == 'E'){
            men1 = ori_men4; men3 = ori_men1;
            men6 = ori_men3; men4 = ori_men6;
        }else if(di == 'S'){
            men1 = ori_men5; men5 = ori_men6;
            men6 = ori_men2; men2 = ori_men1;
        }else if(di == 'W'){
            men1 = ori_men3; men3 = ori_men6;
            men6 = ori_men4; men4 = ori_men1;
        }
    }

    int display_up(){ return men1; }
    int display_front(){ return men2; }
    int display_right(){ return men3; }
    int display_left(){ return men4; }
    int display_back(){ return men5; }
    int display_down(){ return men6; }
};

int main()
{
    int n1, n2, n3, n4, n5, n6;
    cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    dice dice1(n1, n2, n3, n4, n5, n6);
    cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    dice dice2(n1, n2, n3, n4, n5, n6);
    string s1 = "NNNNENNNN";
    string s2 = "WWWW";
    
    bool isSame = false;
    for(int i=0; i<s1.size(); i++){
        char com = s1[i];
        dice1.roll(com);
        if(dice1.display_front() == dice2.display_front()){
            for(int k=0; k<s2.size(); k++){
                com = s2[k];
                dice1.roll(com);
                if(dice1.display_up() == dice2.display_up()){
                    if(dice1.display_right() == dice2.display_right() && dice1.display_left() == dice2.display_left() && dice1.display_back() == dice2.display_back() && dice1.display_down() == dice2.display_down()){
                        isSame = true;
                        break;
                    }
                }
            }
        }
        if(isSame) break;
    }
    if(isSame) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3212
b, n=map(int,input().split())
d=[list(map(int, input().split())) for i in range(n)]

import numpy as np

d2=np.array(d)

#d3=d2[np.argsort(d2[:,1])][::-1]
d3=d2[np.lexsort(d2.T)][::-1]
#print(d3)

cnt=1
i=0

while i<n:
	j=i+1
	st=d3[i][0]
	while j<n:
		if d3[j][1]<=st:
			#print(d3[i][0])
			#print(d3[j][1])
			#print(i)
			#print(j)            
			cnt+=1
			i=j-1
			j=n-1
		if st<d3[j][0]:
			st=d3[j][0]
		j+=1
	i+=1
print(cnt)

Measured memory_bytes: 40924
import sys
K = int(input())
A, B = map(int, input().split())

i = 1
while(True):
  if((A<=K*i) and (K*i<=B)):
    print('OK')
    sys.exit()
  if(B<K*i):
    print('NG')
    sys.exit()
  i += 1

Measured memory_bytes: 9172
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			var abc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var set = new HashSet<int>();
			for (int i = 0; i < 3; i++) {
				set.Add(abc[i]);
			}

			Console.WriteLine(set.Count);
		}
	}
}


Measured memory_bytes: 28340
gets =~ /(\d{2})(\d{2})/
a, b = $~.captures.map{ |s| (1..12).cover?(s.to_i) ? 'MM' : 'YY' }

result = if a == b
  if a == 'YY'
    'NA'
  else
    'AMBIGUOUS'
  end
else
  "#{a}#{b}"
end

puts result


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OUT(x) cout << (x) << endl;
#define REP(i, n) for (int i=0; i<n; ++i)

char op[] = {'+', '-'};

int ope(int x, char o, int y){
    if(o == op[0]){
        return x+y;
    }else{
        return x-y;
    }
}

int main(){
    string str;
    cin >> str;
    int A=str[0]-'0', B=str[1]-'0', C=str[2]-'0', D=str[3]-'0';
    string ans="";
    REP(i, 2){
        REP(j, 2){
            REP(k, 2){
                if(ope(ope(ope(A, op[i], B), op[j], C), op[k], D) == 7){
                    cout << A << op[i] << B << op[j] << C << op[k] << D << "=7" <<endl;
                    return 0;
                };
            }
        }
    }
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    string s;
    while(cin>>s){
        if(s=="0"){break;}
    vector<ll> M(11,0);
    M[0]=1;
    ll ans=0;
    ll sum=0;
    ll k=1;
    for(int i=0;i<s.size();i++){
        sum*=10;
        sum+=s[i]-'0';
        sum%=11;
        ans+=M[(11+k*sum)%11];
        if(i+1<s.size() && s[i+1]!='0'){
            M[(11+k*sum)%11]++;
        }
        k*=-1;
    }
    cout<<ans<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3300
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    C = list(input().strip())
    l, r = 0, N-1
    ans = 0
    if 'R' not in C or 'W' not in C:
        print(0)
        return True
    while l < r:
        while C[l] == 'R':
            l += 1
        while C[r] == 'W':
            r -= 1
        if l < r:
            ans += 1
            l += 1
            r -= 1
            
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 10664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int ans=0;
  int a,b,c;
  while(A%2==0 && B%2==0 && C%2==0){
    ans++;
    a=(B+C)/2;
    b=(A+C)/2;
    c=(A+B)/2;
    A=a;
    B=b;
    C=c;
    if(ans>32){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
using namespace std;

const unsigned long long BASE = 1e9 + 7;

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


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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

int main(){
  string s;cin>>s;
  for(char p:s)for(char q:s)if(p!=q)fin("Yes");
  fin("No");
}


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

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


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

int main(){
	string S;
	string cp;
	int t;

	cin >> S;
	cp = S;
	reverse(S.begin(), S.end());
	if(cp!=S){
		cout << "No" << endl; return 0;
	}
	reverse(S.begin(), S.end());
	
	t = (S.size()-1)/2;
	cp = S.substr(0,t);
	reverse(S.begin(), S.begin()+t);
	if(cp != S.substr(0,t)){
		cout << "No" << endl; return 0;
	}

	t = (S.size()+3)/2-1; 
	cp = S.substr(t);
	reverse(S.begin()+t, S.end());
	if(cp != S.substr(t,S.size())){
		cout << "No" << endl; return 0;
	}

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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  double n;
  double ans;
  scanf("%lf", &n);
  if(n == 1.0) ans = n;
  else if((int)n % 2) ans = (1.0 - (int)(n / 2) / n);
  else ans = 0.5;
  printf("%f\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<int(n);i++)
int a[10];
int main(){
	int t;
	cin>>t;
	while(t--){
		forn(i,10) cin>>a[i];
		int fi=0,se=0;
		bool b=true;
		forn(i,10){
			if(fi<a[i]&&se<a[i]){
				if(fi<=se) se=a[i];
				else fi=a[i];
			}
			else if(fi<a[i]) fi=a[i];
			else if(se<a[i]) se=a[i];
			else{
				b=false;
				break;
			}
		}
		if(b) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define ppp pair< pair<int,int>, int>
using namespace std;

int main(){
    int N;
    cin >> N;
    
    vector< ppp > A(N);
    for(int i=0; i<N; ++i) {
        cin >> A[i].first.first >> A[i].first.second >> A[i].second;
    }
    
    for(int i=0; i<=100; ++i) {
        for(int j=0; j<=100; ++j) {
            int H = 0;
            for(int k=0; k<N; ++k) {
                if(A[k].second != 0) {
                    H = abs(i - A[k].first.first) + abs(j - A[k].first.second) + A[k].second;
                    break;
                }
            }
            bool flag = true;
            for(int k=0; k<N; ++k) {
                int h = max(H - abs(i - A[k].first.first) - abs(j - A[k].first.second), 0);
                if(h != A[k].second) {
                    flag = false;
                    break;
                }
            }
            if(!flag) continue;
            else {
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int max(int x,int y){
    if(x>y)return x;
    else return y;
}
int main(void){
    int x,y,z;
    cin>>x>>y>>z;
    int ma=0;
    ma = max(ma,x*10+y+z);
    ma = max(ma,y*10+x+z);
     ma = max(ma,z*10+y+x);
     cout<<ma<<endl;
     return 0;
    
}


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

const int jmp[12][2] = {
    {-1, -2}, {0, -2}, {1, -2},
    {2, -1}, {2, 0}, {2, 1},
    {1, 2}, {0, 2}, {-1, 2},
    {-2, 1}, {-2, 0}, {-2, -1}
};

int main(void) {
    int sx, sy, n, sprx[10], spry[10];
    int i, j, k, l, x, y, p;
    int wet[2][3][3], (*s)[3], (*t)[3], survive;

    while (scanf("%d%d", &sx, &sy) == 2 && (sx || sy)) {
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
            scanf("%d%d", &(sprx[i]), &(spry[i]));
        }
        memset(wet[0], 0, 9*sizeof(int));
        wet[0][1][1] = 1;
        for (i = 0; i < n; i++) {
            s = wet[i&1];
            t = wet[(i+1)&1];
            memset(t, 0, 9*sizeof(int));
            p = i % n;
            survive = 0;
            for (j = 0; j < 3; j++) {
                for (k = 0; k < 3; k++) {
                    if (s[j][k] == 1) {
                        for (l = 0; l < 12; l++) {
                            x = sx-1+k+jmp[l][0];
                            y = sy-1+j+jmp[l][1];
                            if (0 <= x && x < 10 && 0 <= y && y < 10 &&
                                sprx[p]-1 <= x && x <= sprx[p]+1 &&
                                spry[p]-1 <= y && y <= spry[p]+1) {
                                t[y-spry[p]+1][x-sprx[p]+1] = 1;
                                survive = 1;
                            }

                        }
                    }
                }
            }
            if (!survive) break;
            sx = sprx[p];
            sy = spry[p];
        }
        if (!survive) {
            puts("NA");
        }
        else {
            puts("OK");
        }
    }
    return 0;
}

Measured memory_bytes: 1012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

import static java.lang.Integer.parseInt;

/**
 * Rearranging a Sequence
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int n, m;
		n = parseInt(line.substring(0, line.indexOf(' ')));
		m = parseInt(line.substring(line.indexOf(' ') + 1));

		int[] seq = new int[n + 1];
		int head = 1;

		seq[0] = Integer.MIN_VALUE;
		for (int i = 1; i <= n; i++) seq[i] = i;

		for (int i = 0; i < m; i++) {
			int e = parseInt(br.readLine());
			seq[e] = --head;
		}

		int[][] res = new int[n + 1][2];

		for (int i = 0; i <= n; i++) {
			res[i][0] = i;
			res[i][1] = seq[i];
		}

		Arrays.sort(res, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[1], o2[1]);
			}
		});

		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			sb.append(res[i][0]).append('\n');
		}

		System.out.print(sb.toString());

	}
}

Measured memory_bytes: 56532
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>
#include<iomanip>

using namespace std;
int func(double x);

int main() {

	long long  N = 0;
	long long result = 0;
	string S;
	cin >> N;
	cin >> S;
	/*
	vector<long long> A(N);
	vector<long long> sum(N);
	for (long long i = 0; i < N; i++) {
		cin >> A[i];
		sum[i] =sum[i-1]+ A[i];
	}
	*/
	for(int i=0;i<S.length();i++)
	if (S[i] + N>90)
	{
		S[i] += N - 26;
	}
	else {
		S[i] += N;
	}
	cout << S;
}

int func(double x)
{
	if (x > 1) {
		x *= func(x - 1);
	}
	return x;
}

Measured memory_bytes: 256
'''
4 4
4 1 2 3
-19 4 10 6

4 5
4 1 2 3
-19 4 10 6

4 8
4 1 2 3
-19 4 10 6
'''
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [i-1 for i in p]
c = list(map(int, input().split()))

minusOnly = True
for i in range(n):
    if c[i] > 0:
        minusOnly = False
        break

if minusOnly:
    print(max(c))
    exit()

ans = 0
used = [False]*n

for st in range(n):
    if not used[st]:
        gr = []
        now = st
        gr.append(st)
        used[st] = True
        while True:
            now = p[now]
            gr.append(now)
            used[now] = True
            if now == st:
                break
        gr.pop()

        cs = [c[i] for i in gr]
        s = sum(cs)
        point = 0
        r = k
        if r > 2*len(gr):
            if s > 0:
                point += s*(k//len(gr)-1)
                r -= len(gr)*(k//len(gr)-1)
            else:
                r = 2*len(gr)
        
        cs = cs + cs + cs
        plus = 0
        for i in range(len(gr)):
            nowSum = 0
            for g in range(r):
                nowSum += cs[i+g]
                plus = max(plus, nowSum)
        
        point += plus
        ans = max(ans, point)

print(ans)

Measured memory_bytes: 74472
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const long long MOD = 1000000007;

class Combination {
private:
  vector<long long> fac_;
  vector<long long> finv_;
  vector<long long> inv_;
  long long prime_;

public:
  Combination(long long n, long long prime) {
    fac_ = vector<long long>(n + 1);
    finv_ = vector<long long>(n + 1);
    inv_ = vector<long long>(n + 1);
    prime_ = prime;

    fac_[0] = fac_[1] = 1;
    finv_[0] = finv_[1] = 1;
    inv_[1] = 1;
    for (long long i = 2; i <= n; i++) {
      fac_[i] = fac_[i - 1] * i % prime_;
      inv_[i] = prime_ - inv_[prime_ % i] * (prime_ / i) % prime_;
      finv_[i] = finv_[i - 1] * inv_[i] % prime_;
    }
  }

  // nCk
  long long getCombination(long long n, long long k) {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;

    return fac_[n] * (finv_[k] * finv_[n - k] % prime_) % prime_;
  }
};

void solve(long long H, long long W, long long A, long long B) {
  Combination comb = Combination(1e6, MOD);

  ll ans = 0;
  for (ll b = B + 1; b <= W; b++) {
    ll n1 = (H - A - 1) + (b - 1);
    ll n2 = (A - 1) + (W - b);
    ans +=
        comb.getCombination(n1, (H - A - 1)) * comb.getCombination(n2, (A - 1));
    ans %= MOD;
  }

  print(ans);
}

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


Measured memory_bytes: 23680
#! python3
# min_max_and_sum.py

n = int(input())
a = [int(x) for x in input().split(' ')]

min_val = a[0]
max_val = a[0]
sum_val = a[0]

for i in range(1, n):
    if a[i] < min_val:
        min_val = a[i]
    if a[i] > max_val:
        max_val = a[i]
    sum_val += a[i]

print(min_val, max_val, sum_val)


Measured memory_bytes: 6604
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
vector<int> scc(const vector<vector<int>> &G) {
    int N = G.size();
    vector<int> low(N), dfsnum(N, -1), comp(N, -1);
    stack<int> L;
    int num = 0, conum = 0;
    auto visit = [&](auto&& visit, int p) -> void {
        L.push(p);
        low[p] = dfsnum[p] = num++;
        for (int q : G[p]) {
            if (comp[q] >= 0) continue;
            if (dfsnum[q] < 0) {
                visit(visit, q);
                low[p] = min(low[p], low[q]);
            } else {
                low[p] = min(low[p], dfsnum[q]);
            }
        }
        if (low[p] == dfsnum[p]) {
            for (;;) {
                int v = L.top(); L.pop();
                comp[v] = conum;
                if (v == p) break;
            }
            conum++;
        }
    };
    for (int i = 0; i < N; i++) {
        if (comp[i] < 0) visit(visit, i);
    }
    return comp;
}
int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
    }
    auto comp = scc(G);
    map<int, vector<int>> components;
    for (int i = 0; i < N; i++) {
        components[-comp[i]].push_back(i);
    }
    cout << components.size() << '\n';
    for (auto& [idx, vec] : components) {
        cout << vec.size();
        for (auto elem : vec) cout << ' ' << elem;
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 83280
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
int f[maxn],h[maxn],n,k;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	cin>>h[i];
	memset(f,0x3f,sizeof(f));
	f[1]=0;
	for(int i=1;i<=k;++i)
	for(int j=1;j<i;++j)
		f[i]=min(f[i],f[j]+abs(h[i]-h[j]));
	for(int i=k+1;i<=n;++i)
	for(int j=i-k;j<i;++j)
		f[i]=min(f[i],f[j]+abs(h[i]-h[j]));
	cout<<f[n];
	return 0;
 } 

Measured memory_bytes: 1024