akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_175
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            int[] ps = ReadInts();
            long[] cs = ReadLongs();
            for(int i = 0; i < n; i++)
            {
                ps[i]--;
            }

            long res = long.MinValue;
            int[] visits = new int[n];
            for(int i = 0; i < n; i++)
            {
                if (visits[i] > 0)
                {
                    continue;
                }

                List<int> poses = new List<int>();
                int now = i;
                long cycleScore = 0;
                while (visits[now] == 0)
                {
                    visits[now] = 1;
                    poses.Add(now);
                    now = ps[now];
                    cycleScore += cs[now];
                }

                long baseVal = 0;
                long remain;
                if (k / poses.Count > 1)
                {
                    baseVal = Max(0, cycleScore * (k / poses.Count - 1));
                    remain = k % poses.Count + poses.Count;
                }
                else
                {
                    remain = k;
                }
                for(int j = 0; j < poses.Count; j++)
                {
                    long val = 0;
                    for(int l = 1; l <= remain; l++)
                    {
                        val += cs[poses[(j + l) % poses.Count]];
                        res = Max(res, baseVal + val);
                    }
                }
            }

            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 28972
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const int N = 100*1000+5;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
  	long long int n,b=0,m =2e18+1e17;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
      long long int a;
      cin >> a;
      m = min(a,m);
      if(a <= m)
      {
      	b++;
      }
    }
   	cout << b << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    ans = 0

    for i in range(1, n + 1):
        # k = n // i
        # kk = int((k + 1) * (k / 2) * i)
        # ans += kk
        for j in range(i, n + 1, i):
            ans += j
    print(ans)    

if __name__ == '__main__':
    main()


Measured memory_bytes: 67544
<?php
  $count   = trim(fgets(STDIN));
  $dice_1  = explode(" ", trim(fgets(STDIN)));
  $a_dice  = array();
  $upper_1 = $dice_1[0];
  $side_1  = array($dice_1[2], $dice_1[1], $dice_1[3], $dice_1[4]);
  $bottom_1  = $dice_1[5];
  for($x=0;$x<($count-1);$x++) {
    $dice_2 = explode(" ", trim(fgets(STDIN)));
    array_push($a_dice, $dice_2);
  }
  for($x=0;$x<($count-1);$x++){
    $side_2  = array($a_dice[$x][2], $a_dice[$x][1], $a_dice[$x][3], $a_dice[$x][4]);
    $upper_2 = $a_dice[$x][0];
    $bottom_2  = $a_dice[$x][5];
    $n = 0;
    while (true) {
      for($i=0;$i<4;$i++) {
        if (($upper_1 == $upper_2) && ($bottom_1 == $bottom_2) && ($side_1[0] == $side_2[0]) && ($side_1[1] == $side_2[1]) && ($side_1[2] == $side_2[2]) && ($side_1[3] == $side_2[3])) {
          print "No\n";
          return;
        } else {
          $z = array_shift($side_2);
          array_push($side_2, $z);
        }
      }
      if ($n < 4) {
        $b = $bottom_2;
        $u = $upper_2;
        $upper_2 = $side_2[2];
        $bottom_2 = $side_2[0];
        $side_2[2] = $b;
        $side_2[0] = $u;
      } else if ($n < 10 && $n > 3) {
        $b = $bottom_2;
        $u = $upper_2;
        $upper_2 = $side_2[1];
        $bottom_2 = $side_2[3];
        $side_2[1] = $b;
        $side_2[3] = $u;
      } else if ($n > 10) {
        break 1;
      }
      $n++;
    }
  }
  print "Yes";
?>

Measured memory_bytes: 6748
import numpy as np
N,M,C=map(int,input().split())
B=np.array(list(map(int,input().split())))
ans = 0
for _ in range(N):
    A = np.array(list(map(int,input().split())))
    if np.sum(A*B)+C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 27284
import sys
input = sys.stdin.readline

