akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

using namespace std;

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

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

bool cmp(P a, P b)
{
  if(a.first!=b.first)
    return a.first < b.first; 
  else
    return a.second < b.second;
}

int main()
{
  int N;
  cin >> N;
  
  vector<P> ab(N), cd(N);
  for(int i=0; i<N; i++)
    cin >> ab[i].first >> ab[i].second;
  for(int i=0; i<N; i++)
    cin >> cd[i].first >> cd[i].second;

  sort(ab.begin(), ab.end(), cmp);
  reverse(ab.begin(), ab.end());
  sort(cd.begin(), cd.end(), cmp);

  
  ll count = 0;
  
  for(int i=0; i<N; i++)
    {
      int index=-1;
      int ymax=1000;
      for(int j=0; j<N; j++)
	{
	  if(ab[i].first < cd[j].first && ab[i].second < cd[j].second)
	    {
	      if(ymax>cd[j].second)
		{
		  ymax=cd[j].second;
		  index=j;
		}
	    }
	}
      if(index!=-1){
	cd[index] = P(-1, -1);
	count++;
      }
    }

  cout << count << endl;
  
  
  


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VMM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VU.Unbox a => Int -> VM.IOVector a
unew !n = accursedUnutterablePerformIO $ VM.unsafeNew n

uread :: VU.Unbox a => Int -> VM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VM.IOVector a -> VM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VM.IOVector a -> VM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

solve :: Int -> Int -> B.ByteString -> Bool
solve !x !y !bs =
  foldl' go dpX rx VU.! toIndex x && foldl' go dpY ry VU.! toIndex y
 where
  go !prev !i = VU.fromList
    [ (if (k + i) < maxN then prev VU.! toIndex (k + i) else False)
        || (if (k - i) >= -maxN then prev VU.! toIndex (k - i) else False)
    | k <- [-maxN .. maxN]
    ]

  maxN = B.length bs
  dpX  = VU.fromList [ i == rx0 | i <- [-maxN .. maxN] ]
  dpY  = VU.fromList [ i == 0 | i <- [-maxN .. maxN] ]

  toIndex !k = k + maxN

  (!rx0, !rx, !ry) =
    let
      (bs0, bs1)     = B.span (== 'F') bs
      (rx, ry, _, _) = if B.length bs1 == 0
        then ([], [], B.empty, 0)
        else fix
          (\f (!rx, !ry, !bs, !parity) ->
            let (bs0, bs1) = B.span (== 'F') bs
                r          = B.length bs0
                next       = if B.length bs1 == 0 then id else f
                bs1'       = if B.length bs1 == 0 then B.empty else B.tail bs1
                cons       = if r > 0 then (r :) else id
            in  if parity == 0
                  then next $ (cons rx, ry, bs1', 1)
                  else next $ (rx, cons ry, bs1', 0)
          )
          ([], [], B.tail bs1, 1)
    in
      (B.length bs0, rx, ry)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  bs     <- B.getLine
  (x, y) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  putStrLn $ if solve x y bs then "Yes" else "No"


Measured memory_bytes: 5500
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n,a[105],max,min,sum=0,summin=1000000007,i;
	scanf("%d",&n);
	scanf("%d",&a[1]);
	max=a[1];min=a[1];
	for( i=2;i<=n;i++){
		scanf("%d",&a[i]);
		if(max<a[i])max=a[i];
		if(min>a[i])min=a[i];
	}
	for( i=min;i<=max;i++){
		sum=0;
		for(int j=1;j<=n;j++){
			sum+=(a[j]-i)*(a[j]-i);
		}
		if(sum<summin)summin=sum;
	}
	printf("%d",summin);
 } 

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

char field[9][9];

void bomb(int px,int py)
{
	field[py][px]='0';
	for(int x=-3;x<=3;x++)if(1<=px+x&&px+x<=8&&field[py][px+x]=='1')bomb(px+x,py);
	for(int y=-3;y<=3;y++)if(1<=py+y&&py+y<=8&&field[py+y][px]=='1')bomb(px,py+y);
}

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

	for(int k=1;k<=n;k++){
		for(int i=1;i<=8;i++){
			for(int j=1;j<=8;j++){
				field[i][j]=getchar();
			}
			getchar();
		}
		int sx,sy;
		scanf("%d%d ",&sx,&sy);

		bomb(sx,sy);

		printf("Data %d:\n",k);
		for(int i=1;i<=8;i++){
			for(int j=1;j<=8;j++){
				putchar(field[i][j]);
			}
			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int r, c;
        cin >> r >> c;
        if(r == 0)
            return 0;

        vector<bitset<10> > osenbei(c);
        for(int i=0; i<r; ++i){
            for(int j=0; j<c; ++j){
                int a;
                cin >> a;
                osenbei[j][i] = (a == 1);
            }
        }

        int ret = 0;
        for(int i=0; i<(1<<r); ++i){
            bitset<10> bs(i);
            int num = 0;
            for(int j=0; j<c; ++j){
                int tmp = (osenbei[j] ^ bs).count();
                tmp = max(tmp, r-tmp);
                num += tmp;
            }
            ret = max(ret, num);
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  if (a[(a.size())-1]==b[0] && b[(b.size())-1]==c[0]){
    cout<<"YES";}
  else cout<<"NO";
 
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    string s;
    cin >> s;
    int ans = 700;
    rep(i, s.size())
    {
        if (s[i] == 'o')
        {
            ans += 100;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//#include "bits\stdc++.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long LL;

int main()
{
    int n, temp;
    vector<int> array;

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> temp;
        array.emplace_back(temp);
    }

    sort(array.begin(), array.end());
    cout << array[n - 1] - array[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        w: usize,
        h: usize,
        s: [chars; w],
    }

    let mut ans = true;
    for x in 0..w {
        for y in 0..h {
            let no = if y < h - 1 { s[x][y + 1] } else { '.' };
            let ea = if x < w - 1 { s[x + 1][y] } else { '.' };
            let so = if y > 0 { s[x][y - 1] } else { '.' };
            let we = if x > 0 { s[x - 1][y] } else { '.' };
            if s[x][y] == '#' && no == '.' && ea == '.' && so == '.' && we == '.' {
                ans = false;
            }
        }
    }

    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <stdio.h>

int	main(void)
{
	int	a, b;
	while (1)
	{
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0)
			break ;
		else if (a <= b)
			printf("%d %d\n", a, b);
		else
			printf("%d %d\n", b, a);
	}
	return (0);
}



Measured memory_bytes: 2044
import heapq

def dijkstra(G, s, g, n):
    cost = [10**9] * n
    cost[s] = 0
    pre = [-1] * n
    q = []
    heapq.heappush(q, (0, s))
    while q:
        d, to = heapq.heappop(q)
        if to == g:
            break
        if cost[to] < d:
            continue
        for n, dist in G[to]:
            nd = d + dist
            if cost[n] > nd:
                cost[n] = nd
                heapq.heappush(q, (nd, n))
                pre[n] = to

    if pre[g] == -1:
        return []
    ans = [g]
    cur = g
    while True:
        ans.append(pre[cur])
        cur = pre[cur]
        if cur == s or cur == -1:
            break

    return ans[::-1]

while True:
    n = int(input())
    if n == 0:
        break
    bldgs = [-1] * n
    G = [[] for _ in range(n)]
    for _ in range(n):
        b, x, y = map(int, input().strip().split(" "))
        bldgs[b-1] = (x, y)

    for i in range(n):
        x_i, y_i = bldgs[i]
        for j in range(i+1, n):
            x_j, y_j = bldgs[j]
            d = ((x_i-x_j)**2 + (y_i-y_j)**2) ** 0.5
            if d <= 50:
                G[i].append((j, d))
                G[j].append((i, d))
    m = int(input())
    for _ in range(m):
        s, g = map(int, input().strip().split(" "))
        ans = dijkstra(G, s-1, g-1, n)
        if ans == []:
            print("NA")
        else:
            print(" ".join([str(i+1) for i in ans]))


Measured memory_bytes: 5772
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
 
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
 
class Point{
	public:
		double x, y;
 
		Point(double x = 0, double y = 0): x(x), y(y) {}
 
		Point operator + (Point p){ return Point(x + p.x, y + p.y);}
		Point operator - (Point p){ return Point(x - p.x, y - p.y);}
		Point operator * (double a){ return Point(a * x, a * y);}
		Point operator / (double a){ return Point(x / a, y / a);}
 
		double abs(){ return sqrt(norm());}
		double norm(){ return x * x + y * y;}
 
		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}
		bool operator > (const Point &p) const{
			return x != p.x ? x > p.x : y > p.y;
		}
		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};
 
typedef Point Vector;
typedef vector<Point> Polygon;
 
double dot(Vector a, Vector b){
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
	return a.x * b.y - a.y * b.x;
}
 
int ccw(Point p0, Point p1, Point p2){
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
	if(cross(a, b) < -EPS) return CLOCKWISE;
	if(dot(a, b) < -EPS) return ONLINE_BACK;
	if(a.norm() < b.norm()) return ONLINE_FRONT;
 
	return ON_SEGMENT;
}
double getDistance(Point a, Point b){
	return (a - b).abs();
}
Polygon convex_hull(Polygon ps){
	int n = ps.size();
	int k = 0;
	sort(ps.begin(), ps.end());
	Polygon ret(2 * n);
	for(int i = 0; i < n; ret[k++] = ps[i++]){
		while(k >= 2 && ccw(ret[k - 2], ret[k - 1], ps[i]) <= 0 && ccw(ret[k - 2], ret[k - 1], ps[i]) != -2) --k;
	}
	for(int i = n - 2, t = k + 1; i >= 0; ret[k++] = ps[i--]){
		while(k >= t && ccw(ret[k - 2], ret[k - 1], ps[i]) <= 0 && ccw(ret[k - 2], ret[k - 1], ps[i]) != -2) --k;
	}
	ret.resize(k - 1);
	return ret;
}

int main(){
	int n;
	scanf("%d", &n);
	Polygon p(n);
	for(int i = 0; i < n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
	Polygon qs = convex_hull(p);
	if(qs.size() == 2){
		printf("%.10lf\n", getDistance(qs[0], qs[1]));
		return 0;
	}
	int l = 0, r = 0;
	for(int i = 0; i < qs.size(); i++){
		if(qs[i] < qs[l]) l = i;
		if(qs[i] > qs[r]) r = i;
	}
	double res = 0.0;
	int i = l, j = r;
	while(i != r || j != l){
		res = max(res, getDistance(qs[i], qs[j]));
		if(cross(qs[(i + 1) % n] - qs[i], qs[(j + 1) % n] - qs[j]) < 0){
			i = (i + 1) % qs.size();
		}else{
			j = (j + 1) % qs.size();
		}
	}
	printf("%.10lf\n", res);
	return 0;
}



Measured memory_bytes: 7924
#include <stdio.h>
#include <algorithm>
using namespace std; 
int main(){ int H,W; 
while(true){ scanf("%d %d",&H,&W); 
if(H == 0 && W == 0) break; 

for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ if((i+j)%2 == 0) printf("#");
else{ printf(".");
} 
    
} 
printf("\n");
} 

printf("\n");
} 
    
} 


Measured memory_bytes: 2620
n, k = map(int, input().split())
mod = 10 ** 9 + 7

MAX = 2000

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod


def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % mod


for i in range(1, k + 1):
    ans = comb(n - k + 1, i) * comb(k - 1, i - 1) % mod
    print(ans)


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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    rep(i, n)
    {
        ans += min(a[i], b[i]);
        b[i] -= min(a[i], b[i]);
        ans += min(a[i + 1], b[i]);
        a[i + 1] -= min(a[i + 1], b[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC096_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int A = int.Parse(input[0]);  //それぞれのピザの金額
            int B = int.Parse(input[1]);
            int AB = int.Parse(input[2]);
            int needA = int.Parse(input[3]);  //ピザの必要枚数
            int needB = int.Parse(input[4]);

            int common = Math.Min(needA , needB); //AとBが両方存在しているとき
            int single = Math.Abs(needA - needB); //残りがAとBのどちらかのとき
            int moreNeed = needA > needB ? A : B; //要求数の多いほうを代入
            int total = Math.Min((A + B) * common, AB * common * 2) + Math.Min(moreNeed * single, AB * single * 2);
            Console.WriteLine(total);


            //if (AB <= A / 2 && AB <= B / 2)
            //{
            //    totalMin = AB * Math.Max(needA, needB) * 2;
            //}
            //else if (AB <= (Math.Abs(A - B) / 2 + Math.Min(A, B)))
            //{
            //    int defNeed = Math.Abs(needA - needB);
            //    if (needA < needB)
            //    {
            //        totalMin = B * defNeed + AB * needA * 2;
            //    }
            //    else if (needA > needB)
            //    {
            //        totalMin = A * defNeed + AB * needB * 2;
            //    }
            //    else
            //    {
            //        totalMin = AB * needA * 2;
            //    }
            //}
            ////else if (A < AB / 2 || B < AB / 2)
            ////{
            ////    totalMin = A * needA + B * needB;
            ////}
            //else if (AB > (Math.Abs(A - B) / 2 + Math.Min(A, B)))
            //{
            //    totalMin = A * needA + B * needB;
            //}
            //else
            //{
            //    totalMin = A * needA + B * needB;
            //}
            //Console.WriteLine(totalMin);
            //return;

            //for (int a = 0; a <= needA; a++)  //小文字のa,bはピザの枚数
            //{
            //    for (int b = 0; b <= needB; b++)
            //    {
            //        int ab = Math.Max(needA - a, needB - b) * 2;
            //        if (ab < 0)  //abは必ず2枚ずつでないとaとbの1枚ずつにカウントされない
            //        {
            //            ab = 0;
            //        }

            //        money = a * A + b * B + ab * AB;
            //        if (a == 0 && b == 0)
            //        {
            //            totalMin = money;
            //        }
            //        else if (a == needA && b == needB)
            //        {
            //            Console.WriteLine(Math.Min(totalMin, money));
            //            return;
            //        }
            //        else
            //        {
            //            totalMin = Math.Min(totalMin, money);
            //        }
            //    }
            //}
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>

using namespace std;

int main() {

	char a[100], b[100], c[100];
	int d, ai, bi, ci;

	cin >> a;
	cin >> b;
	cin >> c;

	for (d = 0; d < 100; d++) {
		if (a[d] == '\0') {
			ai = d - 1;
			break;
		}
	}
	for (d = 0; d < 100; d++){
		if (b[d] == '\0') {
			bi = d - 1;
			break;
		}

	}
	
	if (a[ai] == b[0]) {

		if (b[bi] == c[0]) {


			cout << "YES" << endl;
		}

		else {
			cout << "NO" << endl;
		}
	}
	else {
		cout << "NO" << endl;
	
	}


	return 0;
}

Measured memory_bytes: 256
li = list(input())
ans = 0
num = 0
for i in range(len(li)):
    if li[i] == 'A' or li[i] == 'G' or li[i] == 'C' or li[i] == 'T':
        num += 1
    else:
        if ans < num:
            ans = num
        num = 0
if ans == 0:
    ans = num
if ans < num:
    ans = num
print(ans)

Measured memory_bytes: 8948
N, P=gets.split.map &:to_i
A=gets.split.map &:to_i
O=A.count{|e|e.odd?}
E=N-O

odd=0
nCr=1
1.upto(O){|i|
    nCr*=O-i+1
    nCr/=i
    odd+=nCr if i.odd?
}
even=2**O-odd

puts (P==0 ? 2**E*even : 2**E*odd)


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln << "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// ⊂ニニニニニニニニニニニニニ( ^ω^)ニニニニニニニニニニニニニ⊃

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	int n;
	cin >> n;
	int F[n];
	rep(i,n) {
		F[i] = 0;
		rep(j,10) {
			int tmp;
			cin >> tmp;
			F[i] |= (tmp << j);
		}
	}
	int P[n][11];
	rep(i,n) rept(j,10) cin >> P[i][j];
	
	int ans = -inf;
	reps(i, 1, (1<<10)) {
		int tmp = 0;
		rep(j,n) {
			int c = __builtin_popcount(i&F[j]);
			tmp += P[j][c];
		}
		chmax(ans, tmp);
	}
	
	cout << ans ln;
}

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

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int a[100000];
int f[100000];

int find(int x){
	if(x==f[x]) return x;
	else return f[x]=find(f[x]);
}

int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		f[i]=i;
	}
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		x=find(x),y=find(y);
		if(x!=y) f[x]=y; 
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(find(i)==find(a[i])) sum++;
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int main(){
    char s[100];
    gets(s);
    int b;
    b=strlen(s);
    for(int c=0;c<b;c++){
        if(c%2==1){if(s[c]=='L' || s[c]=='U' || s[c]=='D'){}
                   else{printf("No\n");return 0;}}
        else{if(s[c]=='R' || s[c]=='U' || s[c]=='D'){}
             else{printf("No\n");return 0;}}
    }
    printf("Yes\n");
    return 0;
}

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

int main() {
    int n; cin >> n;
    double c = 380000.0;
    double ans = 0;
    for (int i = 0; i < n; i++) {
        double a; string s; cin >> a >> s;
        if (s[0] == 'J') ans += a;
        else ans += a * c;
    }
    printf("%.12f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
    }
    let i = n / 111;
    let j = n % 111;
    let result = i * 111 + if j == 0 { 0 } else { 111 };

    println!("{}", result);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pr printf
#define P push
#define PB push_back
#define F front
#define T top
#define MP make_pair
#define Fi first
#define Se second
using namespace std;
inline long long gcd(long long a,long long b){return b==0?a:gcd(b,a%b);}
inline long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
inline void read(long long &x){
    char ch;
    do ch=getchar();while(ch<48||ch>57);
    x=0;while(ch<=57&&ch>=48){x=x*10+ch-48;ch=getchar();}
}
inline void read(int &x){
    char ch;
    do ch=getchar();while(ch<48||ch>57);
    x=0;while(ch<=57&&ch>=48){x=x*10+ch-48;ch=getchar();}
}
int i,j,k,n,m;
string s;
double x,ans;
int main(){
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>x>>s;
        if(s=="BTC")
            x*=380000.0;
        ans+=x;
    }
    printf("%lf",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n;
   cin>>n;

   vector<long int> v(n);
   for(long int i = 0; i < n; i++)
   		cin>>v[i];

   	sort(v.begin(),v.end());

   	long int ans = 0;
   for(long int i = 0; i < n; i++){
   	for(long int j = i + 1; j < n; j++){
   		for(long int k = j + 1; k < n; k++){
   			if(v[i] == v[j])
   					continue;

   			if(v[j] == v[k])
   				continue;

   			if(v[i] == v[k])
   					continue;

   			if(v[k] < v[i] + v[j])
   				ans++;
   		}
   	}
   }

   cout<<ans;
   return 0;
}

Measured memory_bytes: 3640
def main():
    N = int(input())
    ls = [0]
    ans = []

    for i in range(1,N+1):
        ls.append(ls[-1]+i)
        ans.append(i)
        if N<=ls[-1]:
            break
                
    for i in range(len(ans)):
        if ans[i]==(ls[-1]-N):
            pass
        else:
            print(ans[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 42968
#include<bits/stdc++.h>
#define maxn 30
#define u32d unsigned int
#define LL   long long
#define INF  0x7FFFFFFF
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	if(ceil(n / 2019.0) != ceil(m / 2019.0)){
		cout << 0 << endl;
	}
	else{
		LL mul;
		LL ans = INF;
		for(int i = n; i <= m; ++i){
			for(int j = i + 1; j <= m; ++j){
				mul = 1;
				mul = mul * i;
				mul = mul * j;
				ans = min(mul % 2019, ans);
			}
		}
		cout << ans << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
if __name__ == '__main__':
  
  h, w = map(int, input().split())
  s = []
  
  s.append('.' * w)
  for i in range(h):
      s.append('.' + input() + '.')
  s.append('.' * w)
  
  for i in range(h):
      result_list = []
      for j in range(w):
          target_cell = ''
          if s[i + 1][j + 1] == '.':
            target_cell += s[i][j:j+3]
            target_cell += s[i+1][j:j+3]
            target_cell += s[i+2][j:j+3]
              
            print(target_cell.count('#'), end="")
          else:
            print('#', end="")
            
      print()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int64;
char s[15];
int main() {
    scanf("%s",s + 1);
    int l = strlen(s + 1);
    for(int i = 1 ; i < l ; ++i) {
        if(s[i] == 'A' && s[i + 1] == 'C') {
            puts("Yes");return 0;
        }
    }
    puts("No");return 0;
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define sz(c) (ll) c.size()
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
    ld n; cin >> n;
    cout.precision(10);
    cout << fixed << (n/3) * (n/3) * (n/3);
}

Measured memory_bytes: 3692
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

ll power(ll a,ll n,ll m=M){
    ll ans=1;
    while(n){
        if(n&1) ans=ans*a;
        a=a*a;
        n=n>>1;
        ans=ans%m;
        a=a%m;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll A[n], B[n];
    rep(i,0,n)  cin>>A[i]>>B[i];
    map<pll,ll> m;
    ll cnt = 0;
    ll zero = 0;
    rep(i,0,n){
        ll g = __gcd(A[i], B[i]);
        if(A[i] == B[i] and B[i] == 0){
            zero++;
        }
        else if(A[i] == 0){
            m[{0,1}]++;
        }
        else if(B[i] == 0){
            m[{-1,0}]++;
        }
        else{
            A[i] = A[i]/g;
            B[i] = B[i]/g;
            if(B[i] < 0)    B[i] = -B[i], A[i] = -A[i];
            m[{A[i], B[i]}]++;
        }
    }
    ll ans = 1;
    for(auto i:m){
        if(i.ft.ft < 0 or i.ft.sd < 0){
            ll p = m[{abs(i.ft.sd), abs(i.ft.ft)}];
            cnt = (power(2, i.sd) + power(2, p) - 1);
            ans = (ans * cnt) % M;
        }
        else{
            if(m[{-i.ft.sd, i.ft.ft}] == 0){
                cnt = power(2, i.sd);
                ans = (ans * cnt) % M;
            }
        }
    }
    ans += zero;
    cout << (ans-1+M)%M << endl;
    return 0;
}

Measured memory_bytes: 31712
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define repi(m, itr) for (auto itr = m.begin();itr != m.end();++itr)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// D - Wide Flip
string S;
const int INF = 10000000;
int ans = INF;

int main(){
    cin >> S;

    int len = S.length();

    rep(i, 0, len-1){
        if(S[i] != S[i+1]){
            ans = min(ans, max(i+1, len - (i+1)));
        }
    }

    if(ans == INF){
        ans = len;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 512
import sys
input=sys.stdin.readline
n,y=map(int,input().split())
mm=min(n,y//10000)+1
for m in range(mm):
  ny=y-10000*m
  gg=min(n-m,ny//5000)+1
  for g in range(gg):
    if m*10000+g*5000+(n-m-g)*1000==y:print(m,g,n-m-g);exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false INT_MAX INT_MIN insert erase clear pop push compare INT64_MAX INT64_MIN  reverse replace stringstream string::npos length substr front
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const int mod = 1e9 + 7 ;
const int inf =
 1e9 + 5 ;
 //1e18L + 5;
const int nax = 2e5 + 5;
void min_self(int&a , int b){a=min(a,b);}
void max_self(int&a , int b){a=max(a,b);}
void add_self(int& a , int b){a =  (a + b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int n , k ; cin>>n>> k ;
vector<int>arr(n);for(int i = 0 ; i<n ; i++)cin>>arr[i] ; 
vector<bool>dp(k+1);
dp[0]=true;
for(int j = 1 ; j<=k ;j++ ){
dp[j] = false ;
for(auto i:arr){
	
	if(i-j==0)dp[j] = true;
	else if(j-i>0){
		dp[j] = dp[j]||(!dp[j-i]);
	}

}
}
if(dp[k])cout<<"First";
else cout<<"Second";




	
}

Measured memory_bytes: 256
import math
ALPHABET = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
result = []

def alphabet_decimal(v):
    quotient = math.floor(v / len(ALPHABET))
    surplus = v % len(ALPHABET)
    quotient -= 1 if surplus == 0 else 0
    surplus = len(ALPHABET) if surplus == 0 else surplus
    result.append(surplus)
    if len(ALPHABET) < quotient:
        alphabet_decimal(quotient)
    elif len(ALPHABET) < v:
        result.append(quotient)
    return "".join([ALPHABET[i - 1] for i in reversed(result)])

n = int(input())
#s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
print(alphabet_decimal(n))

Measured memory_bytes: 9236
n = int(input())
a = list(map(int, input()))
a = [e - 1 for e in a]


def cnt_div2(x):
    ret = 0
    while x % 2 == 0 and x != 0:
        x //= 2
        ret += 1

    return ret


now = 0
cnt = [0]
for i in range(1, n):
    now += cnt_div2(n - i)
    now -= cnt_div2(i)
    cnt.append(now)

div2 = [e == 0 for e in cnt]


def f(li):
    ret = 0
    for e1, e2 in zip(li, div2):
        e1 %= 2
        ret ^= e1 * e2

    return ret


if f(a):
    ans = 1

elif 1 in a:
    ans = 0

else:
    a = [e // 2 for e in a]
    if f(a):
        ans = 2
    else:
        ans = 0

print(ans)


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

int main(){
    ll K,N;
    cin >> K >> N;
    ll A[N+1], dismax=0;
    cin >> A[0];
    A[N] = A[0]+K;
    for(int i=1;i<N;i++){
        cin >> A[i];
        if(A[i]-A[i-1]>dismax){
            dismax = A[i]-A[i-1];
        }
    }
    if(A[N]-A[N-1]>dismax){
        dismax = A[N]-A[N-1];
    }
    cout << K - dismax << endl;

}


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

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    for (;;) {
        if (a == 0)
            return b;
        b %= a;
        if (b == 0)
            return a;
        a %= b;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll res = 0;
    vector<vector<int>> diffSum(3, vector<int>(n));
    for (int j = 1; j < n-1; j++) {
        for (int k = j+1; k < n; k++) {
            if (s[j]==s[k]) {
                continue;
            }
            if ('R' != s[j] && 'R' != s[k]) {
                diffSum[0][j]++;
            } else if ('G' != s[j] && 'G' != s[k]) {
                diffSum[1][j]++;
            } else {
                diffSum[2][j]++;
            }
        }
    }

    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            if (s[i] == 'R') {
                res += diffSum[0][j];
                int k = j+(j-i);
                if (k >= n) continue;
                if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
                    res--;
                }
            } else if (s[i] == 'G') {
                res += diffSum[1][j];
                int k = j+(j-i);
                if (k >= n) continue;
                if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
                    res--;
                }
            } else {
                res += diffSum[2][j];
                int k = j+(j-i);
                if (k >= n) continue;
                if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
                    res--;
                }
            }
        }
    }
    
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3716
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N):
    for j in range(i + 1, N):
        if S[i] != S[j]:
            x = 2 * j - i
            if x < N and S[i] != S[x] and S[x] != S[j]:
                ans -= 1

print(ans)


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


int main()
{
    int N; cin >> N;
    vector<string> vec(N);
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        sort(s.begin(), s.end());
        vec[i] = s;
    }

    map<string, int> cnt_map;

    long long cnt = 0;
    for (int i = 0; i < N; i++) {
        cnt += cnt_map[vec[i]];
        cnt_map[vec[i]]++;
    }

    cout << cnt << endl;

}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
} 

const ll sqrtN = 512;
struct SqrtDecomposition {
  int N, K;
  vector<ll> data;
  vector<ll> bucket;
  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, (1LL<<31)-1);
    bucket.assign(K, -1);
  }
  void update(int s,int t,ll x) {
    for(int k=0;k<K;++k){
        int l=k*sqrtN,r=(k+1)*sqrtN;
        if (r <= s || t <= l)
          continue;
        if (s <= l && r <= t) {
            bucket[k]=x;
        } 
        else {
            for (int i = max(s, l); i < min(t, r); ++i) {
                if(bucket[k]!=-1){
                    for(int j=k*sqrtN;j<(k+1)*sqrtN;j++){
                        data[j]=bucket[k];
                    }
                    bucket[k]=-1;
                }
                data[i]=x;
            }
        }
    }
  }
  // [x, y)
  int get(int x) {
    int k=x/sqrtN;
    if(bucket[k]!=-1){
        for(int i=k*sqrtN;i<(k+1)*sqrtN;i++){
            data[i]=bucket[k];
        }
        bucket[k]=-1;
    }
    return data[x];
  }
};



int main(){
    ll n,q;cin >> n >> q;
    SqrtDecomposition sq(n);
    while(q--){
        ll a;cin >> a;
        if(a){
            ll s;cin >> s;
            cout << sq.get(s) <<endl;
        }
        else{
            ll s,t,x;cin >> s >> t>>x;t++;
            sq.update(s,t,x);
        }
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

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


int main()
{
  int n;
  cin >> n;
  for (int i = n; i < 1000; i++)
  {
    if(i % 111 == 0)
    {
      cout << i << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> graph;

int dist[110000];

int main() {
  int n;
  cin >> n;
  graph g(n);
  vi a(n), b(n);
  rep(i,n-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  int k = 0;
  int root;
  rep(i,n) {
    int s = g[i].size();
    k = max(k,s);
    if(k==s) root = i;
  }
  rep(i,n) dist[i] = -1;
  vi color_of_ver(n);
  queue<int> q;
  q.push(root);
  color_of_ver[root] = -1;
  dist[root] = 0;
  while(!q.empty()) {
    int v = q.front();
    q.pop();
    int c = 0;
    for(auto u : g[v]) {
      if(dist[u]!=-1) continue;
      if(c==color_of_ver[v]) c++;
      dist[u] = dist[v]+1;
      color_of_ver[u] = c;
      c++;
      q.push(u);
    }
  }
  cout << k << endl;
  rep(i,n-1) {
    int m;
    if(dist[a[i]]<dist[b[i]]) m = color_of_ver[b[i]];
    else m = color_of_ver[a[i]];
    cout << m+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a[4];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    string s, ans;
    cin >> s;
    rep(i, 0, 4) a[i] = s[i] - '0';
    rep(bit, 0, 1 << 4) {
        int sum = a[0];
        ans = to_string(a[0]);
        rep(i, 1, 4) {
            if (bit >> i & 1) {
                sum += a[i];
                ans += "+";
            }
            else {
                sum -= a[i];
                ans += "-";
            }
            ans += to_string(a[i]);
        }
        if (sum == 7) {
            ans += "=7";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 555;

int n, k, s;
int a[N], r[N];
vector<int> Div;

void Analyze() {
    for (int i = 1; i * i <= s; i++) if (!(s % i))
        Div.push_back(i), Div.push_back(s / i);
    sort(Div.begin(), Div.end(), greater<int>());
}

bool check(int m) {
    LL ls = 0, rs = 0, ret = -1;
    vector<int> v;
    for (int i = 1; i <= n; i++)
        if (a[i] % m) v.push_back(a[i] % m);
    sort(v.begin(), v.end());
    for (int x: v) ls += 1ll * x;
    ret = ls;
    for (int i = v.size() - 1; i >= 0; i--)
        ls -= 1ll * v[i], rs += 1ll * (m - v[i]),
        ret = min(ret, max(ls, rs));
    return (ret <= (LL)k);
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]),
        s += a[i];
    Analyze();
    for (int i = 0; i < Div.size(); i++)
        if (check(Div[i])) {
            cout << Div[i]; return 0;
        }
}


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

using namespace std;


int main() {

	int a = 0;
	int b = 0;
	int d = 0;
	int r = 0;
	double f = 0;

	cin >> a >> b;

	d = a / b;
	r = a % b;
	f = double(a) / double(b);

	cout << fixed;
	cout << setprecision(100);

	cout << d << " " << r << " " << f << endl;

	return 0;
}




Measured memory_bytes: 3240
#include <stdio.h>
int main(void){
    int a, b;
    int slot;
    int count = 0;
    scanf("%d %d", &a, &b);

    slot = a;

    for(count = 0; slot < b; count++){
        slot = a * (count+1) - count;
    }

    if(a >= b){
        count++;
    }

    if(b == 1){
        count = 0;
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

const int MAX_V = 200;

struct edge{
    int to, cap, cost, rev;
};

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];    // 頂点にflowを1流すときのコストの総和
int prevv[MAX_V], preve[MAX_V]; // prev_vertex, prev_edge
const int INF = 1<<30;

void add_edge(int from, int to, int cap, int cost){
    G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].push_back((edge){from, 0, -cost, (int)G[from].size()-1});
}

// flow from s to t, the amount of that is f
int min_cost_flow(int s, int t, int f){
    int res = 0;
    while(f > 0){
        for(int i = 0; i < V; i++)  dist[i] = INF;
        dist[s] = 0;
        bool update = true;
        // bellman-ford
        while(update){
            update = false;
            for(int v = 0; v < V; v++){
                if(dist[v] == INF)  continue;
                for(int i = 0; i < G[v].size(); i++){
                    edge &e = G[v][i];
                    if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
                        dist[e.to] = dist[v] + e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }
        if(dist[t] == INF){
            return -1;
        }
        int d = f;
        // 辺を逆に辿る、流せるだけ流す
        for(int v = t; v != s; v = prevv[v]){
            d = min(d, G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * dist[t];
        for(int v = t; v != s; v = prevv[v]){
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d; // 順方向に流したので-
            G[v][e.rev].cap += d;   // 逆方向に流したので+
        }
    }
    return res;
}

int main(){
    int e, f;
    cin >> V >> e >> f;
    for(int i = 0; i < e; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        add_edge(a, b, c, d);
    }
    cout << min_cost_flow(0, V-1, f) << endl;
    return 0;
}


Measured memory_bytes: 3200