akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, k; cin >> n >> k;
    ll ans = k;
    FOR(i, 0, n - 1)ans *= k - 1;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
 
int n,k;
ld p[200010],S[200010];
 
void solve(){
  cin >> n >> k;
  S[0]=0;
  rep(i,n){
    cin >> p[i];
    S[i+1]=S[i]+(p[i]+(ld)1)/(ld)2;
    //cout << S[i+1] << endl;
  }
  ld ma=0;
  rep(i,n-k+1){
    //cout << S[i+k]-S[i] << endl;
    ma=max(ma,S[i+k]-S[i]);
  }
  cout << ma << endl;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

int main(){
	int h,w;
	cin>>h>>w;
	char c[h][w];
	rep(i,h){
		rep(j,w){
			cin>>c[i][j];
		}
		rep(j,w){
			cout<<c[i][j];
		}
		cout<<endl;
		rep(j,w){
			cout<<c[i][j];
		}
		cout<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define loop(n) for (ll i = 0; i < n; i++)
#define loopy(n) for (ll j = 0; j < n; j++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define oo 1e18
#define fr first
#define se second
#define in(x) scanf("%d",&x)
using namespace std;
const int N = 2e5 + 10;
const int M = 1e7 + 10;
const ll mod = 1e9 + 7;
pair < int , int >  a[N] ; 
int main(){ 
    
    int n , m ; cin >> n >> m ; 

    for( int i = 0 ; i < m ; i ++ ){
        cin >> a[i].fr >> a[i].se  ; 
    }
    
    // sort( a , a + m ) ;
    
    int l = a[0].fr ; 
    int r = a[0].se ;  
    int sum = 0 ;  
    
    for( int i = 1 ; i < m ; i ++  ){
            l = max ( l , a[i].fr ) ; 
            r = min ( r , a[i].se ) ; 
    }
    sum += r - l + 1 ; 
    cout<<max ( 0 , sum ) <<endl ; 

    return 0;
}
 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 155;
lint MOD;
inline void chkMOD(int & x) {
	if (x >= MOD) x -= MOD;
}
inline lint calc(int n, int k) {
	static int dp[MAXN];
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	rep (i, 0, n - 1) if (dp[i]) {
		rep (j, 1, k) if (i + j <= n) {
			chkMOD(dp[i + j] += dp[i]);
		}
	}
	int res = 0;
	rep (i, 0, n) {
		if (n - i < k) chkMOD(res += dp[i]);
	}
	return res;
}
inline void solveEven(int n, int k) {
	cout << calc(n / 2, k / 2 + 1) * calc((n + 1) / 2, k / 2 + 1) % MOD << endl;
}
inline void solveOdd(int n, int m) {
	static int dp[MAXN][MAXN][MAXN];
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	rep (i, 0, m / 2 + (n + 1) / 2 - 1) {
		rep (j, 0, n / 2) rep (k, 0, m + 1) {
			chkMOD(dp[i + 1][0][0] += dp[i][j][k]);
			if (i < n / 2) chkMOD(dp[i + 1][j + 1][0] += dp[i][j][k]);
			if (i >= m / 2) chkMOD(dp[i + 1][0][k ? k + 1 : 0] += dp[i][j][k]);
			if (i < n / 2 && i >= m / 2) chkMOD(dp[i + 1][j + 1][max(j + 2, k + 1)] += dp[i][j][k]);
		}
	}
	int res = 0;
	rep (j, 0, n / 2) rep (k, 0, m + 1) {
		chkMOD(res += dp[m / 2 + (n + 1) / 2][j][k]);
	}
	cout << res << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, k;
	cin >> n >> k >> MOD;
	if (k & 1) {
		solveOdd(n, k);
	} else {
		solveEven(n, k);
	}
	return 0;
}

Measured memory_bytes: 14848
import sys

def merge(A, left, mid, right):
    L = A[left: mid] + [sys.maxsize]
    R = A[mid: right] + [sys.maxsize]
    i = j = count = 0
    k = left
    while k < right:
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        k += 1
    return count

def merge_sort(A, left, right):
    if right - left > 1:
        mid = (left + right) // 2
        lcost = merge_sort(A, left, mid)
        rcost = merge_sort(A, mid, right)
        tot = merge(A, left, mid, right)
        return tot + lcost + rcost
    else:
        return 0

if __name__ == '__main__':
    n = int(input())
    A = [int(i) for i in input().split()]
    count = merge_sort(A, 0, n)
    print(str(A).replace(',', '').replace('[', '').replace(']', ''))
    print(count)


Measured memory_bytes: 63704
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Point p1 = new Point(0, 0), p2 = new Point(100, 0);
        System.out.println(p1.x + " " + p1.y);
        kochCurve(n, p1, p2);
        System.out.println(p2.x + " " + p2.y);
    }

    private static void kochCurve(int count, Point p1, Point p2) {
        if (count == 0) {
            return;
        }
        double a = Math.PI * 60 / 180;
        Point s = new Point((2 * p1.x + 1 * p2.x) / 3, (2 * p1.y + 1 * p2.y) / 3);
        Point t = new Point((1 * p1.x + 2 * p2.x) / 3, (1 * p1.y + 2 * p2.y) / 3);
        Point u = new Point((t.x - s.x) * Math.cos(a) - (t.y - s.y) * Math.sin(a) + s.x,
                            (t.x - s.x) * Math.sin(a) + (t.y - s.y) * Math.cos(a) + s.y);

        kochCurve(count - 1, p1, s);
        System.out.println(s.x + " " + s.y);
        kochCurve(count - 1, s, u);
        System.out.println(u.x + " " + u.y);
        kochCurve(count - 1, u, t);
        System.out.println(t.x + " " + t.y);
        kochCurve(count - 1, t, p2);
    }

    static class Point {

        public Point(double x, double y) {
            this.x = x;
            this.y = y;
        }

        double x;
        double y;
    }
}

Measured memory_bytes: 31780
import java.util.Scanner;

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

        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int l = Integer.parseInt(sc.next());

        int[][] A = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                A[i][j] = Integer.parseInt(sc.next());
            }
        }

        int[][] B = new int[m][l];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                B[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                long tmp = 0;
                for (int k = 0; k < m; k++) {
                    tmp += A[i][k] * B[k][j];
                }

                if (j == l - 1) {
                    System.out.printf("%d\n", tmp);
                } else {
                    System.out.printf("%d ", tmp);
                }
            }
        }
    }
}

