akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S; cin >> S;
	int W; cin >> W;
	int i = 0;
	while (i < S.size()) {
		cout << S[i];
		i += W;
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<(n);i++)
using namespace std;
int main(){   
   int n;
   cin>>n;
   vector<string> s(n);
   vector<int> a(n);

   rep(i,0,n){
      cin>>s[i]>>a[i];
   }
   string x;
   cin>>x;
   int sum=0;
   int count=0;
   rep(i,0,n){
      if(x==s[i]){
         count=i;
         break;
      }
   }
   count++;
   rep(i,count,n){
      sum+=a[i];
   }
   cout<<sum;
   return 0;
}

Measured memory_bytes: 256
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_array len read_func = Array.init len (fun _ -> read_func())
let print_int n = Printf.printf "%d\n" n

let input n =
  let arr = Array.make n 0 in
  let _ =
    for i = 0 to n-1 do
      let a = scan_int() in
      arr.(a-1) <- arr.(a-1) + 1
    done in
  arr

let cumulative_sum n arr =
  let ret = Array.make (n+1) 0 in
  let _ =
    for i = 0 to n-1 do
      ret.(i+1) <- ret.(i) + arr.(i)
    done in
  ret

let rec binary_search left right eval =
  if right - left <= 1 then right
  else 
    let mid = (right + left) / 2 in
    if eval mid then binary_search mid right eval
    else binary_search left mid eval

let inner_eval arr value mid = arr.(mid) > value

let eval i arr cum remain mid =
  let r = binary_search (-1) i (inner_eval arr mid) in
  let require = (i-r) * mid - (cum.(i) - cum.(r)) in
  remain >= require

let solve i n arr cum =
  let remain = n - cum.(i) in
  (binary_search 0 (n+1) (eval i arr cum remain)) - 1  (* get left *)


let () =
  let n = scan_int() in
  let arr = input n in
  let _ = Array.fast_sort (fun x y -> if x < y then 1 else 0) arr in
  let cum = cumulative_sum n arr in
  for i = 1 to n do
    print_int (solve i n arr cum)
  done
  

Measured memory_bytes: 10368
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int temp;
	int i;

	scanf("%d%d%d", &a, &b, &c);

	if( a<0 || a>10000 || b<0 || b>10000 || c<0 || c>10000 )
	{
		return 1;
	}

	for( i=0; i<3; i++)
	{
		if( a > b )
		{
			temp = a;
			a = b;
			b = temp;
		}
		else
		{/*No Operation*/}

		if( b > c )
		{
			temp = b;
			b = c;
			c = temp;
		}
		else
		{/*No Operation*/}
	}

	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 596
import java.util.*;
import java.io.*;


public class Main{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String S = sc.next();
        int[] l = new int[q], r = new int[q];
        for(int i=0;i<q;i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        int[] s = new int[n+1];
        for(int i=1;i<n;i++){
            if(S.charAt(i-1)=='A'&&S.charAt(i)=='C'){
                s[i+1] = s[i] +1;
            }
            else{
                s[i+1] = s[i];
            }
        }
        for(int i=0;i<q;i++){
            out.println(s[r[i]]-s[l[i]]);
        }

        out.flush();
    }

