akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define INF 100000000000000000LL
using namespace std;
signed main() {
  int n, ma = 0, mi = INF;
  ll b, c = INF;
  int a[10000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ma = max(ma, a[i]);
    mi = min(mi, a[i]);
  }
  for (int i = mi; i <= ma; i++) {
    b = 0;
    for (int j = 0; j < n; j++) {
      b += (a[j] - i) * (a[j] - i);
    }
    c = min(c, b);
  }
  
  cout << c << "\n";
  return (0);
}

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

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    if((w*y == h*x || (w-x)*y == h*x) && x != 0 && x != w && y != 0 && y != w){
        printf("%.9lf 1", h*w/2);
    }else{
        printf("%.9lf 0", h*w/2);
    }
    return 0;
}

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

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

    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l.at(i);

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (l.at(i) != l.at(j) 
                        && l.at(i) != l.at(k) 
                        && l.at(j) != l.at(k)) {
                    if (l.at(i) + l.at(j) > l.at(k) &&
                            l.at(j) + l.at(k) > l.at(i) &&
                            l.at(k) + l.at(i) > l.at(j)) {
                        cnt++;
                    }
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3504
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long  arr[n][3];
    long long a,b,c;
    cin>>arr[0][0]>>arr[0][1]>>arr[0][2];
    for(long long i=1;i<n;i++)
    {
        cin>>a>>b>>c;
        arr[i][0]=max(a+arr[i-1][1],a+arr[i-1][2]);
        arr[i][1]=max(b+arr[i-1][0],b+arr[i-1][2]);
        arr[i][2]=max(c+arr[i-1][0],c+arr[i-1][1]);
    }
    cout<<max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2]));
}

Measured memory_bytes: 2560
import sys
lis_a = [0] * 3

for i in range(3):
    lis_a[i] = list(map(int, input().split()))

b = [0] * 3

for i in range(min(lis_a[0]) + 1):
    a_1 = i
    for k in range(3):
        b[k] = lis_a[0][k] - a_1
    a_2 = lis_a[1][0] - b[0]
    a_3 = lis_a[2][0] - b[0]
    a = [a_1, a_2, a_3]
    for l in range(3):
        for m in range(3):
            if a[l] + b[m] != lis_a[l][m]:
                print('No')
                sys.exit()
print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
using namespace std;

void solver() {
    int N;
    while(cin>>N){
        bool* isPrime=new bool[N+1];
        FOR(i,N+1)isPrime[i]=false;
        for (int i = 2; i <= N; ++i)
            isPrime[i] = true;
        for (int i = 2; i <= N; ++i) {
            if (isPrime[i])
                for (int j = 2 * i; j <= N; j += i)
                    isPrime[j] = false;
        }
        int cnt=0;
        FOR(i,N+1)if(isPrime[i])cnt++;
        delete[]isPrime;
        cout<<cnt<<endl;
    }
}

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

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

int main() {

    int a,b,c,x;

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

    int ans = 0;

    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
               if(i*500 + j*100 + k*50 == x){
                   ans++;
               }
            }
        }
    }

    cout << ans<< endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        Map<Integer,Integer> rankScore = new TreeMap<>();

        for (int i = 0; i < n ; i++) {
            rankScore.put(sc.nextInt(), sc.nextInt());
        }

        //int goodrank = rankScore.keySet().stream().min(Comparator.naturalOrder()).get();
        int badrank = rankScore.keySet().stream().max(Comparator.naturalOrder()).get();

        int scorebad = rankScore.get(badrank);
        badrank += scorebad;

        System.out.print(badrank);
    }
}

Measured memory_bytes: 99320
n,m=map(int,input().split())
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum(1 for i in  self._parents if i<0)
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size
lanper=[-1]*m
uf=UnionFind(n)
for i in range(n):
    for j in list(map(int,input().split()))[1:]:
        if lanper[j-1]==-1:lanper[j-1]=i
        else:uf.unite(lanper[j-1],i)
print("YES") if uf.connected() else print("NO")


Measured memory_bytes: 62808
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>

using namespace std;