n = int(input()) + 1
h = list(map(int,input().split()))
a = list(map(int,input().split()))

def init_max(init_max_val):
    #set_val
    for i in range(n):
        seg_max[i+num_max-1]=init_max_val[i]    
    #built
    for i in range(num_max-2,-1,-1) :
        seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2]) 
    
def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])
    
def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res

#####単位元######
ide_ele_max = 0

#num_max:n以上の最小の2のべき乗
num_max =2**(n-1).bit_length()
seg_max=[ide_ele_max]*2*num_max


#dp[i] : 最後の花の高さがiの時の最大値

dp = [0]*n

for i in range(n-1):
    tmp = query_max(0,h[i]) + a[i]
    if tmp + a[i] > dp[h[i]]:
        dp[h[i]] = tmp
        update_max(h[i],tmp)

print(query_max(0,n))




Measured memory_bytes: 113276
import math
import collections
from operator import mul
from functools import reduce

W,H,x,y=map(int,input().split())
flag=-1

if W/2==x:
    flag+=1
if H/2==y:
    flag+=1

if flag==-1:
    flag=0
print("{0:.6f}".format(float(W*H/2)),flag)


Measured memory_bytes: 38384
val = int(input())

if val % 10 == 2 or val % 10 == 4 or val % 10 == 5 or val % 10 == 7 or val % 10 == 9:
  print("hon")

elif val % 10 == 0 or val % 10 == 1 or val % 10 == 6 or val % 10 == 8:
  print("pon")
  
elif val % 10 == 3:
  print("bon")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, M;
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    cin >> N >> M;
    vector<ll> A(N), sum(N + 1);
    REP(i, N) {
        cin >> A.at(i);
        sum[i + 1] = (sum[i] + A[i]) % M;
    }

    map<ll, ll> count;
    REP(i, N + 1) { count[sum[i]]++; }

    ll ans = 0;
    for (auto p : count) {
        ans += p.second * (p.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final char[] s = sc.next().toCharArray();
			
			int W_num = 0, E_num = 0;
			for(final char c : s) {
				if(c == 'E') { E_num++; }
			}
			
			int answer = Integer.MAX_VALUE;
			
			for(final char c : s) {
				answer = Math.min(answer, W_num + E_num);
				if(c == 'W') {
					W_num++;
				}else {
					E_num--;
				}
			}
			
			answer = Math.min(answer, W_num + E_num);
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 25424
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  cin >> s;
  if(s.back()!='s') s+='s';
  else s+="es";
  pr(s);
}

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


Measured memory_bytes: 3624
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[i]<=b[i]:
        cnt+=a[i]
        b[i]-=a[i]
    else:
        cnt+=b[i]
        b[i]=0
    if a[i+1]<=b[i]:
        cnt+=a[i+1]
        a[i+1]=0
    else:
        cnt+=b[i]
        a[i+1]-=b[i]
print(cnt)


Measured memory_bytes: 82148
n = int(input())
arr = list(map(int, input().split()))

for i in range(n):
    if i == 0:
        continue

    if arr[i] < arr[i - 1]:
        print("No")
        exit()

    if arr[i] > arr[i - 1]:
        arr[i] -= 1

print("Yes")


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	string X;
	cin >> X;
	stack<char> st;
	REP(i, X.size()){
		if(st.empty()){
			st.push(X[i]);
		}else if(X[i]=='S'){
			st.push(X[i]);
		}else{
			if(st.top()=='S'){
				st.pop();
			}else{
				st.push(X[i]);
			}
		}
	}
	cout << st.size() << endl;
    return 0;
}

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

