akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  string n;
  cin >> n;
  if(n[0]==n[1]&&n[0]==n[2]){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int H,W;
  char board[52][53]={""};
  int i,j,k;
  scanf("%d%d%*c",&H,&W);
  for(i=1;i<=H;i++){
    scanf("%s%*c",board[i]+1);
    board[i][0]=board[i][W+1]='.';
    board[i][W+2]='\0';
  }
  for(i=0;i<=W+1;i++){
    board[0][i]=board[H+1][i]='.';
  }
  board[0][W+2]=board[H+1][W+2]='\0';

  for(i=1;i<=H;i++){
    for(j=1;j<=W;j++){
      if(board[i][j]=='.') continue;
      if(board[i-1][j]=='.' && board[i+1][j]=='.' &&
	 board[i][j-1]=='.' && board[i][j+1]=='.'){
	puts("No");
	return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}

    


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main()
{
    int N, L;
    cin >> N >> L;

    int sumAji = 0;
    int minAji = L + 1 - 1;
    int aji = 0;
    for (int i = 0; i < N; i++) {
        aji = L + (i + 1) - 1;
        if (abs(minAji) > abs(aji)) {
            minAji = aji;
        }
        sumAji += aji;
    }
    sumAji -= minAji;

    cout << sumAji << endl;
    return 0;
}

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

for i in range(min(k, 45)):
    b = [0] * n
    for j in range(n):
        mi = max(0, j-a[j])
        ma = min(n-1, j+a[j])
        b[mi] += 1
        if ma + 1 <= n -1:
            b[ma+1] -= 1
    c = [0] * n
    s = 0
    for k in range(n):
        s += b[k]
        c[k] = s
    a = c

for i in a:
    print(i, end=' ')

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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {
	cin >> n >> m >> k;
	for (int i = 1; i <= m; i ++)
		cin >> a[i];
	for (int i = 1; i <= n; i ++) {
		cur = k;
		for (int j = 1; j <= m; j ++) {
			int x;
			cin >> x;
			cur += x * a[j];
		}
		if (cur > 0) ans ++;
	}
	cout << ans;
	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define MAX_V 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

vector<pii> graph[MAX_V];
bool used[MAX_V] = {false,};

ll prim(){
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push(pii(0,0));
    ll cost_sum = 0;
    while(!q.empty()){
        int cost = q.top().first;
        int v = q.top().second;
        q.pop();
        if(used[v]){continue;}
        used[v] = true;
        cost_sum += cost;
        for(auto edge : graph[v]){
            if(used[edge.second]){continue;}
            q.push(pii(edge.first,edge.second));
        }
    }
    return cost_sum;
}

int main(){
    int n;
    cin >> n;
    vector<pii> town_x(n),town_y(n);
    int x, y;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        town_x[i] = {x,i};
        town_y[i] = {y,i};
    }
    sort(town_x.begin(),town_x.end());
    sort(town_y.begin(),town_y.end());

    int src, dst, cost;
    for(int i = 0; i < n-1; i++){
        src = town_x[i].second;
        dst = town_x[i+1].second;
        cost = town_x[i+1].first-town_x[i].first;
        graph[src].push_back({cost,dst});
        graph[dst].push_back({cost,src});
        src = town_y[i].second;
        dst = town_y[i+1].second;
        cost = town_y[i+1].first-town_y[i].first;
        graph[src].push_back({cost,dst});
        graph[dst].push_back({cost,src});
    }
    ll ans = prim();
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 10616
# 二部ぐらふ、知らなかった
from collections import defaultdict


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n + 1) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N = int(input())
U = UnionFind(2*10**5)
for i in range(N):
    x, y = map(int, input().split())
    U.union(x, y+10**5)
ans = 0
Roots = U.roots()
D = {x: [] for x in Roots}
for i in range(2*10**5+1):
    D[U.find(i)].append(i)
for x in Roots:
    ss = D[x]
    sx = 0
    sy = 0
    for c in ss:
        if c <= 10**5:
            sx += 1
        else:
            sy += 1
    ans += sx*sy
ans -= N
print(ans)

Measured memory_bytes: 54432
#include<bits/stdc++.h>
const long long maxn=1e4+100;
using namespace std;
long long n,m,k,t,a[maxn],x,y,xi,yi,ti;bool le;
int main()
{
    scanf("%lld",&n);
    x=y=0;
    t=0;
    for(int i=1;i<=n;++i)
    {
        scanf("%lld%lld%lld",&ti,&xi,&yi);
        if(abs(xi-x)+abs(yi-y)>ti-t)
        {
            le=1;
        }
        if(   (ti-t -  (abs(xi-x)+abs(yi-y) ))%2==1)
        {
            le=1;
        }
        t=ti;
        x=xi;
        y=yi;
    }
    if(le)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Stream;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int n = sc.nextInt();
        int l = Integer.MAX_VALUE;
        int r = Integer.MIN_VALUE;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        }

        int minCost = Integer.MAX_VALUE;
        for (int i = l; i <= r; i++) {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        }
        System.out.println(minCost);
    }

    private int calc(int i, int[] x) {
        int cost = 0;
        for (int j = 0; j < x.length; j++) {
            cost += Math.pow(x[j] - i, 2);
        }
        return cost;
    }
}


Measured memory_bytes: 23252
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
namespace AtCoder_Beginner_Contest_135
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
        }
        static void Solve()
        {
            var AB = Sarray();
            var A = AB[0];
            var B = AB[1];
            if (A % 2 == B % 2)
            { WriteLine((A + B) / 2); }
            else
            { WriteLine("IMPOSSIBLE"); }
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int c = sc.nextInt();

      if(n==c){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }



  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int a,max=-100;
	cin >> a;
	for (int i = a; i > 1; i--) {
		int tmp = i;
		while(tmp*i <= a){
			if (tmp*i >max) {
				max = tmp*i;
			}
			tmp *= i;
		}
	}
	if (max == -100) {
		max = 1;
	}
	cout << max << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t,u;
  	int a,b;
  	cin>>s>>t;
  	cin>>a>>b;
  	cin>>u;
  	if(s==u){
    	cout<<a-1<<" "<<b<<endl;
    }
  	else{
    	cout<<a<<" "<<b-1<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N ll(1e9+7)
#define endl '\n'
#define cont continue
#define inf ll(1e18)
using namespace std;
//ll power(ll a,ll b,ll mod)
//{
//	if(b==0)return 1;
//	ll ans=1;
//	while(b>0)
//	{
//		if(b&1)ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}
int main()
{
	ios;
	ll n,k,i;cin>>n>>k;
	vtr<ll> a(n+1),vis(n+1,0),tm(n+1,0);
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ll t=0,city=1;tm[1]=0;vis[1]=1;
	while(t<k)
	{
		city=a[city];
		if(vis[city])break;
		vis[city]=1;tm[city]=++t;
	}
	if(t>=k)
	{
		cout<<city;
	}
	else
	{
		ll len=t-tm[city]+1;
		ll val=(k-tm[city])/(len);ll ans;
		ll diff=(k-tm[city])-(val*len);
		for(i=1;i<=n;i++)
		{
			if(tm[i]==diff+tm[city])
			{
				ans=i;break;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 7964
import sys

class alphabet: #Trueなら大文字
    def __init__(self, capitalize):
        self.num = dict() #アルファベットを数字に変換
        self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\
            ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        if capitalize: 
            for i in range(26): self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc): self.num[a] = True


def solve():
    S = input()
    AB = alphabet(False)
    for i in range(len(S)):
        AB.num[S[i]] = False
    for a in AB.abc:
        if AB.num[a]:
            print(a)
            break
    else: print("None")

    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3316
//#include<bits/stdc++.h>
//using namespace std;
#include<stdio.h>
#include<string.h>
char s[100000] = {0};
int cou = 0;

int main()
{
    int length;


        //cin >> s;
        for(int i = 0; i < 100000; i++)
        {
            scanf("%c",&s[i]);
            if(s[i] == '\n')break;
            if('a' <= s[i] && s[i] <= 'z')
            {
                s[i] = s[i] - 32;
            }
            cou++;
        }
        /*length = strlen(s);
        for(int i = 0; i < length; i++)
        {

        }
        //cout << s << endl;*/
        for(int i = 0; i < cou; i++)
        {
            printf("%c",s[i]);
        }
        printf("\n");


    return 0;
}

Measured memory_bytes: 932
package main

import "fmt"

func main() {
	var A, B, C, D int
	fmt.Scan(&A, &B, &C, &D)

	s1 := A * B
	s2 := C * D
	if s1 > s2 {
		fmt.Println(s1)
	} else {
		fmt.Println(s2)
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    int ans=0;
    if(a[2]%2!=a[1]%2 or a[2]%2!=a[0]%2){
        if(a[0]%2==a[1]%2){
            a[0]++; a[1]++;
        }else if(a[0]%2==a[2]%2){
            a[0]++; a[2]++;
        }else{
            a[1]++;a[2]++;
        }
        ans=1;
    } 
    cout<<ans+(a[2]-a[1])/2+(a[2]-a[0])/2<<endl;
    
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
long n=sc.nextInt();
long t=sc.nextInt();
long max = t;
long min = t;
long sum = t;
for(long i=1;i<n;i++)
{
t=sc.nextInt();
if(t > max) max = t ;
if(t < min)min = t ;
sum = sum+=t;
}
System.out.println(min+" "+max+" "+sum);
}
}



Measured memory_bytes: 41772
import java.util.Scanner;

public class Main {
	static long f(long X){
		if(X == 1){
			return 1;
		}
		long H = X / 2;
		return 2 * f(H) + 1;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		System.out.println(f(H));
	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up

//Start from Here
int main(){
    ll K;
    cin>>K;
    queue<ll> Q;
    for(ll i=1;i<=9;i++){
        Q.push(i);
    }
    ll a, b;
    if(K<10){
        cout<<K<<endl;
    }
    else{
        K-=9;
        int check=0;
        while(check==0){
            a=Q.front();
            Q.pop();
            b=a%10;
            if(b==0){
                if(K==1){
                    cout<<a*10<<endl;
                    check=1;
                }
                else if(K==2){
                    cout<<a*10+1<<endl;
                    check=1;
                }
                else{
                    K-=2;
                    Q.push(a*10);
                    Q.push(a*10+1);
                }
            }
            else if(b==9){
                if(K==1){
                    cout<<a*10+b-1<<endl;
                    check=1;
                }
                else if(K==2){
                    cout<<a*10+b<<endl;
                    check=1;
                }
                else{
                    K-=2;
                    Q.push(a*10+b-1);
                    Q.push(a*10+b);
                }
            }
            else{
                if(K==1){
                    cout<<a*10+b-1<<endl;
                    check=1;
                }
                else if(K==2){
                    cout<<a*10+b<<endl;
                    check=1;
                }
                else if (K==3){
                    cout<<a*10+b+1<<endl;
                    check=1;
                }
                else{
                    K-=3;
                    Q.push(a*10+b-1);
                    Q.push(a*10+b);
                    Q.push(a*10+b+1);
                }
            }
        }
    }
}

Measured memory_bytes: 768
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
R, S, P = MAP()
t = input()
s = ''

ans = 0
for i in range(len(t)):
    if t[i] == 'r':
        if i >= k and s[i-k] == 'p':
            s += 'x'
        else:
            ans += P
            s += 'p'
    elif t[i] == 's':
        if i >= k and s[i-k] == 'r':
            s += 'x'
        else:
            ans += R
            s += 'r'
    else:
        if i >= k and s[i-k] == 's':
            s += 'x'
        else:
            ans += S
            s += 's'
print(ans)

Measured memory_bytes: 10568
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

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

int H, W;
string maze[1100];
int dist[1100][1100];

int main() {

    queue<pair<int, int>> que;
    memset(dist, -1, sizeof(dist));

    cin >> H >> W;
    int wnum = 0;
    for (int i = 0; i < H; ++i) {
        cin >> maze[i];
        for (int j = 0; j < W; ++j) {
            if (maze[i][j] == '.') ++wnum;
            else {
                dist[i][j] = 0;
                que.push(pair<int, int>(i, j));
            }
        }
    }

    int cnt = 0;
    while (!que.empty()) {
        pair<int, int> cur = que.front();
        que.pop();
        int x = cur.first;
        int y = cur.second;
        for (int dir = 0; dir < 4; ++dir) {
            int nx = x + dx[dir];
            int ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (maze[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push(pair<int, int>(nx, ny));
                chmax(cnt, dist[nx][ny]);
            }
        }
    }
    //for (int j = 0; j<1100; ++j) {
    //    for (int i = 0; i<1100; ++i) {
    //        if (dist[i][j] < 0) continue;
    //        cout << "(" << i << "," << j << ") " << dist[i][j] << endl;
    //    }
    //}
    cout << cnt << endl;

}



Measured memory_bytes: 14224
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> mp;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  if (n >= 30)
  {
    out("Yes");
  }
  else
  {
    out("No");
  }
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  solve();
}

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

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

using namespace std;

bool check(vector<int> v) {
    rep(i,v.size()) {
        if(v[i] != 0) return false;
    }
    return true;
}

int main()
{
    int n,p;
    while(cin >> n >> p)
    {
        if(n == 0 && p == 0) break;

        int ans = 0;
        int id = 0;
        int sum = p;
        vector<int> v(n);
        rep(i,n) v[i] = 0;
        
        while(true) {
            if(sum) {
                v[id]++;
                sum--;
            }
            else {
                sum += v[id];
                v[id] = 0;
            }

            if(check(v)) break;

            id++;
            id %= n;
            ans++;
        }

        cout << id << endl;
    }  

    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
	int x,a,b;
	cin >> x >> a >> b;
	int xa = abs(x - a), xb = abs(x - b);
	if (xa < xb)
		cout << "A" << endl;
	else
		cout << "B" << endl;
}

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

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

    string ans(s.size(), 'z');
    string no = ans;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == t[0] || s[i] == '?') {
            string tmp = s;
            int cnt = 0;
            for(int j = 0; j < t.size(); j++) {
                if(i + j >= s.size()) break;
                if(s[i+j] == t[j] || s[i+j] == '?') cnt++, tmp[i+j] = t[j];
            }
            if(cnt == t.size()) ans = min(ans, tmp);
        }
    }

    for(auto& c : ans) if(c == '?') c = 'a';

    if(ans != no) cout << ans << endl;
    else cout << "UNRESTORABLE" << endl;

    return 0;
}

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

using namespace std;

typedef struct 
{
    unsigned int left;
    unsigned int area;
}AreaInfo_t;

#define CalcArea(x,y) ((x) - (y))

stack<unsigned int> ArealeftIdxStack;
vector<AreaInfo_t> AreaInfoStack;

unsigned int Decision(char, unsigned int);
void Fusion(AreaInfo_t);
void PrintArea(void);

int main(void){
    char ch;
    unsigned int idx = 0;
    unsigned int total = 0;
    
    while(cin >> ch)
    {
        total += Decision(ch, idx);
        idx++;
    }
    
    cout << total << endl;
    PrintArea();
    
    return 0;
    
}

unsigned int Decision(char ch, unsigned int idx)
{
    unsigned int rslt = 0;
    
    switch(ch)
    {
        case '\\':
            ArealeftIdxStack.push(idx);
            break;
        case '/':
            if(!ArealeftIdxStack.empty())
            {
                AreaInfo_t area;
                area.left = ArealeftIdxStack.top();
                rslt = area.area = CalcArea(idx, ArealeftIdxStack.top());
                ArealeftIdxStack.pop();
                Fusion(area);
            }
            break;
        case '_':
            // pass
            break;
        default:
            // unreachable
            break;
    }

    return rslt;
}

void Fusion(AreaInfo_t tInfo)
{
    
    while(1)
    {
        if(!AreaInfoStack.empty())
        {
            AreaInfo_t tmp = AreaInfoStack.back();
            if(tmp.left > tInfo.left)
            {
                tInfo.area += tmp.area;
                AreaInfoStack.pop_back();
                continue;
            }
        }

        AreaInfoStack.push_back(tInfo);
        break;
    }

    return;
}

void PrintArea()
{
    cout << AreaInfoStack.size();
    for(vector<AreaInfo_t>::iterator it = AreaInfoStack.begin(); it != AreaInfoStack.end(); it++)
    {
        cout << ' ' <<  it->area;
    }
    cout << endl;

    return;
}



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

int main(){
  string s ; 
  int n ; 
  cin >> n >> s ;
  vector<char> az(26) ;
  az = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'} ;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<26;j++){
      if(s.at(i)==az.at(j)){
        s.at(i) = az.at((j+n)%26) ;
        break ;
      }
    }
  }
  cout << s << endl ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a[4];
    for (int i = 0; i < 4; i++) {
        cin >> a[i];
    }
    sort(a, a + 4);

    cout << ((a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 764
import sys
fin = sys.stdin.readline


N, M = [int(elem) for elem in fin().split()]
X_list = sorted([int(elem) for elem in fin().split()])
min_X = X_list[0]
max_X = X_list[-1]
exists = [False] * (max_X - min_X + 1)
for X in X_list:
    X -= min_X
    exists[X] = True

distances = []
last_idx = 0
for i, flag in enumerate(exists[1:], start=1):
    if flag:
        distances.append(i - last_idx - 1)
        last_idx = i

distances.sort(reverse=True)
# print(distances)
# print(len(exists))
minimum_moves = max(0, max(0, len(exists) - N) - sum(distances[:N - 1]))
# minimum_moves = max(0, len(exists) - N) - sum(distances[:N - 1])
print(minimum_moves)


Measured memory_bytes: 13316
# -*- coding: utf-8 -*-

import numpy as np

EDPC = "https://atcoder.jp/contests/DP/"
TDPC = "https://atcoder.jp/contests/tDPc/tasks"

################ DANGER ################
test = ""
#test = \
"""
3 8
3 30
4 50
5 60
ans 90
"""

"""
5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
ans 5000000000(>int32)
"""

"""
6 15
6 5
5 6
6 4
6 6
3 5
7 2
ans 17
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
# np.maximum(np.array([1,3,2]), np.array([2, 1, 3]))
N, W = map(int, input2().split())
WV = np.array([tuple(map(int, input2().split())) for _ in range(N)])

dp = np.zeros(W + 1, dtype="int64")
for w, v in WV:
    dp[W:w-1:-1] = np.maximum(dp[W:w-1:-1], dp[W-w::-1] + v)

print(dp[-1])


Measured memory_bytes: 15508
def resolve():
    # N = int(input())
    # S = input()
    N, R = map(int, input().split())
    # A = list(map(int, input().split()))

    # P = []
    # S = []
    # for i in range(N):
    #     pp, ss = map(int, input().split())
    #     P.append(pp)
    #     S.append(ss)

    if N < 10:
        ans = R + (100 * (10 - N))
        print(ans)
        return

    print(R)

resolve()

Measured memory_bytes: 2940
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

let nk=readInts()
let n=nk[0]
let d=readInts()
var ans=0

for i in 0..<n-1{
  for j in i+1..<n{ans+=d[i]*d[j]}
}

print(ans)

Measured memory_bytes: 13432
#include<iostream>
#include<vector>
#include<cstdio>

using namespace std;

#define MAX (100001/2+1)

int main(){
  int f[MAX]={0};
  vector<int> prime;
  f[0]=1;
  f[1]=1;
  for(int i=2;i<MAX;i++){
    if(f[i]==0){
      prime.push_back(i);
      for(int j=i*2;j<MAX;j+=i){
        f[j]=1;
      }
    }
  }

  pair<int,int> *p[100001]={0};
  for(int i=0;i<prime.size()&&(prime[i]*prime[i]<100001);i++){
    for(int j=i;j<prime.size();j++){
      int m=prime[i]*prime[j];
      if(m>=100001)
        break;
      p[m]=new pair<int,int>(prime[i],prime[j]);
    }
  }

  int m,a,b;
  while(cin >> m >> a >> b,m+a+b){
    while(m>0){
      if(p[m]!=NULL){
        if((double)p[m]->first/(double)p[m]->second >= (double)a/(double)b){
          cout << p[m]->first << " " << p[m]->second << endl;
          break;
        }
      }
      m--;
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 
 
int main()
{
    ll N;
    cin >> N;
 
    cout << N*(N-1)/2 << endl;
 
    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

int N,K;
vector<int> a;

bool check(int d)
{
    vector<int> b(N);
    for(int i=0;i<N;i++){
        b[i]=a[i]%d;
    }
    sort(b.begin(),b.end());

    vector<int> sum(N+1);
    for(int i=0;i<N;i++){
        sum[i+1]=sum[i]+b[i];
    }

    for(int i=0;i<N;i++){
        int x=sum[i];
        int y=d*(N-i)-(sum[N]-sum[i]);
        if(max(x,y)<=K) return true;
    }
    return false;
}

signed main()
{
    cin>>N>>K;
    a.resize(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int S=accumulate(a.begin(),a.end(),0LL);

    int ans=0;
    for(int d=1;d*d<=S;d++) if(S%d==0){
        if(check(d)) ans=max(ans,d);
        if(check(S/d)) ans=max(ans,S/d);
    }
    cout<<ans<<endl;

    return 0;
}

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

#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
vector<long long> dijkstra(vector<vector<pair<long long, long long>>> graph, long long s) {
    vector<long long> ans(graph.size(), -1);
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>
        pq;
    pq.push({0, s});
    while (pq.size() > 0) {
        ll cur1 = 0;
        ll cur2 = 0;
        if (ans[pq.top().second] != -1) {
            pq.pop();
        } else {
            cur1 = pq.top().first;
            cur2 = pq.top().second;
            pq.pop();
            ans[cur2] = cur1;
            for (long long i = 0; i < graph[cur2].size(); i++) {
                pq.push({cur1 + graph[cur2][i].second, graph[cur2][i].first});
            }
        }
    }
    return ans;
}
signed main() {
    long long n;
    cin >> n;
    vector<ll> as(n);
    REP(i, n) { cin >> as[i]; }
    sort(as.begin(), as.end());
    vector<ll> cnt(2000777);
    ll ans = 0;
    REP(i, n) {
        if (cnt[as[i]] == 0) {
            ans++;
        } else {
            continue;
        }
        if (i != n - 1 && as[i + 1] == as[i]) {
            if (cnt[as[i]] == 0) {
                ans--;
            }
        }
        REP(j, 1000000 / as[i] + 1) { cnt[j * as[i]]++; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 20272
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;

bool check(vector<int>& a, vector<int>& b, int& c)
{
    int ans = c;
    rep(i, a.size())
    {
        ans += a[i] * b[i];
    }
    return ans > 0;
}

int main()
{
    int n, m, c, ans = 0;
    cin >> n >> m >> c;
    vector<int> a(m);
    vector<int> b(m);
    rep(i, m) cin >> b[i];

    rep(i, n)
    {
        rep(i, m) cin >> a[i];
        if (check(a, b, c))
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

def is_prime(q):
    import math
    if q == 1:
        return False
    for k in range(2,int(math.sqrt(q)) + 1):
        if q % k == 0:
            return False
    return True

while True:
    if is_prime(x):
        print(x)
        exit()
    x += 1


Measured memory_bytes: 2940
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + 11)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        s += i * dp[Y][i]
    print(int(s))

if __name__ == "__main__":
    import sys

    while True:
        X, Y, Z = map(int, input().split())
        if X | Y | Z == 0:
            sys.exit()
        V = list(map(int, input().split()))
        E = [0] * 100
        A = [0] * 100
        for _ in range(Z):
            n, e, a = map(int, input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

Measured memory_bytes: 10924
n = [int(i) for i in input()]

if(n[0] > n[1]):
    n[1] = n[0]
    n[2] = n[0]
elif(n[0] == n[1] and n[1] >= n[2]):
    n[2] = n[0]
elif(n[0] == n[1] and n[1] < n[2]):
    n[0] = n[0] + 1
    n[1] = n[0]
    n[2] = n[0]
elif(n[0] < n[1]):
    n[0] = n[0] + 1
    n[1] = n[0]
    n[2] = n[0]

print("{}{}{}".format(n[0],n[1],n[2]))


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main()
{
    int n,s =0;
    cin >>n;
    int temp =n;
    
    while(temp>0)
    {
        s+=temp%10;
        temp/=10;    
    }
    if(n%s==0)
    {
        cout << "Yes"<<endl;
    }
    else
    {
        cout << "No"<<endl;
    }

    return 0;
}

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

using namespace std;

const double BLOCK = 100.0;
const double R = 10.0;

const double pi = acos(-1.0);

template <typename T>
int lis(vector <T> a) {
  vector <T> u;
  for (T &x : a) {
    auto it = lower_bound(u.begin(), u.end(), x);
    if (it == u.end()) {
      u.push_back(x);
    } else {
      *it = x;
    }
  }
  return u.size();
}

int main() {
  int xa, ya, xb, yb;
  scanf("%d %d %d %d", &xa, &ya, &xb, &yb);
  bool flip_x = false;
  bool flip_y = false;
  if (xa > xb) {
    flip_x = true;
    xa = -xa;
    xb = -xb;
  }
  if (ya > yb) {
    flip_y = true;
    ya = -ya;
    yb = -yb;
  }
  // now xa <= xb && ya <= yb
  int n;
  scanf("%d", &n);
  vector < pair <int, int> > all;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (flip_x) {
      x = -x;
    }
    if (flip_y) {
      y = -y;
    }
    if (xa <= x && x <= xb && ya <= y && y <= yb) {
      all.emplace_back(x, y);
    }
  }
  sort(all.begin(), all.end());
  vector <int> z;
  for (auto &p : all) {
    z.push_back(p.second);
  }
  int d = lis(z);
  double ans = ((xb - xa) + (yb - ya)) * BLOCK;
  if (d == min(xb - xa + 1, yb - ya + 1)) {
    d--;
    ans += R * (pi - 2);
  }
  ans -= d * R * (2 - 0.5 * pi);
  printf("%.15f\n", ans);
  return 0;
}


Measured memory_bytes: 5360
#include <stdio.h>
#include <string.h>
int find(char u[][11],char t[],int n){
  int i;
  for(i=0;i<n;i++){
    if(strcmp(u[i],t)==0)
      return 1;
  }
  return 0;
}
int main(void){
  int n,m,i,c;
  char u[256][11],t[11];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%s",u[i]);
  scanf("%d",&m);
  for(i=0,c=0;i<m;i++){
    scanf("%s",t);
    if(find(u,t,n)){
      switch(c%2){
      case 0:printf("Opened"); break;
      case 1:printf("Closed"); break;
      }
      printf(" by %s\n",t);
      c++;
    }
    else
      printf("Unknown %s\n",t);
  }
  return 0;
}

Measured memory_bytes: 608
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<lint> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    cin >> n;
    vi v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    int right = 0;
    lint xorcal = 0;
    lint sum = 0;
    lint ans = 0;
    rep(left, n)
    {
        if (right == left)
        {
            xorcal = v[left];
            sum = v[left];
            right++;
        }
        while (right < n && (sum + v[right]) == (xorcal ^ v[right]))
        {
            sum += v[right];
            xorcal ^= v[right];
            right++;
        }
        ans += right - left;
        xorcal ^= v[left];
        sum -= v[left];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, a;
	cin >> n >> a;
	cout << n * n - a << endl;

	return 0;
}

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

int main(void){
    int n, k, r, s, p;
    std::string t;
    std::map<char, int> mp;
    
    std::cin >> n >> k >> r >> s >> p;
    std::cin >> t;

    for(int i = 0; i < k; i++){
	mp[t[i]]++;
    }

    for(int i = k; i < n; i++){
	if(t[i] == t[i-k]){
	    t[i] = 'x';
	}
	else mp[t[i]]++;
    }

    int ans = 0;
    ans = mp['r'] * p + mp['s'] * r + mp['p'] * s;

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



Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<Int> a(n,0);
    rep(i,n) cin>>a[i];
    Int mod=1000000007;
    vector<Int> sa(n,0);
    sa[0]=a[0];
    for(int i=0; i<n-1; i++){
      sa[i+1]=sa[i]+a[i+1];
    }
    Int ans=0;
    for(int i=0; i<n; i++){
      Int tmp=(sa[n-1]-sa[i])%mod;
      tmp*=a[i]%mod;
      ans+=tmp;
      ans%=mod;
      if(ans<0) ans+=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6364
#include<stdio.h>

int main(void){
	int N,K;
	int i;
	int ans = 0;
	
	scanf("%d%d",&N,&K);
	for(i=0;i<N;i++){
		int x;
		scanf("%d",&x);
		if(x<K-x) ans +=2*x;
		else ans += 2*(K-x);
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//sum創る
		int sum = 0;
		int c;
		int s;
		//N入力
		int n = sc.nextInt();
		//K入力
		int k = sc.nextInt();
		for(int i = 0; i <=  n -1; i++){
			int x = sc.nextInt();
			//AorB
			if(k / 2 < x){
				c = k - x;
				s = c * 2;
				sum = sum + s;
			}else{
			int y;
			y = x * 2;
			sum = sum + y;
			}
		}
		// 出力
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        if (d == 25) System.out.println("Christmas");
        if (d == 24) System.out.println("Christmas Eve");
        if (d == 23) System.out.println("Christmas Eve Eve");
        if (d == 22) System.out.println("Christmas Eve Eve Eve");
    }
}

Measured memory_bytes: 35592
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

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

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    a, b = il()
    if a == 1:
        a += 13
    if b == 1:
        b += 13
    print('Alice' if a > b else 'Draw' if a == b else 'Bob')


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;
  int si = s.size();

  int cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < si; ++i) {
    if (i % 2 == 0) {
      if (s[i] == '0') {
        ++cnt1;
      }
    } else {
      if (s[i] == '1') {
        ++cnt1;
      }
    }
    if (i % 2 == 1) {
      if (s[i] == '0') {
        ++cnt2;
      }
    } else {
      if (s[i] == '1') {
        ++cnt2;
      }
    }
  }

  cout << min(cnt1, cnt2) << '\n';

  return 0;
}


Measured memory_bytes: 3708
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, k = map(int, input().split())
a = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ord_ = [-1] * (n + 1) # 何回目に訪れたか
s = []
current = 0
while ord_[current] == -1:
    ord_[current] = len(s)
    s.append(current)
    current = a[current] - 1
c = len(s) - ord_[current]
l = ord_[current]

if k < l:
    print(s[k] + 1)
else:
    k -= l
    k %= c
    print(s[l+k] + 1)



Measured memory_bytes: 33716
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    String s = sc.next();
    int ans = 0;
    int index = -1;
    while ((index = s.indexOf("ABC", index + 1)) != -1) {
      ans++;
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
using namespace std;

int main(){
  long long int INF=1000000000000000000;
  long long int k,ans=0,tmp=0,tmp2=0,tmp_ans=0;
  int arr[3],j=0;
  for(int i=0;i<3;i++)arr[i]=0;
  for(int i=0;i<3;i++)cin>>arr[i];
  cin>>k;
  if((arr[0]==arr[1])&&(arr[1]==arr[2])){//三つとも同じ数であれば何回足しても最後は0
    cout<<0<<endl;
    return 0;
  }
  if(k%2==0)j=2;
  else j=1;
  for(long long int i=0;i<j;i++){
    tmp = arr[0]; tmp2 = arr[1];
    arr[0] = arr[1]+arr[2];
    arr[1] = tmp + arr[2];
    arr[2] = tmp + tmp2;
    //ans = abs(tmp-tmp2);//答えの絶対値
    //if(ans > INF)cout<<"Unfair"<<endl;//
    //cout<<arr[0]<<" "<<arr[1]<<" "<<arr[2]<<endl;
  }
  tmp_ans = abs(arr[0]-arr[1]);
  ans = arr[0]-arr[1];
  if(tmp_ans > INF)cout<<"Unfair"<<endl;
  else cout<<ans<<endl;
  return 0;
}

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

    sum = 0
    for j in range(n):
        j += 1
        # for i in range(n):
        #     if i % j == 0:
        #         sum += i
        k = n // j
        sum += (k * (1 + k) // 2) * j

    print(sum)


if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 10000000000000;

int main() {
  ll X, Y, ans = INF;
  cin >> X >> Y;

  if (X <= Y) ans = min(ans, Y - X);
  if (-X <= Y) ans = min(ans, Y + X + 1);
  if (X <= -Y) ans = min(ans, -Y - X + 1);
  if (-X <= -Y) ans = min(ans, -Y + X + 2);

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


Measured memory_bytes: 256