akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, k, q);
    vc<int> p(n, k-q);
    Rep(q){
        Cin(int, a);
        p[a-1] ++;
    }
    For(i, n){
        CoutYn(p[i] > 0);
    }
}





Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <climits>

using namespace std;
#define forn(x, n)         for (int x = 0; x < n; x++)
#define forr(x, n)         for (int x = n; x >= 0; x--)
#define for1(x, n)         for (int x = 1; x < n; x++)
#define fore(x, a, b, c)   for (int x = a; x <= b; x += c)
#define all(container)     (container).begin(), container.end()
#define rall(container)    (container).rbegin(), container.rend()
#define sz(container)      (int) (container).size()
#define pb                 push_back
#define eb                 emplace_back
#define fi                 first
#define sc                 second

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

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define eprint(...) 0
#endif
template<class T> bool smin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool smax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(void)
{
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    int ans = 0;
    fore(i, l, r, 1) if (i % d == 0) ++ans;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3824
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int n;
    std::cin >> n;
    std::vector<int> p(n);
    rep(i, n) std::cin >> p[i];
    int min_n = 1e7;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(p[i] < min_n) {
            cnt++;
            min_n = p[i];
        }
    }
    std::cout << cnt << std::endl;
}

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

Measured memory_bytes: 1024
//
//  main.cpp
//  ABC174B
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main(int argc, const char * argv[]) {
    ll n,d;
    cin>>n>>d;
    d=d*d;
    ll x,y;
    ll way;
    ll ans=0;
    rep(i,n){
        cin>>x>>y;
        way=x*x+y*y;
        if (way<=d){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3160
import java.io.*;
class Main{

    public static void main(String[] args)throws IOException{
	
	BufferedReader br =
	    new BufferedReader (new InputStreamReader(System.in));
	String buf;
	int time;
	buf=br.readLine();
	time=Integer.parseInt(buf);
	for(int i=0;i<time;i++){
	    int[] side =new int[3];
	    buf=br.readLine();
	    String[] buf2=buf.split(" ");
	    for(int j=0;j<3;j++){
		side[j]=Integer.parseInt(buf2[j]);
	    }
	    java.util.Arrays.sort(side);
	    if((side[2]*side[2]-side[1]*side[1]-side[0]*side[0])==0){
		System.out.println("YES");
	    }else{
		System.out.println("NO");
	    }
	}
    }
}

Measured memory_bytes: 10000
#include <cstdint>
#include <iostream>

using namespace std;

int Digits(int64_t num)
{
    auto digits = 0;
    while (num > 0) {
        digits += 1;
        num /= 10;
    }
    return digits;
}

int64_t MidDivisor(int64_t num)
{
    int64_t div = 1;
    for (int64_t i = 2; i * i <= num; i += 1) {
        if (num % i == 0) {
            div = i;
        }
    }
    return div;
}

int main()
{
    int64_t num;
    cin >> num;

    auto a = MidDivisor(num);
    auto b = num / a;

    cout << max(Digits(a), Digits(b)) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>

using namespace std;

int main(){
    long long N;
    cin >> N;
    int i;
    long long v[5];
    for(i = 0; i < 5; i++){
        cin >> v[i];
    }
    long long minu[5];
    for(i = 0; i < 5; i++){
        if(N%v[i] == 0){
            minu[i] = N/v[i];
        }else{
            minu[i] = N/v[i]+1;
        }
    }
    long long max= 0;
    max = *max_element(minu, minu+5);
    cout << max + 4 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,Ma,Mb,K=1,C[45];
ll A[45],B[45];
ll T,a,b;
ll ans=0;
bool h,o;
//bool D[100005];
string str,str2[55][55];
map<string,int> m;
vector<int> v[10];
ll dp[45][405][405];
int main(){
	cin>>str;
	int i,j;
	for(i=0;i<str.size();++i)if(str[i]=='A')break;
	for(j=str.size()-1;i>=0;--j)if(str[j]=='Z')break;
	cout<<j-i+1<<endl;
	return 0;
}


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

typedef long double ld;

int n, k;
ld res;

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
        int num = i;
        ld prob = 1;
        while (num < k) {
            num *= 2; prob /= 2.0l;
        }
        res += prob;
    }
    res /= n;
    cout << fixed << setprecision(12) << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int len;
    string s, t;
    string newstr = "";

    cin >> len;
    cin >> s >> t;

    for (int i = 0; i < len; i++) {
        newstr += s[i];
        newstr += t[i];
    }

    cout << newstr << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int> ,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int h[200005];
int val[200005];
int n;
long long DP[200005];
long long segTree[800005];
long long getVal(int pos,int l,int r,int UL,int UR)
{
    if(l > UR || r < UL)
        return 0;
    if(l >= UL && r <= UR)
        return segTree[pos];
    int mid = (l+r)/2;
    return max(getVal(pos*2,l,mid,UL,UR),getVal(pos*2+1,mid+1,r,UL,UR));
}
void updateVal(int pos,int l,int r,int UL,int UR,long long v)
{
    if(l > UR || r < UL)
        return;
    if(l >= UL && r <= UR)
    {
        segTree[pos] = v;
        return;
    }
    int mid = (l+r)/2;
    updateVal(pos*2,l,mid,UL,UR,v);
    updateVal(pos*2+1,mid+1,r,UL,UR,v);
    segTree[pos] = max(segTree[pos*2],segTree[pos*2+1]);
}
int main()
{
   // memset(dp,-1,sizeof dp);
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> h[i];
    for(int i = 1;i <= n;i++)
        cin >> val[i];
    long long Best = 0;
    for(int i = 1;i <= n;i++)
        DP[i] = getVal(1,1,n,1,h[i]-1) + val[i],updateVal(1,1,n,h[i],h[i],DP[i]),Best = max(Best,DP[i]);
    cout << Best;
    return 0;
}


Measured memory_bytes: 9728
def cumulative_sum(arr)
  arr.reduce([0]) do |prev, cur|
    prev.push(prev.last + cur)
    prev
  end
end

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

B = cumulative_sum(A)

result = 0

double_num = 0

B.sort.each_cons(2) do |a, b|
  if a == b
    double_num += 1
  else
    if double_num != 0
      result += (double_num + 1) * double_num / 2
      double_num = 0
    end
  end
end

if double_num != 0
  result += (double_num + 1) * double_num / 2
end

puts result


Measured memory_bytes: 20380
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)*}
    };
}

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)*}
    };
}

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        x: usize,
        y: usize
    }
    if h % x == 0 && w % y == 0 {
        println!("No");
        return;
    }
    println!("Yes");
    let hr = h % x;
    let hd = h / x;
    let wr = w % y;
    let wd = w / y;
    let mut a = 0;
    let mut b = 1;
    while a <= 1000000000 && b <= 1000000000 {
        let a2 = b * (x - hr) * (y - wr) * hd * wd / (h * w - (x - hr) * (y - wr) * hd * wd) + 1;
        let b2 = a2 * (x * y - (x - hr) * (y - wr)) / ((x - hr) * (y - wr)) + 1;
        if a == a2 && b == b2 {
            break;
        }
        a = a2;
        b = b2;
    }
    for i in 0..h {
        for j in 0..w - 1 {
            if i % x < hr || j % y < wr {
                print!("{} ", a);
            } else {
                print!("{} ", - (b as i64));
            }
        }
        if i % x < hr || (w - 1) % y < wr {
            println!("{}", a);
        } else {
            println!("{}", - (b as i64));
        }
    }
}