string s;
int main() {

	cin >> s;

	if (s.length() == 2)
		cout << s << endl;
	else {
		char tmp = s[2];
		s[2] = s[0];
		s[0] = tmp;

		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#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>;
const long long AMAX = 119;
const long long AMIN = -118;
const long long BMAX = 118;
const long long BMIN = -119;

ll fact(ll *num){
  ll sum = 1ll;
  rep(_,5) sum = sum * (*num);
  return sum;
}

int main() {
  ll X;
  cin >> X;
  for(ll a = AMIN;a <= AMAX;a++){
    for(ll b = BMIN;b <= BMAX;b++){
      if(fact(&a)-fact(&b)==X){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
function main(input) {
	input = input.trim();
  	const [m, d] = input.split(' ').map(n => Number(n));
  	let result = 0;
  	for (let i = 1; i <= m; i++) {
      for (let j = 1; j <= d; j++) {
      	const d1 = j%10;
        const d10 = Math.floor(j/10);
        if (2 <= d1 && 2 <= d10 && i === d1 * d10) {
          result++;
        }
      }
    }
  	console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string s;
    cin >> s;
    int n = (int)s.size();
    int ans = n;
    int l = 0;
    int m = 0;
    int r = n;
    bool one = false;
    rep(i,n){
        if(s[i]=='1'){
            if(one){
                ++m;
                --r;
            }else{
                one = true;
                l = i;
                m = 1;
                r = n-i-1;
            }
        }else{
            if(one){
                ans = min(ans,max({l,r,min(l+m,r+m)}));
                one = false;
            }
        }
    }
    if(one){
        ans = min(ans,max({l,r,min(l+m,r+m)}));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3740
N = int(input())
A_list= list(input().split())

for i in range(N + 1):
    if i == N:
        print("APPROVED")
        break
    elif int(A_list[i]) % 2 == 0:
        if int(A_list[i]) % 3 == 0 or int(A_list[i]) % 5 == 0:
            continue
        else:
            print("DENIED")
            break


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

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

fn main() {
    let a = read::<i32>();
    let b = read::<i32>();

    let all = [1, 2, 3];
    let ans = all.iter().find(|&x| *x != a && *x != b);
    println!("{}", ans.unwrap());
}

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

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

  return 0;
}

Measured memory_bytes: 256
/*
    Author : Simanta Deb Turja
*/
#include <bits/stdc++.h>
using namespace std;

#define Professor

using ll = long long;
using i64 = unsigned long long;

template <typename T> inline T Min (T a, T b, T c) { return min(a, min(b, c)); }
template <typename T> inline T Min (T a, T b, T c, T d) { return min(a, min(b, min(c, d))); }
template <typename T> inline T Max (T a, T b, T c) { return max(a, max(b, c)); }
template <typename T> inline T Max (T a, T b, T c, T d) { return max(a, max(b, max(c, d))); }

template <typename T> inline T Ceil(T a, T b) { return ((a % b == 0) ? (a / b) : (a / b + 1)); } 
template <typename T> inline T Floor(T a, T b) { return a / b; }

template <typename T> inline T Power (T a, T p) { T res = 1, x = a; while ( p ) { if ( p & 1 ) res = ( res * x ); x = ( x * x ); p >>= 1;}return res; }
template <typename T> inline T BigMod (T a,T p,T M) { a %= M;T ret = 1; while (p) { if (p & 1) ret = (ret * a) % M; a = (a * a) % M; p = p >> 1; } return ret; }
template <typename T> inline T InverseMod (T a,T M) { return BigMod (a, M - 2, M); }

template <typename T> inline T gcd ( T a, T b ) { a = abs(a); b = abs(b); while ( b ) { a = a % b; swap ( a, b ); } return a; }
template <typename T> inline T lcm(T x,T y) { return (((x)/gcd((x),(y)))*(y)); }


#define endl '\n'
#define eb emplace_back

const int N = (int)4e5 + 10;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const ll LLINF = (ll)1e15+1;
const int INF = (int)1e9+1;
const ll MOD = (ll)1e9 + 7;

template <typename T> bool cmp (const pair <T, T> &a, const pair <T, T> &b) { return a.first < b.first; }


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    auto Solve = [&]() {
        #ifdef __APPLE__
            cout << "Running\n";
        #endif
        int n, W;
        cin >> n >> W;
        vector <ll> w(n), v(n);
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            cin >> w[i] >> v[i];
            sum += v[i];
        }
        vector <ll> dp(sum + 2, LLINF);
        dp[0] = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = sum; j >= v[i]; --j) {
                dp[j] = min(dp[j], w[i] + dp[j - v[i]]);
            }
        }
        ll mx = -1;
        for (int i = sum; i >= 0; --i) {
            if (dp[i] <= W) {
                mx = i;
                break;
            }
        }
        cout << mx << endl;
    };
    Solve();
    
    return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int a,b,c,x;
    int count=0;
    scanf("%d %d %d",&a,&b,&c);
    for(x=a;x<=b;x++){
        if(c%x==0){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S = "";
    int A = 0;
    int B = 0;
    int C = 0;
    int D = 0;
    cin >> S ;
    A = S.at(0);
    B = S.at(1);
    C = S.at(2);
    D = S.at(3);
    if(A == B || B == C || C == D){
        cout << "Bad";
    }else{
        cout << "Good";
    }


    return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
wv = []
for _ in range(N):
    wv.append(list(map(int, input().split())))
# print(wv)
dp = [[0] * 100100 for _ in range(110)]


for i in range(N):
    for sum_w in range(W + 1):

        if wv[i][0] <= sum_w:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - wv[i][0]] + wv[i][1])

        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print(dp[N][W])


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


int N;

int main() {
    cin >> N;

    pair<pair<string,int>,int> p[100];

    for (int i = 0; i < N; i++) {
        string S;
        int P;
        cin >> S >> P;
        p[i] = make_pair(make_pair(S,-P),i);
    }

    sort(p, p+N);

    for (int i = 0; i < N; i++) {
        cout << p[i].second+1 << endl;
    }

}

Measured memory_bytes: 256
import math
n = int(input())
x = range(1,math.ceil(n**0.5)+1,1)
b = []
for a in x:
    if n % a == 0:
        y = n//a
        b.append(y)
b_min = min(b)
a = n // b_min
sum = a+b_min-2
print(sum)
    


Measured memory_bytes: 3060
n = int(input())
p = list(map(int, input().split()))
pi = sorted(zip(p, range(n)))
left  = {i: i - 1 for i in range(n)}
right = {i: i + 1 for i in range(n)}
left[-1] = -1
right[n] = n

ret = 0
for p, i in pi:
    ret += p * (left[i] - left[left[i]]) * (right[i] - i)
    ret += p * (i - left[i]) * (right[right[i]] - right[i])
    l, r = left[i], right[i]
    right[l] = r
    left[r] = l
print(ret)

Measured memory_bytes: 74012
#include <iostream>
#include <vector>

int main() {
    int n, t, a;
    std::cin >> n >> t >> a;
    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }
    int diff = 1<<30;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int tmp = t*1000 - 6 * h[i];
        if (abs(tmp - a*1000) < diff) {
            diff = abs(tmp - a*1000);
            ans = i+1;
        }
    }
    std::cout << ans << std::endl;
}




Measured memory_bytes: 256
<?php
    while( true ) {
        fscanf( STDIN, "%d%d", $H, $W );
        if( 0 == $H && 0 == $W ) { return; }
         
        $buf = array();
        for( $i=0; $i<$H; $i++ ) {
            $row = '';
            for( $j=0; $j<$W; $j++ ) {
                $row .= '#';
            }
            array_push( $buf, $row );
        }
        print implode( "\n", $buf ).PHP_EOL.PHP_EOL;
    }

?>

Measured memory_bytes: 6716
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int mod = 1000000007;
        int n = sc.nextInt();
        long ans = powMod(10, n, mod) - powMod(9, n, mod) * 2 + powMod(8, n, mod);
        System.out.println(((ans % mod) + mod) % mod);
	}
  
    static long powMod(long num, int pow, int mod) {
        long r = 1L;
        for (int i = 0; i < pow; i++) {
            r = r * num % mod;
        }
        return r;
    }
}

