akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, K;
vector<int> G[2010];
pii es[2010];

int rec(int pos, int prv, int dist){
    int sum = 0;
    if(dist > K / 2) sum++;
    for(int to : G[pos]){
        if(to == prv) continue;
        sum += rec(to, pos, dist + 1);
    }
    return sum;
}

int main(){

    cin >> N >> K;
    for(int i = 0; i < N - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        es[i] = pii(a, b);
    }

    int ans = 1 << 29;
    if(K % 2){
        for(int i = 0; i < N - 1; i++){
            int a = es[i].first;
            int b = es[i].second;
            ans = min(ans, rec(a, b, 0) + rec(b, a, 0));
        }
    }
    else{
        for(int i = 0; i < N; i++){
            ans = min(ans, rec(i, -1, 0));
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    double a, b, c;
    cin >> a >> b >> c;

    double rad = c / 180 * acos(-1);

    double h = b * sin(rad);
    double s = a * h / 2;
    double l = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    l += a + b;

    printf("%.7f\n%.7f\n%.7f\n", s, l, h);

    return 0;
}


Measured memory_bytes: 3452
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		String s = sc.next();
		sc.close();
		int a = 0;
		int z = s.length() - 1;
		boolean k = true;
		while(k){
			if(s.charAt(a) == 'A') break;
			a++;
		}
		k = true;
		while(k){
			if(s.charAt(z) == 'Z') break;
			z--;
		}
		ou.println(z - a + 1);
		ou.flush();
    }
}

Measured memory_bytes: 40620
N = parse(Int, readline(STDIN))
A, B = map(x -> parse(Int, x), split(readline(STDIN)))
P = map(x -> parse(Int, x), split(readline(STDIN)))
distributions = Dict("underA" => 0, "underB" => 0, "overB" => 0)

for p in P
    if p <= A
        distributions["underA"] += 1
    elseif p <= B
        distributions["underB"] += 1
    else
        distributions["overB"] += 1
    end
end

println(minimum(values(distributions)))

Measured memory_bytes: 111860
// 工夫0の山登り
#include<iostream>
#include<set>
#include<random>
#include<chrono>
using namespace std;
typedef long long ll;

int main(){
    auto start = std::chrono::system_clock::now(); 
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<int> randd(1,365);
    uniform_int_distribution<int> randq(1,26);
    
    int d;
    cin >> d;
    int c[27];
    for(int i = 1; i <= 26; i++) cin >> c[i];
    int s[365+1][27];
    for(int i = 1; i <= d; i++){
        for(int j = 1; j <= 26; j++){
            cin >> s[i][j];
        }
    }
    set<int> h[27];
    for(int i = 1; i <= 26; i++) h[i].insert(0), h[i].insert(d+1);
    int t[365+1];
    int last[27] = {};
    ll now = 0;
    for(int i = 1; i <= 365; i++){
        t[i] = i%26+1;
        h[t[i]].insert(i);
        now += s[i][t[i]];
        last[t[i]] = i;
        ll dec = 0;
        for(int j = 1; j <= 26; j++)    dec += c[j]*(i-last[j]);
        now -= dec;
    }

    while(1){
        auto nowt = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()-start).count();
        if(nowt > 1900)  break;
        int d = randd(mt), q = randq(mt);
        ll diff = 0;
        int bef = t[d];
        diff -= s[d][bef];
        h[bef].erase(d);
        {
            int from = *(--h[bef].lower_bound(d));
            int to = *(h[bef].lower_bound(d));
            diff -= (ll)c[bef]*(to-d)*(d-from);
        }
        t[d] = q;
        diff += s[d][q];
        h[q].insert(d);
        {
            int from = *(--h[q].lower_bound(d));
            int to = *(h[q].upper_bound(d));
            diff += (ll)c[q]*(to-d)*(d-from);
        }
        if(diff < 0){
            h[t[d]].erase(d);
            t[d] = bef;
            h[t[d]].insert(d);
        }else{
            now += diff;
        }
    }

    for(int i = 1; i <= d; i++) cout << t[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    string a;
    cin>>a;
    int ans=0;
if(a[0]=='1') ans++;
if(a[1]=='1') ans++;
if(a[2]=='1') ans++;
cout<<ans<<endl;
}

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

