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

int isPal(char str[],int l,int h)
{
    // Start from leftmost and rightmost corners of str

    // Keep comparing characters while they are same
    while (h > l)
    {
        if (str[l++] != str[h--])
        {

            return 0;
        }
    }
    return 1;

}


int main()
{
    char str[1000];
    cin>>str;
    int l = strlen(str);
    /*cout<<isPal(str,0,l-1);
    cout<<isPal(str,0,((l-1)/2)-1);
    cout<<isPal(str,((l+3)/2)-1,l-1);
    */
    if(isPal(str,0,l-1)==1&&isPal(str,0,((l-1)/2)-1)==1&&isPal(str,((l+3)/2)-1,l-1)==1)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    unsigned int havingCardNum;
    char havingCardMark;
    unsigned int havingCardRank;
    bool isHavingCard[4][13];
    
    
    for(int i = 0; i < 4; ++i) {
        for(int j = 0; j < 13; ++j) {
            isHavingCard[i][j] = false;
        }
    }
    
    cin >> havingCardNum;
    
    for(int i = 0; i < havingCardNum; ++i) {
        cin >> havingCardMark >> havingCardRank;
        switch(havingCardMark) {
            case 'S':
                isHavingCard[0][havingCardRank - 1] = true;
                break;
            case 'H':
                isHavingCard[1][havingCardRank - 1] = true;
                break;
            case 'C':
                isHavingCard[2][havingCardRank - 1] = true;
                break;
            case 'D':
                isHavingCard[3][havingCardRank - 1] = true;
                break;
        }
    }
    
    for(int i = 0; i < 4; ++i) {
        for(int j = 0; j < 13; ++j) {
            if(isHavingCard[i][j] == false) {
                switch(i) {
                case 0:
                    cout << 'S' << ' ' << (j + 1) << endl;
                    break;
                case 1:
                    cout << 'H' << ' ' << (j + 1) << endl;
                    break;
                case 2:
                    cout << 'C' << ' ' << (j + 1) << endl;
                    break;
                case 3:
                    cout << 'D' << ' ' << (j + 1) << endl;
                    break;
                }
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;


int main() {
    int X,m=0;
    cin>>X;
    for (int i = 0; X >4 ; ++i) {
        if(X%500==0){
            m+=(X/500)*1000;
            break;
        }else if (X%500<5) {
            X-=X%500;
            m+=X/500*1000;
            break;
        }else{
            X-=5;
            m+=5;
        }
    }
    cout<<m;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int A,B,s_size;
    string s;
    cin >> A >> B >> s;
    s_size = s.size();
    bool fla = true;

    for(int i = 0;i < s_size;i++){
        if(i < A){
            if(s.at(i) < 48 or s.at(i) > 57){
                fla = false;
                break;
            }
        }else if(i == A and s.at(i) != '-'){
            fla = false;
            break;
        }else if(i > A){
            if(s.at(i) < 48 or s.at(i) > 57){
                fla = false;
                break;
            }
        }
    }

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

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int n;
main()
{
	cin>>n;
	for(int i=0;i<1<<n;i++)
	{
		cout<<i<<":";
		for(int j=0;j<n;j++)if(i>>j&1)cout<<" "<<j;
		cout<<endl;
	}
}



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

using namespace std;




int main()
{
	int A, B;

	cin >> A >> B;

	if (A < 10 && B < 10) {
		cout << A * B;
	}
	else {
		cout << -1;
	}


	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! {
        n: usize,
        es: [(usize1, usize1); n-1],
        cs: [i64; n],
    }

    let mut g = vec![vec![]; n];

    for &(f, t) in es.iter() {
        g[f].push(t);
        g[t].push(f);
    }

    let mut cs = cs;
    cs.sort();
    cs.reverse();

    let sum = cs.iter().sum::<i64>() - cs[0];
    let mut dest = vec![0; n];

    dfs(0, None, &g, &mut cs, &mut dest);

    println!("{}", sum);
    for i in 0..dest.len() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", dest[i]);
    }
    println!("");
}

fn dfs(cur: usize, prev: Option<usize>, g: &Vec<Vec<usize>>, cs: &mut Vec<i64>, dest: &mut Vec<i64>) {
    for &next in g[cur].iter() {
        if prev == Some(next) {
            continue;
        }
        dfs(next, Some(cur), g, cs, dest);
    }

    dest[cur] = cs.pop().unwrap();
}


Measured memory_bytes: 5244
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

LL A,B,n,x,ans;

int main() {
	cin>>A>>B>>n;
	x=min(B-1,n);
	ans=(A*x)/B;
	cout<<ans<<endl;
	return 0;
}



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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;
typedef long long int ll;

const int MOD = 1000000007;

int main() {
    int A, B;
    cin >> A >> B;
    if (A + B >= 10) {
        printf("%s\n", "error");
        return 0;
    }
    printf("%d\n", A+B);
    return 0;
}


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

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

    string ans;
    if (S == "Sunny")  ans = "Cloudy";
    if (S == "Cloudy") ans = "Rainy";
    if (S == "Rainy")  ans = "Sunny";

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


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=1e6;
ll d[mm];
ll p=1e9;
int main()
{
	ll n,m,i,j,k,kk,a,b,t,x;
	cin>>x;
    for(i=-300;i<=300;i++)
    for(j=-300;j<=300;j++)
    {
    	if(i*i*i*i*i-j*j*j*j*j==x)
    	{
    	cout<<i<<' '<<j<<endl;return 0;}
	}


}

Measured memory_bytes: 3620
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int a, b, k;
    scan(a, b, k);

    int[] d;

    foreach (i ; 1 .. min(a, b) + 1) {
        if (a % i == 0 && b % i == 0) {
            d ~= i;
        }
    }

    d.sort!"a > b"();

    writeln(d[k - 1]);
}




int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {writeln(b ? "Yes" : "No");}
void YES(bool b) {writeln(b ? "YES" : "NO");}
T[] readArr(T)() {return readln.split.to!(T[]);}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int main(){
  string S;
  cin >> S;
  
  string ACGT="ACGT";
  
  int count=0;
  int ans=0;
  
  for(int i=0; i<S.size();i++){
    bool isACGT=false;
    for(int j=0; j<ACGT.size(); j++){
      if(S[i]==ACGT[j]){
        isACGT=true;
      }
    }
    if (isACGT==true){
      count++;
      ans=max(ans, count);
    }
    else count=0;
  }
    cout << ans << endl;
  }
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int S = sc.nextInt();
        int count = 0;
        for (int i = 0 ; i <= K ; i++ ) {
            for (int j = 0 ; j <= K ; j++ ) {
                if (S - i - j >= 0  && S - i - j <= 3 * K && S - i - j <= K) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }

}

Measured memory_bytes: 22996
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    sm = sum(A)
    A.sort(reverse=True)
    if A[M - 1] >= sm / (4 * M):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int MAX = 1000000;
    ll p[MAX+1];
    rep(i, MAX+1) p[i] = i+1;
    p[0] = 0;
    rep2(i, 1, MAX){
        for(int j = 2; i*j <= MAX; j++){
            p[i*j] -= p[i];
        }
    }
    ll sum[MAX+1];
    sum[0] = 0;
    rep2(i, 1, MAX+1) sum[i] = sum[i-1]+p[i];
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        cout << sum[n] << endl;
    }
}


Measured memory_bytes: 18604
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        int x = sc.nextInt();
        
        if (x == 1)
            System.out.println(0);
        else
            System.out.println(1);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 32688
// I/O
#include <iostream>

// data structures
#include <queue>
#include <set>
#include <vector>

// manipulations
#include <algorithm>

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define for_lowercase(c) for(int c='a';c<='z';++c)
#define for_uppercase(c) for(int c='A';c<='Z';++c)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;
template<class T> bool is_odd (T x){ return   x%2 ; }
template<class T> bool is_even(T x){ return !(x%2); }

int main() {
    std::ios::sync_with_stdio(false);
    LLI N;
    std::cin >> N;

    VI a(3*N);
    rep(i,3*N)
        std::cin >> a[i];

    VI max_left(N+1),min_right(N+1);
    std::priority_queue<LLI> left,right;
    LLI sum_left=0,sum_right=0;
    rep(i,N)
    {
        left.push(-a[i]);
        sum_left += a[i];
        right.push(a[2*N+i]);
        sum_right += a[2*N+i];
    }
    max_left[0] = sum_left;
    min_right[N] = sum_right;
    rep(i,N)
    {
        sum_left += a[N+i];
        left.push(-a[N+i]);
        sum_left -= -left.top();
        left.pop();
        max_left[i+1] = sum_left;

        sum_right += a[2*N-1-i];
        right.push(a[2*N-1-i]);
        sum_right -= right.top();
        right.pop();
        min_right[N-i-1] = sum_right;
    }

    VI diff(N+1);
    rep(i,N+1)
        diff[i] = max_left[i] - min_right[i];

    std::cout << *std::max_element(ALL(diff)) << std::endl;
    return 0;
}

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

#define INF (1 << 29)
#define rep2(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define EPS 1e-10

using namespace std;

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

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

int main()
{
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    ll res = 0;
    rep(i,n) if(a[i]>x) {
        res += a[i]-x;
        a[i] = x;
    }

    rep(i,n-1) if(a[i]+a[i+1] > x){
        res += a[i+1]+a[i]-x;
        a[i+1] = x-a[i];
    }

    cout << res << endl;
    return 0;
}



Measured memory_bytes: 640
use itertools::iproduct;
use proconio::input;

fn main() {
    input!(r: usize, c: usize, goods: [(usize, usize, u64)]);

    let mut val = array![0; r + 1, c + 1];
    for &(r, c, v) in &goods {
        val[r][c] = v;
    }

    let mut dp = array![0; r + 1, c + 1, 4];
    for (i, j, k) in iproduct!(1..=r, 1..=c, (0..=3).rev()) {
        max_assign!(dp[i][j][0], dp[i - 1][j][k]);
        max_assign!(dp[i][j][k], dp[i][j - 1][k]);
        if val[i][j] != 0 {
            max_assign!(dp[i][j][1], dp[i - 1][j][k] + val[i][j]);
            if k > 0 {
                max_assign!(dp[i][j][k], dp[i][j - 1][k - 1] + val[i][j]);
            }
        }
    }

    println!("{}", dp[r][c].iter().max().unwrap())
}

#[macro_export]
macro_rules! array {
    ($v:expr; $l:expr, $($r:expr),*) => { vec![array!($v; $($r),*); $l] };
    ($v:expr; $l:expr) => { vec![$v; $l] };
    () => { vec![] };
}

#[macro_export]
macro_rules! max_assign {
    ($x:expr, $y:expr) => {{
        let rhs = $y;
        if $x < rhs {
            $x = rhs
        }
    }};
}


Measured memory_bytes: 713600
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val n = readInt
  var taro = 0
  var hanako = 0

  for(i <- 1 to n) {
    val l = readLine.split(" ")

    if(l(0) > l(1)) taro += 3
    else if(l(0) < l(1)) hanako += 3
    else { taro += 1;hanako += 1 }
  }

  println(taro + " " + hanako)
}