Measured memory_bytes: 35804
using namespace std;
#include <bits/stdc++.h>
#define fdto(i, r, l) for(int i = r; i >= l; --i)
#define fto(i, l, r) for(int i = l; i <= r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;

    cout<<(1000-n%1000)%1000<<endl;
    return 0;
}

Measured memory_bytes: 3660
package main

import (
	"fmt"
	"strings"
)

func main() {

	var s string
	fmt.Scan(&s)

	s = reverse(s)
	s = strings.Replace(s, "resare", "", -1)
	s = strings.Replace(s, "esare", "", -1)
	s = strings.Replace(s, "remaerd", "", -1)
	s = strings.Replace(s, "maerd", "", -1)

	var res string
	if len(s) == 0 {
		res = "YES"
	} else {
		res = "NO"
	}
	fmt.Println(res)
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

bitset<100000> get_zigzag(bool b){
    bitset<100000> ret;
    for (ll i=0;i<100000;i++){
        ret[i] = (i % 2);
    }
    if (b) return ret; else {
        ret.flip();
        return ret;
    }
};


int main() {
    ll n;
    cin >> n;
    ll c1{0}, c2{0}, s_now{0}, s_prev{0};
    vector<ll> as(n, 0);
    for (auto &&i: irange(0LL, n)){
        cin >> as.at(i);
    }
    auto b = get_zigzag(true);
    for (auto &&i: irange(0LL, n)){
        s_now = s_prev + as.at(i);
        if (s_now == 0 || (b[i] != (s_now > 0))){
            c1 += abs((b[i] ? 1 : -1) - s_now);
            s_now = b[i] ? 1 : -1;
        }
        s_prev = s_now;
    }
    b = get_zigzag(false);
    s_now = 0;
    s_prev = 0;
    for (auto &&i: irange(0LL, n)){
        s_now = s_prev + as.at(i);
        if (s_now == 0 || (b[i] != (s_now > 0))){
            c2 += abs((b[i] ? 1 : -1) - s_now);
            s_now = b[i] ? 1 : -1;
        }
        s_prev = s_now;
    }
    cout << min(c1, c2) << endl;

    return 0;
}

Measured memory_bytes: 1024
N = int(input())
check = [0, 0, 0]
for i in range(N):
  str = input().split()
  check[i%3] = 1 if str[0] == str[1] else 0
  if sum(check) == 3:
    break
print('Yes') if sum(check) == 3 else print('No')

Measured memory_bytes: 8696
import sys

n = int(input())
a = list(map(int,input().split()))
dp = [sys.maxsize]*(n)
dp[0] = 0
for i in range(n-1):
  for j in (i+1,i+2):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))

