akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t) {
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back


#define MOD  1000000007LL
#define EPS 1e-8

int main() {


	int n, m;
	cin >> n >> m;
	vector<uint64_t> x(n), y(m);

	REP(i, n) cin >> x[i];
	REP(i, m) cin >> y[i];

	
	uint64_t sum = 0,sumy=0,sumx=0;
	
	for (int k = 0; k < x.size(); k++) {
		sumx +=( (k )*x[k] - (x.size()-1 - k)*x[k]);
	}
	for (int k = 0; k < y.size(); k++) {
		sumy += ((k )*y[k] - (y.size()-1 - k)*y[k]);
	}
	sumx=sumx % MOD;
	sumy=sumy % MOD;
	cout << (sumx*sumy) % MOD << endl;

}


Measured memory_bytes: 1920
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a[] = new int[n];
        HashMap<Integer, Long> count = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int ai = scanner.nextInt();
            a[i]  = ai;
            count.put(ai, count.getOrDefault(ai,0L)+1);
        }
        long sum = 0;
        for (long value : count.values()) {
            sum+=value*(value-1)/2;
        }
        for (int i = 0; i < n; i++) {
            long ac = count.get(a[i]);
            System.out.println(sum - (ac-1));
        }
    }
}

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

vector<int> ans;

void calcl(int l, int r) {
	int n = (r - l) / 2;
	if ((r - l) % 2) {
		ans[r - 1] += n;
		ans[r] += n;
	}
	else {
		ans[r - 1] += n - 1;
		ans[r] += n;
	}
}

void calcr(int l, int r) {
	int n = (r - l) / 2;
	if ((r - l) % 2) {
		ans[l] += n + 1;
		ans[l + 1] += n + 1;
	}
	else {
		ans[l] += n + 1;
		ans[l + 1] += n;
	}
}