long long N;
//            num    , idx
vector<pair<long long, long long> > A;

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		long long a;
		cin >> a;
		A.push_back(make_pair(a, i+1));
	}
	sort(A.begin(), A.end());

	for(long long i = 0; i < N; i++){
		cout << A[i].second;
		if(i != N - 1){
			cout << " ";
		}else{
			cout << endl;
		}
	}
}


Measured memory_bytes: 2544
#!/usr/bin/env python3
from collections import deque

n, *a = map(int, open(0).read().split())
a.sort()
a = deque(a)
que = deque([])
que.append(a.pop())
c = 0
while a:
    c += que.popleft()
    nt = a.pop()
    que += [nt] * 2
print(c)


Measured memory_bytes: 99088
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

H,W=ma()
def f(H,W):
    ret=10**10+5
    for h in range(1,H):
        s1 = h*W
        s2,s3 = (H-h)//2*W,(H-h+1)//2*W
        ret=min(ret,max(s1,s2,s3) -min(s1,s2,s3) )
        s2,s3 = W//2*(H-h),(W+1)//2*(H-h)
        ret=min(ret,max(s1,s2,s3) -min(s1,s2,s3) )
    return ret
print(min(f(H,W),f(W,H)))


Measured memory_bytes: 9384
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

co = 0
for i in range(n):
    a,b = m()
    if a == b:
        co += 1
        if co >= 3:
            print("Yes")
            exit()
    else:
        co = 0