print(dp[n-1])

 

Measured memory_bytes: 13928
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

struct uf_tree {
  vector<int> par, sizes;
  uf_tree(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  int find(int x) {
    if (x == par[x]) {
      return x;
    }
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return;
    }
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};

const int MAX_E = 100001;

struct edge {
  int u, v, cost;
};
bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }

edge es[MAX_E];
int V, E;

int kruskal() {
  sort(es, es + E, comp);
  uf_tree uf(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=jp
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int si, ti, wi;
    cin >> si >> ti >> wi;
    es[i] = edge{si, ti, wi};
  }

  cout << kruskal() << endl;
  return 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 110;
const int MW = 100010;

ll dp[MN][MW];

int main() {
    int N, W; cin >> N >> W;
    memset(dp, -1, sizeof(dp));

    dp[0][0] = 0;

    rep(i, N) {
        int w, v;
        cin >> w >> v;
        for (int j = 0; j <= W; ++j) if (dp[i][j] != -1) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j + w <= W) {
                dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j] + v);
            }
        }
    }

    cout << *max_element(dp[N], dp[N] + W + 1) << endl;

    return 0;
}

Measured memory_bytes: 86144
n, p = map(int, input().split())
A = list(map(int, input().split()))  

for a in A:
  if a % 2 != 0:
    break 
else:
  if p == 1: 
    print(0)
    exit()
  if p == 0: 
    print(2**n)
    exit()
  
ans = 2**(n-1)
print(ans)


Measured memory_bytes: 9140
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

typedef long long LL;
int n,m,d[100100],p[100100],a[100100],ans[100100];
LL k;
bool flag[100100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()) && ch!='-');
    bool flag=ch=='-';
    if (flag)
        ch=getchar();
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return flag?-x:x;
}

int main()
{
    n=getint()-1;
    repu(i,0,n)
        d[i]=getint();
    repd(i,n,1)
        d[i]-=d[i-1];
    repu(i,1,n)
        p[i]=i;
    for (scanf("%d%lld",&m,&k); m--;)
    {
        int x=getint();
        swap(p[x],p[x-1]);
    }
    repu(i,1,n)
        if (!flag[i])
        {
            flag[a[0]=i]=1,m=1;
            for (int j=p[i]; j!=i; flag[a[m++]=j]=1,j=p[j]);
            repu(j,0,m-1)
                ans[a[j]]=a[(j+k)%m];
        }
    LL sum=d[0];
    printf("%lld\n",sum);
    repu(i,1,n)
        printf("%lld\n",sum+=d[ans[i]]);
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()
const ll mod=1e9+7;

ll modpow(ll a,ll b){
  ll ans=1%mod;
  while(b){	
    if(b&1) ans=(ans*a)%mod;
    a=(a*a)%mod;
    b=b>>1; 
  }
  return ans;
  }

int main(){
  ll N;cin>>N;
  ll ans = modpow(10, N) - 2 * modpow(9, N) + modpow(8, N);
  //ans = (ans + mod * ((ans / mod) + 1)) % mod;
  ans = (ans + mod * 100000) % mod;
  cout << ans << endl;
}

Measured memory_bytes: 3632
h,w = gets.chomp.split.map(&:to_i)
s = h.times.map{gets.chomp.chars}
  0.upto(h-1) do |i|
    0.upto(w-1) do |j|
      next if i-1 < 0 || i+1 > h-1 || j-1 < 0 || j+1 > w-1
      if s[i][j] == '#'
        ( puts 'No';exit ) if [s[i+1][j],s[i-1][j],s[i][j-1],s[i][j+1]].all?{|n| n == '.'}
      end
    end
  end
puts "Yes"


Measured memory_bytes: 2172
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); i++)
#define rep1(i,n) for(int (i) = 1; (i) <= (int)(n); i++)
#define INF 1000000
#define MOD (ll)(1e9 + 7)