signed main() {
	string s;
	cin >> s;
	int n = s.size();
	ans.resize(n);

	for (auto& c : s) {
		if (c == 'L')c = 'R';
		else c = 'L';
	}

	bool to_right = true;
	int start = 0;
	for (int i = 1; i < n; ++i) {
		if (s[i] == 'R' && to_right) {
			calcl(start, i);
			start = i - 1;
			to_right = !to_right;
		}
		else if (s[i] == 'L' && !to_right) {
			calcr(start, i - 1);
			start = i;
			to_right = !to_right;
		}
	}

	calcr(start, n - 1);
	for (auto x : ans) {
		cout << x << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1408
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#![allow(non_snake_case)]

macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> 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")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[allow(dead_code)]
fn lcm(a: i64, b: i64) -> i64 {
    a*b / gcd(a, b)
}

fn main() {
    input! { 
         N: usize, 
         M: usize,
         denkyus: [[usize]; M],
         p: [usize; M]
    }
    let mut ans = 0; 
    for bit in 0..1<<N {
        let mut is_incr = true;
        for (i, switches) in denkyus.iter().enumerate() {
            let mut cnt = 0;
            for switch in switches {
                if (bit & 1<<switch-1) > 0 {
                    cnt += 1;
                }
            }
            if cnt % 2 != p[i] {
                is_incr = false;
                // break;
            }
        }
        if is_incr {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

ll modsub(ll a, ll b) {
  ll ans = (a - b) % MOD;
  if (ans < 0)
    ans += MOD;
  return ans;
}

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

  ll N;
  cin >> N;
  ll ans = (mod_pow(10, N)+mod_pow(8, N))%MOD;
  ans = modsub(ans, mod_pow(9, N)*2);

  cout << ans << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)

using namespace std;


int main() {
  int M;
  vector<int> B(200005, 0);
  vector<bool> exist(200005, false);
  vector<int> ans;
  cin >> M;
  rep1(i, M) {
    int b;
    cin >> b;
    B[i] = b;
  }
  for (int i = M; i > 0; i --) {
    int b = B[i];
    int cnt = 0;
    int mul = i * 2;
    while(mul <= M) {
      if (exist[mul]) cnt += 1;
      mul += i;
    }
    if ((cnt % 2) != b) {
      exist[i] = true;
      ans.push_back(i);
    }

  }
  int a_len = ans.size();
  cout << a_len << endl;
  if (a_len != 0) {
    rep(i, a_len-1) {
      cout << ans[i] << " ";
    }
    cout << ans[a_len-1] << endl;
  }


  return 0;
}


Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int L[N],n,r1[N],l1[N],Left[N],Right[N];
char s1[N],s2[N];
struct Ask{
	int x,y;
	Ask(int _x=0,int _y=0){x=_x;y=_y;}
}A[N];
int cmp(Ask x,Ask y){
	return x.x<y.x;
}
int check(int l,int r){
	if (l>r)return L[n-1]-L[l-1]+L[r]>0;
	return L[r]-(l==0?0:L[l-1])>0;
}
int solve(Ask A[],int n){
	memset(r1,0,sizeof r1);
	memset(l1,0,sizeof l1);
	int ans=1e9;
	for (int i=n;i;i--)r1[i]=max(r1[i+1],A[i].y);
	for (int i=1;i<=n;i++)l1[i]=max(l1[i-1],A[i].x);
	for (int i=0;i<=n;i++)ans=min(ans,l1[i]+r1[i+1]);
	return ans;
}
int main(){
	scanf("%s%s",s1,s2);
	n=strlen(s1);
	int ans=1e9;
	for (int i=0;i<n;i++)Left[i]=Right[i]=1e9,L[i]=L[i-1]+(s2[i]=='1'?1:0);
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			if (s2[j]=='1')Left[i]=min(Left[i],(i-j+n)%n),Right[i]=min(Right[i],(j-i+n)%n);
	for (int i=0;i<=n;i++){
		int tot=0,num=0;
		for (int j=0;j<n;j++){
			if (s1[j]==s2[(j-i+n)%n])continue;
			if ((i==n&&L[n-1])||(i!=n&&check((j-i+n)%n,j)))num++;
			else A[++tot]=Ask(Right[j],Left[(j-i+n)%n]),num++;
		}
		sort(A+1,A+tot+1,cmp);
		ans=min(ans,num+i+solve(A,tot)*2);
	}
	for (int i=0;i<=n;i++){
		int tot=0,num=0;
		for (int j=0;j<n;j++){
			if (s1[j]==s2[(i+j)%n])continue;
			if ((i==n&&L[n-1])||(i!=n&&check(j,(i+j)%n)))num++;
			else A[++tot]=Ask(Left[j],Right[(i+j)%n]),num++;
		}
		sort(A+1,A+tot+1,cmp);
		ans=min(ans,num+i+solve(A,tot)*2);
	}
	if (ans==1e9)puts("-1");
	else printf("%d\n",ans);
} 

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

using namespace std;

typedef long long ll;

long long test_cases;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    /* cin >> test_cases; */
    test_cases = 1;

    int n;
    multiset<int> a;
    
    while (test_cases > 0)
    {
        cin >> n;
        
        int ans;
        int number;
        int count_ones = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> number;
            a.insert(number);
            if (number == 1)
                count_ones++;
        }

        if (n == 1)
        {
            cout << 1 << endl;
            return 0;
        }

        if (count_ones > 1)
        {
            cout << 0 << endl;
            return 0;
        }
        if (count_ones == 1)
        {
            cout << 1 << endl;
            return 0;
        }

        
        for(auto it = a.begin(); it != a.end(); it++)
        {
            for (int i = 2; (*(it))*i <= *(--a.end()); i++)
            {
                if (a.find((*(it))*i) != a.end())
                {
                    a.erase((*(it))*i);
                }
            }
           
        }
            
        map<int,int> freq;
        for(auto it = a.begin(); it != a.end(); it++)
        {
            
            freq[*(it)] += 1;
        }
        
        ans = 0;
        for (auto it = freq.begin(); it != freq.end(); it++)
        {
            if (it -> second == 1)
                ans+=1;
        }
        
        cout << ans << endl;

        test_cases--;
    }
    return 0;
}

Measured memory_bytes: 22332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    string S, add[4] = {"dream", "dreamer", "erase", "eraser"};
    cin >> S;
    for (int i = S.length() - 5; i >= 0; --i) {
        for (int j = 0; j < 4; ++j) {
            if (S.substr(i) == add[j]) {
                S.erase(S.begin() + i, S.end());
                i -= 4;
                break;
            }
        }
    }
    cout << (S.empty() ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 512
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, A, B = MAP()
C = B - A
if C <= 0:
    print("delicious")
else:
    if X >= C:
        print("safe")
    else:
        print("dangerous")


Measured memory_bytes: 5148
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=0,k=0,s=0;
        if(scan.hasNext())
            n=scan.nextInt();
        if(scan.hasNext())
            k=scan.nextInt();
        if(scan.hasNext())
            s=scan.nextInt();

        int[] arr=new int[n];
        for(int i=0;i<k;i++){
            arr[i]=s;
        }
        for(int i=k;i<n;i++){
            if(s%2!=0){
                arr[i]=2;
                continue;
            }
            if(s!=1000000000)
            arr[i]=s+1;
            else
                arr[i]=s-1;
        }
        for(int i=0;i<n;i++){
            System.out.print(arr[i]+" ");
        }
    }

}


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

using namespace std;

const int mod = 1e9 + 7;

int dp[1010][1010];
string b[1010];
int h, w;

int chk(int r, int c){
    return (r >= 0 && c >= 0 && b[r][c] == '.');
}

int main(){
    cin >> h >> w;
    for(int i = 0; i < h; i++) cin >> b[i];
    dp[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(chk(i, j - 1)) dp[i][j] += dp[i][j - 1];
            if(chk(i - 1, j)) dp[i][j] += dp[i - 1][j];
            dp[i][j] %= mod;
        }
    }
    cout << dp[h - 1][w - 1] << '\n';
}

Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
using namespace std;

