akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

void solve(){
    
    long long n, a, b;

    cin >> n >> a >> b;

    long long head = n / (a + b) * a;

    long long tail = min(n % (a + b),  a);

    cout << head + tail << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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 gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}
int c['z'+1];

void solve(void){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    ll ans = 0;
    for(int i = 0;r*i <=n;i++){
        for(int j = 0;g*j <= n;j++){
               if(n - r*i - g*j >= 0 && (n-r*i-g*j) % b == 0) ans++;                
        }
    } 
    cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;

string s;
ll n;
ll a[100005][5];

int main()
{
    //freopen("input.txt", "r", stdin);
    cin>>s;
    n = s.size();
    s = ' ' + s;
    a[0][3] = 1;
    for(ll i = 1; i <= n; i++)
    {
        if(s[i] == 'A' || s[i] == '?')
        {
            a[i][0] += a[i - 1][0] + a[i - 1][3];
            a[i][1] += a[i - 1][1];
            a[i][2] += a[i - 1][2];
            a[i][3] += a[i - 1][3];
        }
        if(s[i] == 'B' || s[i] == '?')
        {
            a[i][0] += a[i - 1][0];
            a[i][1] += a[i - 1][1] + a[i - 1][0];
            a[i][2] += a[i - 1][2];
            a[i][3] += a[i - 1][3];
        }
        if(s[i] == 'C' || s[i] == '?')
        {
            a[i][0] += a[i - 1][0];
            a[i][1] += a[i - 1][1];
            a[i][2] += a[i - 1][2] + a[i - 1][1];
            a[i][3] += a[i - 1][3];
        }
        a[i][0] %= M;
        a[i][1] %= M;
        a[i][2] %= M;
        a[i][3] %= M;
    }
    printf("%lld", a[n][2]);
    return 0;
}


Measured memory_bytes: 4348
#include<iostream>

int main() {
    int a, b;
    std::cin >> a >> b;

    if(a > b) {
        std::cout << "a" << " " << ">" << " " << "b" << "\n";
    }else if(a < b) {
        std::cout << "a" << " " << "<" << " " << "b" << "\n";
    }else {
        std::cout << "a" << " " << "==" << " " << "b" << "\n";
    }

    return 0;
}


Measured memory_bytes: 3076
lst1=[]
lst2=[]
answer=0
n,m=(int(x) for x in input().split())
for s in range(n):
    aij=input().split()
    lst1.append(aij)
for t in range(m):
    bi=int(input())
    lst2.append(bi)
for u in range(n):
    lstA=lst1[u]
    for v in range(m):
        number1=int(lstA[v])
        number2=lst2[v]
        answer+=number1*number2
    print(answer)
    answer=0


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

int main(){
  string a;
  cin >> a;
  
  int c=0;
  
  if(a[0]=='1') c++;
  if(a[1]=='1') c++;
  if(a[2]=='1') c++;
  
  
  cout << c << endl;
}
  
  
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<queue>
#define sqr(x) (x)*(x)
#define mk(w,x,y,z) make_pair(make_pair(w,x),make_pair(y,z))
using namespace std;
int n,m,i,j,num[200005],pos[200005];
priority_queue<pair<pair<int,int>,pair<int,int> > > pq;
struct seg
{
	struct node
	{
		int l,r,sum[2];
	}tr[800005];
	void pushup(int x)
	{
		tr[x].sum[0]=max(tr[x*2].sum[0],tr[x*2+1].sum[0]);
		tr[x].sum[1]=max(tr[x*2].sum[1],tr[x*2+1].sum[1]);
	}
	void build(int x,int l,int r)
	{
		tr[x].l=l;
		tr[x].r=r;
		memset(tr[x].sum,-22,sizeof(tr[x].sum));
		if (l!=r)
		{
			int mid=(l+r)/2;
			build(x*2,l,mid);
			build(x*2+1,mid+1,r);
			pushup(x);
		}
		else
		{
			tr[x].sum[l&1]=num[l];
		}
	}
	int query(int x,int l,int r,int c)
	{
		if (tr[x].l>r||tr[x].r<l) return -0x16161616;
		if (tr[x].l>=l&&tr[x].r<=r) return tr[x].sum[c];
		return max(query(x*2,l,r,c),query(x*2+1,l,r,c));
	}
}tr;
void insert(int x,int y)
{
	int t=tr.query(1,x,y,x&1);
	pq.push(mk(t,tr.query(1,pos[-t]+1,y,(!(pos[-t]&1))),x,y));
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n; 
	for (i=1;i<=n;i++)
	{
		cin>>num[i];
		pos[num[i]]=i;
		num[i]=-num[i];
	}
	tr.build(1,1,n);
	int t=tr.query(1,1,n,1);
	pq.push(mk(t,tr.query(1,pos[-t]+1,n,(!(pos[-t]&1))),1,n));
	while (!pq.empty())
	{
		int y=-pq.top().first.first;
		int z=-pq.top().first.second;
		int w=pq.top().second.first;
		int x=pq.top().second.second;
		//cerr<<w<<' '<<x<<' '<<y<<' '<<z<<endl;
		pq.pop();
		cout<<y<<' '<<z<<' ';
		y=pos[y];
		z=pos[z];
		if (w<y-1) insert(w,y-1);
		if (z+1<x) insert(z+1,x);
		if (y+1<z-1) insert(y+1,z-1);
	}
	return 0;
}

Measured memory_bytes: 14068
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(D, T, S):
    if S * T >= D:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    D, T, S = map(int, input().split())
    # As = [int(i) for i in input().split()]
    # Bs = [int(i) for i in input().split()]
    solve(D, T, S)


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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using  vi = vector<int>;
using  vl = vector<ll>;
using  vd = vector<double>;
template<class T,class U>
using umap = unordered_map<T,U>;
template<class T>
using uset = unordered_set<T>;

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

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

template<class T>
inline void putv(const vector<T>&v,char c = '\n'){
  for(auto&&e:v){
    cout << e << c;
  }
}

void add_map(map<int,int>&mp,int n){
  for(int i = 1; i*i<=n; ++i){
    if(n % i == 0){
      mp[i]++;
      if(i*i!=n)mp[n/i]++;
    }
  }
}

int main(){
  int n; cin >> n;
  vi v(n);
  for(auto&&e:v){
    cin >> e;
  }
  vi ans;
  map<int , int>mp;
  int cnt = 0;
  for(int i = n - 1; i >= 0; --i){
    int c;
    if(mp.count(i+1)==0)c=0;
    else c = mp[i+1];
    if(v[i] != c%2){
      ans.push_back(i+1);
      add_map(mp,i+1);
    }
  }
  cout << ans.size() << endl;
  putv(ans,'\n');
  return 0;
}


Measured memory_bytes: 10744
import java.util.*;
import java.util.regex.*;
import static java.lang.System.out;

// String
public class Main {
	public static void main(String[] args) {
		new Main().AOJ0077();
	}
	Scanner sc = new Scanner(System.in);
	
	void AOJ0077(){	// Run Length
		while(sc.hasNext()){
			char[] c=sc.nextLine().toCharArray();
			StringBuilder sb = new StringBuilder();
			for(int i=0; i<c.length; i++){
				if(c[i]=='@'){
					for(int j=0; j<Character.digit(c[i+1], 10); j++)	sb.append(c[i+2]);
					i+=2;
				}else	sb.append(c[i]);
			}
			out.println(sb.toString());
		}
	}
	
	void AOJ0064(){	// Secret Number
		int ans=0;
		while(sc.hasNext()){
			Matcher m = Pattern.compile("\\d+").matcher(sc.nextLine());
			while(m.find())	ans+=Integer.parseInt(m.group());
		}
		out.println(ans);
	}
	
	void AOJ0050(){	// Apple and Peach
		while(sc.hasNext()) out.println(sc.nextLine().replaceAll("apple", "PEACH").replaceAll("peach", "apple").replaceAll("PEACH", "peach"));
	}
	
	void AOJ0039(){	// Roman Figure ローマ数字 -> 10進数
		HashMap<Character,Integer> dic = new HashMap<Character,Integer>();
		dic.put('I', 1);	dic.put('V', 5);	dic.put('X', 10);	dic.put('L', 50);
		dic.put('C', 100);	dic.put('D', 500);	dic.put('M', 1000);
		while(sc.hasNext()){
			char[] c = sc.next().toCharArray();
			int ans=0,last=dic.get(c[0]);
			for(int i=0; i<c.length; i++){
				if(last>=dic.get(c[i])){
					ans+=dic.get(c[i]);
					last=dic.get(c[i]);
				}else{
					ans+=dic.get(c[i])-last-last;
					last=dic.get(c[i]);
				}
			}
			out.println(ans);
		}
	}
	
	void AOJ0020(){	// Capitalize 大文字変換
		while(sc.hasNext())	out.println(sc.nextLine().toUpperCase());
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] D = new int[N];
		for (int i = 0; i < N; i++) {
			int d = sc.nextInt();
			
			if (i == 0 ^ d == 0) {
				System.out.println(0);
				return;
			}
			
			D[d]++;
		}

		int mod = 998244353;
		long mul = 1;
		int i = 1;
		for (; i < D.length; i++) {
			int n = D[i];
			if (n <= 0) break;
			mul = (mul * pow(D[i - 1], n, mod)) % mod;
		}
		for (; i < D.length; i++) {
			if (D[i] > 0) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(mul);
	}

	long pow(long a, long n, long mod){
		long res = 1;
		while (n > 0) {
			if (n % 2 == 1) res = (res * a) % mod;
			a = a * a % mod;
			n >>= 1;
		}
		return res;
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

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

int N, T[500][3];

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N - 1; i++) scanf("%d%d%d", &T[i][0], &T[i][1], &T[i][2]);
	for(int i = 0; i < N - 1; i++){
		int t = T[i][1] + T[i][0];
		for(int j = i + 1; j < N - 1; j++){
			if(t < T[j][1]) t = T[j][1];
			int diff = t - T[j][1];
			if(diff % T[j][2] == 0) t += T[j][0];
			else t += (T[j][2] - diff % T[j][2]) + T[j][0];
		}
		printf("%d\n", t);
	}
	printf("0\n");
	return 0;
}


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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE

const Int MAX = 3030;
Int dp[4][MAX][MAX]={};
Int vs[MAX][MAX]={};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int h,w,n;
  cin>>h>>w>>n;

  for(Int i=0;i<n;i++){
    Int r,c,v;
    cin>>r>>c>>v;
    r--;c--;
    vs[r][c]=v;
  }

  dp[1][0][0]=vs[0][0];

  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      for(Int k=0;k<4;k++){
        if(i+1<h){
          chmax(dp[0][i+1][j],dp[k][i][j]);
          chmax(dp[1][i+1][j],dp[k][i][j]+vs[i+1][j]);
        }
        if(j+1<w){
          chmax(dp[k][i][j+1],dp[k][i][j]);
          if(k+1<4) chmax(dp[k+1][i][j+1],dp[k][i][j]+vs[i][j+1]);
        }
      }
    }
  }

  Int ans=0;
  for(Int k=0;k<4;k++) chmax(ans,dp[k][h-1][w-1]);
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 358624
package main