int main()
{
    char c;
    int a=0,b=0;
    rep(i, 3){
        cin >> c;
        if(c=='A'){
            a=1;
        }
        if (c=='B') {
            b=1;
        }
    }
    
    if(a&&b){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 256
/*
 * FileName:     C
 * CreatedDate:  2020-06-25 23:41:46 +0900
 * LastModified: 2020-06-26 00:04:58 +0900
 */

#include <stdio.h>
#define ama 1000000007
long long int factorial(long long int a){
    long long int ans = 1;
    while(a>0){
        ans *= a;
        ans %= ama;
        a--;
//        printf("%lld\n",ans);
    }
    return ans;
}
int main(void){
    long long int n, m;scanf("%lld%lld",&n,&m);
//    printf("%lld\n",factorial(n));
//    return 0;
    if(n==m){
        printf("%lld\n",2*factorial(n)*factorial(m)%ama);
    }
    else if( n+1==m || n==m+1 ){
        printf("%lld\n",factorial(n)*factorial(m)%ama);
    }
    else{
        printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 1700
N = int(input())
line = list(map(int, input().split()))

cnt = 0
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if line[j] < line[minj]:
            minj = j
    if minj != i:
        tmp = line[i]
        line[i] = line[minj]
        line[minj] = tmp
        cnt += 1

print(' '.join(list(map(str, line))))
print(cnt)

Measured memory_bytes: 7680
#include <iostream>
#define ll long long
using namespace std;

int main()
{
    ll n,d;
    cin >> n >> d;
    int coun=0;
    for(int i=0;i<n;i++)
    {
        ll x,y;
        cin >> x >> y;
        if(((x*x)+(y*y))<=(d*d))
            coun++;
    }
    cout << coun << endl;
}


Measured memory_bytes: 3632
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


K = int(sys.stdin.buffer.readline())
A, B = list(map(int, sys.stdin.buffer.readline().split()))

ok=False
for a in range(A, B + 1):
    if  a %K== 0:
        ok=True
if ok:
    print('OK')
else:
    print('NG')


Measured memory_bytes: 27228
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
string S; int a[4], b, cnt;
int main() {
	while (true) {
		cin >> S;
		if (S == "0000") { break; }
		if (S[0] == S[1] && S[2] == S[3] && S[1] == S[2]) { cout << "NA" << endl; }
		else {
			b = stoi(S);
			cnt = 0;
			while (b != 6174) {
				cnt++;
				for (int i = 0; i < 4; i++) {
					a[i] = (b / (int)pow(10, i)) % 10;
				}
				sort(a, a + 4);
				b = (a[3] - a[0]) * 1000 + (a[2] - a[1]) * 100 + (a[1] - a[2]) * 10 + (a[0] - a[3]);
			}
			cout << cnt << endl;
		}
	}
}

Measured memory_bytes: 3360
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdouble(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int main(void) {
	int n, m, i;
	n = getint();
	m = getint();
	int l[m], r[m];
	ROOP(i, m) {
		scanf("%d %d", &l[i], &r[i]);
	}
	int lMax = l[0], rMin = r[0];
	ROOP(i, m) {
		if (lMax < l[i]) lMax = l[i];
		if (rMin > r[i]) rMin = r[i];
	}
	if ((rMin - lMax) >= 0) {
		showint(abs(rMin - lMax) + 1);
	} else {
		showint(0);
	}
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdouble(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


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

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

int main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << min(A, B) + min(C, D) << endl;
}

Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = [0]*n
c = []
for i in range(n):
    a[i] = list(map(int,input().split()))
# 0 から (2^n)-1 までループ
for bit in range(1 << n):
    s = [0]*(m+1)

    for i in range(n):
        # bit に i 番目のフラグが立っているかどうか
        if bit & (1 << i):
            for j in range(m+1):
            # フラグが立っているならば sum に加算する
                s[j] += a[i][j]

    if all(s[j] >= x for j in range(1,m+1)):
        c.append(s[0])

if not c:
    print(-1)
else:
    print(min(c))

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

#define P(X) cout<<"db "<<X<<endl;
#define P2(X,Y) cout<<"d2 "<<X<<" "<<Y<<endl;
#define P3(X,Y,Z) cout<<"d3 "<<X<<" "<<Y<<" "<<Z<<endl;
#define SQ(x) ((x) * (x))

#define ll long long
#define pii pair<int,int>

#define bchk(n,i) ((bool)(n&(1<<i)))
#define bon(n,i) (n|(1<<i))
#define boff(n,i) n=n&(~(1<<i))

#define distance(a,b) (sq(a.x-b.x) + sq(a.y-b.y))
#define MAX3(a,b,c) max(a,max(b,c))
#define MS(XX,YY) memset(XX,YY,sizeof(XX));
#define FastIO ios_base::sync_with_stdio(0);cin.tie(nullptr);
#define eps 10e-9
#define MX 10000005

using namespace std;
int m,n,dp[16][(1<<16)+1];
vector <int> edge[16],ecost[16];
int tsp(int u,int mask){
    if(dp[u][mask]!=-1) return dp[u][mask];
    if(mask==((1<<n)-1)){
        for(int i=0;i<edge[u].size();i++){
            if(edge[u][i]==0) return ecost[u][i];
        }
        return MX;
    }
    int i,v,r,rm=MX;
    for(i=0;i<edge[u].size();i++){
        v=edge[u][i];
        if(!bchk(mask,v)){
            r=ecost[u][i]+tsp(v,bon(mask,v));
            rm=min(rm,r);
        }
    }
    return dp[u][mask]=rm;
}
int main()
{
    int i,j,test,cas=0;
    int a,b,r,w;
    //freopen("test.txt","r",stdin);
    scanf("%d %d",&n,&m);
    MS(dp,-1)
    for(i=0;i<m;i++){
        scanf("%d %d %d",&a,&b,&w);
        edge[a].push_back(b);
        ecost[a].push_back(w);
    }
    r=tsp(0,1);
    if(r>=MX)r = -1;
    printf("%d\n",r);

    return 0;
}



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

int main(){
    int n;
    cin>>n;
    int q[n];
    for(int i=0;i<n;i++)
        cin>>q[i];
    for(int k=0;k<n;k++)
        if(k==n-1) cout<<q[k]<<endl;
        else cout<<q[k]<<' ';
    for(int i=1;i<n;i++){
        int j=i-1,t=q[i];
        while(j>=0 && q[j]>t){
            q[j+1] = q[j];
            j--;
        }
        q[j+1] = t;
        for(int k=0;k<n;k++)
            if(k==n-1) cout<<q[k]<<endl;
            else cout<<q[k]<<' ';
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int prev; cin >> prev;
    int res = prev;

    for(int i=1; i+1<N; ++i) {
        int b; cin >> b;
        res += min(prev, b);
        prev = b;
    }
    res += prev;
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int check(int start, int end, string s){
    if(start > end || s[start-1] == '#'){
        return 1;
    }
    for(int i = start; i < end; i++){
        if(s[i] == '#' && s[i-1] == '#'){
            return 1;
        }
    }
    return 0;
}
int irekawari(int a, int b, string s, int N){
    for(int i = a; i < N-1; i++){
        if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' && (i+2) != b){
            //cout << i << endl;
            return i+2; //su
        }
    }
    return 0;
}
int main(){
    int N, a, b, c, d;
    int tmp1, tmp2;
    string s;
    cin >> N >> a >> b >> c >> d;
    cin >> s;
    // irekawari
    int e, f;
    if(c > d){
        f = irekawari(a, b, s, N);
        e = f-1;
        tmp1 = check(a, f, s);
        tmp2 = check(b, e, s);
        if(tmp1 == 1 || tmp2 == 1){
            cout << "No" << endl;
            return 0;
        }
        if(f == 0){
            cout << "No" << endl;
            return 0;
        }
        tmp1 = check(e, d, s);
        tmp2 = check(f, c, s);
        if(tmp1 == 1 || tmp2 == 1){
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
        return 0;
    }else{
        tmp1 = check(a, c, s);
        tmp2 = check(b, d, s);
        if(tmp1 == 1 || tmp2 == 1){
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
        return 0;
    }


}

Measured memory_bytes: 772
import java.util.Scanner;

public class Main {

		public static void main(String[] args){
			
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			// スペース区切りの整数の入力
			int b = sc.nextInt();
			int a = sc.nextInt();
			
			int intArray[][] = new int[a][2];
			for (int i = 0; i < a;i ++ ){
				intArray[i][0] = sc.nextInt();
				intArray[i][1] = sc.nextInt();
			}

			
			int intArray2[] = new int[b];
			for (int i = 0; i < b;i ++ ){
				intArray2[i] = 0;
			}
			
			for (int i = 0; i < a;i ++ ){
				intArray2[intArray[i][0] - 1] ++ ;
				intArray2[intArray[i][1] -1 ] ++ ;
			}

			for (int i = 0; i < b;i ++ ){
				System.out.println(intArray2[i]);
			}

		}
}


Measured memory_bytes: 23124
class fenwick_tree():
    def __init__(self, n:int, mod:int = 0):
        self.__mod = mod
        self.__n = n
        self.__data = [0] * self.__n

    def add(self, p:int, x:int):
        assert (0 <= p) & (p < self.__n)
        if(self.__mod == 0):
            self.__add_mod0(p,x)
        else:
            self.__add_mod(p,x)

    def __add_mod0(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            p += p & -p

    def __add_mod(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            self.__data[p-1] %= self.__mod
            p += p & -p

    def sum(self, l:int, r:int):
        assert (0 <= l) & (l <= r) & (r <= self.__n)
        if(self.__mod == 0):
            return self.__sum_mod0(r) - self.__sum_mod0(l)
        else:
            return self.__sum_mod(r) - self.__sum_mod(l)

    def __sum_mod0(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            r -= r & -r
        return s

    def __sum_mod(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            s %= self.__mod
            r -= r & -r
        return s

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
a = list(map(int,readline().split()))
query = list(map(int,read().split()))

ft = fenwick_tree(n,mod=10**18)
ans = []

for i,ai in enumerate(a):
    ft.add(i,ai)

i = 0
for _ in range(q):
    if(query[i]==0):
        p,x = query[i+1:i+3]
        ft.add(p,x)
    else:
        l,r = query[i+1:i+3]
        ans.append(ft.sum(l,r))
    i += 3

print('\n'.join(map(str,ans)))

Measured memory_bytes: 252772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int n, k, tmp;
    string s;
    vector<int> d(10, 0);
    cin >> n >> k;
    for(int i=0; i<k; i++){
        cin >> tmp;
        d[tmp] = 1;
    }
    for(int i=0; i<pow(10,6); i++){
        s = to_string(n);
        bool ans = true;
        for(int j=0; j<(int)s.length(); j++){
            if(d[(int)s[j] - 48] == 1){
                ans = false;
            }
        }
        if(ans){break;}
        n++;
    }
    cout << n << "\n";
    return 0;
}

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

char b[8][8];

void dfs(int x, int y) {
	b[y][x] = '0';
	for (int d = -3; d <= 3; d++) {
		if (0 <= x + d && x + d < 8 && b[y][x + d] == '1') dfs(x + d, y);
		if (0 <= y + d && y + d < 8 && b[y + d][x] == '1') dfs(x, y + d);
	}
}

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

	int T;
	cin >> T;
	for (int i = 1; i <= T; i++) {

		for (int y = 0; y < 8; y++) {
			for (int x = 0; x < 8; x++) {
				cin >> b[y][x];
			}
		}

		int sx, sy;
		cin >> sx >> sy;
		sx-- , sy--;
		dfs(sx, sy);

		cout << "Data " << i << ":" << endl;

		for (int y = 0; y < 8; y++) {
			for (int x = 0; x < 8; x++) {
				cout << b[y][x];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3200
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N,A[100001];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  int j = 0;
  int ans(1);
  for (int i(1);i<N;i++){
    if (A[i] == A[i-1]){
      if (j == 0) continue;
    }else if(A[i] > A[i-1]){
      if (j == 0){
        j = 1;
      }else if (j == -1){
        j = 0;
        ans++;
      }
    }else{
      if (j == 0){
        j = -1;
      }else if (j == 1){
        j = 0;
        ans++;
      }
    }
  }
  cout << ans << endl;
}




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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

ll fac[maxn], ifac[maxn], inv[maxn];

ll nck(ll n, ll k) {
    if (n<k) return 0;
    return fac[n]*ifac[k]%mod*ifac[n-k]%mod;
}

void gen_inv() {
    fac[0]=inv[0]=ifac[0]=1;
    fac[1]=inv[1]=ifac[1]=1;

    for (int i=2; i<maxn; i++) {
	fac[i]=fac[i-1]*i%mod;
	inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	ifac[i]=ifac[i-1]*inv[i]%mod;
    }

    assert(nck(4,2)==6);
}

void add(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x += y;
    if (x>=mod) x%=mod;
}



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

    gen_inv();

    ll s;
    cin>>s;

    ll res=0;

    for (int i=1; i<=2000; i++) {
	add(res, nck(s-3*i+(i-1), i-1));
    }

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


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



int main() {
int N;
cin >> N;
string tori[200];
for(int i = 0; i < N; i++){
cin >> tori[i];
}
bool check = 1;
for(int i = 0; i < N; i++){
    int count = 0;
for(int j = 0; j < N; j++){
if(tori[i] == tori[j])count++;
}
if(count > 1)check = 0;
}
for(int i = 0; i < N-1; i++){
int n = tori[i].size();
if(tori[i][n-1] != tori[i+1][0]) check = 0;
}
if(check == 1)cout << "Yes" << endl;
else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
main()
{
    int h,w,n,k;
    cin>>h>>w>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int c[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            c[i][j]=0;
        }
    }
    k=1;
    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;j++){
                c[i][j]=k;
                a[k]--;
                if(a[k]==0)
                    k++;
            }
        }
        else if(i%2==1) {
            for(int j=w-1;j>=0;j--){
                a[k]--;
                c[i][j]=k;

                if(a[k]==0)
                    k++;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<c[i][j]<<" ";
        }
        cout<<endl;
    }
}

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

int main() {
  string n;
  cin >> n;
  
  if(n.substr(0, 1) == n.substr(1, 1) && n.substr(1, 1) == n.substr(2, 1)){
    cout << "Yes" << endl;
  }
  else if(n.substr(1, 1) == n.substr(2, 1) && n.substr(2, 1) == n.substr(3, 1)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n = I()
        a = []
        e = collections.defaultdict(list)
        for i in range(n):
            k = I()
            l = S()
            e[k].append(i+1)
            a.append(l)
        f = [None] * n
        def ff(i,d):
            f[i-1] = 1
            r = ['.' * d + a[i-1]]
            for j in e[i]:
                r += ff(j,d+1)
            return r
        for i in range(n):
            if f[i]:
                continue
            rr += ff(i+1,0)

        break



    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 11528
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

int x;
vi dp, ps{100, 101, 102, 103, 104, 105};

int main(){
    R(x);
    dp.assign(x + 1, 0);

    dp[0] = 1;
    FORI(i, x){
        for(int p: ps){
            if(i >= p) dp[i] |= dp[i-p];
        }
    }

    W(dp[x]);

    return 0;
}


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

T = [0]
X = [0]
Y = [0]

judge = 'Yes'

for i in range(n):
    t, x, y = map(int,input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

for i in range(1, n+1):
    delt_t = T[i] - T[i-1]
    t_parity = delt_t % 2
    d = abs(X[i] - X[i -1]) + abs(Y[i] - Y[i - 1])
    d_parity = d % 2
    if delt_t >= d and t_parity == d_parity:
        continue
    else:
        judge = 'No'
        break

print(judge)

Measured memory_bytes: 17712
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int x = 1;
        for (int i = 0; i < n; i++) {
            x = Math.min(x*2, x+k);
        }

        System.out.println(x);
    }

}

Measured memory_bytes: 21204
import itertools
n, m, q = map(int,input().split())
a = []
b = []
c = []
d = []
for i in range(q):
    ai, bi, ci, di = map(int,input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)
ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    tmp = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)
print(ans)

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

int main(){
	int t,n;
	int a[100];
	cin >> t;
	for(int i=0 ; i<t ; ++i ){
		cin >> n ;
		for(int j=0 ; j<n ; ++j ){
			cin >> a[j];
		}
		int max_ = 0 ;
		int min_ = 0 ;
		for(int j=0 ; j<n-1 ; ++j ){
			int d = a[j+1] - a[j];
			max_ = max( max_ , d );
			min_ = min( min_ , d );
		}
		cout << max_ << " " << -min_ << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define N 100007
#define inf 9999999999
using namespace std;

long long mem[N];
long long ara[N];
int n, k;

long long dp(int i, int j)
{
    if(i >= n)
        return inf;
    if(i == j)
        return 0;
    if(mem[i] != -1)
        return mem[i];
    long long ans = inf;
    for(int p = 1;p <= k;p++)
    {
        ans = min(ans, abs(ara[i + p] - ara[i]) + dp(i + p, j));
    }
    mem[i] = ans;
    return ans;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> k;
    for(int i = 0;i < n;i++)
        cin >> ara[i];
    memset(mem, -1, sizeof(mem));
    cout << dp(0, n - 1) << endl;
    return 0;
}

Measured memory_bytes: 12936
#include <stdio.h>
#include <limits.h>

int main (void) {
    int n, i;
    scanf("%d", &n);
    int p[n + 1], min = INT_MAX, ans = 0;
    for ( i = 1; i <= n; i++ ) {
        scanf("%d", &p[i]);
        if ( p[i] <= min ) {
            ans++;
            min = p[i];
        }
    }

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

    return 0;
}



Measured memory_bytes: 896
j,k;long a[444],p[444][444],T,P;main(i){for(gets(p);~scanf("%d",a+j);)for(T=a[i=j++];i--;p[i][j]=P)for(P=9e18,T+=a[k=i];++k<j;)P=fmin(P,p[i][k]+p[k][j]+T);printf("%ld",P);}

Measured memory_bytes: 1664
#include <stdio.h>

int main(void)
{
	int N,D,i,j;
	scanf("%d",&N);
	scanf("%d",&D);
	i=2*D+1;
	j=N/i;
  	if(N%i>0)
    {
      j=j+1;
    }
	printf("%d",j);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

money = 1000
stock = 0

for i in range(n-1):
  if a[i+1] > a[i]:
    stock = money // a[i]
    money = money - stock * a[i] + stock * a[i+1]
    
print(money)

Measured memory_bytes: 9000
#include<bits/stdc++.h>
using namespace std;
int main(){
/*入力*/
int n,m;
/*問題*/
cin >> n;
vector<int> t(n,0);
for(int i=0;i<n;i++) cin >> t[i];
/*ドリンク*/
cin >> m;
vector<int> p(m,0),x(m,0);
for(int i=0;i<m;i++) cin >> p[i] >> x[i];

for(int i=0;i<m;i++){
  int sum = 0;
  for(int j=0;j<n;j++){
    if((p[i]-1) == j) sum+=x[i];
    else sum+=t[j];
  }
  cout << sum << endl;
}
}


Measured memory_bytes: 256