int main(){
	int N, Y;
	int result[3];
	int i;
	rep(i,3)
		result[i] = -1;

	cin >> N >> Y;

	int target = N * 10000 - Y;
	bool flag = false;

	if(target == 0){
		result[0] = N;
		result[1] = 0;
		result[2] = 0;
		flag = true;
	}

	for(int i=1;i <= N;i++){
		if(flag)
			break;
		for(int j=0; j <= i; j++){
			int num1000 = j;
			int num5000 = i-j;
			int temp = target - num1000 * 9000 - num5000 * 5000;
			if(temp == 0){
				result[0] = N-i;
				result[1] = num5000;
				result[2] = num1000;
				flag = true;
			}
		}
	}

	cout << result[0] <<' '<< result[1] <<' '<< result[2] <<endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    b[a[i]-1]=i+1;
    
  }
  for(int i=0;i<n;i++){
    if(i!=n-1){
    cout<<b[i]<<" ";
    }
    else{
      cout<<b[i]<<endl;
  }
  }
}
    
  

Measured memory_bytes: 1664
n, k, c = map(int, input().split())
plan = list(input())

a = [0] * k
b = [0] * k

idx = 0
pause = c
for i in range(n):
  pause += 1
  if plan[i]=='x':
    continue
  if pause>c and idx<k:
    a[idx] = i+1 
    idx += 1
    pause = 0
  
idx = k-1
pause = c
for i in range(n-1, -1, -1):
  pause += 1
  if plan[i]=='x':
    continue
  if pause>c:
    if idx>=0:
      b[idx] = i+1
      idx -= 1
      pause = 0
#print(a)
#print(b)

for i in range(k):
  if a[i]==b[i]:
    print(a[i])

Measured memory_bytes: 21912
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

// this solution is wrong because 
// we don't check that 2nd last elemwnt val[i-2][j]
//and the last element can be same
int main(){

//#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
  //  freopen("output.txt", "w", stdout);
//#endif
int n;
cin>>n;
vector<vector<int>>val(n+1,vector<int>(3));
// vector<int>b(n);
// vector<int>c(n);
for(int i=1;i<=n;i++){
	cin>>val[i][0];
	cin>>val[i][1];
	cin>>val[i][2];
}
int dp[n+1][3];
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = 0;
for(int i=0;i<3;i++)
	dp[1][i] = val[1][i];
for(int i=2;i<=n;i++){
	// int m = INT_MIN;
	//wrong code
  	//
	// for(int j=0;j<3;j++){
	// 	m = max(dp[i-1][j],m);
	// }
	// for(int j=0;j<3;j++){
	// 	int m_except = INT_MIN;
	// 	for(int k=0;k<3;k++){
	// 		if(k!=j)
	// 			m_except = max(m_except,val[i-1][k]);
	// 	}

	// 	dp[i][j] = m+m_except+val[i][j];
	// }
	// right code
  	//cosidering combination of previous answer(for particular element) and 
  	//present element which is not same as previos element
	for(int j=0;j<3;j++){
		int m = INT_MIN;
		for(int k=0;k<3;k++){
			if(k!=j)
				m = max(dp[i-1][k]+val[i][j],m);
		}
		dp[i][j] = m;
	}
}
cout<<max(dp[n][1],max(dp[n][0],dp[n][2]));


}
		


Measured memory_bytes: 9792
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    //int[] num = new int[N];
    //int count = 0;
    while(A > 0 && C > 0){
        C -= B;
        if(C <= 0){
            break;
        }
        A -= D;
    }
    //System.out.println(A+","+C);
    if(A <=0){
        System.out.println("No");
    }else{
        System.out.println("Yes");
    }
    /*for(int i=0; i<N; i++){
        num[i] = sc.nextInt();
        H -= num[i];
    }*/
    //if(str.charAt(0) == str.charAt(1)){
    //}
  }
}

Measured memory_bytes: 35564
n = int(input())
x = list(map(int,input().split()))
j = max(x)
m = 0
y = True

for i in range(n):
    if x[0] != x[i]:
        y = False

if y:
    print(0)
    exit(0)

for p in range(j):
    c = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        c = c + (z * z)
    
    if m == 0:
        m = c
    else:
        if m > c:
            m = c

print(m)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    arc073c()
}

fun arc073c() {
    val (nTemp, t) = readLine()!!.split(" ").map { it.toLong() }
    val n = nTemp.toInt()
    val tList = readLine()!!.split(" ").map { it.toLong() }

    val sum = t + (1 until n).map { l -> Math.min(tList[l] - tList[l - 1], t) }.sum()

    println(sum)
}