int main() 
{ 
    
    int n;
    cin>>n;
    vector<int> cost(n);
    vector<int> ans(n,0);
    
    for(int i=0;i<n;i++){cin>>cost[i];}
    ans[1] = abs(cost[1]-cost[0]);
    for(int i=2;i<n;i++){
        ans[i] = min(abs(cost[i]-cost[i-2])+ans[i-2],abs(cost[i]-cost[i-1])+ans[i-1]);
    }
    cout<<ans[n-1];
      
    return 0; 
} 

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string A,B;
  cin >> A >> B;
  
  if(A.at(0) == B.at(2) && A.at(1) == B.at(1) && A.at(2) == B.at(0)){
  	cout << "YES" << endl;
  }else{
  	cout << "NO" << endl;
  }
}


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

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

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

    vector<vector<long long>> dp(n + 1, vector<long long>(2, -1));

    dp[0][0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int prev = 0; prev < 2; ++prev) {
            if (dp[i][prev] == -1) {
                continue;
            }
            if (i == n - 1) {
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][prev] + ((a[i] - prev) >> 1));
            } else {
                for (int nxt = 0; nxt < 2; ++nxt) {
                    if (a[i] >= nxt + prev && a[i + 1] >= nxt) {
                        dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][prev] + ((a[i] - prev - nxt) >> 1) + nxt);
                    }
                }
            }
        }
    }

    cout << dp[n][0] << endl;

    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	int n;
	while(scanf("%d",&n)==1){
		long long k = 600/n-1;
		long long ex = (n*pow(n,2)*((k*(k+1)*(2*k+1))/6));
		cout<<ex<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <string.h>
#include <iostream>
using namespace std;
int main() 
{
  char str1[100];
  char str2[100];
  int num[2];
  char input[100];
  cin >> str1 >> str2;
  cin >> num[0] >> num[1];
  cin >> input;
  
  if(strcmp(str1,input)){
    num[1]--;
  }
  else if(strcmp(str2,input)){
    num[0]--;
  }
  cout << num[0] << " " << num[1] << endl;
}


Measured memory_bytes: 256
N=int(input())
c8=0 # 約数が8個の奇数の数

# 各奇数について
for ni in range((N-1)//2+1):
    n=ni*2+1
    c=0 # 約数の数

    for i in range(1,n+1): # 各数について、割り切れるかどうかを判定してゆく
        c+=int(n%i==0)

    if c==8: # 約数が8個なら
        c8+=1

print(c8)

Measured memory_bytes: 3060
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [list(map(int,input().split())) for i in range(M)]

ans = min(a) + min(b)
# print(ans)

for cc in c:
    ans = min(ans, a[cc[0]-1] + b[cc[1]-1] - cc[2])

print(ans)

Measured memory_bytes: 80196
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    string str;
    int q;
    cin >> str >> q;

    deque<char> dq;

    for (char c : str)
        dq.push_back(c);

    bool rev = false;

    for (int i = 0; i < q; ++i) {
        int t, f;
        char c;

        cin >> t;

        if (t == 1)
            rev = !rev;
        else {
            cin >> f >> c;

            if (f == 1) {
                if (!rev) {
                    dq.push_front(c);
                } else {
                    dq.push_back(c);
                }
            } else {
                if (rev) {
                    dq.push_front(c);
                } else {
                    dq.push_back(c);
                }
            }
        }
    }

    string out;

    if (!rev) {
        while (!dq.empty()) {
            out += dq.front();
            dq.pop_front();
        }
    } else {
        while (!dq.empty()) {
            out += dq.back();
            dq.pop_back();
        }
    }

    cout << out << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    vector<vi> a(3, vi(3, 0));
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n;
    cin >> n;
    vi b(n);
    rep(i, n) cin >> b[i];

    rep(p, n) {
        rep(i, 3) rep(j, 3) {
            if (a[i][j] == b[p]) a[i][j] = 0;
        }
    }

    bool f = false;
    rep(i, 3) {
        if (a[i][0] + a[i][1] + a[i][2] == 0) f = true;
        if (a[0][i] + a[1][i] + a[2][i] == 0) f = true;
    }
    if (a[0][0] + a[1][1] + a[2][2] == 0) f = true;
    if (a[2][0] + a[1][1] + a[2][0] == 0) f = true;

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
# @author 

import sys

class BBuffet:
    def solve(self):
        n = int(input())
        a = [int(_) - 1 for _ in input().split()]
        b = [int(_) for _ in input().split()]
        c = [int(_) for _ in input().split()]
        ans = 0
        last = -2
        for i in range(n):
            ans += b[a[i]]
            if a[i] - 1 < n - 1 and a[i] - 1 == last:
                ans += c[a[i] - 1]
            last = a[i]
            # print(ans)

        print(ans)

solver = BBuffet()
input = sys.stdin.readline

solver.solve()


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

int main(){
    int r, c, i, j, x, y, res = 0;
    int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    pair<int, int> tem, g;
    queue<pair<int, int>> q;
    cin >> r >> c;
    g = make_pair(r-1, c-1);
    string mp[r];
    for(i=0; i<r; i++){
        cin >> mp[i];
    }
    int d[r][c];
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
            d[i][j] = -1;
            if(mp[i][j] == '#'){
                d[i][j] = 0;
                q.push(make_pair(i, j));
            }
        }
    }
    while(!q.empty()){
        tem = q.front();
        q.pop();
        for(i=0; i<4; i++){
            y = tem.first+dy[i];
            x = tem.second+dx[i];
            if(0 <= y && y < r && 0 <= x && x < c && mp[y][x] == '.' && d[y][x] == -1){
                q.push(make_pair(y, x));
                d[y][x] = d[tem.first][tem.second] + 1;
                res = max(res, d[y][x]);
            }
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	string s;
	while(n)
	{
		--n;
		s.push_back('a'+n%26);
		n=n/26;
	}
	for(int i=s.length()-1;i>=0;i--)
	cout<<s[i];
	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    int N; string S;
    cin >> N >> S;
    vector<int> rs(N + 1, 0), gs(N + 1, 0), bs(N + 1, 0);
    const auto f = [&](vector<int>& arr, char c){
        for (int i = 1; i <= N; ++i) {
            arr[i] = arr[i - 1] + (S[i - 1] == c ? 1 : 0);
        }
    };
    f(rs, 'R'); f(gs, 'G'); f(bs, 'B');
    map<char, pair<vector<int>*, vector<int>*>> m;
    m['R'] = make_pair(&gs, &bs);
    m['G'] = make_pair(&rs, &bs);
    m['B'] = make_pair(&gs, &rs);
    int64_t sum = 0;
    for (int j = 0; j < N; ++j) {
        auto p = m[S[j]];
        auto a1 = *p.first, a2 = *p.second;
        sum += a1[j] * (a2[N] - a2[j + 1]);
        sum += a2[j] * (a1[N] - a1[j + 1]);
    }
    debug(sum);
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int k = j + (j - i);
            if (k >= N) { break; }
            if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) { sum--; }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long
int gcd(int m,int n){return n?gcd(n,m%n):m;}
int lcm(int m,int n){return m/gcd(m,n)*n;}
signed main(){
  int n;
  cin>>n;
  vector<string> name(n);
  vector<int> dur(n);
  for(int i=0;i<n;++i){
    cin>>name[i]>>dur[i];
  }
  string x;
  cin>>x;
  for(int i=n-1;i>0;--i)dur[i-1]+=dur[i];
  for(int i=0;i<n;++i)if(name[i]==x)return cout<<(i+1>=n?0:dur[i+1]),0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 2000
int solve(int i, int m);
int i,j,n,q;
int A[N],m[N];
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  
  scanf("%d",&q);
  for(j=0;j<q;j++) scanf("%d",&m[j]);
  
  for(j=0;j<q;j++){
    i=0;
    if(solve(0,m[j])==1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i ,int m){
  int res;
  
  if(m==0) return 1;
  
  if(i>=n || m<=-1) return 0;
  i++;
  res=solve(i,m)+solve(i,m-A[i-1]);
  if(res>=2) res =1; 
  return res;
  
}

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

int main() {
	int K, S, ans=0;
	cin >> K >> S;

	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (S - i - j <= K && S - i - j >= 0) {
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
	int nW, nH, nX, nY, nR;
	cin >> nW >> nH >> nX >> nY >> nR;
	if ((nX + nR <= nW) && (nX - nR >= 0) && (nY + nR <= nH) && (nY - nR >= 0))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	/*system("pause");*/
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod


using ld = long double;
using Point = complex<ld>;
using Set = vector<Point>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

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

    int n;
    ll k;
    cin >> n >> k;
    vector<P> input(n);
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        input[i] = P(a, b);
    }
    sort(input.begin(), input.end());
    for(int i = 0; i < n; ++i){
        k -= input[i].second;
        if(k <= 0){
            cout << input[i].first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  char a,b;
  cin>>a>>b;
  if(a=='H') {
cout<<b<<endl;
  }
  else if(b=='H') {
    cout<<'D'<<endl;
  }
  else {
cout<<'H'<<endl;
  }
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Yahoo2019
{
    class F
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Read();
            int[] rCnt = new int[s.Length * 2 + 1];
            int[] bCnt = new int[s.Length * 2 + 1];
            for (int i = 0; i < s.Length; i++)
            {
                switch (s[i])
                {
                    case '0':
                        rCnt[i+1] = 2;
                        break;
                    case '1':
                        rCnt[i+1] = 1;
                        bCnt[i+1] = 1;
                        break;
                    case '2':
                        bCnt[i+1] = 2;
                        break;
                }
                if (i > 0)
                {
                    rCnt[i+1] += rCnt[i];
                    bCnt[i+1] += bCnt[i];
                }
            }
            for (int i = s.Length + 1; i <= s.Length * 2; i++)
            {
                rCnt[i] = rCnt[i - 1];
                bCnt[i] = bCnt[i - 1];
            }
            /*for (int i = 0; i < rCnt.Length; i++)
                Console.WriteLine(rCnt[i] + " " + bCnt[i]);*/
            int[,] dp = new int[s.Length * 2 + 1, s.Length * 2 + 1];
            //i個目まで取り，赤をj個取った時のパターン数
            int mask = 998244353;
            dp[0, 0] = 1;
            for (int i = 1; i <= s.Length * 2; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    int red = j;
                    int blue = i - j;
                    if (red > rCnt[i] || blue > bCnt[i]) dp[i, j] = 0;
                    else
                    {
                        if (j == 0)
                        {
                            dp[i, j] = blue > bCnt[i] ? 0 : dp[i - 1, j];
                        }
                        else
                        {
                            if (red <= rCnt[i]) dp[i, j] = dp[i - 1, j - 1];
                            if (blue <= bCnt[i]) dp[i, j] += dp[i - 1, j];
                        }
                    }
                    dp[i, j] %= mask;
                }
            }
            Console.WriteLine(dp[s.Length * 2, rCnt[s.Length * 2]]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 72672
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<vector>
#include<stack>
#include<ctime>
#include<vector>
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define LL long long
#define Re(a,b) memset(a,b,sizeof(a))
#define scanf scanf_s
using namespace std;
const int N = 1e9 + 1;
const int M = 0;
int n, a[200001],k,x;
map<int, int>m;
struct pp{
	int a,  b;
};
vector<pp>v;
bool cmp(pp a, pp b){
	return a.b < b.b;
}
int main(){
	cin >> n>> k;
	for (int i = 0; i < n; i++)
		cin >> x, m[x]++;
	if (k >= m.size())puts("0");
	else{
		int d = m.size() - k;
		for (auto x : m)
			v.push_back(pp{ x.first, x.second });
		sort(v.begin(), v.end(),cmp);
		int ans = 0;
		for (int i = 0; i < d; i++)
			ans += v[i].b;
		cout << ans << endl;
	}
}

Measured memory_bytes: 11764
//#define LOCAL
#define INPUT
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define MAXSIZE 10010

bool solve(int n){
    int a=0,b=0,c=0;
    while(n){
        int temp = n % 10;
        if(temp == 3 || temp == 5 || temp == 7){
            n /= 10;
            if(temp == 3) a++;
            if(temp == 5) b++;
            if(temp == 7) c++;
        }
        else{
            return false;
        }
    }
    if(a&&b&&c){
        return true;
    }
    else{
        return false;
    }
}


int main(){
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif

    int t;
    scanf("%d", &t);

    if(t <= 356){
        printf("0\n");
        return 0;
    }
    int res = 0;
    for(int i = 357; i <= t; i += 2){
        if(solve(i)){
            res++;
        }
        if(i%100 == 37){
            i += 14;
        }
        if(i%100 == 57){
            i += 14;
        }
        if(i%100 == 77){
            i += 52;
        }
    }

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








    return 0;

}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e18
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = INF;
    for (int i = -100; i <= 100; i++) {
        int sum = 0;
        for (auto j : a) {
            sum += abs(j - i) * abs(j - i);
        }
        chmin(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for (int i = 0; i < s.length(); i++) cnt += (s[i] != t[i]);
    cout << cnt << newl;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    for(int i = 1; i <= n; ++i){
        int tmp; cin >> tmp;
        v.push_back(make_pair(tmp, i));
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n; ++i){
        cout << v[i].second << " ";
    }

    return 0;

}


Measured memory_bytes: 1780
mod = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), "b").zfill(60), input().split()))

ans = 0
for i in range(60):
    cnt = 0
    for j in a:
        if j[- i - 1] == "1":
            cnt += 1
    tmp = cnt * (n - cnt)
    for _ in range(i):
        tmp = tmp * 2 % mod
    ans += tmp
print(ans % mod)

Measured memory_bytes: 154216
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    ll A[N + 1], B[N];
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll left = min(A[i], B[i]);
        ans += left;
        A[i] -= left;
        B[i] -= left;

        ll right = min(A[i+1], B[i]);
        ans += right;
        A[i+1] -= right;
        B[i] -= right;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  vector<int> a(210);
  cin >> n;
  
  for(int i=0;i<n;i++) cin >> a[i];
  
  int ans = 0;
  
  while(1){
    bool odd = false;
    for(int i=0;i<n;i++) if(a[i]%2==1) odd = true;
    if (odd == true) break;
    ans++;
    for(int i=0;i<n;i++){
      a[i] /= 2;
    } 
  }
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

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

const int N = 1e5 + 20 ;
int n , r1 , r2 ;
vector <int> g1[N] , g2[N] ;

int res[N] ;
vector <int> h[N] ;

inline void err () {
	cout << "IMPOSSIBLE\n" ;
	exit(0) ;
}

inline void get_tree (vector <int> g[N] , int &root) {
	for (int i = 0 , p ; i < n ; i ++) {
		cin >> p ;
		if (p == -1) {
			root = i ;
			continue ;
		}
		p -- ;
		g[p].pb(i) ;
	}
}

int dfs (vector <int> g[N] , int v , int par = -1) {
	int x = -1 ;
	for (int u : g[v]) {
		if (u == par) continue ;	

		int y = dfs(g , u , v) ;
		
		if (x == -1) x = y ;
		else {
			h[x].pb(y) ;
			h[y].pb(x) ;
			x = -1 ;
		}
	}

	if (x == -1) x = v ;

	return x ;
}

bool vis[N] ;

void go (int v) {
	vis[v] = 1 ;
	for (int u : h[v]) {
		if (vis[u]) continue ;
		res[u] = -res[v] ;
		go(u) ;
	}
}

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

	cin >> n ;
	get_tree(g1 , r1) ;
	get_tree(g2 , r2) ;

	for (int i = 0 ; i < n ; i ++)
		if ((_sz(g1[i]) & 1) != (_sz(g2[i]) & 1)) err() ;

	dfs(g1 , r1) ;
	dfs(g2 , r2) ;

	for (int i = 0 ; i < n ; i ++) {
		if (!vis[i] && !(_sz(g1[i]) & 1)) res[i] = 1 , go(i) ;
	}

	cout << "POSSIBLE\n" ;
	for (int i = 0 ; i < n ; i ++) cout << res[i] << ' ' ;
	cout << '\n' ;
}


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

vector<int> edges[100001];
int n,m;
bool *visited = new bool[100001]();

void dfs(int ind){
	
	visited[ind] = true;
	for(int i=0;i<edges[ind].size();i++){
		if(!visited[edges[ind][i]]){
			dfs(edges[ind][i]);
		}
			
	}
	
}

int main() {
	// your code goes here

	cin>>n>>m;
	
	for(int i=0;i<m;i++){
		int f,s;
		cin>>f>>s;
		edges[f].push_back(s);
		edges[s].push_back(f);
	}
	int cnt = 0;
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			cnt++;
			dfs(i);
		}	
	}
	cout<<cnt-1;
	return 0;
}


Measured memory_bytes: 9652
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  for(long i = N;;i--){
    if((long)Math.sqrt(i) * (long)Math.sqrt(i) == i){
      System.out.println(i);
      break;
    }
  }
}}
    