    public static long repeatSquarePow(int a, int n, int p){
        if(n==1) return a % p;
        if(n%2==1) return a * repeatSquarePow(a,n-1,p) % p;
        long tmp = repeatSquarePow(a, n/2, p) % p;
        return tmp*tmp % p;
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 32984
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
int w[110], v[110];
ll dp[110][100010];

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

Measured memory_bytes: 79360
N = int(input())
S = input()

if N % 2 != 0:
  print('No')
else:
  tn = N // 2
#  print(S[:tn])
#  print(S[tn:])
  if S[:tn] == S[tn:]:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 2940
from collections import deque


def bfs(h, w, board, visited):
    queue = deque([])
    for i in range(h):
        for j in range(w):
            if board[i][j] == "#":
                queue.append([i, j])
                visited[i][j] = 0
    ans = 0
    while queue:
        y, x = queue.popleft()
        for i, j in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            yn, xn = y+i, x+j
            if yn >= h or xn >= w or yn < 0 or xn < 0:
                continue
            if visited[yn][xn] == -1 and board[yn][xn] == ".":
                visited[yn][xn] = visited[y][x] + 1
                queue.append([yn, xn])
                ans = max(ans, visited[yn][xn])

    return ans


def main():
    h, w = map(int, input().split())
    board = [input() for _ in range(h)]
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    print(bfs(h, w, board, visited))


if __name__ == "__main__":
    main()


Measured memory_bytes: 142172
#include <stdio.h>

int main(void) {
  long long unsigned int a;
  int b, c;
  scanf("%llu %d.%d", &a, &b, &c);
  b = b * 100 + c;
  
  printf("%llu", (long long unsigned int)(a * b / 100));
  
  return 0;
}

Measured memory_bytes: 1736
import sys
readline=sys.stdin.readline
read=sys.stdin.read
n,*abc=map(int,read().split())

abc=[(t,x,y) for t,x,y in zip(*[iter(abc)]*3)]
abc=[(0,0,0)]+abc
diff=[abs(nxt[2]-cur[2])+abs(nxt[1]-cur[1])-nxt[0]+cur[0] for cur,nxt in zip(abc,abc[1:])]
for d in diff:
  if d>0 or d%2==1:
    print('No')
    break
else:
  print('Yes')

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

#define ll long long int 
#define ull unsigned long long
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main()
{
	_fastio
	ll n,ans=0;
	ll a[200005];
	map<ll,ll>mp;
	si(n);
	for1(i,n)
	{
		si(a[i]);
		mp[i+a[i]]=mp[i+a[i]]+1;
	}
	rep1(i,n)
	{
		mp[i+a[i]]=mp[i+a[i]]-1;
		ans=ans+mp[i-a[i]];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 28012
#include <cstdlib>
#include <iostream>

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

    int n,m;
    while (std::cin >> n) {
        m = 0;
        for(int i=0;i<=9;i++){
            for(int j=0;j<=9;j++){
                for(int k=0;k<=9;k++){
                    for(int l=0;l<=9;l++){
                        if (i+j+k+l == n){
                            m += 1;
                        }
                    }
                }
            }
        }
        std::cout << m << std::endl;
    }
    return EXIT_SUCCESS;
}


Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int A = intArray[0];
            int B = intArray[1];
            int Plus = A + B;
            int Minus = A - B;
            int Multi = A * B;
            int[] sum = { Plus, Minus, Multi };
            Console.WriteLine(sum.Max());
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28304
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
short f[105][105][105][105],sline[105][105],scol[105][105];
char st[105];
int n,m;
void chkmax(short &a,short b){if(b>a)a=b;}
int main()
{
    scanf("%d%d",&n,&m);int X,Y;
    for(int i=1;i<=n;i++)
    {
        scanf("%s",st+1);
        for(int j=1;j<=m;j++)
        {
            if(st[j]=='E'){X=i,Y=j;}
            sline[i][j]=sline[i][j-1]+(st[j]=='o'),scol[i][j]=scol[i-1][j]+(st[j]=='o');
        }
    }
    int mxl=Y-1,mxr=m-Y,mxu=X-1,mxd=n-X;
    for(int l=0;l<=mxl;l++)
        for(int r=0;r<=mxr;r++)
            for(int u=0;u<=mxu;u++)
                for(int d=0;d<=mxd;d++)
                {
                    int L=max(d+1,X-u),R=min(X+d,n-u);
                    short t=f[l][r][u][d];
                    if(L<=R)
                        chkmax(f[l+1][r][u][d],t+(Y-l-1>r?scol[R][Y-l-1]-scol[L-1][Y-l-1]:0)),
                        chkmax(f[l][r+1][u][d],t+(Y+r+1<=m-l?scol[R][Y+r+1]-scol[L-1][Y+r+1]:0));
                    L=max(r+1,Y-l),R=min(Y+r,m-l);
                    if(L<=R)
                        chkmax(f[l][r][u+1][d],t+(X-u-1>d?sline[X-u-1][R]-sline[X-u-1][L-1]:0)),
                        chkmax(f[l][r][u][d+1],t+(X+d+1<=n-u?sline[X+d+1][R]-sline[X+d+1][L-1]:0));
                }
    cout<<f[mxl][mxr][mxu][mxd]<<endl;
}

Measured memory_bytes: 57296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int H,W; cin >> H >> W;
    ves S(H); 
    rep(i,H) cin >> S[i];

    rep(i,H){
        rep(j,W){
            int cnt = 0;
            if(S[i][j] == '.'){
                if(j < W-1 and S[i][j+1] == '#') cnt++;
                if(j > 0 and S[i][j-1] == '#') cnt++;
                if(i > 0 and S[i-1][j] == '#') cnt++;
                if(i < H-1 and S[i+1][j] == '#') cnt++;
                if(j < W-1 and i > 0 and S[i-1][j+1] == '#') cnt++;
                if(j > 0 and i < H-1 and S[i+1][j-1] == '#') cnt++;
                if(i > 0 and j > 0 and S[i-1][j-1] == '#') cnt++;
                if(j < W-1 and i < H-1 and S[i+1][j+1] == '#') cnt++;

                char temp = cnt + '0';
                S[i][j] = temp;
            }
        }
    }
    rep(i,H) {
        rep(j,W) cout << S[i][j];  
        cout << endl;      
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int inf=-2e9;

int main()
{
    vector<pair<int, int>>v;
    int n;
    cin>>n;
    while(n--){
        int x, y;
        cin>>x>>y;
        v.push_back({x+y, x-y});
    }
    
    sort(v.begin(), v.end());
    int Ans= 0;
    for(auto X : v){
        if(X.second >= inf){
            inf = X.first;
            Ans++;
        }
    }
    
    cout<<Ans<<endl;
    
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  int l[n+1];
  l[0]=100000;
  l[n]=100000;
  rep(i,n-1)cin >> l[i+1];
  int ans=0;
  rep(i,n)ans+=min(l[i],l[i+1]);
  cout << ans << endl;
}  


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

int main(){
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;

    if(a < b && b < c && a < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
 
int main(){
 
  int n,i,j,max,mini,R[200000];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++)
    scanf("%d",&R[i]);
 
  max=R[1]-R[0];
  mini=R[0];
 
  for(j=2;j<n;j++){
    if(mini > R[j-1])mini=R[j-1];
    if(max < R[j]-mini)max=R[j]-mini;
  }
     
 
  printf("%d\n",max);
 
  return 0;
}

Measured memory_bytes: 1376
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
char s[10];
int n;
int main(){
	scanf("%s",s+1);
	fo(i,1,6) if (s[i]=='1') n++;
	printf("%d\n",n);
	return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    N %= 10;

    Vi hon{2, 4, 5, 7, 9};
    Vi pon{0, 1, 6, 8};

    string ans;
    for (const auto& v : hon) {
        if (N == v) {
            ans = "hon";
        }
    }
    for (const auto& v : pon) {
        if (N == v) {
            ans = "pon";
        }
    }
    if (N == 3) {
        ans = "bon";
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long

//互除法
ll gcd(ll a, ll b)
{
	if (a < b)
	{
		return gcd(b, a);
	}
	else if (a % b)
	{
		return gcd(b, a % b);
	}
	else
	{
		return b;
	}
}

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

	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	int ans = A[0];
	for (int i = 0; i < N; i++)
	{
		ans = gcd(ans, A[i]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BDigitSums solver = new BDigitSums();
        solver.solve(1, in, out);
        out.close();
    }

    static class BDigitSums {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextInt();

            boolean answer = n % s(n) == 0;

            out.println(answer ? "Yes" : "No");
        }

        static long s(long n) {
            long sum = 0;
            while (n > 0) {
                sum += (n % 10);
                n /= 10;
            }
            return sum;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

using namespace std;

#define INF 1e9
#define MAX_N 810
typedef vector<int> Vec;
typedef pair<int,int> pii;

struct Edge{
  int to,cost;
  Edge(int to,int cost) :
    to(to),cost(cost) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int N;
Graph G;
bool leaf[MAX_N];

Vec dijkstra(int s){
  Vec dist(N,INF);
  dist[s] = 0;
  priority_queue<pii,vector<pii>,greater<pii> > Q;
  Q.push(pii(0,s));
  while(!Q.empty()){
    pii p = Q.top(); Q.pop();
    int v = p.second;
    if(dist[v] < p.first){
      continue;
    }
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge &e = G[v][i];
      if(dist[v] + e.cost < dist[e.to]){
        dist[e.to] = dist[v] + e.cost;
        Q.push(pii(dist[e.to],e.to));
      }
    }
  }
  return dist;
}

int getFarthestPoint(int v){
  Vec vec = dijkstra(v);
  int resv = -1, max = -1;
  for(int i = 0 ; i < N ; i++){
    if(max < vec[i] && vec[i] != INF){
      max = vec[i];
      resv = i;
    }
  }
  return resv;
}

int getTreeDiameter(){
  int v = -1;
  for(int i = 0 ; i < N ; i++){
    if(!leaf[i]){
      v = i;
      break;
    }
  }
  int v1 = getFarthestPoint(v);
  int v2 = getFarthestPoint(v1);
  Vec d = dijkstra(v2);
  int res = 0;
  for(int i = 0 ; i < (int)d.size() ; i++){
    if(d[i] != INF){
      res = max(res,d[i]);
    }
  }
  return res;
}

void init(){
  for(int i = 0 ; i < (int)G.size() ; i++){
    G[i].clear();
  }
  G.clear();
  G.resize(N);
}

int main(){
  while(cin >> N, N){
    init();
    int sum = 0;
    Vec p(N-1);
    for(int i = 0 ; i < N-1 ; i++){
      cin >> p[i]; p[i]--;
    }
    Graph G2(N);
    for(int i = 0 ; i < N-1 ; i++){
      int d; cin >> d; sum += d;
      G2[p[i]].push_back(Edge(i+1,d));
      G2[i+1].push_back(Edge(p[i],d));
    }
    memset(leaf,false,sizeof(leaf));
    for(int i = 0 ; i < (int)G2.size() ; i++){
      if(G2[i].size() == 1){
        leaf[i] = true;
      }
    }
    for(int i = 0 ; i < (int)G2.size() ; i++){
      if(!leaf[i]){
        for(int j = 0 ; j < (int)G2[i].size() ; j++){
          if(!leaf[G2[i][j].to]){
            G[i].push_back(G2[i][j]);
            sum += G2[i][j].cost;
          }
        }
      }
    }
    cout << sum-getTreeDiameter() << endl;
  }
  return 0;
}

Measured memory_bytes: 1296
// luogu-judger-enable-o2
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

template <typename QvQ> inline QvQ Min(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max(QvQ a,QvQ b){if(a>b) return a;return b;}

#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void

#define bl putchar(' ')
#define ed putchar('\n')

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

template <typename QvQ>inv read(QvQ &x)
{
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define MAXN 10005
int n,a[MAXN],b[MAXN],c[MAXN];
int main()
{
	read(n);
	for(rei i=1;i<=n;++i) read(a[i]);
	for(rei i=1;i<=n;++i) read(b[i]);
	for(rei i=1;i<n;++i) read(c[i]);
	int ans=b[a[1]],pos=a[1];
	for(rei i=2;i<=n;++i)
	{
		ans+=b[a[i]];
		if(a[i]==pos+1) ans+=c[pos];
		pos=a[i];
	}
	write(ans);
	return 0;
}

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

string s;
vector<int> p,q,r;
int x;

int formula(){
	int ans;
	if(s[x] == '0' || s[x] == '1' || s[x] == '2'){
		stringstream ss;
		ss << s[x];
		ss >> ans;
		return ans;
	}
	else if(s[x] == '-'){
		x++;
		return 2 - formula();
	}
	else if(s[x] == '('){
		x++;
		int a = formula();
		x++;
		if(s[x] == '+'){
			x++;
			int b = formula();
			x++;
			return max(a,b);
		}
		else if(s[x] == '*'){
			x++;
			int b = formula();
			x++;
			return min(a,b);
		}
	}
}

int main(){
	int ans;
	while(1){
		cin >> s;
		if(s[0] == '.')break;
		ans = 0;
		p.clear();
		q.clear();
		r.clear();
		for(int i = 0;i < s.size();i++){
			if(s[i] == 'P')p.push_back(i);
			else if(s[i] == 'Q')q.push_back(i);
			else if(s[i] == 'R')r.push_back(i);
		}
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 3;j++){
				for(int k = 0;k < 3;k++){
					for(int l = 0;l < p.size();l++)s[p[l]] = '0' + i;
					for(int l = 0;l < q.size();l++)s[q[l]] = '0' + j;
					for(int l = 0;l < r.size();l++)s[r[l]] = '0' + k;
					x = 0;
					if(formula() == 2)ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
  int R,G,B,N;
  cin >> R >> G >>B >> N;
  int counter = 0;
  for(int i = 0; i <= N; i++){
    for(int j = i; j <= N; j++){
      if(i % R == 0 && (j-i) % G == 0 && (N-j) % B == 0)
        counter++;
    }
  }
  
  cout << counter << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int q = sc.nextInt();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			int[] num = new int[n+1];
			int sum = 0;
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					sum++;
				}
				
				num[i] = sum;
			}
			
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				System.out.println(num[r[i]]-num[l[i]]);
			}
			
			
	    }
		
	}
	


Measured memory_bytes: 64976
/* Author : tushar3105 */

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

typedef pair<long long int,long long int> ii;					// Pair of integers
typedef vector<long long int> vi;                   				// Vector of integers
typedef vector<vector<long long int>> vvi;                 			// Vector of vi
typedef vector<pair<long long int, long long int>> vii;				// Vector of ii

#define pb push_back								// Push back to vectors
#define mp make_pair								// For pairs
#define ff first								// For pairs
#define ss second								// For pairs
#define all(c) (c).begin(),(c).end()						// Use in sorting
#define sz(a) ((long long int)(a).size())
#define lli long long int
#define ull unsigned long long int
#define ld long double
#define ref(i,x,y) for(long long int i=(x);i<=(y);++i)				// Loop to go forward
#define reb(i,x,y) for(long long int i=(x);i>=(y);--i)				// Loop to go backward
#define trf(c,it) for(auto it = (c).begin(); it != (c).end(); it++)		// Remember it is an iterator
#define trb(c,it) for(auto it = (c).end()-1; it != (c).begin()-1; it--)		// Remember it is an iterator
#define tc(t) long long int (t); cin>>(t);while((t)--)				// Test cases
//fill (dist,dist+110000,pinf);							// For setting default

const long long int mod = 1e9+7;
const long long int pinf = 9223372036854775807;
const long long int ninf = -9223372036854775807;

/*-----------------------------Code begins----------------------------------*/

int main (void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	lli n, mx = 0, mn = 0, cst = 1000, stk = 0;
	cin>>n;
    
    lli a[n + 90];
    ref(i, 1, n) 
		cin >> a[i];
    
    
    if (a[1] <= a[2])
        mn = a[1];
    
    ref(i, 2, n-1)
    {
        if (a[i] >= a[i - 1] && a[i] >= a[i + 1] && mn > 0)
        {
            stk = cst / mn;
            cst = cst % mn;
            mx = a[i];

            cst += (mx * stk);
            stk = 0;
            mn = 0;
        }
    
        if (a[i] <= a[i - 1] && a[i] <= a[i + 1])
            mn = a[i];
    }
    
    if (a[n] >= a[n - 1] && mn > 0)
    {
        stk = cst / mn;
        cst = cst % mn;
        mx = a[n];

        cst += (mx * stk);
        stk = 0;
        mn = 0;
    }
    
    cout << cst << endl;

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int a,b;
  cin>>a>>b;
  int ans=b;
  for(int i=2;i<=a;i++){
    ans*=b-1;
  }
  cout<<ans<<endl;
}

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

bool prime[10000005];
int p[700000]; 
int main()
{	
	int k=0;
	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<=999999;++i)
	{
		if(prime[i]==0)
		{	
			p[k++]=i;		
			for(int j=i+i;j<=999999;j+=i)	
			{
				prime[j]=1;
			}
		}
	}
	int n;
	while(cin>>n){
		//for(int i=0;i<10;++i)cout<<p[i]<<endl;
		int ans = lower_bound(p,p+k,n)-p;
		//cout<<p[ans]<<endl;
		if(p[ans]==n)ans++;
		cout<<ans<<endl;
	} 

}

Measured memory_bytes: 4268
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  VI ans(2001);
  rep(i,N) rep(j,N){
    if(i<j){
      int Z=min({abs(i-j),abs(i+1-X)+abs(j+1-Y)+1,abs(i+1-Y)+abs(j+1-X)+1});
      ans[Z]++;
    }
  }
  rep(i,N-1) cout<<ans[i+1]<<endl;
}

Measured memory_bytes: 256
n = int(input())
nums = [int(s) for s in input().split(" ")]

absmin=abs(nums[0])
abssum=0
minus=0

for n in nums:
    if n < 0:
        minus += 1
    absmin = min(absmin, abs(n))
    abssum += abs(n)

if minus % 2 == 0:
    print(abssum)
else:
    print(abssum - (absmin * 2))


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

using int64 = long long;

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

    vector<int64> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    int64 ans    = 0,
          blocks = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (blocks > A[i]) {
            cout << -1 << endl;
            return 0;
        } else if (blocks < A[i]) {
            ans += A[i];
            blocks = A[i];
        }
        blocks = max(blocks - 1, 0LL);
    }
    if (blocks > 0) ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N; 
  string S;
  cin >> N >> S;
  long long ans = 0;
  for (int i = 0; i < S.size()-2; ++i) {
    if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

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

# define C continue;
# define R return

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

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

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

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

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

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

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

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

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

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

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    string a , b ;
    cin >> a >> b ;

    int p , q ;
    cin >> p >> q ;

    string u ; cin >> u ;

    if ( u == a )
        p -- ;

    if ( u == b )
        q -- ;

    cout << p << " " << q ;
    line ;
}

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

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


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 4007;
const int K = 5000;
int used[N][N], dp[N][N], n, ps[N], r[N], a[N];
int solve(int i, int p, int s){
    if (s < 0) return 0;
    if (s > p - i + 1) return 0;
    if (used[i][s]) return dp[i][s];
    if (i == n) return 1;
    int s0 = s;
    used[i][s] = 1;
    if (r[i] > p){
        s += ps[r[i]] - ps[p];
        p = r[i];
    }
    return dp[i][s0] = (solve(i + 1, p, s - 1) + solve(i + 1, p, s)) % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int m;
    string s;
    cin >> n >> m;
    cin >> s;
    for (int i = 1; i <= n; i++) r[i] = i;
    for (int i = 1; i <= m; i++){
        int x, y;
        cin >> x >> y;
        r[x] = max(y, r[x]);
    }
    for (int i = 0; i < n; i++){
        a[i + 1] = s[i] - '0';
        ps[i + 1] = ps[i] + a[i + 1];
    }
    cout << solve(1, 1, a[1]);
}


Measured memory_bytes: 189312
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n,0);
    
    rep(i,n-1){
        int s;
        cin >> s;
        a[s-1]++;
    }
    
    rep(i,n) {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 3980
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;

int main(){
    string str;
    int n;
    ll A[10];
    cin>>str;
    n = str.length();
    for(int i = 0;i < n;i++){
        A[i] = (int)(str[i]-'0');
    }
    ll ret = 0;
    for(int sig = 0;sig < (1<<(n-1));sig++){
        ll sum = 0;
        int digit = 1;
        for (int i = 0;i < n-1;i++){
            sum += digit * A[n-1-i];
            if((sig&(1<<i))==0){
                digit *=10;
            }else{
                digit = 1;
            }
        }
        sum += digit * A[0];
        ret += sum;
    }
    cout<<ret<<endl;
}


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

int main(){
	
	int n;
	int b[4]={0};
	char s[4],comma;
	
	while(cin>>n>>comma>>s){
		if(strcmp(s,"A")==0)
			b[0]++;
		else if(strcmp(s,"B")==0)
			b[1]++;
		else if(strcmp(s,"AB")==0)
			b[2]++;
		else if(strcmp(s,"O")==0)
			b[3]++;
		else
			break;
	}
	for(int i=0;i<4;i++)
		cout<<b[i]<<endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
  
	int r, D, x;
	cin >>r >> D >> x;
	fy(10) {
		ce(r*x - D)
			x = r*x - D;
	}

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

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

    int cnt = 0;
    rep(i,n){
        int a;
        cin >> a;
        if(a % 2) cnt++;
    }
    if(cnt % 2) cout << "NO" << endl;
    else cout << "YES" << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main (void){
  int H,W,h,w;

  while(1){
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0){
      break;
    }

    for(h=0; h<H; h++){
      for(w=0; w<W; w++){
        if(w == 0 || h == 0 || w == (W-1) || h == (H-1)){
        printf("#");
      }else{
        printf(".");
      }
    }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


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

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

	vector<int>a(n,-1);

	rep(i,m) {
		int s, c;
		cin >> s >> c;
		if (a[s-1]!=-1 && a[s - 1]!=c) {
			cout << -1<<endl;
			return 0;
		}
		else {
			a[s - 1] = c;
		}
	}

	if (a[0]==0 && n!=1) {
		cout << -1 << endl;
		return 0;
	}
	else if(a[0] == -1 && n != 1) {
		a[0] = 1;
	}

	rep(i,n){
		if (a[i]!=-1) {
			cout << a[i];
		}
		else {
			cout << 0;
		}
	}

	return 0;
}


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

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> dp(n);
  vector<int> h(n);
  int s;
  int t;
  
  rep(i,n)cin>>h.at(i);
  rep(i,n){
    if(i==0)dp.at(i)=0;
    else if(i==1)dp.at(i)=abs(h.at(0)-h.at(1)); 
    else{
      s=dp.at(i-1)+abs(h.at(i)-h.at(i-1));
      t=dp.at(i-2)+abs(h.at(i)-h.at(i-2));
      dp.at(i)=min(s,t);
    }
  }
    cout<<dp.at(n-1)<<endl;
  }

Measured memory_bytes: 1024
import math
import numpy as np

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
b = a[-1]
c = getNearestValue(a,b/2)
ans = str(b) + ' ' + str(c)
print(ans)

Measured memory_bytes: 37824
# Aizu Problem ITP_1_10_A: Distance
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


x1, y1, x2, y2 = [float(_) for _ in input().split()]
print("%.8f" % math.sqrt((x1 - x2)**2 + (y1 - y2)**2))

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

char s;
int k = 0,q = -1,first,new1,old =0;
int ans = 0, temp = 0, total = 0;

int main() {
  int N, K;
  cin >> N >> K;
  queue<int> que, que2;
  for(int i = 0; i < N + 1 ; i++ ){
    cin >> s;
    if(i != 0) old = new1;
    new1 = s - '0';
    if(i == 0) first = new1;
    q++;
    if((old != new1 && i != 0) || i == N)que.push(q),q = 0;
  }
  if(!first) k++;
  int K2 = K*2;
  while(total != N) {
    //cout << que.front() << endl;
    temp += que.front();
    k++;
    que2.push(que.front());
    if(k > K2 && (k & 1) == 1) {
      ans = max(ans,temp);
      temp -= que2.front();
      que2.pop();
      if(k != K2 + 1 || first == 1) {
        temp -= que2.front();
        que2.pop();
      }
    }
    total += que.front();
    que.pop();
  }
  ans = max(ans,temp);

  cout << ans << endl;

}

Measured memory_bytes: 640
a , b , c = map (int , input() . split())
if( a == 1 and b == 0 and b == 0 ):
    print( "Close" )
elif( a == 0 and b == 1 and c == 0 ):
    print( "Close" )
elif( a == 1 and b == 1 and c == 0 ):
    print( "Open" )
elif( a == 0 and b == 0 and c == 1 ):
    print( "Open" )
elif( a == 0 and b == 0 and c == 0 ):
    print( "Close" )


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
constexpr int MAX = 625;
constexpr int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int H, W;
int board[MAX];
int memo[MAX];

// https://ja.wikipedia.org/wiki/幅優先探索
// 迷路を幅優先探索する.
// ※bfsの動作確認用.
// @param s: 探索開始地点の迷路上の座標.
// @return: 特に無し.
void bfs(int s){
    
    // 1. 空のキュー.
    queue<int> q;
    
    // 2. memo初期化.
    memset(memo, 0, sizeof(memo));
    
    // 3. 訪問済みフラグ設定.
    // ※スタート地点は, 距離ゼロを指定.
    memo[s] = 0;
    
    // 4. 探索地点 s をキュー q に追加.
    q.push(s);
    while(!q.empty()){
        // 5. キューから取り出す.
        int v = q.front();
        q.pop();
        // 6. 取り出した要素を処理.
        // x: 列方向, y: 行方向 で考える.
        int nx, ny, n;
        int cx = v % W , cy = v / W;
        rep(i, 4){
            nx = cx + dx[i];
            ny = cy + dy[i];
            n = nx + ny * W;
            // 7. 訪問不可能なマス であれば, 処理をスキップ.
            if(n < 0 || nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
            if(board[n] == '#')                                 continue;
            
            // 8. 訪問先のマスで, 訪問可能 かつ スタート地点でない かつ 未訪問 であれば, 訪問済み(※最短ルート)を設定.
            if(board[n] == '.' && n != s && memo[n] == 0) memo[n] = memo[v] + 1, q.push(n);
        }
    }
    return;
}

int main(){
    
    // 1. 入力情報.
    scanf("%d %d", &H, &W);
    rep(i, H){
        char c[33];
        scanf("%s", c);
        rep(j, W) board[i * W + j] = c[j];
    }
    
    // 2. スタートとゴールを決めて, 移動回数の最大値を探索.
    int ans = 0;
    rep(si, H){
        rep(sj, W){
            if(board[si * W + sj] != '#'){
                bfs(si * W + sj);
                rep(gi, H) rep(gj, W) ans = max(ans, memo[gi * W + gj]);
            }
        }
    }
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
        cin >> H[i];

    int pre = -1;
    for (int i = 0; i < N; i++) {
        if (pre <= H[i] - 1) {
            pre = H[i] - 1;
        } else if (pre <= H[i]) {
            pre = H[i];
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	ll n, a, b; cin >> n >> a >> b;
	ll ans;
	if ((b - a) % 2 == 0) ans = (b - a) / 2;
	else
	{
		ll s = a + (b - a - 1) / 2;
		ll t = (n - b + 1) + (b - a - 1) / 2;
		ans = min(s, t);
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

struct RollingHash {
    typedef unsigned long long ull;

    const ull MASK30 = (1ull << 30) - 1;
    const ull MASK31 = (1ull << 31) - 1;
    const ull mod = (1ull << 61) - 1;
    const ull POSITIVIZER = mod * 3;
    const ull base = 10007;

    vector<ull> hash,power;

    RollingHash(const string &s) {
        int sz = s.size();
        hash.assign(sz + 1,0);
        power.assign(sz + 1,1);
        for (int i = 0; i < sz; i++) {
            power[i+1] = CalcMod(Mul(power[i],base));
            hash[i+1] = CalcMod(Mul(hash[i],base) + s[i]);
        }
    }

    ull get(int l, int r) {
        ull res;
        res = CalcMod(hash[r] + POSITIVIZER - Mul(hash[l],power[r-l]));
        return res;
    }


    ull Mul (ull a, ull b) {
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return (au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    ull CalcMod(ull val) {
        val = (val & mod) + (val >> 61);
        if (val > mod) val -= mod;
        return val;
    }
};

int N;
string S;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string T,S; cin >> T >> S;
    int N = T.size();
    int M = S.size();

    RollingHash RT(T), RS(S);
    vector<int> ans;
    rep(i,N-M+1) {
        if (RT.get(i,i+M) == RS.get(0,M)) ans.emplace_back(i);
    } 

    rep(i,ans.size()) cout << ans[i] << endl;
}



Measured memory_bytes: 3240