Measured memory_bytes: 44088
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int D, Q, x[131072], ls, rs, es, a, b; vector<int> seg[262144];
inline int query(int k, int l, int r) {
	if (r <= ls || rs <= l) return 0;
	if (ls <= l && r <= rs) return lower_bound(seg[k].begin(), seg[k].end(), b) - lower_bound(seg[k].begin(), seg[k].end(), a);
	int lc = query(2 * k, l, (l + r) / 2);
	int rc = query(2 * k + 1, (l + r) / 2, r);
	return lc + rc;
}
int main() {
	scanf("%d", &D);
	for (int i = 0; i < D; i++) {
		scanf("%d", &x[i]);
		int t = i + 131072;
		while (t > 0) {
			seg[t].push_back(x[i]);
			t >>= 1;
		}
	}
	for (int i = 1; i < 262144; i++) {
		if (seg[i].size() > 1) {
			sort(seg[i].begin(), seg[i].end());
		}
	}
	scanf("%d", &Q);
	for (int i = 0; i < Q; i++) {
		scanf("%d%d%d", &ls, &rs, &es); ls--;
		a = min(x[ls], x[rs - 1]) - es;
		b = max(x[ls], x[rs - 1]) + es + 1;
		printf("%d\n", rs - ls - query(1, 0, 131072));
	}
	return 0;
}