Measured memory_bytes: 23764
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

vector<int> G[100001];
int N;
int root;
int MAX_LOG_V = 17;

int** parent;
int* depth;
int* visit_order;

void dfs(int node_id,int parent_id,int d){
	parent[0][node_id] = parent_id;
	depth[node_id] = d;
	for(int i = 0; i < G[node_id].size(); i++){
		if(G[node_id][i] != parent_id)dfs(G[node_id][i],node_id,d+1);
	}
}

//?????????
void init(){
	dfs(root,-1,0);
	for(int k = 0; k + 1 < MAX_LOG_V; k++){
		for(int node_id = 0; node_id < N; node_id++){
			if(parent[k][node_id] < 0)parent[k+1][node_id] = -1;
			else{
				parent[k+1][node_id] = parent[k][parent[k][node_id]];
			}
		}
	}
}

int lca(int left,int right){
	if(depth[left] > depth[right])swap(left,right);
	for(int k = 0; k < MAX_LOG_V; k++){
		if((depth[right]-depth[left]) >> k & 1){
			right = parent[k][right];
		}
	}
	if(left == right)return left;
	for(int k = MAX_LOG_V-1; k >= 0; k--){
		if(parent[k][left] != parent[k][right]){
			left = parent[k][left];
			right = parent[k][right];
		}
	}
	return parent[0][left];
}