print("No")

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int count = 101;
    while (K > 0)
    {
        count--;
        if ((A % count == 0) and (B % count) == 0)
            K--;
    }

    cout << count;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int H, W;
    while(1){
    cin >> H;
    cin >> W;
    if(H == 0){
        break;
    }
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(i==0||i==H-1||j==0||j==W-1){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
h,w = map(int,input().split())
A = [list(input()) for i in range(h)]
B = [['']*(w+2)]*(h+2)
for i in range(h+2):
    for j in range(w+2):
        if i==0 or i==h+1:
            B[i][j]='#'
        elif j == 0 or j == w+1:
            B[i][j]='#'
        else:
            B[i][j]=A[i-1][j-1]
    print(*B[i],sep='')

Measured memory_bytes: 4596
from collections import deque

h, w = map(int, input().split())
a = ['#' * (w + 2)] * 2
a[1: 1] = ['#' + input() +  '#' for _ in range(h)]
r = 0
for i in range(1, h + 1):
  for j in range(1, w + 1):
    if a[i][j] == '.':
      b = list(map(list, a))
      q = deque()
      b[i][j] = 0
      q.append((i, j))
      while(q):
        i, j = q.popleft()
        r = max(r, b[i][j])
        d = 0
        for i1 in range(i - 1, i + 2):
          for j1 in range(j - d, j + 2, 2):                
            if b[i1][j1] == '.':
              b[i1][j1] = b[i][j] + 1
              q.append((i1, j1))
          d ^= 1
print(r)


Measured memory_bytes: 3316
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const WHITE: u32 = 0;
const GRAY: u32 = 1;
const BLACK: u32 = 2;
const INFINITY: u32 = 1000000;
const MAX: usize = 100;

fn dijkstra(m: &mut Vec<Vec<u32>>, n: usize) {
    let mut d: Vec<u32> = vec![0; MAX];
    let mut color: Vec<u32> = vec![0; MAX];
    for index in 0..n {
        d[index] = INFINITY;
        color[index] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;

    loop {
        let mut minv = INFINITY;
        let mut u: i32 = -1;
        for index in 0..n {
            if minv > d[index] && color[index] != BLACK {
                u = index as i32;
                minv = d[index]
            }
        }
        if u == -1 {
            break;
        }
        color[u as usize] = BLACK;
        for v in 0..n {
            if color[v] != BLACK && m[u as usize][v] != INFINITY {
                if d[v] > d[u as usize] + m[u as usize][v] {
                    d[v] = d[u as usize] + m[u as usize][v];
                    color[v] = GRAY
                }
            }
        }
    }
    for index in 0..n {
        print!("{} ", index);
        println!("{}", d[index]);
    }
}

fn main() {
    let n: usize = read();
    let mut m: Vec<Vec<u32>> = vec![vec![INFINITY; MAX]; MAX];
    for _ in 0..n {
        let u: usize = read();
        let k: usize = read();
        for _ in 0..k {
            let v: usize = read();
            let c: u32 = read();
            m[u][v] = c;
        }
    }

    dijkstra(&mut m, n);
}



Measured memory_bytes: 5052
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct V {
  double x, y;
  V(double x=0, double y=0): x(x), y(y) {}
  V& operator+=(const V& v) { x += v.x; y += v.y; return *this;}
  V operator+(const V& v) const { return V(*this) += v;}
  V& operator-=(const V& v) { x -= v.x; y -= v.y; return *this;}
  V operator-(const V& v) const { return V(*this) -= v;}
  V& operator*=(double s) { x *= s; y *= s; return *this;}
  V operator*(double s) const { return V(*this) *= s;}
  V& operator/=(double s) { x /= s; y /= s; return *this;}
  V operator/(double s) const { return V(*this) /= s;}
  double dot(const V& v) const { return x*v.x + y*v.y;}
  double cross(const V& v) const { return x*v.y - v.x*y;}
  double norm2() const { return x*x + y*y;}
  double norm() const { return sqrt(norm2());}
  
  int ort() const { // 象限
    if (abs(x) < eps && abs(y) < eps) return 0;
    if (y > 0) return x>0 ? 1 : 2;
    else return x<0 ? 3 : 4;
  }
  //偏角ソート
  bool operator<(const V& v) const {
    int o = ort(), vo = v.ort();
    if (o != vo) return o < vo;
    return cross(v) > 0;
  }
};
//ベクトルの入出力
istream& operator>>(istream& is, V& v) {
  is >> v.x >> v.y; return is;
}
ostream& operator<<(ostream& os, const V& v) {
  os<<"("<<v.x<<","<<v.y<<")"; return os;
}

int main(){
    ll n; cin >> n;
    vector<V> v(n);
    rep(i,n) cin >> v[i];
    sort(all(v));
    double ans = 0;
    rep(i,n){
        double x = 0, y = 0;
        rep(j,n){
            ll k = (i+j) % n;
            y += v[k].y;
            x += v[k].x;
            chmax(ans, sqrt(x*x + y*y));
        }
    }
    printf("%.10f\n",ans);
}

Measured memory_bytes: 3856
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

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



int main(){

    int n;
    cin >> n;
    pair<double,double> d[n];

    rep(i,0,n)cin >> d[i].ft >> d[i].sd;

    vector<int> v(n);
    rep(i,0,n)v[i] = i;

    double ans = 0;
    itn c = 0;
    do{
	double t = 0;
	rep(i,0,n-1){
	    t += sqrt(pow(d[v[i]].ft - d[v[i+1]].ft,2) + pow(d[v[i]].sd - d[v[i+1]].sd,2)); 
	}
	ans += t;
	c++;
    }while(next_permutation(v.begin(),v.end()));

    printf("%.10f\n",ans/c);
    return  0;
}


Measured memory_bytes: 256
n = int(input())
lst = []

for i in range(n):
    a = int(input())
    tmp = []
    for j in range(a):
        x,y = map(int,input().split())
        tmp.append((x,y))
    lst.append(tmp)

ans = 0
for i in range(2**n):
    tmp = '0'*n
    for j in range(n):
        if i >> j & 1:
            tmp = tmp[:j]+'1'+tmp[j+1:]
    
    flg = True
    
    for j in range(n):
        if tmp[j] =='1':
            for k in range(len(lst[j])):
                x,y = lst[j][k]
                if tmp[x-1] == str(y):
                    continue
                else:
                    flg = False
        else:
            continue
    if flg:
        ans = max(ans, list(tmp).count('1'))

print(ans)

Measured memory_bytes: 3064
import java.time.LocalDate;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		LocalDate ld = LocalDate.of(2017, 9, sc.nextInt());

			switch(ld.getDayOfWeek()) {
			case FRIDAY:
				System.out.println("fri");
				break;
			case MONDAY:
				System.out.println("mon");
				break;
			case SATURDAY:
				System.out.println("sat");
				break;
			case SUNDAY:
				System.out.println("sun");
				break;
			case THURSDAY:
				System.out.println("thu");
				break;
			case TUESDAY:
				System.out.println("tue");
				break;
			case WEDNESDAY:
				System.out.println("wed");
				break;
			default:
				break;

			}

		sc.close();
	}

}


Measured memory_bytes: 31928
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int dp[200010][62];
int main() {
	int64_t n, k; cin >> n >> k;
	int a[n];
	rep(i,n){
		cin >> a[i];
		a[i]--;
	}
	rep(i,n) dp[i][0] = a[i];
	for(int i = 1; i < 60; ++i) {
		for(int from = 0; from < n; ++from) {
			dp[from][i] = dp[dp[from][i - 1]][i - 1];
		}
	}
	int now = 0;
	for(int64_t i = 60; i >= 0; --i) {
		if(k >> i & 1) {
			now = dp[now][i];
		}
	}
	cout << now + 1 << '\n';
	return 0;
}

Measured memory_bytes: 52840
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n,k;
    cin >> n >> k;

    LL ans = 0;
    for(LL i = 1; i < n+1; i++){
        if(k == 1){
            ans += n*n;
        }else if((2*i)%k == 0){
            LL ok1 = n+2;
            LL ng1 = 0;
            while(abs(ok1-ng1) > 1){
                LL middle = (ok1+ng1)/2;
                if(middle*k-i > 0){
                    ok1 = middle;
                }else{
                    ng1 = middle;
                }
            }
            if(ok1 == n+2)continue;
            LL ok2 = 0;
            LL ng2 = n+2;
            while(abs(ok2-ng2) > 1){
                LL middle = (ok2+ng2)/2;
                if(middle*k-i <= n){
                    ok2 = middle;
                }else{
                    ng2 = middle;
                }
            }
            if(ok2 == 0)continue;
            ans += (ok2-ok1+1)*(ok2-ok1+1);
        }
    }

    cout << ans << endl;
    
    return 0;
}

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