Measured memory_bytes: 21228
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

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

  vector<int> v;
  REP(i,n){
    int t;
    scanf("%d", &t);
    v.pb(t);
  }

  int num_4 = 0, num_2 = 0, num_o = 0;
  REP(i,n){
    if(v[i] % 4 == 0){
      num_4++;
    }else if(v[i] % 2 == 0){
      num_2++;
    }else{
      num_o++;
    }
  }

  if(num_2 > 0){
    if(num_4 >= num_o){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }else{
    if(num_4 + 1 >= num_o){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }
  return 0;
}



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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    ll x, y;
    cin >> x >> y;
    if (x == 0 and y == 0) {
        cout << 0 << endl;
    }
    else if (x*-1 == y or x == y*-1) {
        cout << 1 << endl;
    }
    else if (x >= 0 and y >= 0) {
        ll ans = 0;
        if (y >= x) {
            ans = y - x;
        }
        else {
            if (y == 0) {
                ans = x + 1;
            }
            else {
                ans = x - y + 2;
            }
        }
        cout << ans << endl;
    }
    else if (x <= 0 and y >= 0) {
        if (y == 0) {
            cout << abs(x) << endl;
        }
        else if (y >= abs(x)) {
            cout << y-abs(x)+1 << endl;
        }
        else {
            cout << abs(x)-y+1 << endl;
        }
    }
    else if (x >= 0 and y <= 0) {
        if (x >= abs(y)) {
            cout << x-abs(y)+1 << endl;
        }
        else {
            cout << abs(y)-x+1 << endl;
        }
    }
    else if (x <= 0 and y <= 0) {
        ll ans = 0;
        if (y == 0) {
            ans = abs(x);
        }
        else if (x <= y) {
            ans = abs(x)-abs(y);
        }
        else {
            ans = abs(y) - abs(x) + 2;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split())
def one_14(num):
  if num==1:
    return 14
  else:
    return num
a=one_14(a)
b=one_14(b)
if a > b:
  print("Alice")
elif a < b:
  print("Bob")
else:
  print("Draw")


Measured memory_bytes: 2940
S1,S2,S3 = input()
S = [S1,S2,S3]
T1,T2,T3 = input()
T = [T1,T2,T3]

ans_count = 0

for i in range(0,3,1):
  if S[i] == T[i]:
    ans_count += 1
    
print(ans_count)
    

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (v <= w) {
        cout << "NO" << endl;
        return 0;
    } else {
        ll dist = abs(a - b);
        if (t * (v - w) >= dist) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main(void)
{
   int h,w;
   cin>>h>>w;
   string s[h];
   for(int  i = 0;i<h;i++)
    cin>>s[i];
  int dp[h][w];
  
  for(int  i = 0;i<h;i++)
  {
     for(int j = 0;j<w;j++)
     {
         if(i ==0 && j==0){
           dp[i][j]= 1;    
           continue; 
         }

         if(s[i][j]=='#')
          dp[i][j] = 0;
         else{
          dp[i][j] = (((i-1>=0)?dp[i-1][j]:0)+((j-1>=0)?dp[i][j-1]:0))%mod;
           
            }

     }
  }

  cout<<dp[h-1][w-1]<<endl; 
}

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

using namespace std;

int main() {
   int n, k, ans = 0, tmp;
   
   cin >> n >> k;

   int x[100];
   
   for(int i=0; i<n; i++) cin >> x[i];
   for(int i=0; i<n; i++) {
     tmp = min(x[i], k - x[i]);
     ans += tmp;
   }
   cout << ans * 2 << endl;
}

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

int main(){
    double A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int water = 0, sugar = 0;
    double ret = 0;
    for (int i = 0; i <= F/100/A; i++)
    {
        for (int j = 0; j <= (F-100*A*i)/100/B; j++)
        {
            int tmp = F - (i*100*A + j*100*B);
            for (int k = 0; k <= (tmp/C); k++)
            {
                for (int l = 0; l <= (tmp-k*C)/D; l++)
                {
                    if(((i*100*A + j*100*B)/100) * E >= k*C + l*D)
                    {
                        if(i == 0 && j == 0 && k == 0 && l == 0) continue;
                        if((k*C + l*D)*100/(i*A + j*B + k*C + l*D) >= ret)
                        {
                            water = i*100*A + j*100*B;
                            sugar = k*C + l*D;
                            ret = (k*C + l*D)*100 / (i*A + j*B + k*C + l*D);
                        }
                    }
                }
                
            }
            
        }
        
    }
    
    cout << sugar + water << " " << sugar << endl;



    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;


int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    bool map[21][21];
    for (int i = 0; i < 21; i++)
      for (int j = 0; j < 21; j++)
	map[i][j] = false;
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      map[x][y] = true;
    }
    int m;
    cin >> m;
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    int x, y;
    x = y = 10;
    map[x][y] = false;
    for (int i = 0; i < m; i++) {
      char d; int l;
      cin >> d >> l;
      int j = 0;
      switch(d) {
      case 'N': j = 0; break; 
      case 'E': j = 1; break;
      case 'S': j = 2; break;
      case 'W': j = 3; break;
      }
      for (int k = 0; k < l; k++) {
	x += dx[j]; y += dy[j];
	map[x][y] = false;
      }
    }
    bool flag = false;
    for (int i = 0; i < 21; i++) {
      for (int j = 0; j < 21; j++) {
	if (map[i][j]) {
	  flag = true;
	  break;
	}
      }
    }
    if (flag)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll dp[105][305][105];
int main(){
  ll n,W;
  cin>>n>>W;
  memset(dp,-1,sizeof(dp));
 
  vll w(n),v(n);
  rep(i,n){
    cin>>w[i]>>v[i];
  } ll k=w[0];
  FOR(i,1,n){
    w[i]-=w[0];
  }
  w[0]=0;
  dp[0][0][0]=0;
  rep(i,n){
    rep(j,300){
      rep(z,101){
        if(dp[i][j][z]>=0)chmax(dp[i+1][j][z],dp[i][j][z]);
        if(dp[i][j][z]>=0&&z+1<=100)chmax(dp[i+1][j+w[i]][z+1],dp[i][j][z]+v[i]);
      }
    }
  }
  ll ans=0;
 rep(i,300){
   rep(j,101){
     if(k*j+i<=W)ans=max(ans,dp[n][i][j]);
   }
 }
  COUT(ans);
}

Measured memory_bytes: 26624
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        
        for(int i=0; a!=0; i++){
            System.out.println("Case "+(i+1)+": "+a);
            a = scan.nextInt();
        }
    }
}


Measured memory_bytes: 41344
import math

n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

D = [0,0,0]

# P = 1-3
for p in range(1,4):
    for i in range(n):
        D[p-1] += abs(x[i] - y[i]) ** p

    D[p-1] = D[p-1] ** (1 / p)

# P = inf
Dinf = abs(x[0] - y[0])
for i in range(n):
    Dinf = max(Dinf,abs(x[i] - y[i]))

# output
print(D[0])
print(D[1])
print(D[2])
print(Dinf)


Measured memory_bytes: 5696
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

#define PC __builtin_popcountll
#define subset(a, b) (((a) & (b)) == (a))

int main() {
	IN(int, n, k);
	IN(LL, s, t);
	vector<LL> a(n);
	cin >> a;
	
	if_not(subset(s, t)) { OUT(0); exit(0); }
	
	{
		vector<LL> b;
		RF(e, a) { if(subset(s, e) && subset(e, t)) { b.PB(e); } }
		a = b;
		n = SI(a);
		setmin(k, n);
		s ^= t;
	}
	
	vector<LL> f(n + 1);
	inc1(i, n) {
		LL v = 1;
		inc1(j, min(i, k)) {
			v *= i - (j - 1);
			v /= j;
			f[i] += v;
		}
	}
	
	LL ans = f[n];
	incID(b, 1, 1 << 18) {
		if_not(subset(b, s)) { continue; }
		
		map<LL, LL> c;
		RF(e, a) { c[e & b]++; }
		RF(e, c) { ans -= (PC(b) % 2 == 0 ? -1 : +1) * f[e.SE]; }
	}
	OUT(ans);
}


Measured memory_bytes: 3612
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0

for i in range(0,a+1):
  for j in range(0,b+1):
    for k in range(0,c+1):
      if i*500 + j*100 + k*50 == x:
        count += 1
        
        
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long dp[101][100005];
int main(){
    int n,w;
    cin >> n >> w;
    vector<pair<int,int> > v(n+1);
    int s=0;
    for(int i=1;i<=n;i++){
        int w,va;
        cin >> w >> va;
        v[i]={w,va};
        s+= va;
    }
    // no of elements  value min wt
    for(int i=0;i<=s;i++){ dp[1][i]= INT_MAX;}
    dp[1][v[1].second]=v[1].first;
    dp[1][0]=0;
    for(int i=2;i<=n;i++){
        for(int j=s;j>=0;j--){
            dp[i][j]= INT_MAX;
            dp[i][j]=dp[i-1][j];
            if(j-v[i].second >=0)
            dp[i][j]=min(dp[i][j], dp[i-1][j-v[i].second]+v[i].first);
        }
    }
    int ans=0;
    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=s;j++)
    //     {
    //         if(dp[i][j]==INT_MAX) cout << "oo ";
    //         else cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    for(int i=0;i<=s;i++){
        if(dp[n][i]<=w)
            ans= i;
    }
    cout << ans;
}