int main(){

	scanf("%d",&N);
	if(N == 1){
		printf("0\n");
		return 0;
	}

	int parent_id;

	for(int i = 2; i <= N; i++){
		scanf("%d",&parent_id);
		parent_id--;
		G[parent_id].push_back(i-1);
	}

	for(int i = 0; i < N; i++)sort(G[i].begin(),G[i].end());

	parent = new int*[MAX_LOG_V];
	for(int i = 0; i < MAX_LOG_V;i++)parent[i] = new int[N];
	depth = new int[N];
	root = 0;
	init();

	visit_order = new int[N];
	visit_order[0] = 0;

	queue<int> Q;
	int order = 1;
	for(int i = 0; i < G[0].size();i++){
		Q.push(G[0][i]);
	}

	while(!Q.empty()){

		visit_order[order++] = Q.front();
		for(int i = 0; i < G[Q.front()].size();i++){
			Q.push(G[Q.front()][i]);
		}
		Q.pop();
	}

	ll sum = 1;
	int lca_id;
	for(int i = 2; i < N; i++){
		lca_id = lca(visit_order[i-1],visit_order[i]);
		sum += (depth[visit_order[i-1]]-depth[lca_id])+(depth[visit_order[i]]-depth[lca_id]);
	}

	printf("%lld\n",sum);

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  int prev = a[0], sum = 1, ans = 0;
  for(int i = 1; i < n; i++){
    if(prev == a[i]) sum++;
    else{
      ans += sum / 2;
      prev = a[i];
      sum = 1;
    }
  }
  cout << ans + sum / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int64 n, a[200200];
int64 _dp[200200][5];

int64 getdp(int i, int j) {
    if (i / 2 - 2 <= j && j <= i / 2 + 2)
        return _dp[i][j - i / 2 + 2];
    else
        return -INF64;
}

void chmaxdp(int i, int j, int64 x) {
    if (i / 2 - 2 <= j && j <= i / 2 + 2)
        chmax(_dp[i][j - i / 2 + 2], x);
}

void d(int64 x) {
    if (x < -10000000) cerr << "-oo ";
    else cerr << x << ' ';
}

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


    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, 200200) rep(j, 5) _dp[i][j] = -INF64;

    chmaxdp(0, 0, 0);
    chmaxdp(1, 1, a[0]);
    rep(i, n) {
        for (int j = i / 2 - 2; j <= i / 2 + 2; ++j) chmaxdp(i + 2, j + 1, getdp(i, j) + a[i + 1]);
        for (int j = i / 2 - 2; j <= i / 2 + 2; ++j) chmaxdp(i + 1, j, getdp(i, j));
    }

    print(getdp(n, n / 2));

    return 0;
}

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