Measured memory_bytes: 5372
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		int N = sc.nextInt();
		ArrayList<Integer> a = new ArrayList<Integer>();

		for(int i = 0 ; i < N ; i++) {
			a.add(sc.nextInt());
		}

		int result = a.get(0);


		for(int i = 1 ; i < N ; i++) {
			result ^=   a.get(i);
		}

		if(result == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 58716
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s1,s2,s3;
   while(cin>>s1>>s2>>s3)
   {
       if(s1[s1.size()-1]==s2[0]&&s2[s2.size()-1]==s3[0])
       {
           cout<<"YES"<<endl;

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


   return 0;
}


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

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

    for (int i = 0; i < s.size(); ++i) {
        char c = s[i] - 'A';
        c = (c + n) % 26 + 'A';
        s[i] = c;
    }

    cout << s;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#define loop(i,a,b) for(int i=a ;i < b ; i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(void){
	string a;

	getline(cin,a);
	
	rep(i,a.size())a[i]=toupper(a[i]);
	
	cout<<a<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
ll nCr[51][51];
ll N,A,B;
ll v[60];

ll com(int n, int r) {
  return nCr[n][r];
}

void init(int n) {
  for(int i = 0; i <= n; i++) nCr[i][0] = nCr[i][i] = 1;

  for(int i = 1; i < n; i++) {
    for(int j = 0; j < i; j++) {
      nCr[i+1][j+1] = nCr[i][j] + nCr[i][j+1];
    }
  }
  return;
}
    
int main() {
  cin >> N >> A >> B;
  for(int i = 0; i < N; i++) cin >> v[i];

  init(N);

  sort(v,v+N,greater<ll>());
  ll sum = 0;
  for(int i = 0; i < A; i++) sum += v[i];

  cout <<fixed<< sum / (double)A <<endl;

  if(v[0] != v[A-1]) {
    int tmp = 0;
    int k = 50;
    for(int i = 0; i < N; i++) {
      if(v[A-1] == v[i]) {
	tmp++;
	if(i < k) k = i;
      }
    }
    cout << com(tmp,A-k) << endl;
    return 0;
  }
  else {
    int tmp = A;
    int k = A;
    while(v[0] == v[k]) {
      k++;
      tmp++;
    }

    ll ans = 0;
    for(int i = A; (i <= B && i <= tmp); i++) {
      ans += com(tmp,i);
    }
    cout << ans <<endl;
    return 0;
  }
      
}

  
  
  
  
  


Measured memory_bytes: 256
x,k,d = map(int,input().split())
n = abs(x)//d

if k>n:
    if x<0:
        a = x+n*d
        b = a+d
        if (k-n)%2 == 0:
            print(abs(a))
        else:
            print(abs(b))
    else:
        a = x-n*d
        b = a-d
        if (k-n)%2 == 0:
            print(abs(a))
        else:
            print(abs(b))
else:
    if x<0:
        print(abs(x+k*d))
    else:
        print(abs(x-k*d))


Measured memory_bytes: 9208
from itertools import count, combinations, product

H,W = map(int,input().split())

grid = [[False]*(W+2) for _ in range(H+2)]

for i in range(1,H+1):
    S = input()
    for j,v in zip(range(1,W+1),S):
        grid[i][j] = v == '.'

visited = [[0 if v else float('inf') for v in row] for row in grid]
cnt = 1
def dist(p1,p2):
    global cnt
    q = [p1]
    visited[p1[0]][p1[1]] = cnt 
    for d in count():
        if not q:
            break
        nq = []
        for x,y in q:
            if (x,y) == p2:
                cnt += 1
                return d
            else:
                for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
                    if visited[x+dx][y+dy] < cnt:
                        visited[x+dx][y+dy] = cnt
                        nq.append((x+dx,y+dy))
        q = nq
    cnt += 1
    return float('inf')

emp = [(i,j) for i,j in product(range(H+2),range(W+2)) if grid[i][j]]

print(max(dist(*p) for p in combinations(emp,2)))

Measured memory_bytes: 45276
fun main(args: Array<String>) {
    val mod = 1000000007L
//    val (N,D) = readLine()!!.split(" ").map { it.toInt() }
    val N = readLine()!!.toInt()

    val A = Array(N) {readLine()!!.toInt()}
    val (m0,m1) = A.sortedDescending().take(2)
    val list = mutableListOf<Int>()

    for (a in A)
        list.add(if(m0 != a) m0 else m1)

    println(list.joinToString("\n"))
}



Measured memory_bytes: 62068
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <cstdlib>

using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
int ilimit = INT_MAX;
long int llimit = LONG_MAX;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

int Func2(int n,int m){
    long int s2 = 1,
        r = 1;


    for(int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % pow107;
    }

    return s2;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2

int main(){
    int a,b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
int a[man];
ll s[man],dp[man];

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	s[1] = a[1];
	for(int i = 3;i <= n;i+=2){
		s[i] = s[i-2] + a[i];
	}
	for(int i = 2;i <= n;i++){
		if(i&1)dp[i] = max(dp[i-1],dp[i-2]+a[i]);
		else dp[i] = max(s[i-1],dp[i-2]+a[i]);
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 7516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		int n = Integer.parseInt(tmpArray[0]);
		int k = Integer.parseInt(tmpArray[1]);

		int input[] = new int[n];
		tmpArray = br.readLine().split(" ");

		int firstPositiveIndex = -1;
		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(tmpArray[i]);

			if(firstPositiveIndex < 0 && input[i] >= 0){
				firstPositiveIndex = i;
			}
		}

		int posSum[] = new int[n];
		int negSum[] = new int[n];

		if(input[0] >= 0){
			posSum[0] = input[0];
		}
		if(input[n - 1] < 0){
			negSum[n - 1] = input[n - 1];
		}
		for(int i = 1 ; i < n; i++){
			if(input[i] >= 0){
				posSum[i] = posSum[i - 1] + input[i];
			}

			if(input[n - i - 1] < 0){
				negSum[n - i - 1] = negSum[n - i] + input[n - i - 1];
			}
		}

		//debug
//		for(int i = 0; i < n; i++){
//			System.out.println(posSum[i] +" "+negSum[i]);
//		}

		long result = Long.MAX_VALUE;
		for(int i = 0; i + k <= n; i++){
//			int pos = posSum[i + k - 1];
//			int neg = negSum[i];
			int pos = Math.max(input[i + k - 1] , 0);
			int neg = Math.min(0, input[i]);
//			System.out.println("pos neg "+pos+" "+neg);

			long tmpCost = 0;
			if(pos >= -neg){
				tmpCost = (-neg)*2 + pos;
			}
			else {
				tmpCost = (-neg) + pos*2;
			}

//			System.out.println("cost "+tmpCost );
			result = Math.min(result, tmpCost);
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 44924
N, K = map(int, input().split())
p = list(map(int, input().split()))
import numpy as np
p = np.array(p)
p = (p + 1)/2
ans = -1
for i in range(N-K+1):
  if i == 0:
    a = np.sum(p[:K])
  else:
    a = (a-p[i-1]+p[i+K-1])
  if a > ans:
    ans = a
print(ans)

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

using namespace std;

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

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define X first
#define Y second
const int MAXN = 200100;
vi adj[MAXN];
int res = 0;
int n, k;
int dfs(int u, int p){
    if (u == 0){
        for (int v : adj[u]){
            if (v != p){
                dfs(v, u);
            }
        }
        return 0;
    }
    int child = 0;
    for (int v : adj[u]){
        if (v != p){
            child = max(child, dfs(v, u));
        }
    }
    if (child + 1 == k && p != 0){
        res += 1;
        return 0;
    }
    return child + 1;
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        int v; cin >> v; v--;
        if (i == 0){
            if (v == 0);
            else res += 1;
        } else {
            adj[v].push_back(i);
        }
    }
    dfs(0, -1);
    cout << res << endl;
    return 0;
}


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

using namespace std;


const int money[3] = {10000, 5000, 1000};

void solve() {
    int N, Y; cin >> N >> Y;

    int x = -1, y = -1, z = -1;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            int sum = money[0] * i + money[1] * j + money[2] * (N - i - j);
            if (sum == Y) {
                x = i; y = j; z = N - i - j;
            }
        }
    }

    cout << x << " " << y << " " << z << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template<typename T>
void print(vector<T> v, uint8_t delimiter = ' ') {
    for (uint32_t i = 0; i < v.size() - 1; i++) {
        cout << v[i] << delimiter;
    }
    cout << v[v.size() - 1] << endl;
}

template<typename T>
int32_t insertion_sort(vector<T> &v, int64_t g) {
    int32_t count = 0;
    for (int64_t i = g; i < (int64_t) v.size(); i++) {
        int64_t val = v[i];
        int64_t j = i - g;
        while (j >= 0 && v[j] > val) {
            v[j + g] = v[j];
            j = j - g;
            count++;
        }
        v[j + g] = val;
    }

    return count;
}

template<typename T>
void shell_sort(vector<T> &v) {
    int32_t count = 0;

    vector<int64_t> G = {1};
    for (int32_t i = 0; 4 * G[i] <= (int64_t) v.size() ; i++) {
        G.push_back(4 * G[i]);
    }
    reverse(G.begin(), G.end());

    cout << G.size() << endl;
    print(G);

    for (int64_t i = 0; i < (int64_t) G.size(); i++) {
        count += insertion_sort(v, G[i]);
    }

    cout << count << endl;

    return;
}

int main() {
    int64_t N;

    cin >> N;

    vector<int64_t> A(N);

    for (int64_t i = 0; i < N; i++) cin >> A[i];

    shell_sort(A);
    print(A, '\n');

    return 0;
}

Measured memory_bytes: 18468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h , w;
  
  while (1) {
    cin >>h >>w;
    if (h==0 && w==0)
      break;
    
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i%2 == 0) {
          if (j%2 == 0)
            cout << '#';
          else
            cout << '.';
        }
        else
          if (j%2 != 0)
            cout << '#';
          else
            cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int a[100010], b[100010], c[100010]; 
int main() {
  int n;
  cin >> n;
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll ans = 0, change = 0;
  vector<int> c;
  rep(i,n) {
    if (a[i] < b[i]) {
      ans++;
      change += b[i] - a[i];
    } else {
      c.push_back(a[i]-b[i]);
    }
  }
  sort(c.begin(), c.end(), greater<int>());
  //int j = 0;
  for (auto v: c) {
    if (change <= 0) break;
    change -= v;
    ans++;
  }
  
  if (change <= 0) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 4640
// URL: https://atcoder.jp/contests/abc135/tasks/abc135_c

import std.algorithm, std.container, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  int n; io.getV(n);
  int[] a; io.getA(n+1, a);
  int[] b; io.getA(n, b);

  auto r = 0L;
  foreach (i; 0..n) {
    auto c1 = min(a[i], b[i]);
    r += c1;
    b[i] -= c1;
    auto c2 = min(a[i+1], b[i]);
    r += c2;
    a[i+1] -= c2;
  }

  io.put(r);
}

auto io = IO();

struct IO
{
  import std.algorithm, std.conv, std.format, std.meta, std.range, std.stdio, std.traits;

  dchar[] buf;
  auto sp = (new dchar[](0)).splitter;
  int precision = 10;
  string delimiter = " ";

  void nextLine()
  {
    stdin.readln(buf);
    sp = buf.splitter;
  }

  auto get(T)(ref T v)
  {
    if (sp.empty) nextLine();
    v = sp.front.to!T;
    sp.popFront();
  }

  auto getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }

  auto getA(T)(size_t n, ref T v)
  if (hasAssignableElements!T)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }

  auto getC(T...)(size_t n, ref T v)
  if (allSatisfy!(hasAssignableElements, T))
  {
    foreach (ref w; v)
      w = new typeof(w)(n);
    foreach (i; 0..n)
      foreach (ref w; v) get(w[i]);
  }

  auto getM(T)(size_t r, size_t c, ref T v)
  if (hasAssignableElements!T && hasAssignableElements!(ElementType!T))
  {
    v = new T(r);
    foreach (ref w; v) getA(c, w);
  }

  auto putA(T)(T v)
  {
    static if (isInputRange!T && hasLength!T && !isSomeString!T) {
      foreach (i, w; v) {
	putA(w);
	if (i < v.length - 1) write(delimiter);
      }
    } else if (isFloatingPoint!T) {
      writef(format("%%.%df", precision), v);
    } else {
      write(v);
    }
  }

  auto put(T...)(T v)
  {
    foreach (i, w; v) {
      putA(w);
      if (i < v.length - 1) write(delimiter);
    }
    writeln;
  }

  auto putB(S, T)(bool c, S t, T f)
  {
    if (c)
      put(t);
    else
      put(f);
  }

  auto dbg(T...)(T v)
  {
    stderr.writeln(v);
  }
}


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

int main() {
	int N;
	cin >> N;
	vector<int> V(N), C(N),ans;
	for (int i = 0; i < N; i++) cin >> V[i];
	for (int i = 0; i < N; i++) cin >> C[i];
	for (int i = 0; i < N; i++) {
		if (V[i] > C[i]) {
			ans.push_back(V[i] - C[i]);
		}
	}
	cout<<accumulate(ans.begin(),ans.end(),0)<<endl;

	return 0;
}

Measured memory_bytes: 256
using System;

class Program {
    static void Main(string[] args) {
        //入力
        string s = Console.ReadLine();
        string[] t = s.Split(' ');
        int X = int.Parse(t[0]);
        int Y = int.Parse(t[1]);

        //出力

        Console.WriteLine(X + Y / 2);

    }
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    ll a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;

    if((v-w)*t - abs(a-b) >= 0){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
bool v[30005];
int n,a[20005],t;
 
int main(){
    scanf("%d",&n);
    if(n==3){ puts("2 5 63"); return 0;}
    for(int i=2;i<n;i+=2) if((n-i)<=15000&&i<=5000&&(n-i)%3!=1){
        for(int j=2,c=1;j<=30000&&c+i<=n;j+=2,c++) printf("%d ",j);
        for(int j=3,c=1;j<=30000&&c<=i;j+=3) if(j&1) printf("%d ",j),c++;
        break;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+7;
#define ll long long
int f[20][N];
int p[N],c[N];
int main(){
	int d,g;
	scanf("%d%d",&d,&g);
	g/=100;
	for(int i = 1;i<=d;i++){
		scanf("%d%d",&p[i],&c[i]);
		c[i]/=100;
	}
	memset(f,0x3f3f3f3f,sizeof(f));
	for(int i = 1;i<=d;i++) f[i][0]=0;
	f[0][0]=0;
	for(int i = 1;i<=d;i++){
		for(int j = 1;j<=g;j++){
			for(int k = 0;k<=p[i];k++){
				int tmp=max(0,j-k*i);
				{
					f[i][j]=min(f[i][j],f[i-1][tmp]+k);
				}
				if(k==p[i]){
					int tmp=max(0,j-k*i-c[i]);
					{
						f[i][j]=min(f[i][j],f[i-1][tmp]+k);
					}
				}
			}
		}
	}
	printf("%d\n",f[d][g]);
	
}

Measured memory_bytes: 82176
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>


using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const ll INF1 = ll(1e18);
const int MAX = 1000002;

int N;
int a[MAX];
int flag = 0;

int main()
{
    cin>>N;
    for(int i = 1;i <= N;i++){
        cin>>a[i];
        if(a[1]!=0||a[i]-a[i-1]>1)flag = 1;
    }
    if(flag == 1){
        cout<<-1<<endl;
        return 0;
    }
    ll sum = 0;
    for(int i = N;i > 1;i--){
        if(a[i]>a[i-1]){
            sum += a[i]-a[i-1];
        }else {
            sum += a[i];
        }
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 1024
l = input().split()
N = int(l[0])

C = []
S = []
F = []

for i in range(N - 1):
    l = input().split()
    C.append(int(l[0]))
    S.append(int(l[1]))
    F.append(int(l[2]))

# print(N, C, S, F)

for i in range(N - 1):
    spent = 0
    for j in range(i, N - 1):
        c = C[j]
        s = S[j]
        f = F[j]
        if spent < s:
            spent = s
        remain = (spent - s) % f
        if remain != 0:
            spent += f - remain
        spent += c
    print(spent)
print(0)


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
using namespace std;

ll N, K;
ll M = 1000000007;
vector<ll> gids; // グループID一覧
vector<ll> sizes; // gid_ix => グループの要素数
vector<vector<ll>> dp; // dp[i][gid_ix]: i個の並べた時に、最後の数が gid に属する
vector<vector<ll>> memo;

ll f (ll i, ll gid_ix) {
  //if (gid_ix >= gids.size())
  //  return 0;
  auto gid = gids[gid_ix];
  // static map<PLL, ll> memo;
  //if (memo.find(make_pair(i, gid_ix)) != memo.end())
  //  return memo[make_pair(i, gid_ix)];
  if (memo[i][gid_ix] != -1)
    return memo[i][gid_ix];

  // cout<<"gid="<<gid<<endl;
  ll res;
  if (i == 0)
    res = 0;
  else if (gid == 0)
    res = 0; // need?
  else if (gid == N)
    res =  dp[i][gids.size()-1];
  else
    res = f(i, gid_ix+1) + (dp[i][gid_ix] * sizes[gid_ix]) %M;

  // cout<<"i="<<i<<" gid="<<gid<<endl;
  res %= M;
  return memo[i][gid_ix] = res;
}

signed main() {
  cin >> N >> K;

  for (int x = 1; x * x <= N; x++) {
    gids.push_back(x);
    gids.push_back(N/x);
  }
  sort(begin(gids), end(gids));
  gids.erase(unique(begin(gids), end(gids)), end(gids));
  sizes.resize(gids.size());
  // cout<<"max gid="<<gids[gids.size()-1]<<endl;

  for (int i = 0; i < gids.size()-1; i++) {
    sizes[i] = N/gids[i] - N/gids[i+1];
    sizes[i] %= M;
  }
  sizes[gids.size()-1] = 1;

  // for (auto p: sizes) {
  //   cout<<"gid="<<p.first<<" size="<<p.second<<endl;
  //   cout<<"gid="<<p.first<<" next_gid="<<next_gid[p.first]<<endl;
  // }

  // cout<<"gids.size()="<<gids.size()<<endl;
  dp.resize(K+1, vector<ll>(gids.size()+1));
  memo.resize(K+1, vector<ll>(gids.size()+1, -1));
  for (int gid_ix = 0; gid_ix < gids.size(); gid_ix++) {
    dp[1][gid_ix] = 1;
    // printf("dp[%d][%d] = %d\n", 1, gid, dp[1][gid]);
  }
  for (int i=2; i<=K; i++) {
    // for (int x = 1; x <= N; x++) {
    // for (auto gid: gids) {
    for (int gid_ix=gids.size()-1; gid_ix>=0; gid_ix--) {
      auto gid = gids[gid_ix];
      dp[i][gid_ix] = f(i-1, gids.size()-1 - gid_ix) %M;
      // printf("dp[%d][%d] = %d\n", i, x, dp[i][x]);
    }
  }

  ll ans = 0;
  for (int gid_ix = 0; gid_ix < gids.size(); gid_ix++) {
    auto gid = gids[gid_ix];
    ans += (dp[K][gid_ix] * sizes[gid_ix])%M;
    ans %= M;
  }
  cout << ans << endl;
  return 0;
}



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

int m;
int g[1000000];
int cnt=0;
std::vector<int> G;
void insertionSort(int array[], int n, int g){
	int tmp,j;
	for(int i=g;i<n;i++){
		tmp = array[i];
		j= i-g;
		while(j>=0 && array[j]>tmp){
			array[j+g] = array[j];
			j=j-g;
			cnt++;
		}
		array[j+g]=tmp;
	}
}

void shellSort(int array[],int n){
	cnt = 0;

	for(int h=1; ;){
		if(h>n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}

	for(int i=G.size()-1;i>=0;i--){
		insertionSort(array,n,G[i]);
	}
}

int main(){
	int n;
	int array[1000001];
	cin >> n;

	for(int i=0;i<n;i++){
		cin >>array[i];
	}

	shellSort(array,n);

	cout << G.size() << endl;
	for(int i=G.size()-1;i>=0;i--){
		cout<<G[i];
		if(i) cout<<" ";
	}
	cout << endl;

	cout << cnt << endl;

	for(int i=0;i<n;i++){
		cout << array[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 5120
A = int(input())#500
B = int(input())#100
C = int(input())#50
X = int(input())#合計

cnt=0
max_500 = int(X/500)
cnt_500 = min(max_500,A)+1
#print(cnt_500)
for i in range(cnt_500):
    X_500=X-i*500
    max_100=int(X_500/100)
    cnt_100=min(max_100,B)+1
    #print(cnt_100)
    for j in range(cnt_100):
        X_100=X_500-j*100
        if X_100%50==0 and int(X_100/50)<=C:
            cnt+=1
print(cnt)

Measured memory_bytes: 39152
#include<bits/stdc++.h>
using namespace std;
const int N=110,INF=0x3f3f3f3f;
int n,m,dp[N][N];
char s[N][N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=m;++i)
	s[0][i]='.';
	for(int j=1;j<=n;++j)
	s[j][0]='.';
	memset(dp,INF,sizeof dp);
	dp[1][1]=(s[1][1]=='#');
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){			
			if(i>1){
				if(s[i][j]=='.')dp[i][j]=min(dp[i][j],dp[i-1][j]);
				else dp[i][j]=min(dp[i][j],dp[i-1][j]+(s[i-1][j]!='#'));
			}
			if(j>1){
				if(s[i][j]=='.')dp[i][j]=min(dp[i][j],dp[i][j-1]);
				else dp[i][j]=min(dp[i][j],dp[i][j-1]+(s[i][j-1]!='#'));
			}
			//printf("dp[%d][%d]:%d\n",i,j,dp[i][j]); 
		} 
	}
	printf("%d\n",dp[n][m]);
	return 0;
}

Measured memory_bytes: 256
/* ex6_2 KitamoriFumiya */
#include <stdio.h>
#include <string.h>

int main(void){
	char word[100]; // word(英単語)を文字列として宣言
	int length; // length(wordの長さ)をint型の変数として宣言
	scanf("%s", word); // wordを入力
	length = strlen(word); // 単語の長さを求める
	printf("%c", word[0]); // 単語の先頭文字を出力
	printf("%d", length-2); // 単語の文字数から先頭文字と末尾文字の2文字を抜いた文字数を出力
	printf("%c\n", word[length-1]); // 単語の末尾文字を出力
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

    
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }
    else
        cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  a--;
  b--;
  if(a==b){
    printf("1");
    return 0;
  }
  if(b%a==0){
    printf("%d",b/a);
  }else{
  	printf("%d",(b/a)+1);
  }
  return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

queue = []
for i in range(N):
  queue += [i + 1] * a[i]
  
for y in range(H):
  print(*queue[y * 2 * W:(y * 2 + 1) * W], sep=' ')
  if (y * 2 + 1 >= H):
    break
  print(*reversed(queue[(y * 2 + 1) * W:(y * 2 + 2) * W]), sep=' ')


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

// greatest common divisor and least common multiple
// gcd is calculated by Euclidean Algorithm
// lcm = m * n / gcd(m,n)
template <typename T = int>
T gcd(T a, T b) {
    if (a < b)
        return gcd(b, a);
    if (b == 0)
        return a;
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template <typename T = int>
T lcm(T m, T n) {
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint k;
    cin >> k;
    lint ret = 0;
    for (lint i = 1; i <= k; ++i) {
        for (lint j = 1; j <= k; ++j) {
            for (lint m = 1; m <= k; ++m) {
                ret += gcd(i, gcd(j, m));
            }
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	cin >> h >> w;
	int srow,scol,erow,ecol;
	cin >> srow >> scol;
	cin >> erow >> ecol;
	--srow,--scol,--erow,--ecol;
	string grid[h];
	for(int i = 0; i < h;++i){
		cin >> grid[i];
	}
//	bool ok = false;
	deque<pair<int,int> > dq;
	int dist[h][w];
	for(int i = 0; i < h;++i){
		for(int j = 0; j < w;++j){
			dist[i][j] = 1e7;
		}
	}
	dist[srow][scol] = 0;
	dq.push_back({srow,scol});
	while(!dq.empty()){
		pair<int,int> cur_node = dq.front();
		dq.pop_front();
		int row = cur_node.first;
		int col = cur_node.second;
//		if(row == erow && col == ecol){
//			ok = true;
//			break;
//		}
		for(int dx = -2;dx <= 2;++dx){
			for(int dy = -2;dy <= 2;++dy){
				int nrow = row + dx;
				int ncol = col + dy;
//				if(nrow == row && ncol == col)
//					continue;
				if(nrow < 0 || ncol < 0 || nrow >= h || ncol >= w ||(!dx && !dy) || grid[nrow][ncol] == '#')
					continue;
				int w = 1;
//				if(grid[nrow][ncol] == '#')
//					continue;
				if((abs(nrow-row) == 1 && abs(ncol-col) == 0) || (abs(ncol-col) == 1 && abs(nrow-row) == 0))
					w = 0;
				if(dist[nrow][ncol] > dist[row][col] + w){
					dist[nrow][ncol] = dist[row][col] + w;
					if(w == 0)
						dq.push_front({nrow,ncol});
					else
						dq.push_back({nrow,ncol});
				}
			}
		}
	}
//	if(!ok)
//		dist[erow][ecol] = -1;
//	cout << dist[erow][ecol] << "\n";
    cout<<(dist[erow][ecol] == 1e7?-1: dist[erow][ecol]);
    return 0;
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int x = abs(a-b);
    int y = abs(b-c);
    int z = abs(c-a);
    cout << min( min(x+y, y+z), z+x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> A(N), B(N), C(M), D(M);
    rep(i, N) cin >> A[i] >> B[i];
    rep(i, M) cin >> C[i] >> D[i];

    rep(i, N) {
        ll Min = 1e9, ans = 0;
        rep(j, M) {
            ll dist = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            if (dist < Min) {
                Min = dist; ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

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

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

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

Measured memory_bytes: 4096
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;
typedef vector<ll>		VLL;
typedef vector<VLL>		VVLL;
typedef vector<VVLL>	VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	VLL a(N);
	REP(i, N) cin >> a[i];
	
	bool isOk = true;
	REP(i, N) {
		int val = a[i];
		if (IsEven(val)) {
			if (val % 3 == 0 || val % 5 == 0) {
			} else {
				isOk = false;
			}
		}
	
	}

	if (isOk) {
		cout << "APPROVED" << endl;
	} else {
		cout << "DENIED" << endl;
	}
	return 0;
}


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

int main() {
    int N, K; cin >> N >> K;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    // ソート
    sort(a.begin(), a.end());

    // K 差の最小値
    long long res = 1LL<<60; // INF の気持ち
    for (int i = 0; i+K-1 < N; ++i) res = min(res, a[i+K-1] - a[i]);
    cout << res << endl;
}


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

const int64_t mod = 1000000007;
vector<int64_t> fact, inv;

int64_t power(int64_t n, int64_t k) {
  if (k == 0) return 1;
  int64_t ans = power(n * n % mod, k / 2);
  if (k % 2) ans = ans * n % mod;
  return ans;
}

void init(int64_t n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 1; i <= n; i++) {
    fact.push_back(fact.at(i - 1) * i % mod);
    inv.push_back(power(fact.at(i), mod - 2));
  }
}

int64_t comb(int64_t n, int64_t r) {
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}

int main() {
  int64_t n, k;
  cin >> n >> k;
  if (k >= n) k = n - 1;
  init(2 * n);
  int64_t ans = 0;
  for (int i = 0; i <= k; i++) {
    ans += comb(n, i) * comb(n - 1, i);
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 10080
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

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

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

main()
{
	IOS
	
	int a, b, c = 0;
	cin >> a >> b;
	
	for(int i = 1; i < b - a; i++)
	{
		c += i;
	}
	
	cout << c - a;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for(int i = 0; i <= s.size() - 2; i++){
        if(s[i] == s[i + 1]){
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
        if(i <= s.size() - 3){
            if(s[i] == s[i + 2]){
                cout << i + 1 << " " << i + 3 << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
D.sort()
T.sort()
j = 0
for i in range(N):
    if D[i] == T[j]:
        j += 1
    if j == M:
        print('YES')
        exit()
print('NO')

Measured memory_bytes: 34988
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N;
	double ans;
	ans = 0;
	cin >> N;
	vector<double> x(N);
	vstr u(N);

	for (int i = 0; i < N; i++) {
		cin >> x[i] >> u[i];
		if (u[i] == "JPY")ans += x[i];
		else ans += 380000 * x[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256