Measured memory_bytes: 78336
class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n
        self.u = n
    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        self.u -= 1
        return True
    def same(self, x, y):
        return self.root(x) == self.root(y)
    def size(self, x):
        return -self.d[self.root(x)]
    def num_union(self):
        return self.u


import sys
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
E = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j, (a, b) in enumerate(E):
        if i == j:
            continue
        uf.unite(a, b)
    if uf.num_union() != 1:
        ans += 1
print(ans)


Measured memory_bytes: 9268
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        String[] arr = new String[2];
        for(int i = 0;i < arr.length;i++) {
            arr[i] = scanner.nextLine();
        }

        int n = Integer.parseInt(arr[0]);

        String[] line2 = arr[1].split(" ");

        int[] a = new int[line2.length];
        for (int i = 0; i < line2.length; i++) {
            a[i] = Integer.parseInt(line2[i]);
        }

        int[] answers = new int[n];
        for (int id : a) {
            answers[id - 1] ++;
        }

        for (int answer : answers) {
            System.out.println(answer);
        }

        scanner.close();
    }
}


Measured memory_bytes: 75300
#include <cstdio>

using namespace std;
int n,i,p,j;
long long s;
char x,a[6][56];
int main()
{
    scanf ("%d\n", &n);
    for (i=1;i<=2;i++)
    {
        for (j=1;j<=n;j++)
            scanf ("%c", &a[i][j]);
        scanf ("%c", &x);
    }
    if (a[1][1]==a[2][1])
    {
        p=2;
        s=3LL;
    }
    else
    {
        p=3;
        s=6LL;
    }
    for (i=p;i<=n;i++)
    {
        if (a[1][i]==a[2][i])
        {
            if (a[1][i-1]==a[2][i-1])
                s=(1LL)*s*2%1000000007;
        }
        else
        {
            if (a[1][i-1]==a[2][i-1])
                s=(1LL)*s*2%1000000007;
            else
                s=(1LL)*s*3%1000000007;
            i++;
        }
    }
    printf ("%lld\n", s);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int M=998244353;
int N,K,ans,cnt[303],dp[303][303][303]={1};
int main(){
	string S;cin>>S>>K;K=min((int)S.size(),K);
	for(auto c:S)c=='0'?++N:++cnt[N];
    f(i,0,N) f(j,0,K) f(k,0,j) f(l,-min(k,cnt[i]),K-j) (dp[i+1][j+max(l,0)][k+l] += dp[i][j][k])%=M;
    f(i,0,K) (ans+=dp[N+1][i][0])%=M;
    cout<<ans;
}

Measured memory_bytes: 57984
import sys
from collections import Counter
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    N = int(input())
    cA = Counter(inpl())
    for i in range(1, N + 1):
        print(cA.get(i, 0))


if __name__ == '__main__':
    main()


Measured memory_bytes: 116788
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int N;
string s[2];
vector<int> domino;
int ans=1;

void check(){
    for(int i=0;i<N;++i){
        if(i != N-1 && s[0][i] == s[0][i+1]){
            domino.PB(0);
            i++;
        }
        else if(s[0][i] == s[1][i])domino.PB(1);
    }
}

signed main(){
    cin>>N;
    cin>>s[0];
    cin>>s[1];
    check();
    for(int i=0;i<domino.size();++i){
        if(domino[i] == 0){
            if(i == 0)ans*=6;
            else if(domino[i-1]==0)ans*=3;
            else if(domino[i-1]==1)ans*=2;
        }
        else {
            if(i==0)ans*=3;
            else if(domino[i-1]==0)ans*=1;
            else if(domino[i-1]==1)ans*=2;
        }
        ans%=mod;
    }
    cout<<ans<<endl;
}


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

int main(){
    int a, b, c, cnt = 0;
    cin >> a >> b >> c;
    
    for(int i = a; i <= b; i++){
        if(c % i == 0) cnt++;
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3084
import sys
from collections import deque
import copy
from math import gcd
def main():
    K = int(input())
    a = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            a.append(gcd(i, j))
    count = 0
    for i in range(1, K+1):
        for j in range(len(a)):
            count += gcd(i, a[j])
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9804
package main

import (
   "fmt"
)

func solution(h, w, k int, c [][]byte) int {
   out := 0
   for R := 0; R < 1<<uint(h)-1; R++ {
        for C := 0; C < 1<<uint(w)-1; C++ {
                b := 0
                for i := range c {
                        for j := range c[i] {
                                if R>>uint(i)&1 == 0 && C>>uint(j)&1 == 0 && c[i][j] == '#' {
                                        b++
                                }
                        }
                }
                if b == k {
                        out++
                }
        }
   }
   return out
}

func re(t, c [][]byte) [][]byte {
   t = make([][]byte, len(c)+1)
   for i := range t {
        t[i] = make([]byte, len(c[0])+1)
   }
   for i := range c {
        for j := range c[i] {
                t[i+1][j+1] = c[i][j]
        }
   }
   return t
}
func count(c [][]byte) int {
   cnt := 0
   for i := range c {
        for j := range c[i] {
                if c[i][j] == '#' {
                        cnt++
                }
        }
   }
   return cnt
}

func main() {
   var h, w, k int
   fmt.Scan(&h, &w, &k)
   c := make([][]byte, h)
   for i := range c {
        var t string
        c[i] = make([]byte, w)
        fmt.Scan(&t)
        for j := 0; j < w; j++ {
                c[i][j] = t[j]
        }
   }
   fmt.Println(solution(h, w, k, c))
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    int a, b, c, d; cin >> a >> b >> c >> d;
    if(a != c) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#define AB 'a'
#define N 26
#define S 32
int main(void)
{
	int a=AB, i;
	int counter[N]={0};
	char ch;
	while(scanf("%c", &ch) != EOF){
	    if(isalpha(ch)){
			counter[(ch-'A')%S]++;
		}
	}
	for(i=0; i<N; i++){
		printf("%c : %d\n", a+i, counter[i]);
	}
    return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;
const double EPS = 1e-10;
const double INF = 1e12;

double cross(P a, P b) {
    return imag(conj(a) * b);
}

double dot(P a, P b) {
    return real(conj(a) * b);
}

struct L {
    P a, b, v;
    L(){}
    L(P _a, P _b) {a = _a, b = _b, v = b - a;}
    L(double _ax, double _ay, double _bx, double _by) {
        a = P(_ax, _ay), b = P(_bx, _by), v = b - a;
    }
};

// +1: counter-clockwise
// -1: clockwise
// +2: online_back
// -2: online_front
// 0: on_segment
int ccw(P p0, P p1, P p2) {
    if (cross(p1 - p0, p2 - p0) > 0) return +1;
    if (cross(p1 - p0, p2 - p0) < 0) return -1;
    if (dot(p1 - p0, p2 - p0) < 0) return +2;
    if (dot(p0 - p1, p2 - p1) < 0) return -2;
    return 0;
}

bool intersectSS(L l1, L l2) {
    return (ccw(l1.a, l1.b, l2.a) * ccw(l1.a, l1.b, l2.b) <= 0 &&
            ccw(l2.a, l2.b, l1.a) * ccw(l2.a, l2.b, l1.b) <= 0);
}

double distanceLP(L l, P p) {
    return abs(cross(l.v, p - l.a)) / abs(l.v);
}

double distanceSP(L l, P p) {
    if (dot(l.v, p - l.a) < 0) return abs(p - l.a);
    if (dot(-l.v, p - l.b) < 0) return abs(p - l.b);
    return distanceLP(l, p);
}

double distanceSS(L l1, L l2) {
    if (intersectSS(l1, l2)) return 0;
    double d = INF;
    d = min(d, distanceSP(l1, l2.a));
    d = min(d, distanceSP(l1, l2.b));
    d = min(d, distanceSP(l2, l1.a));
    d = min(d, distanceSP(l2, l1.b));
    return d;
}

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

    int q;
    cin >> q;
    while (q--) {
        double v[4][2];
        rep(i, 4) rep(j, 2) cin >> v[i][j];
        L l1(v[0][0], v[0][1], v[1][0], v[1][1]);
        L l2(v[2][0], v[2][1], v[3][0], v[3][1]);
        printf("%.10f\n", distanceSS(l1, l2));
    }

}

Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

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

int main() {
  ll n, t;
  cin >> n >> t;
  vector<P> a(n);
  REP(i, n) { cin >> a[i].first >> a[i].second; }
  sort(ALL(a));
  vector<vector<ll>> dp(n + 1, vector<ll>(t + 1, -1));
  dp[0][0] = 0;
  REP(i, n) {
    REP(j, t + 1) if (dp[i][j] != -1) {
      chmax(dp[i + 1][j], dp[i][j]);
      if (j < t)
        chmax(dp[i + 1][min(j + a[i].first, t)], dp[i][j] + a[i].second);
    }
  }

  ll ans = 0;
  REP(i, t + 1) { chmax(ans, dp[n][i]); }
  cout << ans << endl;
}


Measured memory_bytes: 70784
n, k =map(int, input().split())
p = list(map(int, input().split()))
lista = [(i + 1) / 2 for i in p]
listb = [0]
ans = 0
for i in range(n):
    listb.append(lista[i] + listb[i])
for i in range(n - k + 1):
    ans = max(ans, listb[i + k] - listb[i])
print(ans)

Measured memory_bytes: 78984
def solve():
    H,W = map(int,input().split())
    N = int(input())
    A = list(map(int,input().split()))

    paint = []
    for i in range(N):
        paint += [i+1] * A[i]

    field = [[0] * W for _ in range(H)]

    w = 0
    toRight = True
    idx = 0
    for h in range(H):

        while 0 <= w < W:
            field[h][w] = str(paint[idx])
            idx += 1
            if toRight:
                w += 1
            else:
                w -= 1

        if toRight:
            toRight = False
            w = w-1
        else:
            toRight = True
            w = 0

    for i in range(H):
        print(" ".join(field[i]))

    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 40048
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>

using int64 = long long;

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

    int N;
    std::cin >> N;

    std::vector<std::string> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }

    int ans = 0;

    for (int i = 0; i < N; i++) {
        bool good = true;  // 左上が(i, 0)の正方形領域

        for (int r = 0; r < N; r++) {
            for (int c = 0; c < N; c++) {
               good = good && (S[(r - i + N) % N][c] == S[(c - i + N) % N][r]); 
            }
        }
        if (good) ans += N;
    }
    std::cout << ans << std::endl;

    return 0;
}


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

int main()
{
    int N; ll T;
    scanf("%d %lld", &N, &T);
    ll query[N];
    for(int i = 0; i < N; ++i) scanf("%lld", &query[i]);

    sort(query, query + N);

    ll res = 0;
    for(int i = 0; i < N-1; ++i) res += min(T, query[i+1] - query[i]);
    res += T;
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1792
# coding: utf-8
from decimal import Decimal


def solve(*args: str) -> str:
    a, b, c = map(int, args[0].split())

    return 'Yes' if Decimal(a).sqrt()+Decimal(b).sqrt() < Decimal(c).sqrt() else 'No'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 5076