Measured memory_bytes: 80892
#include <iostream>
#include <list>
#include <queue>
#include <array>
#include <limits>
#include <utility>

using namespace std;

struct Node
{
	int y;
	int x;
	int dir;
};

void adjacent(int& x, int& y, int dir)
{
	switch (dir)
	{
	case 0:
		y++;
		break;
	case 1:
		x++;
		break;
	case 2:
		y--;
		break;
	case 3:
		x--;
		break;
	}
}

long long MAX = numeric_limits<long long>::max();

struct MyGreater {
	bool operator()(const pair<Node, long long>& n1, const pair<Node, long long>& n2)
	{
		return n1.second > n2.second;
	}
};

int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	int x1, y1, x2, y2;
	cin >> y1 >> x1 >> y2 >> x2;
	vector<vector<char>> c(h, vector<char>(w));
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> c[i][j];
	
	vector<vector<array<long long, 4>>> dist(h, vector<array<long long, 4>>(w, {MAX, MAX, MAX, MAX}));
	vector<vector<array<bool, 4>>> visited(h, vector<array<bool, 4>>(w, {false, false, false, false}));
	for (int k = 0; k < 4; k++)
		dist[y1 - 1][x1 - 1][k] = 0;

	MyGreater myGreater;
	priority_queue<pair<Node, long long>, vector<pair<Node, long long>>, MyGreater> q(myGreater);
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			for (int k = 0; k < 4; k++)
				q.push({ { i, j, k }, dist[i][j][k] });


	while (!q.empty())
	{
		const auto& top = q.top();
		Node minNode = top.first;
		long long minDist = top.second;
		if (minDist == MAX)
			break;
		if (visited[minNode.y][minNode.x][minNode.dir])
		{
			q.pop();
			continue;
		}

		int newX = minNode.x;
		int newY = minNode.y;
		adjacent(newX, newY, minNode.dir);
		if (!(newX < 0 || newX >= w || newY < 0 || newY >= h)
			&& (c[newY][newX] != '@')
			&& (!visited[newY][newX][minNode.dir]))
		{
			long long newDist = minDist + 1;
			if (newDist < dist[newY][newX][minNode.dir])
			{
				dist[newY][newX][minNode.dir] = newDist;
				q.push({ {newY, newX, minNode.dir}, newDist });
			}
		}

		long long newRotationDist = minDist;
		if (minDist % k != 0)
			newRotationDist = (minDist / k + 1) * k;
		for (int dir = 0; dir < 4; dir++)
		{
			if (dir == minNode.dir)
				continue;
			if (newRotationDist < dist[minNode.y][minNode.x][dir])
			{
				dist[minNode.y][minNode.x][dir] = newRotationDist;
				q.push({ {minNode.y, minNode.x, dir}, newRotationDist });
			}
		}

		visited[minNode.y][minNode.x][minNode.dir] = true;
		q.pop();
	}

	long long minDist = MAX;
	for (int dir = 0; dir < 4; dir++)
	{
		long long temp = dist[y2 - 1][x2 - 1][dir];
		if (temp < minDist)
			minDist = temp;
	}
	if (minDist == MAX)
		cout << -1 << endl;
	else if (minDist % k == 0)
		cout << minDist / k << endl;
	else
		cout << minDist / k + 1 << endl;

	return 0;
}

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

#define int long long
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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int n; cin >> n;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }

    int res=0;
    map<int,int> map;
    for(int i=1; i<=n; i++){
        map[a[i]+i]++;
    }
    for(int i=1; i<=n; i++){
        if(i-a[i]>0) res+=map[i-a[i]];
    }
    cout<<res<<endl;

}

Measured memory_bytes: 18424
#include<cstdio>
#include<cstring> 
char k[1000000];
int main()
{
    scanf("%s",k);
	int c = strlen(k);
	for(int i=0;i<c;i++)
	{
		if((i+1)%2==1)
		{
			printf("%c",k[i]);
		}
	} 
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n, x;
    cin >> n >> x;
    std::vector<int> a;
    for (int i = 0; i < n; i++) {
        int m1;
        cin >> m1;
        a.push_back(m1);
    }
    std::sort(a.begin(), a.end());
    int result = 0;
    bool jump  = false;
    for (int i = 0; i < n - 1; i++) {
        int give = a[i];
        if (x - give >= 0) {
            result++;
            x -= give;
        } else {
            jump = true;
            break;
        }
    }

    if (!jump) {
        if (x == a[n - 1])
            result++;
    }

    cout << result << endl;

    return 0;
}


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

string con(ll n){
	string ans = "";
	while(n!=0){
		ans = ((char)('0'+n%2))+ans;
		n=n/2;
	}

	return ans;
}


ll doWork(ll a){
	a++;
	ll ans = 0;
	ll t;
	for(ll i=0;i<62;i++){
		t = (a/(1LL<<(i+1)))*(1LL<<i);
		t+= max(0LL,a%(1LL<<(i+1))-((1LL<<(i+1))>>1));

		if(t%2==1){
			ans = ans | (1LL<<i);
		}
	}

	//cout << con(ans) << "\n";
	return ans;
}