int main(){
    int X;
    int Y;

    cin >> X >> Y;

    bool flag = false;
    for(int i = 0; i <= X; i++){
        int sum = i*2 + (X - i)*4;
        if(sum == Y)
        flag = true;
    }

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

Measured memory_bytes: 3636
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		for(int i = 1; i <= n; i++){
			if(isOddDigit(i)){
				count++;
			}
		}
		System.out.println(count);
		
	}
	
	public static boolean isOddDigit(int a){
		int num = a, count1 = 0;
		while(a != 0){
			int rem = a % 10;
			count1++;
			a /= 10;
		}
		if(count1 % 2 != 0){
			return true;
		}
		return false;
	}

	}

Measured memory_bytes: 22100
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;



int main() {
    int a, b;
    cin >> a >> b;
    if ((a+b)%2 == 0) cout << (a + b) / 2 << endl;
    else cout << (a + b) / 2 + 1 << endl;
    return 0;
}

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

int main() {
  constexpr int max = 1000000;
  vector<bool> isPrime(max, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < max; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < max; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3128
public class Main {


  private static void solve() {
    int n = ni();
    int[] w = na(n);
    
    int ret = Integer.MAX_VALUE;
    for (int i = 0; i < n - 1; i ++) {
      int left = 0;
      int right = 0;
      for (int j = 0; j <= i; j ++) {
        left += w[j];
      }
      for (int j = i + 1; j < n; j ++) {
        right += w[j];
      }
      ret = Math.min(ret, Math.abs(left - right));
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22868
class node():
    def __init__(self, id, parent, child, depth, type_t, sibling, height=0):
        self.id = id
        self.parent = parent
        self.child = child
        self.depth = depth
        self.type_t = type_t
        self.sibling = sibling
        self.height = height


def add(t, d, i, parent, depth, sibling):
    type_t = 'internal node'
    if d[i][1] == -1 and d[i][2] == -1:
        type_t = 'leaf'
    if depth == 0:
        type_t = 'root'

    child = []
    if d[i][1] >= 0:
        child.append(d[i][1])
    if d[i][2] >= 0:
        child.append(d[i][2])

    new_node = node(i, parent, child, depth, type_t, sibling)
    t.append(new_node)
    sib = -1
    if len(child) == 1:
        add(t, d, child[0], i, depth + 1, sib)
    elif len(child) == 2:
        add(t, d, child[0], i, depth + 1, child[1])
        add(t, d, child[1], i, depth + 1, child[0])


def calc_height(t, i):
    if len(t[i].child) == 0:
        return 0
    max_h = -1
    for c in t[i].child:
        max_h = max(max_h, calc_height(t, c))
    return max_h + 1


N = int(input())
tree = []
data = [[] for i in range(N)]
for i in range(N):
    data[i] = [int(i) for i in input().split()]

data.sort(key=lambda x: x[0])
root = [True for i in range(N)]
for d in data:
    for c in d[1:]:
        if c == -1:
            continue
        root[c] = False

root_index = root.index(True)
add(tree, data, root_index, -1, 0, -1)

tree.sort(key=lambda x: x.id)

for i in range(N):
    h = calc_height(tree, i)
    tree[i].height = h


for t in tree:
    print(f'node {t.id}: parent = {t.parent}, sibling = {t.sibling},'
          f' degree = {len(t.child)}, depth = {t.depth},'
          f' height = {t.height}, {t.type_t}')




Measured memory_bytes: 5636
package main

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

// Print Rectangle
func main() {
	sc := bufio.NewScanner(os.Stdin)
	s := ""
	for {
		sc.Scan()
		ary := strings.Split(strings.TrimSpace(sc.Text()), " ")
		H, _ := strconv.Atoi(ary[0])
		W, _ := strconv.Atoi(ary[1])
		if H == 0 && W == 0 {
			break
		}
		for i := 0; i < H; i++ {
			for j := 0; j < W; j++ {
				s += "#"
			}
			s += "\n"
		}
		s += "\n"
	}
	fmt.Print(s)
}



Measured memory_bytes: 16524
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

pub fn prime_factorize(mut n: usize) -> Vec<(usize, usize)> {
    let mut res: Vec<(usize, usize)> = Vec::new();
    let mut i: usize = 2;
    while i * i <= n {
        if n % i == 0 {
            let mut ex: usize = 0;
            while n % i == 0 {
                ex += 1;
                n = n / i;
            }
            res.push((i, ex));
        }
        i += 1;
    }
    if n != 1 {
        res.push((n, 1))
    }
    res
}


pub fn enum_divisors(n: usize) -> Vec<usize> {
    let mut res: Vec<usize> = Vec::new();
    let mut i: usize = 1;
    while i * i <= n {
        if n % i == 0 {
            res.push(i);
            if n / i != i {
                res.push(n / i)
            }
        }
        i += 1;
    }
    res.sort();
    res
}

#[fastout]
fn main() {
    input!{
        n: usize,
    }

    let mut ans = 0;
    let mut vec = vec![0; n+1];
    for i in 1..=n {
        for j in (i..=n).step_by(i) {
            vec[j] += 1;
        }
    }

    for i in 1..vec.len() {
        ans += i * vec[i];
    }

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


Measured memory_bytes: 80164
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = map(int, input().split())
a_lst = set(prime_factorize(a))
b_lst = set(prime_factorize(b))
print(len(a_lst & b_lst)+1)

Measured memory_bytes: 3064
import collections
import bisect
n=int(input())
a=collections.Counter(map(int,input().split()))
a=list(a.values())
a.sort()
b=[0]*len(a)
b[0]=a[0]
for i in range(len(a)-1):
    b[i+1]=b[i]+a[i+1]
s=sum(a)
ans=[i for i in range(0,n+1)]
ans=ans[::-1]
for t in range(1,n+1):
    ANS=ans[n+(-n//t):]
    for A in ANS:
        z=bisect.bisect_right(a,A)
        if A*t<=(b[z-1] if z>=1 else 0)+A*(len(b)-z):
            print(A)
            break

Measured memory_bytes: 122516
//use proconio::input;
//use std::io;
use std::io::stdin;
//use std::cmp::Ordering;
//use rand::Rng;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut v: Vec<_> = s.split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect();
    v.swap(0,1);
    v.swap(0,2);
    for i in v {
        print!("{} ", i);
    }
}

Measured memory_bytes: 4352
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

get_numbers_2(0, _, []).
get_numbers_2(N1, N2, [X|Xs]) :- 
    get_numbers(N2, X), 
    N12 is N1 - 1, 
    get_numbers_2(N12, N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

get_i_to_x_rbtree0(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 0, T2, T).

get_i_to_x_rbtree1(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 1, T2, T).

get_i_to_x_rbtree(0, _, T, T).
get_i_to_x_rbtree(N, I, T2, T) :-
    get_number(X),
    rb_insert(T2, I, X, T3),    
    N2 is N - 1,
    I2 is I + 1,
    get_i_to_x_rbtree(N2, I2, T3, T).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

all_pair(Xs, Zs) :- all_pair(Xs, [], Zs).

all_pair([], Zs, Zs).
all_pair([X|Xs], Zs, Zs2) :- 
    all_pair_sub(X, Xs, Zs, Zs3), 
    all_pair(Xs, Zs3, Zs2).

all_pair_sub(_, [], Zs, Zs).
all_pair_sub(X, [Y|Ys], Zs, Zs2) :-
    Zs3 = [(X,Y)|Zs],
    all_pair_sub(X, Ys, Zs3, Zs2).

f([], [], C, C).
f([X|Xs], [Y|Ys], C, Z) :-
    C2 is C + (X - Y) * (X - Y),
    f(Xs, Ys, C2, Z).

g((Xs, Ys)) :- f(Xs, Ys, 0, Z2), between(0, Z2, Z), Z2 =:= Z * Z.

main :-
    get_number(N, D),
    get_numbers_2(N, D, Xss),
    all_pair(Xss, Yss),
    include(g, Yss, Yss2),
    length(Yss2, L),
    writeln(L).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8240
N=int(input())
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
A = [bin(i)[2:].zfill(k) for i in A]
mod = 10**9+7
ans = 0
for i in range(k):
  cnt = sum([1 for j in A if j[i]=='1'])
  ans += cnt*(N-cnt)*(2**(k-i-1))
  ans %= mod 
print(ans)

Measured memory_bytes: 56264
string = list(input())
q = int(input())
for _ in range(q):
    cmd = input().split()
    op = cmd[0]
    a, b = map(int, cmd[1:3])
    if op == "print":
        print("".join(string[a:b + 1]))
    elif op == "reverse":
        string = string[:a] + list(reversed(string[a:b + 1])) + string[b + 1:]
    elif op == "replace":
        for s in list(cmd[3]):
            string[a] = s
            a += 1



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

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

    int N;
    string s, t;
    cin >> N >> s >> t;
    for(int i=N; i>=0; i--){
        string ss = s.substr(N - i, i);
        string tt = t.substr(0, i);
        if(ss==tt){
            cout << 2*N  - i << endl;
            return 0;
        }
    }

	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;


ll comb(ll n, ll r){
  ll res=1;
    for(ll i=0;i<r;i++){
      res*=n-i;
    }
  for(ll i=0;i<r;i++){
    res/=i+1;
  }
  return res;
}

int main(){
  int n;
  cin>>n;
  vector<string>s(n);
  for(int i=0;i<n;i++)cin>>s[i];
  for(int i=0;i<n;i++){
    sort(s[i].begin(),s[i].end());
  }
  sort(s.begin(),s.end());
  ll ans=0;
  ll count=1;
  for(int i=1;i<n;i++){
    //cout<<count<<endl;
    if(s[i-1]==s[i]){
      count++;
      if(i==n-1){
        
        ans+=comb(count,2);
      }
    }
    if(s[i-1]!=s[i]){
      
      if(count>=2){
        ans+=comb(count,2);
      }
      count=1;
      
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ll N,ans=0;
	cin >> N;
	vector<ll> a(N),gcdb(N),gcdf(N);
	FOR(i,0,N)cin>>a[i];
	gcdf[0] = a[0];
	FOR(i,1,N){
		gcdf[i] = gcd(a[i],gcdf[i-1]);
	}
	gcdb[N-1] = a[N-1];
	FORR(i,0,N-1){
		gcdb[i] = gcd(a[i],gcdb[i+1]);
	}
	ans = max(gcdb[1],gcdf[N-2]);
	FOR(i,1,N-1){
		ans = max(ans,gcd(gcdb[i+1],gcdf[i-1]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
	int H, W, i, j;
	
	do {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
			break;
		
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				if ((i + j) % 2)
					putchar('.');
				else
					putchar('#');
			}
			putchar('\n');
		}
		putchar('\n');
	} while (1);
	
	return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<unordered_map>
#include<utility>
#include<algorithm>

using namespace std;

typedef long long unsigned int ll;

ll  cmb(ll n) {
	return (n*(n - 1)) / 2;
}

int main(void) {
	ll n, m;
	unordered_map<ll, ll> b;
	cin >> n >> m;
	ll md(0);
	for (int i(0); i < n; i++) {
		ll tmp;
		cin >> tmp;
		md += tmp;
		md %= m;
		b[md]++;
	}
	ll ans(0);
	b[0]++;
	for (auto itr = b.begin(), e = b.end(); itr != e; itr++) {
		ll tmp = itr->second;
		ans += cmb(tmp);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3596
#include <cmath>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int N, M, x[55], y[55], p[55], q[55];
int md(int i, int j) {
	return abs(x[i] - p[j]) + abs(y[i] - q[j]);
}
int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
	for (int i = 0; i < M; i++)  cin >> p[i] >> q[i];
	for (int i = 0; i < N; i++) {
		int r = 999999999, ptr = -1;
		for (int j = 0; j < M; j++) {
			if (md(i, j) < r) {
				r = md(i, j);
				ptr = j;
			}
		}
		cout << ptr + 1 << endl;
	}
	return 0;
}

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

const int MAX_N = 123456*2;

bool isPrime[MAX_N];

void make() {
  fill(isPrime, isPrime+MAX_N, true);
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i < MAX_N; ++i) {
    if(!isPrime[i]) continue;
    for(int j = i*2; j < MAX_N; j += i)  {
      isPrime[j] = false;
    }
  }
}

int main() {
  make();
  int n;
  while((cin >> n) && n) {
    int cnt = 0;
    for(int i = n+1; i <= n*2; ++i) {
      if(isPrime[i]) ++cnt;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
plst = list(map(int,input().split()))
plst_sort = sorted(plst)
cnt = 0
for i in range(len(plst)):
    if plst[i] != plst_sort[i]:
        cnt += 1
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 2940
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n,K;
    scanf("%d%d", &n, &K);
    vector<long double> a(n), s(n+1);
    int i;
    for(i=0; i<n;  i++) {
        int tmp;
        scanf("%d", &tmp);
        a[i]=(long double)(1+tmp)/2;
        s[i+1]=s[i]+a[i];
    }
    long double ans=-HUGE_VAL;
    for(i=0; i<=n-K; i++) {
        long double tmp=s[i+K]-s[i];
        ans=MAX(ans,tmp);
    }
    printf("%.10Lf\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		String s = sc.next();
		int x = 0;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'I') {
				x++;
			} else if (s.charAt(i) == 'D') {
				x--;
			}
			ans = Math.max(ans, x);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
//     String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu[3]);


//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}

if(nyu.contains("111") || nyu.contains("222") ||
nyu.contains("333") ||  nyu.contains("444") ||
nyu.contains("555") || nyu.contains("666") || 
nyu.contains("777") || nyu.contains("888") || 
nyu.contains("999") || nyu.contains("000")   ){
//double res=Math.ceil((AB)/2);

System.out.println("Yes");
//}else if(A+B>C+D){
//System.out.println("Left");

}else{
System.out.println("No");

}




	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define ll long long 
#define P pair<int,int>
#define PP pair<P,int>
using namespace std;
int inf = 1ll<<30;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
    int h,w;
    cin >> h >> w;
    char g[1005][1005];
    queue<PP>que;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++) {
        cin >> g[i][j];
        if(g[i][j] == '#') que.push(PP{P{i, j}, 0});
    }

    int ans;
    while(!que.empty()){
        PP p = que.front(); que.pop();
        ans = p.second;
        for(int i=0;i<4;i++){
            int nx = p.first.first + dx[i];
            int ny = p.first.second + dy[i];
            if(!(0 <= nx && 0 <= ny && h > nx && w > ny)) continue;
            if(g[nx][ny] == '#') continue;
            g[nx][ny] = '#';
            que.push(PP{P{nx, ny}, ans + 1});
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 13328
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    for(int i=k;i<n;i++)
    {
        if(ar[i]<=ar[i-k])
        cout<<"No\n";
        else
        cout<<"Yes\n";
    }
}

Measured memory_bytes: 5236
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#define maxn 1005
using namespace std;

int dp[maxn][maxn];
int len1, len2;
string s1, s2;

int lcs()
{
	memset(dp, 0, sizeof(dp));
	for(int i=1;i<=len1;i++)
		for (int j = 1; j <= len2; j++)
		{
			if (s1[i] == s2[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	return dp[len1][len2];
}

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		cin >> s1 >> s2;
		len1 = s1.size(), len2 = s2.size();
		s1 = ' ' + s1;
		s2 = ' ' + s2;
		cout << lcs() << endl;
	}
	return 0;
}

Measured memory_bytes: 7172
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  S=input()
  A=int(S[:2])
  B=int(S[2:])
  if 1<=A<=12:
    if 1<=B<=12:
      print("AMBIGUOUS")
    else:
      print("MMYY")
  else:
    if 1<=B<=12:
      print("YYMM")
    else:
      print("NA")
      
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0; i<x; i++)
#define repn(i,x) for(int i=1; i<=x; i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main() {
    int n;
    cin >> n;
    cout << (n - 2) * 180;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

    int Q,H,S,D,N;

    public void solve() {
        Q = nextInt();
        H = nextInt();
        S = nextInt();
        D = nextInt();
        N = nextInt();

        long oneOfHalf = Math.min(2 * Q,H);
        long one = Math.min(oneOfHalf * 2,S);
        long two = Math.min(one * 2,D);

        long ans = N / 2 * two;
        ans += N % 2 * one;

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23124
#include <cstdio>
#include <cctype>
#define rr register
using namespace std;
const int N=3011,mod=1000000007,inv2=(mod+1)>>1;
int n,Q,a[N],dp[N][N],f[N][N],ans,mi;
inline signed iut(){
	rr int ans=0; rr char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
	return ans;
}
inline signed mo(int x,int y){return x+y>=mod?x+y-mod:x+y;}
signed main(){
	n=iut(),Q=iut(),mi=1;
	for (rr int i=1;i<=n;++i) a[i]=iut();
	for (rr int i=1;i<=n;++i)
	for (rr int j=1;j<=n;++j) dp[i][j]=a[i]>a[j];
	for (rr int i=1;i<=Q;++i,mi=mo(mi,mi)){
		rr int x1=iut(),x2=iut();
		for (rr int j=1;j<=n;++j) if (j!=x1&&j!=x2)
			f[x1][j]=f[x2][j]=1ll*inv2*mo(dp[x1][j],dp[x2][j])%mod,
			f[j][x1]=f[j][x2]=1ll*inv2*mo(dp[j][x1],dp[j][x2])%mod;
		for (rr int j=1;j<=n;++j) if (j!=x1&&j!=x2)
		    dp[x1][j]=f[x1][j],dp[x2][j]=f[x2][j],
		    dp[j][x1]=f[j][x1],dp[j][x2]=f[j][x2];
		dp[x1][x2]=dp[x2][x1]=1ll*inv2*mo(dp[x1][x2],dp[x2][x1])%mod;
	}
	for (rr int i=1;i<n;++i)
	for (rr int j=i+1;j<=n;++j)
	    ans=mo(ans,dp[i][j]);
	return !printf("%d\n",1ll*ans*mi%mod);
}

Measured memory_bytes: 72200