bool isprime(ll n){
    if(n==1) return false;
    if(n==2) return true;
    REP(i,2,(ll)sqrt(n)+2){
        if(n%i==0) return false;
    }
    return true;
}

int main(){
    ll X;
    cin >> X;
    for(ll i = X; ; i++){
        if(isprime(i)){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
from fractions import gcd

def mi():
    return map(int, input().split())

def main():
    N, X = mi()
    x = list(mi())
    y = [abs(x[i]-X) for i in range(N)]
    t = y[0]
    for i in range(N):
        t = gcd(t, y[i])
    print(t)


if __name__ == '__main__':
    main()

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  string s;
  int p;  
  map<string, VI> index;

  while(cin >> s >> p) index[s].PB(p);

  map<string, VI>::iterator it = index.begin();
  while(it != index.end()) {
    cout << it->first << endl;
    sort(ALL(it->second));
    REP(i, it->second.size()) {
      cout << it->second[i];
      if(i != it->second.size()-1) cout << ' ';
    }
    cout << endl;
    it++;
  } 
}

Measured memory_bytes: 1244
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <list>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)

using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	int a[200000+10];
	FOR(i, 0, n){
		scanf("%d", a+i);
	}
	list<int> ans;
	FOR(i, 0, n){
		if(i%2==0) ans.push_back(a[i]);
		else ans.push_front(a[i]);
	}
	list<int>::iterator v;
	int i = 0;
	if(n%2) reverse(ans.begin(), ans.end());
	for(v=ans.begin(); v!=ans.end(); v++){
		printf("%d", *v);
		if(i < n-1) printf(" ");
	}
	printf("\n");
	return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    int result = 0;
    rep(i,n){
        int x;
        cin >> x;
        if(x>k-x)result += 2*(k-x);
        else result += 2*x;
    }
    cout << result << endl;
}

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

int main()
{
	int n;
    cin >> n;
    bool OK = false;
	for (int j = 0; j <= n / 4; j++)
    {
      for (int k = 0; k <= n / 7; k++)
        {
          if (4 * j + 7 * k == n)
               OK = true;
		}
	}
	if (OK == false)
          cout << "No" <<"\n";

	else
        cout << "Yes" << "\n";

}



Measured memory_bytes: 256