int main(){

	ll l,r;
	cin >> l >> r;

	ll t1 = doWork(min(l,r)-1);
	ll t2 = doWork(max(l,r));


	cout << (t1^t2) << "\n";



	return 0;
}

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

using namespace std;

int main(){
  int n, max_ans, another_lenght;
  another_lenght = 0;
  max_ans = 0;
  cin >> n;
  int L[n];
  for(int i=0; i<n; i++){
    cin >> L[i];
    another_lenght += min(max_ans, L[i]);
    max_ans = max(max_ans, L[i]);
  }
  if(max_ans < another_lenght){
    cout << "Yes" <<endl;
  }
  else cout << "No" <<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(void) {
  int num;
  stack<int> s;
  while(cin >> num) {
    if(num != 0) s.push(num);
    else { printf("%d\n", s.top()); s.pop(); }
  }
  return 0;
}

Measured memory_bytes: 0
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 9060
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.Char
import Control.Monad
import Control.Monad.ST

solve :: Int -> Int
solve 0 = 1
solve n = mulMod 2 $ solve (n-1)
    where
        mulMod a b = (a * b) `rem` (10^9+7)

search :: VU.Vector Int -> Int -> Bool 
search vec n = runST $ do
    (vec' :: VUM.STVector s Int) <- VUM.replicate n 0
    forM_ [0..n-1] $ \i -> do
        let v = vec VU.! i
        VUM.modify vec' (+1) v 
    vec'' <- VU.unsafeFreeze vec'
    if odd n
        then do
            let step b (i,e) = if i == 0 then (e == 1) && b else if even i then (e == 2) && b else (e == 0) && b
            return $ VU.foldl' step True (VU.zip (VU.fromList [0..n-1]) vec'')
        else do
            let step b (i,e) = if odd i then (e == 2) && b else (e == 0) && b
            return $ VU.foldl' step True (VU.zip (VU.fromList [0..n-1]) vec'')

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ 
        if search xs n
            then solve (n `quot` 2)
            else 0

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

namespace Contest_20191116
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x1 = int.Parse(s[0]);
            int y1 = int.Parse(s[1]);
            int x2 = int.Parse(s[2]);
            int y2 = int.Parse(s[3]);

            int x, y;
            x = x2 - x1;
            y = y2 - y1;

            int x3, y3, x4, y4;
            x3 = x2 - y;
            y3 = y2 + x;

            x4 = x3 - x;
            y4 = y3 - y;

            Console.WriteLine(x3 + " " + y3 + " " + x4 + " " + y4);
            

              


        }
    }
}


Measured memory_bytes: 13140
N = int(input())
x = [input() for i in range(N)]
AC = 0
WA = 0
TLE = 0
RE = 0
j = 0
while j < N :
  if x[j] == "AC":
    AC += 1
  if x[j] == "WA":
    WA += 1
  if x[j] == "TLE":
    TLE += 1
  if x[j] == "RE":
    RE += 1
  j += 1
  
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

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

int main(){
    int N; cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d.at(i);
    
    vector<int> ans(110);
    for (int i = 0; i < N; i++)
    {
        ans.at(d.at(i)) = 1;
    }
    int count = 0;
    for (int i = 0; i < ans.size(); i++)
    {
        if(ans.at(i) == 1) count++;
    }
    cout << count << endl;
    return 0;
}

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

int main(){
  string s; cin >> s;
  for(auto &c: s) if(c=='?') c = 'D';
  int count = 0;
  for(auto c: s) if(c=='D') count++;
  for(int i=0;i<s.length()-1;i++) if(s[i]=='P' && s[i+1]=='D') count++;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3720
# from line_profiler import LineProfiler
from collections import deque

def main():
    while(True):
        W, H = map(int, input().split())
        # print(W,H)
        if not W: break
        tx,ty = map(int, input().split())
        kx,ky = map(int, input().split())
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(input().split()):
                ma[i][j+1] = bool(1-int(a))
        from pprint import pprint
        que = deque([[tx,ty,kx,ky,0]])
        # pa = [[[[False]*(W+2) for ii in range(H+2)] for jj in range(W+2)] for kk in range(H+2)]
        pas = set()
        ans = "NA"
        while(que):
            # if len(que)>10:break
            # pprint(que)
            tx,ty,kx,ky,c = que.popleft()
            # import copy
            # toprint = copy.deepcopy(ma)
            # toprint[ty][tx] = "tt"
            # toprint[ky][kx] = "kk"
            # for i in range(H+2):
            #     print("".join(( toprint[i][j] if toprint[i][j] in ["tt","kk"] else "  ") if toprint[i][j] else "**" for j in range(W+2)))
            if c > 100: break
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
                kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
                # if pa[tx+tdx][ty+tdy][kx+kdx][ky+kdy]: continue
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                # pa[tx+tdx][ty+tdy][kx+kdx][ky+kdy] = True
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)
        # pprint(ma)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 35880
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