import "fmt"

func main() {
	a := [3][3]int{}
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&a[i][j])
		}
	}

	var n int
	fmt.Scan(&n)
	var b int
	for i := 0; i < n; i++ {
		fmt.Scan(&b)
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if a[i][j] == b {
					a[i][j] = -1
				}
			}
		}
	}

	if a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1 {
		fmt.Println("Yes")
		return
	}
	if a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1 {
		fmt.Println("Yes")
		return
	}

	for i := 0; i < 3; i++ {
		ok := true
		for j := 0; j < 3; j++ {
			if a[i][j] != -1 {
				ok = false
			}
		}
		if ok {
			fmt.Println("Yes")
			return
		}
	}

	for i := 0; i < 3; i++ {
		ok := true
		for j := 0; j < 3; j++ {
			if a[j][i] != -1 {
				ok = false
			}
		}
		if ok {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")

}


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

int main() {
	string s;
	cin >> s;
    int ans;
    if(s == "SUN")ans = 7;
    else if (s == "MON")ans = 6;
    else if (s == "TUE")ans = 5;
    else if (s == "WED")ans = 4;
    else if (s == "THU")ans = 3;
    else if (s == "FRI")ans = 2;
    else if (s == "SAT")ans = 1;
    cout << ans <<endl;
}


Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


def func(x, m):
    return x % m


# 処理内容
def main():
    N = int(input())
    z = [0] * N
    w = [0] * N
    for i in range(N):
        x, y = map(int, input().split())
        z[i] = x + y
        w[i] = x - y
    
    ans = max(max(z) - min(z), max(w) - min(w))
    
    print(ans)



if __name__ == '__main__':
    main()

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

const int MAXN = 1e5 + 5;

int ans[MAXN];
vi gr[MAXN];

bool comp(int a, int b) {
    return ans[a] > ans[b];
}

void dfs(int u) {
    for (auto v : gr[u])
        dfs(v);
    ans[u] = 0;
    sort(all(gr[u]), comp);
    for (int i = 0; i < (int)gr[u].size(); i++) {
        ans[u] = max(ans[u], i+1 + ans[gr[u][i]]);
    }
}

int main() {
    //freopen("", "rt", stdin);
    //freopen("", "wt", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        int p;
        scanf("%d", &p);
        gr[p].pb(i);
    }
    dfs(1);
    printf("%d\n", ans[1]);
    return 0;
}