Measured memory_bytes: 56600
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  h, w = map(int, input().split())
  grid = []
  for _ in range(h):
    grid.append(list(input().strip()))
  dp = [[0]*(w) for _ in range(h)]
  
  def cals_score(i, j):
    score = 10**9 + 7
    if i >= 1:
      score = dp[i-1][j] + (1 if grid[i-1][j]!=grid[i][j] else 0)
    if j >= 1:
      score = min(score, dp[i][j-1] + (1 if grid[i][j-1]!=grid[i][j] else 0))
    return score
      
  dp[0][0] = 1
  for i in range(1, w):
    dp[0][i] = cals_score(0, i)
  for i in range(1, h):
    dp[i][0] = cals_score(i, 0)

    
  for i in range(1, h):
    for j in range(1, w):
      dp[i][j] = cals_score(i, j)
  print(dp[-1][-1]//2 + dp[-1][-1]%2 * (grid[0][0]=='#'))

if __name__=='__main__':
  main()



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
int main(){
	int A;
	cin >> A;
    if(A/10==9 || A%10==9){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0585

"""
import sys
from sys import stdin
from math import sqrt
input = stdin.readline


def closest_part(points, n):
    # ?????¬???p324???
    if n <= 1:
        return float('inf')
    m = n // 2
    x = points[m][0]
    d = min(closest_part(points[:m], m), closest_part(points[m:], n-m))

    points.sort(key=lambda x:x[1])
    b = []
    for i in range(n):
        if (points[i][0] - x)**2 >= d:
            continue
        for j in range(len(b)):
            dx = points[i][0] - b[-j-1][0]
            dy = points[i][1] - b[-j-1][1]
            if dy**2 >= d:
                break
            d = min(d, (dx**2 + dy**2))
        b.append(points[i])
    return d


def main(args):
    n = int(input())
    points = [tuple(map(int, input().split())) for _ in range(n)]
    points.sort()               #  x????????§??????????????????

    result = closest_part(points, n)
    print(result)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 84180
n = int(input())
B = [int(i) for i in input().split()]
if n == 2:
    print(B[0]*2)
    exit()

ans = []
ans.append(B[0])
for i in range(n-2):
    ans.append(min(B[i],B[i+1]))
ans.append(B[-1])
#print(ans)
print(sum(ans))


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int i;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	i = atoi(ch);

	if(i == 0) {
		printf("1\n");
	} else {
		printf("0\n");
	}

	return 0;
}


Measured memory_bytes: 2024
program atcoder
    implicit none
    integer(8) :: i,j,n,m,ans=0,k
    integer(8),allocatable,dimension(:) :: a,sum
    read*,n
    allocate(a(n))
    read(*,*)(a(j),j=1,n)
    ans = a(1)
    do i=2,n
        ans = gcd(ans,a(i))
    enddo
    write(*,'(i0)')ans
    stop 
contains
    function gcd(x,y)
        implicit none
        integer(8) :: gcd
        integer(8) :: x,y
        if(y>x)then
            gcd=x
            x=y
            y=gcd
        endif
        gcd = 1
        do while(gcd/=0)
            gcd = mod(x,y)
            x = y
            y = gcd
        enddo
        gcd = x
    end function gcd
end program atcoder

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
#define REP(i,b,e) for(int i=b;i<(int)e;i++)
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
ll INF=1e18;
int inf=1e9+1000;

int N;
string s;
string ans;

int main(){
    cin>>N>>s;
    auto next_ans=[&](char ans1,char ans2,char s2){
        if(ans1=='S'&&ans2=='S'&&s2=='o') return 'S';
        if(ans1=='S'&&ans2=='W'&&s2=='o') return 'W';
        if(ans1=='W'&&ans2=='S'&&s2=='o') return 'W';
        if(ans1=='W'&&ans2=='W'&&s2=='o') return 'S';
        if(ans1=='S'&&ans2=='S'&&s2=='x') return 'W';
        if(ans1=='S'&&ans2=='W'&&s2=='x') return 'S';
        if(ans1=='W'&&ans2=='S'&&s2=='x') return 'S';
        if(ans1=='W'&&ans2=='W'&&s2=='x') return 'W';
        return '@';
    };
    ans="SS";
    rep(i,N-2){
        ans+=next_ans(ans[i-1],ans[i],s[i]);
    }
    if(next_ans(ans[N-2],ans[N-1],s[N-1])==ans[0]&&next_ans(ans[N-1],ans[0],s[0])==ans[1]){
        cout<<ans<<endl;
        return 0;
    }
    ans="SW";
    rep(i,N-2){
        ans+=next_ans(ans[i-1],ans[i],s[i]);
    }
    if(next_ans(ans[N-2],ans[N-1],s[N-1])==ans[0]&&next_ans(ans[N-1],ans[0],s[0])==ans[1]){
        cout<<ans<<endl;
        return 0;
    }
    ans="WS";
    rep(i,N-2){
        ans+=next_ans(ans[i-1],ans[i],s[i]);
    }
    if(next_ans(ans[N-2],ans[N-1],s[N-1])==ans[0]&&next_ans(ans[N-1],ans[0],s[0])==ans[1]){
        cout<<ans<<endl;
        return 0;
    }
    ans="WW";
    rep(i,N-2){
        ans+=next_ans(ans[i-1],ans[i],s[i]);
    }
    if(next_ans(ans[N-2],ans[N-1],s[N-1])==ans[0]&&next_ans(ans[N-1],ans[0],s[0])==ans[1]){
        cout<<ans<<endl;
        return 0;
    }
    cout<<-1<<endl;

    return 0;
}




Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int isPrime(int);

int main()
{
    int n, x, i, count = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &x);
	count += isPrime(x);
    }
    printf("%d\n", count);
    return 0;
}


int isPrime(int x)
{
    int i = 3;
    if (x == 2){ 
        return 1;
    }
    if (x < 2 || x % 2 == 0)
        return 0;
    while (i <= sqrt(x)) {
	if (x % i == 0)
	    return 0;
	i += 2;
    }
     return 1; 
}





Measured memory_bytes: 2028
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger A = sc.nextBigInteger();
		BigInteger B = sc.nextBigInteger();
		if (A.compareTo(B) > 0) {
			System.out.println("GREATER");
		} else if (A.compareTo(B) < 0) {
			System.out.println("LESS");
		} else {
			System.out.println("EQUAL");
		}
		sc.close();
	}
}

Measured memory_bytes: 23252
import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val Array(a, b, c, d) = StdIn.readLine().split(' ').map(_.toLong)
    println(solve(a, b, c, d))
  }

  def solve(a: Long, b: Long, c: Long, d: Long): Long = {
    count(b, c, d) - count(a - 1, c, d)
  }

  def count(a: Long, c: Long, d: Long): Long = {
    a - a / c - a / d + a / lcm(c, d)
  }

  def lcm(x: Long, y: Long): Long = {
    x * y / gcd(x, y)
  }

  def gcd(x: Long, y: Long): Long = {
    if (y == 0) {
      x
    } else {
      gcd(y, x % y)
    }
  }

}


Measured memory_bytes: 25548
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	S := nextLine()
	if len(S) <= 9 && len(S) >= 5 && !strings.Contains(S, "AA") && !strings.Contains(S, "KA") && !strings.Contains(S, "IA") && strings.ReplaceAll(S, "A", "") == "KIHBR" {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
	// switch S {
	// case "KIHABARA","AKIHBARA","AKIHABRA","AKIHABAR","KIHBARA","KIHABRA","KIHABAR","AKIHABR","AKIHBAR","":

	// }
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

using namespace std;

class Solver {
    public:
        string s;
        bool can_assign() {
            bool exists[52][2];
            bool is_possible;
            int negpos = 1;
            for (int i = 0; i < (int)s.length(); ++i) {
                if (s[i] == '(') {
                    for (int j = 0; j < 52; ++j) {
                        exists[j][0] = exists[j][1] = false;
                    }
                    is_possible = true;
                } else if (s[i] == ')') {
                    if (is_possible) {
                        return true;
                    }
                    ++i;
                } else if (s[i] == '~') {
                    negpos = 1- negpos;
                } else if (('a' <= s[i] && s[i] <= 'z') || ('A' <= s[i] && s[i] <= 'Z')) {
                    int n;
                    if ('a' <= s[i] && s[i] <= 'z') {
                        n = s[i] - 'a';
                    } else {
                        n = s[i] - 'A' + 26;
                    }
                    if (exists[n][1 - negpos]) {
                        is_possible = false;
                    }
                    exists[n][negpos] = true;
                    negpos = 1;
                }
            }
            return false;
        }
};

int main() {
    Solver s;
    while (true) {
        cin >> s.s;
        if (s.s == "#") {
            return 0;
        }
        if (s.can_assign()) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}

Measured memory_bytes: 1180
#include<cstdio>
#include<cstring>


int n;
int m[101],p[101][101];
int k;
int l[101];
int ng[101];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(ng,0,sizeof(ng));
		for(int i=0;i<n;i++){
			scanf("%d",&m[i]);
			for(int j=0;j<m[i];j++){
				scanf("%d",&p[i][j]);
			}
		}
		scanf("%d",&k);
		for(int i=0;i<k;i++){
			scanf("%d",&l[i]);
			ng[l[i]]=1;
		}

		int res=-1,cnt;
		for(int i=0;i<n;i++){
			cnt=0;
			for(int j=0;j<m[i];j++){
				if(ng[p[i][j]]==1)cnt++;
			}
			if(cnt==k){
				if(res!=-1)res=-2;
				if(res==-1)res=i;
			}
		}
		if(res<0)printf("-1\n");
		else printf("%d\n",res+1);

	}
	return 0;
}

Measured memory_bytes: 1080
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)
	writer := bufio.NewWriter(os.Stdout)

	var h, w int
	fmt.Sscan(getNextLine(scanner), &h, &w)

	pic := make([][]byte, h+2)
	for i := 0; i < h+2; i++ {
		pic[i] = make([]byte, w+2)
		for ii := 0; ii < w+2; ii++ {
			pic[i][ii] = '.'
		}
	}

	for i := 1; i <= h; i++ {
		s := getNextLine(scanner)
		for ii := 1; ii <= w; ii++ {
			pic[i][ii] = s[ii-1]
		}
	}
	for i := 1; i <= h; i++ {
		for ii := 1; ii <= w; ii++ {
			if pic[i][ii] == '.' {
				continue
			}
			if pic[i-1][ii] == '.' && pic[i+1][ii] == '.' && pic[i][ii-1] == '.' && pic[i][ii+1] == '.' {
				fmt.Fprintln(writer, "No")
				writer.Flush()
				return
			}
		}
	}
	fmt.Fprintln(writer, "Yes")
	writer.Flush()
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

string vow = "aeiou";

void solve ( int test_case )
{
    int n , k , q ;
    cin >> n >> k >> q ;

    vi v ( n ) ;
    int Q = q ;
    while ( q-- )
    {
        int indx ; cin >> indx ;
        v[indx - 1] ++ ;
    }

    for ( int i=0 ; i < n ; i++ )
    {
        int chk = k - (Q - ( v[i] )) ;
        if ( chk > 0 ) cout << "Yes" ;
        else cout << "No" ;

        line
    }
}

int main()
{fast
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

long long n, a, b;
vector <int> x;

int main() {
	cin >> n >> a >> b;
	x = vector <int> (n);
	rep (i, n) cin >> x[i];
	long long ans = 0;
	rep (i, n - 1) ans += min(b, (x[i + 1] - x[i]) * a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>


using namespace std;


int main()
{
    string text;

    //method 1
    // vector<int> count(26);

    // while (getline(cin,text))
    // {
    //     for (int i = 0; i < text.size(); i++)
    //     {
    //         if (text[i] >= 'a' && text[i] <= 'z')
    //             count[text[i]-'a']++;
    //         else if (text[i] >= 'A' && text[i] <= 'Z')
    //             count[text[i]-'A']++;
    //     }

    // }

    // for (char i = 'a'; i <= 'z'; i++)
    // {
    //     cout << i << " : " << count[i-'a'] << endl;
    // } 


    //method 2
    map<char, int> count;

    while (getline(cin, text))
    {
        int i = 0;
        while (text[i] != '\0')
        {
            char ch = tolower(text[i++]);
            if (ch >= 'a' && ch <= 'z')
                count[ch]++;
        }        
    }

    char ch = 'a';
    while (ch <= 'z')
    {
        cout << ch++ << " : " << count[ch] << endl;
    }


    //method 3
    // map<char, int> count;

    // char ch;
    // while (cin.get(ch))
    // {
    //     ch = tolower(ch);
    //     if (ch >= 'a' && ch <= 'z')
    //         count[ch]++;        
    
    // }

    // for (char i = 'a'; i <= 'z'; i++)
    // {
    //     cout << i << " : " << count[i] << endl;
    // }            

}


Measured memory_bytes: 3172
#include <stdio.h>

#define Mod 1000000007

int main()
{
	int N;
	char S[200001];
	scanf("%d", &N);
	scanf("%s", S);
	
	int i, count = 0;
	long long ans = 1;
	for (i = 0; S[i] != 0; i++) {
		if (i % 2 == 0 && S[i] == 'B' || i % 2 == 1 && S[i] == 'W') count++;
		else if (count > 0) ans = ans * (count--) % Mod;
		else {
			printf("0\n");
			fflush(stdout);
			return 0;
		}
	}
	if (count > 0) {
		printf("0\n");
		fflush(stdout);
		return 0;
	}
	for (i = 2; i <= N; i++) ans = ans * i % Mod;
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

#define SET -1

void sort(int *A,int N){
	int tmp;
	for(int i=0;i<(N-1);i++){
		for(int j=(N-1);j>i;j--){
			if(A[j-1]<A[j]){
				tmp=A[j-1];
				A[j-1]=A[j];
				A[j]=tmp;
			}
		}
	}
}

int frac(int *L,int N,int now,int x,int depth){
	//printf("now=%d\n",now);
	if(now==x){return 1;}
	if(now>x){return -1;}

	int ans;
	int *L2=(int*)malloc(sizeof(int)*N);
	for(int i=0;i<N;i++){
		L2[i]=L[i];
	}

	for(int i=depth;i<N;i++){
		if(L2[i]!=SET){//printf("A=%d\n",L[i]);
		
			L2[i]=SET;
			ans=frac(L2,N,now+L[i],x,depth+1);
			L2[i]=L[i];
			if(ans==1){
				free(L2);
				return 1;
			}
		}
	}
	free(L2);
	return -1;

}

int calc(int *A,int N,int x){
	int max=0;
	for(int i=0;i<N;i++){
		max+=A[i];
	}
	if(max<x){
		return -1;
	}
	if(max==x){
		return 1;
	}

	for(int i=0;i<N;i++){
		if(A[i]<=x){
			//printf("A=%d\n",A[i]);
			if(frac(A,N,A[i],x,(i+1))==1){

				return 1;
			}
		}
	}

	return -1;
}

int main(){
	int N,Q;
	int *A,m;

	scanf("%d",&N);
	A=(int*)malloc(sizeof(int)*N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	sort(A,N);

	scanf("%d",&Q);
	for(int i=0;i<Q;i++){
		scanf("%d",&m);
		if(calc(A,N,m)==1){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 2100
a,b=map(int,input().split())
a-=1
b-=1
s=[".","#"]*50
t=["#"]*100
q=["#","."]*50
p=["."]*100
ans=[]
#白について
aaa=a//50
aa=a%50
for i in range(aaa):
    ans.append(s)
    ans.append(t)
x=[".","#"]*aa+["#","#"]*(50-aa)
ans.append(x)
ans.append(t)
ans.append(p)

bbb=b//50
bb=b%50
for i in range(bbb):
    ans.append(q)
    ans.append(p)
x=["#","."]*bb+[".","."]*(50-bb)
ans.append(x)

print(len(ans),100)
for u in ans:
    print("".join(u))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

 
int main(){
	int a,b;
	bool c = false;
	while(cin>>a>>b,(a||b)){
		if(c) cout << endl;
		bool ok = false;
		for (int i = a; i <= b; i++){
			if(i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)){
				cout << i << endl;
				ok = true;
			}
		}
		if(!ok) cout << "NA" << endl;
		c = true;
	}
    return 0;
}

Measured memory_bytes: 0
//abc095_c.cpp
//Sat Apr 21 20:19:03 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

int main(){
	int a;
	int b;
	int c;
	int x;
	int y;
	cin >> a >> b >> c >> x >> y;

	int cost = 0;

	if (a+b > 2*c){
		if (x>y){
			cost = 2*x*c;
		}else if (x<=y){
			cost = 2*y*c;
		}
	}else {
		cost = a*x + b*y;
	}

	int min = 0;
	int costtemp = 0;
	if (x>y){
		min = y;
	}else if (x<=y){
		min = x;
	}
	costtemp = min * c * 2 + (x-min)*a + (y-min)*b;

	if (costtemp < cost){
		cost = costtemp;
	}

	cout << cost << endl;
}

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

main(){
  string N;
  cin >> N;
  int sum=0;
  char s='0';
for(int i=0; i<N.size();i++){
      sum=sum+(N[i]-s);
  }

int sum1=0;
  for(int i=0; i<N.size();i++){
    int num=N[i]-s;
  for(int j=0; j<N.size()-i-1;j++){
     num=num*10;
  }
   sum1=sum1+num; 
  }
 
  if(sum1%sum==0) cout << "Yes" <<endl;
    else cout << "No" <<endl;

}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main()
 {
     int n,x,y,cnt=0,k=0;
     cin>>n;
     for(int i=1;i<=n;i++)
     {
         cin>>x>>y;
         if(x==y)
         {
             cnt++;
             if(cnt==3)
             {
                 k=1;
             }
         }
         else
            cnt=0;
     }
     if(k==1)
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
 }


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  vector<vector<int>> shop(n, vector<int>(10));
  rep(i, 0, n) scan(shop[i]);
  vector<vector<ll>> profit(n, vector<ll>(11));
  rep(i, 0, n) scan(profit[i]);

  ll ans = -LL_INF;
  rep(i, 1, (1 << 10)) {
    ll total = 0;
    rep(j, 0, n) {
      int count = 0;
      rep(k, 0, 10) { count += (i & (1 << k)) && shop[j][k]; }
      total += profit[j][count];
    }
    chmax(ans, total);
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
choice = n // 2

dic1 = {0:0}
dic2 = {0:0, 1:a[0]}

for i in range(1, n):
    mini = choice - (n-i+1)//2
    new = {}
    for j in range(mini, (i+2)//2+1):
        if j == 0:
            new[j] = 0
            continue
        if j in dic2:
            new[j] = max(dic2[j], dic1[j-1]+a[i])
        else:
            new[j] = dic1[j-1]+a[i]
    dic1 = dic2
    dic2 = new

print(dic2[choice])

Measured memory_bytes: 94160
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    ll h, w;
    cin >> h >> w;
    
    ll ans = 0;

    if (h == 1 || w == 1)
    {
        ans = 1;
    }
    else
    {
        ans = (h * w + 1) / 2;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(void)
{
	long long int i, n, k,t;
	double sum=0;
	

	cin >> n >> k;
	vector<double> num(n,1.0);
	vector<long long int> mt(n, 0);
	for (i = 0; i < n; i++)
	{
		mt[i] = i + 1;
		t = 0;
		for (t = 0; mt[i] < k; t++)
		{
		
			mt[i] = mt[i] * 2;
		}
		mt[i] = t;
	}
	for (i = 0; i <n; i++)
	{
		for (t = 0; t < mt[i]; t++)
		{
			num[i] = num[i] / 2.0;
		}
		if (num[i] == 0)
		{
			num[i] = 1;
		}
		num[i] = num[i] / n;
	}

	for (i = 0; i < n; i++)
	{
		sum = sum + num[i];
	}
 
	printf("%.11lf\n", sum);



	return 0;
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll gcd(ll a, ll b){
    ll tmp;
    if(a%b == 0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}

const ll SIZE = 1e5+10;

string s;

int main(){
    cin >> s;
    for(int i = 1; i <= 2; i++){
        if(s[i] != s[0]){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_set>
#include <string>
#include <random>
#include <queue>


using namespace std;

// ans = a ? b : c; // to simplify: if (a) ans = b; else ans = c;
// ans += val; // to simplify: ans = ans + val; and its variants
// index = (index + 1) % n; // index++; if (index >= n) index = 0;
// index = (index + n - 1) % n; // index--; if (index < 0) index = n - 1;
// int ans = (int)((double)d + 0.5); // for rounding to nearest integer
// ans = min(ans, new_computation); // min/max shortcut
// alternative form but not used in this book: ans <?= new_computation;
// some code use short circuit && (AND) and || (OR)

typedef long long ll; // comments that are mixed in with code
typedef pair<int, int> ii; // are aligned to the right like this
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
#define INF 1000000000
#define M_PI 3.14159265358979323846

void printVector2d(vector<vector<int>> a){
    for(int i=0;i<a.size();i++){
        for(int j=0;j<a[i].size();j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<"end"<<endl;
}

void printVector(vector<int> a){
    for(int i=0;i<a.size();i++){
        int curr_num = a[i]+1;
        cout<<curr_num<<" ";
    }
    cout<<endl;
}

void printVectorTwo(vector<int> a){
    for(int i=0;i<a.size();i++){
        int curr_num = a[i];
        cout<<curr_num<<" ";
    }
    cout<<endl;
}

void printVectorPair(vector<pair<int,int>> a){
    for(int i=0;i<a.size();i++){
        cout<<"Total "<<i<<": "<<a[i].first<<" "<<a[i].second<<endl;
    }
}

void printMap(map<char, int> mp){
    for(auto x:mp){
        cout<<x.first<<": "<<x.second<<endl;
    }
}

void printMapVec(map<int, vector<int>> mpV){
    for(auto x:mpV){
        cout<<x.first<<": ";
        for(auto y:x.second){
            cout<<y<<" ";
        }
        cout<<endl;
    }
}

void printQueue(queue<char> q){
    while(!q.empty()){
        cout<<q.front()<<" ";
        q.pop();
    }
    cout<<" ##### ";
}

void solve(){
    int K, ans;

    cin>>K;

    ll curr_checker  = 0;
    ans = 0;

    if(K%2==0 || K%5==0){
        cout<<-1<<endl;
        return;
    }

    bool found_ans = false;
    while(!found_ans){
        curr_checker = (curr_checker*10 + 7)%K;
        if(curr_checker==0){
            found_ans = true;
//            cout<<curr_checker<<endl;
        }
        ans++;
        if(ans>pow(10,7)){
            ans = -1;
            break;
        }
    }
    cout<<ans<<endl;
}

int main() {
    //solve();
    int T;
//    cin >> T;
    T=1;
    for (int case_num = 1; case_num <= T; case_num++) {
//        cout<<"Case #"<<case_num<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3204
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var tmp = Console.ReadLine().Split(' ');
            var a = int.Parse(tmp[0]);
            var b = int.Parse(tmp[1]);
            var flag = false;
            for (int i = 0; i < 1000 / k + 1; i++)
            {
                if(a <= i * k && i * k <= b)
                {
                    flag = true;
                }
            }
            Console.WriteLine(flag ? "OK" : "NG");
        }
    }
}


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

int main() {
	int N, K, ans = 0;
	cin >> N >> K;
	pair<int, int> p[N];
	for (int i = 0; i < N; i++) {
		cin >> p[i].first;
		p[i].second = (K - p[i].first);
		ans += (2 * min(p[i].first, p[i].second));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
 
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k,t=1;

void solve()
{
   
   cin>>n;
   vector<ll>v(n);
   m=0;
   for(ll i=0;i<n;i++)cin>>v[i],m^=v[i];
   for(ll i=0;i<n;i++)cout<<(m^v[i])<<" ";
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

 // cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 4704
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


//xのn乗%modを計算
ll mod_pow(ll x,ll n,ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

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

    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    map<int,int> m;
    rep(i,n)m[v[i]]++;
    bool ch=true;
    for(auto it=m.begin();it!=m.end();it++){
        if(it->first==0&&it->second!=1)ch=false;
        else {
            if(it->first!=0&&it->second!=2){
                ch=false;
            }
        }
        // cout<<it->first<<" "<<it->second<<endl;
    }
    if(!ch)fin(0);
    else{
        cout<<mod_pow(2,n/2,P)<<endl;
    }

    
    

//////////////////////////////////////////////////////
return 0;}



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

int main()
{
    int a,b,d=0;
    string c;
    cin>>a>>c>>b;
    if(c[0]=='+')
    {
        d=a+b;
    }
    else
    {
        d=a-b;
    }
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

string s;
int dp[330][330][330];

int f(int st,int en,int k){
    if(st >en)return 0;
    if(st == en){
        return 1;
    }
    int &ret = dp[st][en][k];
    if(ret != -1)return ret;
    int r =0;
    r = max(r,f(st+1,en,k));
    r = max(r,f(st,en-1,k));

    if(k ||(s[st] == s[en]))
        r = max(r,f(st+1,en-1,k-(s[st] != s[en]))+2);

    return ret = r;
}

int v[100100];
int main()  {
    int k;
    ios::sync_with_stdio(0);
    cin>>s>>k;
    int n = s.size();
    memset(dp,-1,sizeof dp);

    int mx =f(0,n-1,k);
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 140672
N = int(input())
L = list(map(int, input().split()))
 
ans = 0
if(N >= 3):
  t = []
  for i in range(N):
    for j in range(i+1, N):
      for k in range(j+1, N):
        if((L[i] != L[j]) & (L[i] != L[k]) & (L[j] != L[k]) & (abs(L[j]-L[k]) < L[i]) & (L[i] < L[j]+L[k])): t.append((L[i], L[j], L[k]))
  ans = len(t)

print(ans)

Measured memory_bytes: 20256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    bool ans = true;
    REP(i, s.size()) {
        char c = s[i];
        if(i % 2 == 1) {
            if(c == 'L' || c == 'U' || c == 'D') {

            } else {
                ans = false;
            }
        } else {
            if(c == 'R' || c == 'U' || c == 'D') {

            } else {
                ans = false;
            }
        }
    }
    if(ans) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C, 0));
    rep(i,C) rep(j,C) cin >> D[i][j];
    vector<vector<int>> c(N, vector<int>(N, 0));
    rep(i,N) rep(j,N) {
        cin >> c[i][j];
        c[i][j]--;
    }

    vector<vector<int>> cost(C, vector<int>(3, 0));
    
    rep(k,C) {
        rep(i,N) rep(j,N) cost[k][(i + j) % 3] += D[c[i][j]][k];
    }

    int minimum = INF;
    rep(i,C) rep(j,C) rep(k,C) {
        if (i != j && j != k && k != i) {
            minimum = min(minimum, cost[i][0] + cost[j][1] + cost[k][2]);
        }
    }

    cout << minimum << endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int K;
  cin >> K;
  vector<int> cnts(S.size());
  for (int i = 0; i < S.size(); i++) {
    cnts[i] = 'z' - S[i] + 1;
  }
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'a') continue;
    if (K - cnts[i] >= 0) {
      S[i] = 'a';
      K -= cnts[i];
    }
  }
  S[S.size() - 1] = ((S[S.size() - 1] - 'a') + K) % 26 + 'a';
  cout << S << '\n';
  return 0;
}


Measured memory_bytes: 976