int main(){
    ll S,W;
    cin >> S >> W;
    if(S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    /*ll A,B,C,D;
    cin >> A >> B >> C >> D;
    rep(i,1000){
        if(i % 2 == 0){
            C -= B;
        }else{
            A -= D;
        }
        if(A <= 0){
            cout << "No" << endl;
            break;
        }
        if(C <= 0){
            cout << "Yes" << endl;
            break;
        }

    }*/
}


Measured memory_bytes: 3632
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,k=parseMap(split(readline()))
    println(n%k)
end
main()

Measured memory_bytes: 112264
#include<iostream>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll = long long;
ll box(ll y){
	if(y==1)return 1;
	else if(y==2)return 8;
	else return y+y*(y-1)*3+y*(y-1)*(y-2);
}
int main(){
	ll x[200000]={};
	ll n,k;
	cin>>n>>k;
	rep(i,1,n+1)x[i%k]++;
	if(k%2)cout<<box(x[0])<<endl;
	else cout<<box(x[k/2])+box(x[0])<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N, cin >> S;
    int leftDOTcost[N], rightSHcost[N];
    int leftDOTcur = 0, rightSHcur = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] != '.') ++leftDOTcur;
        leftDOTcost[i] = leftDOTcur;
        if (S[N - 1 - i] != '#') ++rightSHcur;
        rightSHcost[N - 1 - i] = rightSHcur;
    }
    int minCost = min(leftDOTcur, rightSHcur);
    for (int i = 0; i < N - 1; ++i) {
        minCost = min(minCost, leftDOTcost[i] + rightSHcost[i + 1]);
    }
    cout << minCost << endl;
    return 0;
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;

signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
main(){
  int N,L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i=0;i<N;i++) cin >> S[i];
  sort(S.begin(),S.end());
  string ans;
  for(int i=0;i<N;i++) ans+=S[i];
  cout << ans <<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N, K;
	string S;
	cin >> N >> S >> K;
	char target = S[K - 1];
	for(char& c : S)
	{
		if(c != target) cout << '*';
		else cout << c;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

if n >= 1800:
    print(1)
elif n >= 1600:
    print(2)
elif n >= 1400:
    print(3)
elif n >= 1200:
    print(4)
elif n >= 1000:
    print(5)
elif n >= 800:
    print(6)
elif n >= 600:
    print(7)
else:
    print(8)


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL //デバッグ出力系
#define dout cout
#define debug() if(true)
#else
#define dout if(false) cout
#define debug() if(false)
#endif//
#define next asdnext
#define prev asdprev
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define vrep(i, v) for(auto &i : v)
#define all(x) (x).begin(),(x).end()
#define vout(v) for(auto &i:v){cout<<i<<" ";}cout<<"\n"; //配列出力
#define vin(v) for(auto &i:v)cin>>i; //配列入力
#define vec(v,n) vector<int> v(n,0);
typedef long long ll;
typedef unsigned long long ull;

void Main() {
	int N;
	cin >> N;
	vec(d, N);
	vin(d);

	sort(all(d));
	//vout(d);
	//cout << (N / 2) + 1 << "\n";
	int ans = d[(N / 2)] - d[N / 2-1];
	cout << ans << "\n";
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 640
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int B[] = new int[N];
		int A[] = new int[N];
		
		for(int i=0;i<N-1;i++) {
			B[i] = Integer.parseInt(stdin.next());
		}
		
		B[N-1] = 100000;
		int sum = B[0];
		for(int i=N-1;i>=1;i--) {
			int max=0;
			for(int j=0;j<=B[i-1];j++) {
				if(B[i-1] >=j && B[i] >= j) {
					max=j;
				}
			}
			sum += max;
		}

		out.println(sum);
			
		out.flush();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, ar[N], odd;

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> ar[i];
		if(ar[i] % 2 == 1)
			odd++;
	}

	if(odd % 2 == 1) {
		cout << "NO";
		return 0;
	}

	cout << "YES";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

int n;
ll solve(){
   ll ans=0;
   

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

    cin>>n;
    vector<int>a(4);
    rep(i,n){
        string s;
        cin>>s;
        if(s=="AC")a[0]++;
        else if(s=="WA")a[1]++;
        else if(s=="TLE")a[2]++;
        else a[3]++;
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;
    //cout<<solve()<<endl;
    return 0;
}

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

vector <int> prefix;
 
int get (int pos) {
  	if (pos == -1) return 0;
  	return prefix[pos];
}

int main () {
	int n, q, cont = 0, l, r;
	string s;
	char* ps;
	cin >> n >> q;
	cin >> s;
	prefix.resize(n);
	prefix[0] = 0;
	ps = &s[1];
	for(int i = 1; i < n; i++) {
		if (*ps == 'C' && *(ps - 1) == 'A') {
			cont++;
		} 
		prefix[i] = cont;
		ps++;
	}
	
	for(int i = 0; i < q; i++) {
		cin >> l >> r;
		cout << get(r - 1) - get(l - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    string s;
    cin >> s;
    cout << s[0]<<s[1]<<s[2]<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct unionfind{
  int par[200010]; // 親ノード  必要に応じて要素数を変えよう
  int rank[200010]; // ランク　必要に応じて要素数を変えよう
  unionfind(int n){
    init(n);
  }
  void init(int n){
    for(int i=0;i<n;i++){
      par[i]=i;
      rank[i]=0;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }
  bool same(int x,int y) {
    return root(x) == root(y);
  }
  void unite(int x,int y) {
    x=root(x);
    y=root(y);
    if(x==y){
      return;
    }
    if(rank[x]<rank[y]){
      par[x]=y;
    }
    else{
      par[y]=x;
      if(rank[x]==rank[y]){
        rank[x]++;
      }
    }
  }
};
int main(){
  int n,m,k,a,b,c,i,x[200010];
  scanf("%d %d %d\n",&n,&m,&k);
  for(i=0;i<=m+n;i++){
    x[i]=0;
  }
  unionfind tree(m+n);
  unionfind tree1(m+n);
  for(i=0;i<k;i++){
    scanf("%d %d %d\n",&a,&b,&c);
    if(a==1){
      if(x[tree.root(b+m)]==1 && x[tree.root(c+m)]==1 && tree.same(b+m,c+m)==0){
      printf("%d\n",i+1);
      return 0;
      }
      tree.unite(b+m,c+m);
    }
    else{
      if(tree.same(b+m,c)==0 && x[tree.root(b+m)]==1){
        printf("%d\n",i+1);
        return 0;
      }
        tree.unite(b+m,c);
      x[tree.root(b+m)]=1;
    }
  }
  printf("0\n");
  return 0;
}


Measured memory_bytes: 5576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String strn = input.readLine( );
		int n = Integer.parseInt(strn);

		String stra = input.readLine( );
		String[] stralist = stra.split(" ");
		int[] a = new int[n];
		int count = 0;

		for(int i=0; i<n; i++){
			a[i] = Integer.parseInt(stralist[i]);
			if(a[i]%2 == 0){
				count = count+1;
			}
		}

		Arrays.sort(a);

		long answer = 1;
		if(n==1){
			if(a[0]==0){
				System.out.println(1);
			}else{
				System.out.println(0);
			}
		}else if(count==0){
			for(int i=0; i<n; i++){
				if(i%2 == 0 && a[i] != i+1){
					System.out.println(0);
					break;
				}else if(i%2 == 1 && a[i] != i){
					System.out.println(0);
					break;
				}
				if(i%2==0){
					answer = answer * 2 % ((long) Math.pow(10, 9) + 7);
				}
				if(i==n-1){
					System.out.println(answer);
				}
			}
		}else if(count==n){
			for(int i=1; i<n; i++){
				if(i%2 == 0 && a[i] != i){
					System.out.println(0);
					break;
				}else if(i%2 == 1 && a[i] != i+1){
					System.out.println(0);
					break;
				}
				if(i%2==0){
					answer = answer * 2 % ((long) Math.pow(10, 9) + 7);
				}
				if(i==n-1){
					System.out.println(answer);
				}
			}
		}else{
			System.out.println(0);
		}
	}
}



Measured memory_bytes: 37564
local n, y = io.read("*n", "*n")
for i = 0, n do
  for j = 0, n - i do
    local k = n - i - j
    if i * 1000 + j * 5000 + k * 10000 == y then
      print(tostring(k) .. " " .. tostring(j) .. " " .. tostring(i))
      return 
    end
  end
end
return print("-1 -1 -1")

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=301;
//ここまでテンプレ
int main(){
	int N,M;
	cin>>N>>M;
	//条件を、区間の右端で分ける
	vector<tint> Q[SIZE];
	for(int i=0;i<M;i++){
		int l,r,x;
		cin>>l>>r>>x;
		Q[r].eb(l,r,x);
	}
	//DP[i][j][k]=(red,green,bule)がそれぞれ最後に現れた場所
	static ll DP[SIZE][SIZE][SIZE]={};
	DP[0][0][0]=1;
	//DPテーブルを更新する
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			for(int k=0;k<=N;k++){
				//一番右の座標
				int now=max({i,j,k});
				//nowが右端になっている区間を見て、満たしてないのであれば0にする
				for(tint T:Q[now]){
					int l,r,x;
					tie(l,r,x)=T;
					//区間内に入っている色
					int color=(l<=i)+(l<=j)+(l<=k);
					//条件を満たしてなければ0に
					if(color!=x)
						DP[i][j][k]=0;
				}
				//遷移する
				if(now>=N)
					continue;
				DP[now+1][j][k]+=DP[i][j][k];
				DP[i][now+1][k]+=DP[i][j][k];
				DP[i][j][now+1]+=DP[i][j][k];
				DP[now+1][j][k]%=MOD;
				DP[i][now+1][k]%=MOD;
				DP[i][j][now+1]%=MOD;
			}
		}
	}
	ll ans=0LL;
	for(int i=0;i<=N;i++)
		for(int j=0;j<=N;j++)
			for(int k=0;k<=N;k++)
				if(max({i,j,k})==N){
					ans+=DP[i][j][k];
					ans%=MOD;
				}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 213376
#include<bits/stdc++.h>
using namespace std;
const int maxn  = 100005;
const int mod = 1e9+7;
 int dp[maxn];

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

    int n,m;
    cin >> n >> m;
    map<int,bool>ok;
    for(int i = 1; i <= m; i++){
        int x;
        cin >> x;
        ok[x] = true;
    }
    dp[0] = 1;
    dp[1] = 1;
    if(ok[1]) dp[1] = 0;
    for(int i = 2; i <= n; i++){
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
        if(ok[i]) dp[i] = 0;
    }
    cout << dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 5376
import java.util.Scanner;
class Main {
    int a,b; 
    public void kami(){
            Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        
        System.out.println(a * b + " " + (a + b) * 2);   
    }

    public static void main(String[] args) {
        new Main().kami();
    }

}

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

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    int ans = 0;
    int active = 0;
    for(int i = 0; i < n; i++) {
        if(active >= h[i]) {
            active = h[i];
        } else {
            ans += h[i] - active;
            active = h[i];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<setprecision(6)<<(w*h)/2.0<<" ";
	if(x==w/2.0&&y==h/2.0)
		cout<<1;
	else
		cout<<0;
	return 0;
}

Measured memory_bytes: 256
import Data.List

main = do
  [n, k] <- map read . words <$> getLine
  let me = [n, (n - 1)..1]
  let as = group $ map (func 0 k) me
  let zipedAz = zip (map head as) (map length as)
  let answer = solver zipedAz
  print (answer / fromIntegral n)

func :: Int -> Int -> Int -> Int
func n k me
  | me >= k = n
  | me < k  = func (n + 1) k (me * 2)

solver :: [(Int, Int)] -> Double
solver x = foldr (\ x -> (+) ((0.5 ^ (fromIntegral $ fst x) * (fromIntegral $ snd x)))) 0 x

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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  int count = 0;
  for (int x = 1; x <= n; x++) {
    if (to_string(x).length() % 2 == 1) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <climits>

using namespace std;

typedef pair<int, int> T;

bool cmp_pair(T a, T b) {
    return a.first < b.first;
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<T> vec(N);
    for (int i = 0; i < N; i++) {
        int A, B; cin >> A >> B;
        T t = make_pair(A, B);
        vec[i] = t;
    }

    sort(vec.begin(), vec.end(), cmp_pair);

    vec.push_back(make_pair(INT_MAX, 0));

    int sum = 0;
    priority_queue<int> cal;
    int idx = 0;
    for (int i = 1; i <= M; i++) {
        while (vec[idx].first <= i) {
            cal.push(vec[idx].second);
            idx++;
        }

        if (!cal.empty()) {
            sum += cal.top();
            cal.pop();
        }
        
    }

    cout << sum << endl;
}

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

using namespace std;
using ll = long long;

int main() {
    ll a,b,c,k = 0;
    cin >> a >> b >> c >> k;
    
    ll sum = 0;

    if(k >= a){
        sum += a;
        k -= a;
    }else{
        sum = k;
        k = -1;
    }


    if(k >= b){
        k -= b;
        sum -= k;
    }   

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n;
  long a[100000];
  long m[100000];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  long sum = 0;
  for(int i=0;i<n;i++){
    if(i % 2 == 0){
      sum += a[i];
    }else{
      sum -= a[i];
    }
  }
  m[0] = sum;
  printf("%ld ",m[0]);
  for(int i=1;i<n;i++){
    m[i] = 2*(a[i-1]) - m[i-1];
    printf("%ld ",m[i]);
  }
  return 0;
}


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

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

int main(void)
{
    int N;
    cin >> N;
    int A[N];
    REP(i, N)
    {
        cin >> A[i];
    }

    int max_val = 0;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            int sa = abs(A[i] - A[j]);
            max_val = max(sa, max_val);
        }
    }
    cout << max_val << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var x int
	fmt.Scan(&x)

	for i := x; ; i++ {
		ok := true
		for j := 2; j < int(math.Sqrt(float64(i))); j++ {
			if i%j == 0 {
				ok = false
				continue
			}
		}
		if ok {
			fmt.Println(i)
			return
		}
	}
}


Measured memory_bytes: 512