Measured memory_bytes: 10752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int swap;
		if (a > b) {swap = a; a = b; b = swap;}
		if (a > c) {swap = a; a = c; c = swap;}
		if (b > c) {swap = b; b = c; c = swap;}
		System.out.printf("%d %d %d\n", a, b, c);
	}
}

Measured memory_bytes: 26144
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

using edge = std::pair<int, int>;
std::vector<edge> edges[2501 * 50];
long long dist[2501 * 50];

int main()
{
	int n, m, s;
	scanf("%d%d%d", &n, &m, &s);
	for (int i = 0; i < m; ++i)
	{
		int u, v, a, b;
		scanf("%d%d%d%d", &u, &v, &a, &b);
		u = (u - 1) * 2501;
		v = (v - 1) * 2501;
		for (int j = 0; a + j <= 2500; ++j)
		{
			edges[v + a + j].emplace_back(u + j, b);
			edges[u + a + j].emplace_back(v + j, b);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		int c, d;
		scanf("%d%d", &c, &d);
		if (c > 2500)
		{
			c = 2500;
		}
		int v = i * 2501;
		for (int j = 0; j + c <= 2500; ++j)
		{
			edges[v + j].emplace_back(v + j + c, d);
		}
	}

	std::fill(dist, dist + 2501 * 50, 1e18);
	dist[std::min(2500, s)] = 0;
	using P = std::pair<long long, int>;
	std::priority_queue<P, std::vector<P>, std::greater<P>> q;
	q.emplace(0, std::min(2500, s));
	while (q.size() > 0)
	{
		auto [cost, v] = q.top(); q.pop();
		if (cost > dist[v])
		{
			continue;
		}
		for (auto [to, c] : edges[v])
		{
			long long next = cost + c;
			if (dist[to] > next)
			{
				dist[to] = next;
				q.emplace(next, to);
			}
		}
	}
	for (int i = 1; i < n; ++i)
	{
		long long ans = 1e18;
		for (int j = 0; j <= 2500; ++j)
		{
			if (ans > dist[i * 2501 + j])
			{
				ans = dist[i * 2501 + j];
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 17048
#include<iostream>
#include<string>
#include<iomanip>
#include<math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 1; i <= n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define MAX 60

int a[MAX];
signed main(){
	cout<<fixed<<setprecision(7);
	bool flag = true;
	int n, m, ma = 0, A, ti = 0;
	string str;
	
	cin>>n;
	
	rep(i,n){
		cin>>A;
		if(ma <= abs(A)){
			ma = abs(A);
			ti = i;
			if(A >= 0) flag = true;
			else flag = false;
		}
	}
	
	cout<<n+n-1<<endl;
	for(int i = 1; i <= n; i++){
		cout<<ti<<" "<<i<<endl;
	}
	if(flag == true){
		for(int i = 2; i <= n; i++){
			cout<<i-1<<" "<<i<<endl;
		}
	} else {
		for(int i = n; i >= 2; i--){
			cout<<i<<" "<<i-1<<endl;
		}
	}
	return 0;
}

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

int main(){
    int h,w;
    int black_num = 0;
    int direction[4][2] = {{-1,0}, {1,0}, {0,-1}, {0,1}};
    
    string row;
    string grid[1000];
    queue<pair<int, int> > search_queue;

    cin >> h >> w;
    for(int i=0;i<h;i++){
        cin >> row;
        grid[i] = row;
        for(int j=0;j<w;j++){
            if(row[j] == '#'){
                search_queue.push(make_pair(i,j));
                black_num++;
            }
        }
    }

    int iter_num=0;
    while(black_num < h*w){
        queue<pair<int, int> > post_queue;
        iter_num++;
        while(!search_queue.empty()){
            pair<int, int> point = search_queue.front();
            search_queue.pop();
            for(int i=0;i<4;i++){
                int x=point.first + direction[i][0];
                int y=point.second+ direction[i][1];
                if(x< 0 or x>=h or y<0 or y>=w){
                       continue;
                   }
                if(grid[x][y]=='.'){
                    grid[x][y]='#';
                    black_num += 1;
                    post_queue.push(make_pair(x,y));
                }
            }
        }
        search_queue = post_queue;
    }

    cout << iter_num << endl;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

vector<ll> fact,inv;

ll f(ll a,ll b, ll p){  // a^b mod pを求める
	if (b == 0)return 1;
	else if (b % 2 == 0){
		ll d = f(a,b/2,p);  //a^b = a^(2k) = (a^k)^2  k = b / 2
		return d * d % mod;
	}else{
		return a * f(a,b-1,p) % mod;
	}
}

void init(ll n){
	fact.resize(n+1,1LL);
	inv.resize(n+1,1LL);
	for(int i = 2; i <= n; i++)  //　nまでの階乗を求める
		fact[i] = fact[i-1] * i % mod;
	for(int i = 2; i <= n; i++)  //a^(-1) mod p = a^(p-2) mod p  ここをもう少し早くできるぽい
		inv[i] = f(fact[i],mod-2,mod) % mod;
}

ll comb(ll n,ll k){  //n_C_k
	if (n < k) return 0;
	return (fact[n] * inv[k] % mod) * inv[n-k] % mod;
}

vector<vector<ll>> g, di_g;
vector<ll> dp, dp2, subtree_size, parent, used;

void dfs(ll cur){
	used[cur]=true;
	dp[cur] = 1;
	subtree_size[cur] = 1;
	for(auto next: g[cur]){
		if(used[next]) continue;

		di_g[cur].push_back(next);
		parent[next]=cur;
		dfs(next);
		subtree_size[cur] += subtree_size[next];
		dp[cur]*=dp[next];
		dp[cur]%=mod;

		dp[cur]*=inv[subtree_size[next]];
		dp[cur]%=mod;
	}
	dp[cur]*=fact[subtree_size[cur]-1];
	dp[cur]%=mod;
}

int main()
{
	ll n;
	cin>>n;
	g.resize(n,vector<ll>());
	di_g.resize(n,vector<ll>());
	dp.resize(n,0);
	dp2.resize(n,0);
	used.resize(n);
	subtree_size.resize(n,0);
	parent.resize(n,-1);
	rep(i,n-1){
		ll a,b;
		cin>>a>>b;
		g[a-1].push_back(b-1);
		g[b-1].push_back(a-1);
		// parent[b-1] = a-1;
	}
	init(n+10);

	ll root = 0;
	dfs(root);

	// rep(i,n)cout<<dp[i]<<"  ";
	// cout<<endl;

	vector<ll> dp_power(n,0);
	rep(i,n)dp_power[i] = power(dp[i],mod-2);

	queue<int> que;
	que.push(root);
	while(!que.empty()){
		int cur=que.front();que.pop();
		dp2[cur] = 1LL;

		if(parent[cur]!=-1){
			ll tmp=dp2[parent[cur]];
			// tmp *= power(dp[cur], mod-2);
			tmp*=dp_power[cur];
			tmp %= mod;

			tmp *= fact[subtree_size[cur]];
			tmp %= mod;

			tmp *= inv[n-1];
			tmp %= mod;

			tmp *= fact[n-subtree_size[cur]-1];
			tmp %= mod;

			dp2[cur]*=tmp;
			dp2[cur]%=mod;
			dp2[cur]*=inv[n-subtree_size[cur]];
			dp2[cur]%=mod;

		}

		// cout<<"cur = "<<cur<<endl;
		for(auto x:di_g[cur]){
			// cout<<"x = "<<x<<endl;
				dp2[cur]*=dp[x];
				dp2[cur]%=mod;
				dp2[cur]*=inv[subtree_size[x]];
				dp2[cur]%=mod;
				que.push(x);
			
		}
		dp2[cur]*=fact[n-1];
		dp2[cur]%=mod;
	}

	rep(i,n){
		cout<<dp2[i]<<endl;
	}


	return 0;
}

Measured memory_bytes: 36784
#include<bits/stdc++.h>
#include <string> 
using namespace std;
const int mod = 1e9 + 7;
const int mid = 2*1e5;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for(long long i = 0;i < n;i++)


int main()
{
  long long a,b,c,d,ans;
  cin>>a>>b>>c>>d;
  ans=-INF;
  ans=max(ans,a*c);
  ans=max(ans,b*d);
  ans=max(ans,b*c);
  ans=max(ans,a*d);
  cout<<ans;
  return 0;
}




Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  string s;
  cin>>s;
  int count1=0,count2=0;
  bool fg=true;
  rep(i,n){
    if(s[i]=='R'){
      count1++;
      fg=false;
    }
    else if(fg){
      count2++;
    }
  }
  if(count1<count2){
    cout<<count1<<'\n';
  }
  else{
    int ans=0;
    rep(i,n){
      if(count1<=0){
        break;
      }
      if(s[i]=='R'){
        count1--;
      }
      else{
        count1--;
        ans++;
      }
    }
    cout<<ans<<'\n';
  }

  return(0);
}


Measured memory_bytes: 3756
//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
//#include <string.h>
using namespace std;

int main(){
    int n,m;
    cin >> n >>m;
    
    vector<int>h(n);
    rep(i,n){
        cin >>h[i];
    }
    
    //vector<vector<int>> a(n);
    
    vector<bool> a(n,true);
    
    rep(i,m){
        int x,y;
        cin >>x >> y;
        x--;
        y--;
        if(h[x]>=h[y]){
            a[y] = false;
        }
        if(h[x]<=h[y]){
            a[x] = false;
        }
        
    }
    
    int ans = 0;
    
    rep(i,n){
        if(a[i]==true)ans++;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3784
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int md=1000000007;
int n,i,j,ans,a[200005],b[200005],jc[100000],rjc[100000],inv[100000],f[4010][4010];
inline int C(int n,int m)
{
	return 1ll*jc[n]*rjc[m]%md*rjc[n-m]%md;
}
int main()
{
	scanf("%d",&n);
	inv[1]=1;
	for(i=2;i<=20000;++i)
		inv[i]=1ll*inv[md%i]*(md-md/i)%md;
	jc[0]=rjc[0]=1;
	for(i=1;i<=20000;++i)
	{
		jc[i]=1ll*jc[i-1]*i%md;
		rjc[i]=1ll*rjc[i-1]*inv[i]%md;
	}
	for(i=1;i<=n;++i)
	{
		scanf("%d%d",a+i,b+i);
		f[2005-a[i]][2005-b[i]]++;
	}
	for(i=-2000;i<=2000;++i)
		for(j=-2000;j<=2000;++j)
			f[i+2005][j+2005]=(1ll*f[i+2005][j+2005]+f[i+2005][j-1+2005]+f[i-1+2005][j+2005])%md;
	for(i=1;i<=n;++i)
		ans=(1ll*ans+f[a[i]+2005][b[i]+2005]-C(2*(a[i]+b[i]),2*a[i])+md)%md;
	ans=1ll*ans*inv[2]%md;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 65664
#include <stdio.h>
#include <stdlib.h>
 
void max_heapify(int *heap, int i) {
    int heap_size, L, R, largest, tmp;
 
    heap_size = heap[0];
    L = 2*i;
    R = 2*i + 1;
    if (L <= heap_size && heap[L] > heap[i]) {
        largest = L;
    } else {
        largest = i;
    }
    if (R <= heap_size && heap[R] > heap[largest]) {
        largest = R;
    }
    if (largest != i) {
        tmp = heap[i];
        heap[i] = heap[largest];
        heap[largest] = tmp;
        max_heapify(heap, largest);
    }
}
 
int main(void) {
    int *heap, key, index, half, tmp;
    char cmd[20];
 
    heap = malloc(sizeof(int) * 2000001);
    heap[0] = 1;
    while (1) {
        scanf("%s %d ", cmd, &key);
        if (cmd[0] == 'i') {
            heap[0]++;
            index = heap[0];
            heap[index] = key;
 
            half = index / 2;
            while (index > 1 && heap[half] < heap[index]) {
                tmp = heap[index];
                heap[index] = heap[half];
                heap[half] = tmp;
                index /= 2;
                half = index / 2;
            }
        } else if (cmd[1] == 'x') {
            printf("%d\n", heap[1]);
            heap[1] = heap[heap[0]];
            heap[0]--;
            max_heapify(heap, 1);
        } else {
            return 0;
        }
    }
    return 0;
}

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

int main(){
	long long n,c;
	long long *x,*v;
	long long p_now,p_max;
	long long *pt,*ph,*pt_max,*ph_max,*pt_back,*ph_back;
	long long x_now;
	
	long long point,tmp;
	cin >> n>>c;
	
	x = new long long [n];
	v = new long long [n];
	for(int i=0;i<n;i++){
		cin>>x[i]>>v[i];
	}
	pt = new long long[n];//時計回りにi個歩いた場合の得点
	ph = new long long[n];//反時計回りにi個歩いた場合の得点
	pt_max = new long long[n];//時計回りにi個以下歩いた場合の得点の最大値
	ph_max = new long long[n];//反時計回りにi個以下歩いた場合の得点の最大値
	pt_back = new long long[n];//時計回りにiまで歩いて最初の場所に戻った場合の得点
	ph_back = new long long[n];//反時計回りにiまで歩いて最初の場所に戻った場合の得点
	
	p_now=0;
	p_max=0;
	x_now=0;
	for(int i=0;i<n;i++){
		p_now += v[i]-(x[i]-x_now);
		x_now=x[i];
		pt[i] = p_now;
		pt_back[i] = p_now-x[i];
		if(p_now>p_max)p_max=p_now;
		pt_max[i] = p_max;
	}
	p_now=0;
	p_max=0;
	x_now=c;
	for(int i=n-1;i>=0;i--){
		p_now += v[i]-(x_now-x[i]);
		x_now = x[i];
		ph[i] = p_now;
		ph_back[i] = p_now-(c-x[i]);
		if(p_now>p_max)p_max=p_now;
		ph_max[i] = p_max;
	}
	
	point=max(pt_max[n-1],ph_max[0]);
	for(int i=0;i<n-1;i++){
		tmp=pt_back[i]+ph_max[i+1];
		if(tmp>point){
			point = tmp;
		}
			// cout << tmp << endl;
	}
	for(int i=n-1;i>0;i--){
		tmp=ph_back[i]+pt_max[i-1];
		if(tmp>point){
			point = tmp;
		}
			// cout << tmp << endl;
	}
	cout << point << endl;
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

//幅優先探索のテンプレ.デフォルトではstartからの距離を返す.
//graphは隣接リスト.startは探索開始地点
vector<int> bfs(vector<vector<int>> &graph, int start){
	queue<int> todo;
	vector<int> dist(graph.size(),-1);
	dist[start] = 0;
	todo.push(start);
	while(!todo.empty()){
		int now = todo.front();
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt] != -1) continue;
			dist[nxt] = dist[now] + 1;
			todo.push(nxt);
		}
	}
	return dist;
}

//ワーシャルフロイト法のテンプレ.graphに最短経路が格納される.inf + const = inf に気を付ければ大丈夫
//graphは隣接行列
void WF(vector<vector<int>> &graph,vector<int> ks){
	int n = graph.size();
	for (int ki = 0; ki < ks.size(); ki++){
		int k = ks[ki];
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++){
				graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
			}
		}
	}
}

int main(){
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> r(max({a, b, c}), 0);
	vector<int> g(max({a, b, c}), 0);
	vector<int> w(max({a, b, c}), 0);
	rep(i, a) cin >> r[i];
	rep(i, b) cin >> g[i];
	rep(i, c) cin >> w[i];
	r.push_back(inf);
	g.push_back(inf);
	w.push_back(0);

	sort(all(r));
	sort(all(g));
	sort(all(w));
	reverse(all(r));
	reverse(all(g));
	reverse(all(w));

	long long int ans = 0;
	rep2(i,1, x+1) ans += r[i];
	rep2(i,1, y+1) ans += g[i];
	int i = x;
	int j = y;
	int k = 0;
	int flag = 1;
	while (flag)
	{
		flag = 0;
		if (r[i] < g[j])
		{
			if (r[i] < w[k]){
				ans += (w[k] - r[i]);
				k++;
				i--;
				flag = 1;
			}
		}
		else {
			if (g[j] < w[k]){
				ans += (w[k] - g[j]);
				k++;
				j--;
				flag = 1;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1800
d, g = map(int, input().split())
p = [[i*100] + list(map(int, input().split()))
     for i in range(1, d+1)]
p = list(map(lambda x: x + [x[0] * x[1] + x[2]], p))

res = 1001
for bit in range(2**d):
    score = 0
    cnt = 0
    zero = 0
    for i in range(d):
        if bit & (1 << i):
            score += p[i][3]
            cnt += p[i][1]
        else:
            zero = i
    if score >= g:
        res = min(res, cnt)
    else:
        remaining = (g - score + p[zero][0]-1) // p[zero][0]
        if remaining < p[zero][1]:
            res = min(res, cnt+remaining)

print(res)


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int n;
  pair<int, int> v1[100005] = {}, v2[100005] = {};
  cin >> n;
  REP(i,n/2) {
    int a,b;
    cin >> a >> b;
    v1[a].first++;
    v1[a].second = a;
    v2[b].first++;
    v2[b].second = b;
  }
  sort(v1, v1 + 100005, greater<pair<int, int> >());
  sort(v2, v2 + 100005, greater<pair<int, int> >());

  int m = 0;
  if(v1[0].second != v2[0].second) {
    m = v1[0].first + v2[0].first;
  } else {
    m = max(v1[1].first + v2[0].first, v1[0].first + v2[1].first);
  }

  cout << n - m << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;

int main(void){
  multiset<long,greater<long>>ball;
  size_t n;cin>>n;
  for(int i=0;i<n;i++){
    int x;cin>>x;
    ball.insert(x);
  }
  int ans=0;
  while(!ball.empty()){
    int x=*ball.begin();ball.erase(ball.begin());
    int y=pow(2,(int)log2(x)+1)-x;
    auto it=ball.find(y);
    if(it!=ball.end()){
      ball.erase(it);
      ans+=1;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9600
from itertools import combinations

x = int(input())
num = [i**5 for i in range(1000)]

for a, b in combinations(num, 2):
    if a - b == x:
        print(int(a**0.2), int(b**0.2))
    elif a + b == x:
        print(int(a**0.2), -int(b**0.2))
    elif b - a == x:
        print(int(b**0.2), int(a**0.2))
    elif b + a == x:
        print(int(b**0.2), -int(a**0.2))
    else:
        continue
    break


Measured memory_bytes: 9316
# -*- coding: utf-8 -*-
box = []
for i in range(0,5):
    box.append(int(input()))
amari = []
for i in range(0,5):
    amari.append(box[i] % 10)
for i in range(0,5):
    if amari[i] ==0:
        amari[i] = 100
    else:
        pass
sumtime = 0
box4 = box[4]
boxmin = box[amari.index(min(amari))]
box[amari.index(min(amari))] = box4 
box[4] = boxmin
for i in range(0,5):
    if i ==4:
        sumtime += box[i]
    elif box[i]%10==0:
        sumtime +=box[i]
    else:
        sumtime += (box[i] // 10)*10+10
print(sumtime)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 2000000000
using namespace std;

int main(){
  int n, m, r, s[8], d[205][205], i, j, k, a, b, c, sum = 0, ans = INF;
  vector<int> p;
  scanf("%d%d%d", &n, &m, &r);
  for(i = 1; i <= n; i++) for(j = 1; j <= n; j++) d[i][j] = (i == j ? 0 : INF);
  for(i = 0; i < r; i++) scanf("%d", &s[i]);
  sort(s, s+r);
  for(i = 0; i < m; i++){
    scanf("%d%d%d", &a, &b, &c);
    d[a][b] = c;
    d[b][a] = c;
  }
  for(k = 1; k <= n; k++){
    for(i = 1; i <= n; i++){
      if(d[i][k] == INF) continue;
      for(j = 1; j <= n; j++){
        if(d[k][j] == INF) continue;
        if(d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];
      }
    }
  }
  do{
    sum = 0;
    for(i = 1; i < r; i++) sum += d[s[i-1]][s[i]];
    if(ans > sum) ans = sum;
  }while(next_permutation(s, s+r));
  printf("%d", ans);
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringJoiner;

public class Main {

    static class UnionFind {
        private int[] parent;

        public UnionFind(int n) {
            parent = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
            }
        }

        private int root(int x) {
            if (parent[x] == x) {
                return x;
            }
            return parent[x] = root(parent[x]);
        }

        private void union(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx == ry) {
                return;
            }
            parent[rx] = ry;
        }

        private boolean isSame(int x, int y) {
            return root(x) == root(y);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        UnionFind uf = new UnionFind(n + 1);
        Map<Integer, Set<Integer>> friends = new HashMap<>();
        Map<Integer, Set<Integer>> blocks = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            friends.put(i, new HashSet<>());
            blocks.put(i, new HashSet<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            friends.get(a).add(b);
            friends.get(b).add(a);
            uf.union(a, b);
        }
        for (int i = 0; i < k; i++) {
            int c = sc.nextInt();
            int d = sc.nextInt();
            if (!uf.isSame(c, d)) {
                continue;
            }
            blocks.get(c).add(d);
            blocks.get(d).add(c);
        }

        List<Integer> ans = new ArrayList<>();
        int[] groupSize = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            groupSize[uf.root(i)]++;
        }
        for (int i = 1; i <= n; i++) {
            ans.add(groupSize[uf.root(i)] - (friends.get(i).size() + blocks.get(i).size()) - 1);
        }
        StringJoiner sj = new StringJoiner(" ");
        for (int i = 0; i < n; i++) {
            sj.add(String.valueOf(ans.get(i)));
        }
        System.out.println(sj);
    }

}


Measured memory_bytes: 136212
using System;
using System.Linq;

namespace ABC140A
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray().First();
            long[] B = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

            long ans = B[0];
            for (int i = 0; i < N - 2; i++)
            {
                ans += Math.Min(B[i], B[i + 1]);
            }

            ans += B[N - 2];
            Console.WriteLine(ans);
        }
    }
}

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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int a, b, x;
signed main() {
    cin >> a >> b >> x;
    if (a * a * b > 2 * x) {
        cout << atan2(b, 2.0 * x / (a * b)) * 180 / pi << endl;
    } else {
        cout << atan2(2 * b - 2.0 * x / (a * a), a) * 180 / pi;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A==C) cout<<0<<endl;
  else cout<<1<<endl;
}





Measured memory_bytes: 256
from heapq import heappush,heappop
import queue
import re
import math
import functools


def i_raw():
    return int(input())

def ss_raw():
    return input().split()

def is_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

def gcd (a,b):
    if(b==0):
        return a
    return gcd(b,a%b)


def main():
    S,T = ss_raw()
    A,B = is_raw()
    U = input().strip()
    if U==S:
        return " ".join(map(str,[A-1,B]))
    else:
        return " ".join(map(str,[A,B-1]))  


print(main())


Measured memory_bytes: 38384
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,x=map(int,input().split())\n"
"m=x\n"
"for i in range(n):\n"
"  t=int(input())\n"
"  x-=t\n"
"  m=min(m,t)\n"
"print(n+x//m)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
/////////////////////////////////////////////////////////////////////////////////
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'               `$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//  
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$'                   `$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
//$$$'`$$$$$$$$$$$$$'`$$$$$$!                       !$$$$$$'`$$$$$$$$$$$$$'`$$$//
//$$$$  $$$$$$$$$$$  $$$$$$$                         $$$$$$$  $$$$$$$$$$$  $$$$//
//$$$$. `$' \' \$`  $$$$$$$!       $$        $$      !$$$$$$$  '$/ `/ `$' .$$$$//
//$$$$$. !\  i  i .$$$$$$$$       $$$$      $$$$      $$$$$$$$. i  i  /! .$$$$$//
//$$$$$$   `--`--.$$$$$$$$$        $$        $$       $$$$$$$$$.--'--'   $$$$$$//
//$$$$$$L        `$$$$$^^$$                           $$^^$$$$$'        J$$$$$$//
//$$$$$$$.   .'   ""~   $$$    $.                 .$  $$$   ~""   `.   .$$$$$$$//
//$$$$$$$$.  ;      .e$$$$$!    $$.             .$$  !$$$$$e,      ;  .$$$$$$$$//
//$$$$$$$$$   `.$$$$$$$$$$$$     $$$.         .$$$   $$$$$$$$$$$$.'   $$$$$$$$$//
//$$$$$$$$    .$$$$$$$$$$$$$!     $$`$$$$$$$$'$$    !$$$$$$$$$$$$$.    $$$$$$$$//
//$$$$$$$     $$$$$$$$$$$$$$$$.    $    $$    $   .$$$$$$$$$$$$$$$$     $$$$$$$//
//                                 $    $$    $								   //
//                                 $.   $$   .$								   //
//                                `$        $'								   //
//                                 `$$$$$$$$'								   //
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;

// Type-Define 
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef std::vector<char> vc;
typedef std::vector< vector<int> > vii;
typedef std::pair<int, int> pii;

// Hash-Define
#define int long long
#define MOD 1000000007
#define debugStart cerr << "\n[DEBUG START]\n"
#define debugStop cerr << "\n[DEBUG STOP]\n"
#define KHATAM cout << std::endl;
#define set_zero(x) memset(x, 0, sizeof(x));
#define ForPrint(x) std::for_each( begin(x), end(x), []( auto const& el ){ std::cout << el << " ";  } )

//Functions 
template<typename T> auto gcd ( T a, T b ) -> int  { return (b==0)?a:gcd(b,a%b); }

const int inf = 1e9 + 5;

signed
main() {

    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1; 
    //cin >> T;
    for ( int testcase = 1; testcase <= T; ++testcase ) {
        int N;
        std::cin >> N;
        int arr[N];
        int a, b, c = 0;
        for ( int i = 0; i < N; ++i ) {
            
            std::cin >> arr[i];
            if( i == 0 ) {
                c = a = 0;
            }
            else if( i == 1 ) 
                c = b = abs( arr[i] - arr[i-1] );
            else {
                c = min(abs( arr[i] - arr[i-1] ) + b, abs( arr[i] - arr[i-2] ) + a);
                a = b;
                b = c;
            }
        }
        std::cout << c ;
        KHATAM;
    }
    return 0;
}


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

using namespace std;

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

	if(N%X == 0) {
		cout << (N/X) * T << endl;
	} else {
		cout << (N/X + 1) * T << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
// Problem : B - Trick or Treat
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

bool has[maxN];

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	REP(i, k) {
		int l;
		cin >> l;
		REP(j, l) {
			int a;
			cin >> a;
			has[a] = true;
		}
	}
	int ans = 0;
	RI(i, n) {
		if (!has[i]) ans++;
	}
	cout << ans;
	return 0;
}
 


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

int main(){
     string s,t;
     int l,a=0;
     cin>>s>>t;
     l=s.length();
     string u=t+t;
     if(u.find(s)!=std::string::npos){
          a=1;
     }
     if(a==1) cout<<"Yes"<<endl;
     if(a==0) cout<<"No"<<endl;
  
    }

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(int argc, char const* argv[])
{
	double x,h,S;

	while( cin >> x >> h && x != 0 ){
		double x2 = x/2;
		double l = sqrt( x2 * x2 + h * h );
		S = l * x * 2 + x * x;
		printf("%.6f\n",S);
	}
	return 0;
}

Measured memory_bytes: 0
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N, K = getNM()
parent = []
for i in range(N):
    a, b = getNM()
    parent.append((a, b))
parent.sort(key = lambda int: int[0])

A = []
B = []
for a, b in parent:
    A.append(a)
    B.append(b)
alta = [0]
for i in range(N):
    alta.append(alta[i] + B[i])

index = bisect_left(alta, K)
print(A[index - 1])


Measured memory_bytes: 89560
h, w = map(int, input().split())

ll = []
for _ in range(h):
  s = input()
  if '#' in s:
    ll.append([s[i] for i in range(w)])

lr = []
for i in range(w):
  if any(l[i] == '#' for l in ll):
    lr.append(i)

for l in ll:
  ans = ''
  for i in lr:
    ans += l[i]
  print(ans)

Measured memory_bytes: 3064