akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*M]

import sys
sys.setrecursionlimit(10**7)

class UnionFind:
    def __init__(self,N):
        self.Parent = list(range(N))
        self.size = [1]*N
    def get_Parent(self,n):
        if self.Parent[n] == n:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def get_size(self,n):
        return self.size[self.get_Parent(n)]
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y:
            self.size[x] += self.size[y]
            self.Parent[y] = x
            return True
        return False
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)

T = UnionFind(N)
for a,b in AB:
    T.merge(a-1,b-1)

ans = 0
for i in range(N):
    ans = max(ans,T.get_size(i))

print(ans)

Measured memory_bytes: 60740
R, C, K = map(int, input().split())
g = [[-float('inf')]*C for _ in range(R)]
for i in range(K):
    r, c, k = map(int, input().split())
    r -= 1
    c -= 1
    g[r][c] = k

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
for r in range(R):
    for c in range(C):
        # k[0..3] = 0個拾っている状態から3個拾っている状態
        # indexが大きいほど、小さいアイテムとなるので、小さいものから更新していく
        for k in range(2, -1, -1):
            dp[k+1][r][c] = max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            )

        for k in range(4):
            dp[0][r+1][c] = max(dp[0][r+1][c], dp[k][r][c])
            dp[k][r][c+1] = max(dp[k][r][c+1], dp[k][r][c])

ans = 0
for i in range(4):
    ans = max(dp[i][R-1][C-1], ans)
print(ans)


Measured memory_bytes: 444280
N = int(input())
X = list((int(x) for x in input().split()))
X.sort()

if (X[N - 1] - X[0]) % 2 == 0:
    print(round((X[N - 1] - X[0]) / 2))
else:
    print(round(((X[N - 1] - X[0]) + 1) / 2))


Measured memory_bytes: 5624
def main():
    N = int(input())
    X = list(map(int,input().split()))
    MOD = 10 ** 9 + 7
    goal = X[-1]
    ans = goal - X[0]
    #########################################
    fact = [1]
    for i in range(10**5+5):
        new_fact = fact[-1]*(i+1)%MOD
        fact.append(new_fact)
    #########################################
    count = 2
    for i in range(1,N-1): 
        tmp = goal - X[i]
        ########################################################
        ans = ((ans * count) + ((fact[i] * tmp))) % MOD
        ########################################################
        count += 1  
    print(ans)
if __name__ == '__main__':
    main()

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

s = list(str(input()))

test_case = []

for i in range(len(s)-2):
#    print(i)
    temp = s[i:i+3]
    test_case.append(int(temp[0]+temp[1]+temp[2]))

#print(test_case)

memory = []
for i in range(len(test_case)):
    memory.append(abs(753 - test_case[i]))

print(min(memory))

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

int main()
{
    int n;
    cin >> n;
    int * n_input = new int[n];
    char * ch_input = new char[n];
    for(int i = 0; i < n; i++) cin >> ch_input[i] >> n_input[i];
    
    int * n_check_S = new int[13];
    int * n_check_H = new int[13];
    int * n_check_C = new int[13];
    int * n_check_D = new int[13];
    for(int i = 0; i < 13; i++) {
        n_check_S[i] = 0;
        n_check_H[i] = 0;
        n_check_C[i] = 0;
        n_check_D[i] = 0;
    }

    for(int i = 0; i < n; i++) {
        if(ch_input[i] == 'S') n_check_S[n_input[i]-1] = 1;
        else if(ch_input[i] == 'H') n_check_H[n_input[i]-1] = 1;
        else if(ch_input[i] == 'C') n_check_C[n_input[i]-1] = 1;
        else n_check_D[n_input[i]-1] = 1;
    }

    for(int i = 0; i < 13; i++) {
        if(n_check_S[i] == 0) cout << "S " << i+1 << endl;
    }
    for(int i = 0; i < 13; i++) {
        if(n_check_H[i] == 0) cout << "H " << i+1 << endl;
    }
    for(int i = 0; i < 13; i++) {
        if(n_check_C[i] == 0) cout << "C " << i+1 << endl;
    }
    for(int i = 0; i < 13; i++) {
        if(n_check_D[i] == 0) cout << "D " << i+1 << endl;
    }


    delete[] n_input;
    delete[] ch_input;
    delete[] n_check_S;
    delete[] n_check_H;
    delete[] n_check_C;
    delete[] n_check_D;

    return 0; 
}

Measured memory_bytes: 1196
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int numberOfTree = sc.nextInt();
    int numberOfUse = sc.nextInt();
    int[] tree = new int[numberOfTree];
    for (int i = 0; i < tree.length; i++) {
      tree[i] = sc.nextInt();
    }
    Arrays.sort(tree);
    int min = tree[tree.length - 1] - tree[0];
    
    for (int i = 0; i < tree.length - numberOfUse + 1; i++) {
      if (tree[i + numberOfUse - 1] - tree[i] < min) {
        min = tree[i + numberOfUse - 1] - tree[i];
      }
    }
    System.out.println(min);
  }

}


Measured memory_bytes: 52244
# practice for SegTree
from math import gcd

INF = 10**10
class SegTree:
    def __init__(self, vals, seg_f, ide_ele):
        n = len(vals)
        self.seg_f = seg_f
        self.ide_ele = ide_ele
        self.leaf_n = 1 << (n-1).bit_length()
        self.tree = [ide_ele]*(2*self.leaf_n-1)
        for i in range(n):  # init leaf
            self.tree[i+self.leaf_n-1] = vals[i]
        for i in range(self.leaf_n-2, -1, -1):  # bottom-up
            self.tree[i] = self.seg_f(self.tree[2*i+1], self.tree[2*i+2])

    def update(self, i, x):
        i += (self.leaf_n-1)
        self.tree[i] = x
        while i > 0:
            i = (i-1)//2
            self.tree[i] = self.seg_f(self.tree[2*i+1], self.tree[2*i+2])

    # [l,r)
    def query(self, l, r):
        v_l = self.ide_ele
        v_r = self.ide_ele
        l += (self.leaf_n-1)
        r += (self.leaf_n-1)
        while l < r:
            if l&1 == 0:
                v_l = self.seg_f(v_l, self.tree[l])
            if r&1 == 0:
                v_r = self.seg_f(v_r, self.tree[r-1])
                r -= 1
            l >>= 1
            r >>= 1
        return self.seg_f(v_l ,v_r)

def gcd2(a,b):
    if a == INF:
        return b
    elif b == INF:
        return a
    else:
        return gcd(a,b)


n = int(input())
al = list(map(int, input().split()))

st = SegTree(al,gcd2,INF)
# print(st.tree)
ans = 0
for i in range(n):
    if i > 0: st.update(i-1,al[i-1])
    st.update(i,INF)
    c_gcd = st.query(0,n)
    # print(c_gcd,'-')
    ans = max(ans,c_gcd)

print(ans)

Measured memory_bytes: 87948
n = int(input())
arr = []
passed = []
for i in range(n):
  a = int(input())
  arr.append(a)
  
next_position = 1
ans = 0

while(1):
  next_position = arr[next_position-1]
  #print(position)
  if ans == n:
    print(-1)
    break
  #passed.append(next_position)
  ans += 1
  if next_position == 2:
    print(ans)
    break
  

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

#define pb            push_back
#define mp            make_pair
#define ins           insert
#define endl          '\n'
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<endl<<(#X)<<" = "<<(X)<<endl; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin>>s;
    
    if (s[0]==s[1] && s[1]==s[2])
        cout<<"No";
    else
        cout<<"Yes";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

int main(){
    int N, A, B, C, D;  cin >> N >> A >> B >> C >> D;
    string S;   cin >> S;
    S += "###";
    S = '#' + S;
    int a, b;
    a = A;
    b = B;
    if(D > C){
        while(b < D){
            if(S[b+1] == '.')   b++;
            else{
                if(S[b+2] == '.')   b += 2;
                else{print("No"); return 0;}
            }
        }
        while(a < C){
            if(S[a+1] == '.')   a++;
            else{
                if(S[a+2] == '.')   a += 2;
                else{print("No"); return 0;}
            }
        }
        print("Yes");
    }else{
        while(b < D){
            if(S[b-1] == '.' && S[b+1] == '.'){
                break;
            }else{
                if(S[b+1] == '.')   b++;
                else{
                    if(S[b+2] == '.')   b += 2;
                    else{print("No"); return 0;}
                }
            }
        }
        S[b] = 'B';
        while(a < C){
            if(S[a+1] == '.')   a++;
            else{
                if(S[a+2] == '.')   a += 2;
                else{print("No"); return 0;}
            }
        }
        print("Yes");
    }
}

Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <algorithm>
using std::pair;
using std::make_pair;
#include <vector>
using std::vector;

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<vector<PII> > VP;

int main(void) {
    while (1) {
        int n; // pc
        int m; // person
        scanf("%d%d", &n, &m);
        if (n == 0 && m == 0) {
            break;
        }

        VI pc(m + 1, 0);
        VI start(m + 1, 0);

        VP time(m + 1);

        int r;
        scanf("%d", &r);
        for (int i = 0; i < r; i++) {
            int t;
            int n2; // pc
            int m2; // person
            int s;
            scanf("%d%d%d%d", &t, &n2, &m2, &s);
            if (s == 1) {
                if (pc[m2] == 0) {
                    start[m2] = t;
                }
                pc[m2]++;
            } else {
                pc[m2]--;
                if (pc[m2] == 0) {
                    int end = t;
                    time[m2].push_back(make_pair(start[m2], end));
                }
            }
        }

        int q;
        scanf("%d", &q);
        for (int i = 0; i < q; i++) {
            int s;
            int e;
            int m2;
            scanf("%d%d%d", &s, &e, &m2);
            int count = 0;

            for (int j = 0; j < (int)(time[m2].size()); j++) {
                int first = time[m2][j].first;
                int second = time[m2][j].second;
                int start;
                int end;
                if (s < first) {
                    start = first;
                } else if (s <= second) {
                    start = s;
                } else {
                    continue;
                }
                if (e < first) {
                    break;
                } else if (e <= second) {
                    end = e;
                } else {
                    end = second;
                }
                count += end - start;
            }
            printf("%d\n", count);
        }

    }
    return 0;
}

Measured memory_bytes: 3452
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    string s;
    cin >> s;
    if(s.size() == 3)reverse(s.begin(), s.end());
    cout << s << endl;
    
    return 0;
}

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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    double n;
  cin >> n;
  int a=(n+1)/2;
    printf("%f\n",a/n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,c;
int q,t,f;
bool k;
int main()
{
	cin>>s>>q;
	for(int i=1;i<=q;++i)
	{
		cin>>t;
		if(t==1) k^=1;
		else
		{
			cin>>f>>c;
			if(k^(f==1)) s.insert(0,c);
			else s+=c;
		}
	}
	if(k) reverse(s.begin(),s.end());
	cout<<s;
	return 0;
}

Measured memory_bytes: 900
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

//		int b[] = new int[n];
		ArrayList<Integer> list = new ArrayList<Integer>();
//		int diff[] = new int[n];
		for(int i = 0; i < n; i++){
//			b[i] = sc.nextInt();
			list.add(sc.nextInt());

//			System.out.println("I = "+i+" "+list.get(i));
			if(list.get(i) > i + 1){
//				System.out.println(list.get(i));
				System.out.println(-1);
				return;
			}
//
//			diff[i] = (i + 1) - list.get(i);
		}

		int result[] = new int[n];
		for(int i = 0; i < n; i++){
			for(int j = list.size() - 1; j >= 0; j--){
				if(list.get(j) == j + 1){
//					System.out.println("remove "+(j + 1));
					result[i] = j + 1;
					list.remove(j);
					break;
				}
//				if(diff[j] == 0){
//					result[i] = b[j];
//
//					for(int k = j + 1; k < n; k++){
//						diff[k]--;
//					}
//
//					break;
//				}
			}

			//debug
//			for(int j = 0; j < list.size(); j++){
//				System.out.print(list.get(j)+" ");
//			}
//			System.out.println();
		}

		for(int i = n - 1; i >= 0; i--){
			System.out.println(result[i]);
		}
	}
}


Measured memory_bytes: 26908
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S; cin>>S;
    int n=S.length();

    for(int i=0; i<n; i++){
        if(S[i] != S[n-i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    int m=(n-1)/2;
    for(int i=0; i<m; i++){
        if(S[i] != S[m-i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    int o=(n+3)/2;
    int j=0;
    for(int i=o-1; i<n; i++){
        if(S[i] != S[n-j-1]){
            cout<<"No"<<endl;
            return 0;
        }
        j++;
    }

    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3608
// 2019.9.15 bal4u
// Template for Online Contest

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef long long ll;

#define gc() getchar()
#define pc(c) putchar(c)

int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void outL(ll n) { // 整数の表示
	int i; char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

#define QSIZE 200005

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef struct { int t; } QUE;
QUE que[QSIZE + 5]; int qsize;

void max_heapify(int i)
{
	int l, r, max;
	QUE qt;
	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t > que[i].t) max = l; else max = i;
	if (r < qsize && que[r].t > que[max].t) max = r;
	if (max != i) {
		qt = que[i], que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

void deq()
{
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(int t)
{
	int i, max;
	QUE qt;

	i = qsize++;
	que[i].t = t;
	while (i > 0 && que[max = PARENT(i)].t < que[i].t) {
		qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}

#define MIN(a,b)  ((a)<=(b)?(a):(b))
#define MAX(a,b)  ((a)>=(b)?(a):(b))
#define ABS(a)    ((a)>=0?(a):-(a))
inline static int chmax(int *a, int b) { if (*a < b) *a = b; }
inline static ll  chmaxL(ll *a, int b) { if (*a < b) *a = b; }
inline static int chmin(int *a, int b) { if (*a > b) *a = b; }
inline static ll  chminL(ll *a, int b) { if (*a > b) *a = b; }

int N, M;
int A[100005];
int cmp(const void *u, const void *v) { return *(int *)v - *(int *)u; }

int main()
{
	int i, a;
	ll ans;
	
	N = in(), M = in();
	for (i = 0; i < N; i++) enq(in());
	while (M--) a = que[0].t, deq(), enq(a >> 1);
	ans = 0; while (qsize) ans += que[0].t, deq();
	outL(ans);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,j,bl,x,y;
int main(){
	scanf("%d%d%d",&n,&m,&bl);
	for(i=1;i<=n;i++){
	 for(j=1;j<=m;j++){
	 	x=(i+j+m)/bl%2;
	 	y=(i-j+m)/bl%2;
	 	printf("%c","YBGR"[x*2+y]);
	 }
	 puts("");
  }
}

Measured memory_bytes: 512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#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())

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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

void printVec(VS &vec) {
  cout << "";
  for(auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  string s;
  int K;
  cin >> s;
  cin >> K;
  VS vec;
  for( int i = 1 ; i <= K ; i++) {
    int len = strlen(s.c_str());
    for( int j = 0 ; j < len; j++ ) {
      vec.push_back(s.substr(j, i));
    }
  }
  sort(vec.begin(), vec.end());
  unique(vec.begin(), vec.end());
  cout << vec[K-1] << endl;
  return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  REP(i, N)
  cin >> x[i] >> u[i];
  double ans = 0.0;
  REP(i, N)
  {
    if (u[i] == "JPY")
      ans += x[i];
    else
      ans += 380000.0 * x[i];
  }
  printf("%.6f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 100

int main(void)
{
    int i, j, k, tmp, N, A[SIZE];
    
    scanf("%d", &N);
    for ( i=0; i<N; ++i)
        scanf("%d", &A[i]);
    
    for ( i=0; i<N; ++i) {
        tmp = A[i];
        
        for ( j=0; j<i; ++j)
            if ( tmp < A[j])
                break;
        /* j 番に挿入 */
        for ( k=i; k>j; --k)
            A[k] = A[k-1];
        A[j] = tmp;
        
        /* 書き出し */
        for ( j=0; j<N; ++j) {
            printf("%d", A[j]);
            if ( j == N-1)
                putchar('\n');
            else
                putchar(' ');
        }
    }
    return 0;
}


Measured memory_bytes: 2096
from heapq import heappop, heappush
N, M = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))

AB.sort()
pq = []
j = 0
ans = 0
for i in range(1,M+1):
    while j < N:
        a, b = AB[j]
        if a > i:
            break
        heappush(pq, -b)
        j += 1
    if len(pq) == 0:
        continue
    b = heappop(pq)
    b = -b
    ans += b

print(ans)


Measured memory_bytes: 70872
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int INF     = 0x3F3F3F3F;
int main()
{
    int n,k;
   cin>>n>>k;
   vector<int>v(n);
   for(int i=0;i<n;i++) cin>>v[i];
   vector<int> dp(n+1,0);
   dp[0]=0;
   dp[1]=0;
   for(int i=2;i<=n;i++)
   {
       dp[i]=INT_MAX;
       for(int j=i;j>=i-k&&j>0;j--)
       {
           dp[i]=min(abs(v[i-1]-v[j-1])+dp[j],dp[i]);
       }






   }

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

}


Measured memory_bytes: 3900
N, K = map(int, input().split())
p = list(map(int, input().split()))

E = [0] * (N + 1)
for i in range(0, N):
   E[i + 1] = (p[i] + 1) / 2

ans = 0
for i in range(1, K + 1):
    ans += E[i]

cur = ans
for i in range(1, N - K + 1):
    cur = cur - E[i] + E[i + K]
    if cur > ans:
        ans = cur
print(ans)

Measured memory_bytes: 25060
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


fn bfs(n: usize, root: usize, to: &Vec<Vec<(usize, i64)>>) -> Vec<i64> {
  // n is number of node
  // root is start node
  // res is legth of root
  let mut res = vec![-1; n];

  let mut q: Vec<usize> = Vec::new();
  q.push(root);
  res[root] = 0;

  while !q.is_empty() {
    let a: usize = match q.pop() {
      Some(i) => i,
      None => 1,
    };
    for &(i, w) in &to[a] {
      if res[i] != -1 {
        continue;
      }
      else {
        res[i] = (res[a] + w) % 2;
        q.push(i);
      }
    }
  }
  return res;
}


fn main() {
    let n: usize = read();
    let mut to: Vec<Vec<(usize, i64)>> = vec![Vec::new(); n];
    for _ in 0..n-1 {
      let a: Vec<usize> = read_vec();
      to[a[0] - 1].push((a[1] - 1, a[2] as i64));
      to[a[1] - 1].push((a[0] - 1, a[2] as i64));
    }
    let v: Vec<i64> = bfs(n, 0, &to);

    for e in v {
      println!("{}", e);
    }

}


Measured memory_bytes: 14716
#include <bits/stdc++.h>
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;


int32_t main(){IOS;
	int n , w ; cin >> n >> w ; 
	int dp[w+1];
	fill(dp,dp+w+1,0ll);
	int wieght , value ;
	for(int i=0;i<n;i++){
		cin >>  wieght >> value ;
		for(int j = w - wieght ; j >= 0 ; j-- ){
			dp[j + wieght] = max(dp[j+wieght],dp[j]+value);
		}
	}
	cout << dp[w] << endl; 
	return 0;
}


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int a, b; string s;
  cin >> a >> b >> s;

  bool c = false;
  for (int i = 0; i < a + b + 1; ++i) {
    if (i == a && s[i] == '-') {
      c = true;
      continue;
    } else if ('0' <= s[i] && s[i] <= '9') {
      continue;
    } else {
      pn();
      return 0;
    }
  }

  if (!c) {
    pn();
  } else {
    py();
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     ll              long long
#define     MAX             100000
#define     FI              freopen("input.txt","r",stdin)
#define     FO              freopen("output.txt","w",stdout)
#define     fast            ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define     sc(a)           scanf("%d",&a)
#define     sc2(a,b)        scanf("%d %d",&a,&b)


int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int cnt = 1;
    while(a>0 && c>0)
    {
        if(cnt&1)
            c-=b;
        else
            a-=d;
            cnt++;
    }
    if(c>0)
        cout<<"No\n";
        else
            cout<<"Yes\n";
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	if(N>=64) cout<<64;
  else if(N>=32) cout<<32;
  else if(N>=16) cout<<16;
  else if(N>=8) cout<<8;
  else if(N>=4) cout<<4;
  else if(N>=2) cout<<2;
  else cout<<1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int arr[m];
	for(int i=0;i<m;i++){
		cin>>arr[i];
	}
	int sum=0;
	for(int i=0;i<m;i++){
		sum+=arr[i];
	}
	int ans=n-sum;
	if(ans<0){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#define ll long long
#define llu unsigned long long
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define ina for(ll i=0;i<n;i++)cin>>a[i];
#define all(v) v.begin(),v.end()
#define YES printf("YES\n")
#define NO printf("NO\n")
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//long long bigmod/* (a^p)%m */ ( long long a, long long p, long long m ){long long res = 1;long long x = a;while ( p ){if ( p & 1 ){res = ( res * x ) % m;}x = ( x * x ) % m;p = p >> 1;}return res;}
//ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; }
//call manipulated_seive(N) and get prime in prime vector
//const long long MAX_SIZE = 1000001; vector<long long >isprime(MAX_SIZE , true); vector<long long >prime; vector<long long >SPF(MAX_SIZE); void manipulated_seive(int N) { isprime[0] = isprime[1] = false ; for (long long int i=2; i<N ; i++) { if (isprime[i]) { prime.push_back(i); SPF[i] = i; } for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) { isprime[i*prime[j]]=false; SPF[i*prime[j]] = prime[j] ; } } }
//ll phi[5000001];bool mark[5000001];void sievephi(ll n){ll i,j;for(ll i=1;i<=n;i++) phi[i]=i;mark[1]=true;for(ll i=2;i<=n;i++)if(!mark[i]){for(ll j=i;j<=n;j+=i){mark[j]=true;phi[j]=phi[j]/i*(i-1);}}}

/*speedup
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
// vule geli coilbi na dada cout << fixed << setprecision(6) << pi <<" "<<npi<<endl;
//Pattern? OEIS
// prime factorize?? think about 2



vector<ll>v[200005];

int vis[200005];

int k=0;

void dfs(int s)
{
    k++;
    vis[s]=1;
    for(auto c:v[s])
    {
        if(vis[c]==0)
        {
            dfs(c);
        }
    }
}


int main()
{
    fastio;

       int n,m; cin>>n>>m;

            for(int i=0;i<m;i++)
            {
               int a,b; cin>>a>>b;
               v[a].pb(b);
               v[b].pb(a);
            }
            int ans=1;
            for(int i=1;i<=n;i++)
            {
                if(vis[i]==0)
                {
                    k=0;
                    dfs(i);
                    ans=max(ans,k);

                }

            }
            cout<<ans<<endl;

    return 0;
}






Measured memory_bytes: 21044
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

void print_state(std::vector<std::string>& A, int N) {
    for (int i=0; i<N-1; i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A[N-1] << std::endl;
};

void swap(std::string * a, std::string * b) {
    auto tmp = *b;
    *b = *a;
    *a = tmp;
};

int val(std::string s) {
    return s[1] - '0';
}

int main() {
    int N, minj;
    std::vector<std::string> B, S;
    std::cin >> N;
    for (int i=0; i<N; i++) {
        std::string a;
        std::cin >> a;
        B.push_back(a);
    }
    S = B;

    // bubble sort
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (val(B[j]) < val(B[j-1])) {
                swap(&B[j], &B[j-1]);
            }
        } 
    }

    // selective sort
    for (int i=0; i < N; i++) {
        minj = i;
        for (int j = i; j < N; j++) {
            if (val(S[j]) < val(S[minj])) {
                minj = j;
            }
        }
        swap(&S[i], &S[minj]);
    }

    print_state(B,N);
    std::cout << "Stable" << std::endl;
    print_state(S,N);
    if (B == S) {
        std::cout << "Stable" << std::endl;
    } else {
        std::cout << "Not stable" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3216
import java.awt.geom.Point2D;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Map.*;



class Main {
	static long MOD = 1000000007;
	public static void main(String[] args) {	
		FastScanner sc = new FastScanner();
		//Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int sum = 0;
		for(int i = 1; i <= N; i++) {
			sum += i;
		}
		out.println(sum);
		
		
		
		
		
		
		out.flush();
		
		
	}


	
	static 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;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); 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() {
	        if (!hasNext()) throw new NoSuchElementException();
	        int 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();
	        }
	    }
	}
}


Measured memory_bytes: 8016
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		Node[] T = new Node[n];
		for (int i=0; i < n; i++) {
			T[i] = new Node(i);
		}

//		Node dammy = new Node(-1);

		for (int i=0; i < n; i++) {
			String[] info = br.readLine().split(" ");
			int id = Integer.parseInt(info[0]);
			int left = Integer.parseInt(info[1]);
			int right = Integer.parseInt(info[2]);

			if (left == -1) {
				if (right == -1) {
					T[id].degree = 0;
//					T[id].childs = new Node[] {dammy};
				} else {
					T[id].degree = 1;
					T[id].childs = new Node[] {T[right]}; //{null, T[right]};

					T[right].parent = T[id];
				}
			} else {
				if (right == -1) {
					T[id].degree = 1;
					T[id].childs = new Node[] {T[left]}; //{T[left], null};

					T[left].parent = T[id];
				} else {
					T[id].degree = 2;
					T[id].childs = new Node[] {T[left], T[right]};

					T[right].parent = T[id];
					T[left].parent = T[id];

					T[left].sibling = T[right];
					T[right].sibling = T[left];
				}
			}
		}

		for (int i=0; i < n; i++) {
			if (T[i].parent == null) {setdepth(T[i]);}
			if (T[i].degree == 0) {setheight(T[i]);}
		}

		for (Node u : T) {
			System.out.println(u);
		}

	}

	public static class Node {
		int id;
		Node parent;
		Node sibling;
		Node[] childs;
		int degree;
		int depth;
		int height;

		public Node(int id) {
			this.id = id;
//			childs = new Node[2];
		}

		@Override
		public String toString() {
			StringBuilder sb = new StringBuilder();

			sb.append("node " + id);

			if (parent == null) sb.append(": parent = -1");
			else sb.append(": parent = " + parent.id);

			if (sibling == null) sb.append(", sibling = -1");
			else sb.append(", sibling = " + sibling.id);

			sb.append(", degree = " + degree);

			sb.append(", depth = " + depth);

			sb.append(", height = " + height);

			if (parent == null) sb.append(", root");
			else if (degree != 0) sb.append(", internal node");
			else sb.append(", leaf");

			return sb.toString();
		}
	}

	public static void setdepth(Node x) {
		if (x.degree == 0) return;
		for (Node c : x.childs) {
			c.depth = x.depth + 1;
		}
		for (Node c : x.childs) {
			setdepth(c);
		}
	}

	public static void setheight(Node x) {
		if (x.parent == null) return;
		if (x.height+1 <= x.parent.height) return;
		x.parent.height = x.height + 1;
		setheight(x.parent);
	}
}

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

const int N = 1e5 + 5;

int n, a[N];
LL ans;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	for(int i = 1; i <= n; ++i) {
		ans += min(a[i], a[i - 1]);
		a[i] -= min(a[i], a[i - 1]);
		ans += a[i] / 2;
		a[i] %= 2;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 640
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        r: i64,
    }
    let r = r as f64;
    println!("{}", r * 2. * std::f64::consts::PI);
}


Measured memory_bytes: 2172
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <map>
#include <ctime>
#include <set>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 100001
#define MACRO(a) for(int a = 1; a < 1001; a++)

using namespace std;
string s, t;

bool check(int start)
{
	for (int i = 0; i < s.size(); i++)
	{
		if (s[start] != t[i])
			return false;
		start += 1;
		start %= s.size();
	}
	return true;
}

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false); cin >> s >> t;

	for (int i = 0; i < s.size(); i++)
	{
		if (check(i))
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
from numpy import*
M=10**9+7
m=lambda:map(int,input().split())
n,k=m()
a=matrix([list(m())for i in[0]*n],'O')
b=eye(n,n,0,'O')
while k:b=[b,b*a%M][k&1];a=a*a%M;k>>=1
print(b.sum()%M)

Measured memory_bytes: 12508
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace codeTester.contest190727
{
    class ProblemB
    {
        static int n = 0;
        static List<long> ps = new List<long>();
        static string answer = "";

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            n = int.Parse(Console.ReadLine());
            ps = ReadSpaceSeparatedValues();
        }

        public static List<long> ReadSpaceSeparatedValues()
        {
            List<long> values = new List<long>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(long.Parse(input));
            }

            return values;
        }

        static void Logic()
        {
            int wrongs = 0;
            for (int i = 0; i < n; i++)
            {
                if (ps[i] != i + 1)
                {
                    wrongs++;
                    if (wrongs > 2)
                    {
                        answer = "NO";
                        return;
                    }
                }
            }
            answer = "YES";
        }

        static void Output()
        {
            Console.WriteLine(answer);
        }

        static void DebugPrint(string msg)
        {
            // 提出時に消す
            // Console.WriteLine(msg);
        }
    }
}


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

const int MAX_N = 110000;

int dp[MAX_N]; // dp[i] が i についての答え

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

	// 初期化
	for (int i = 0; i < MAX_N; ++i) dp[i] = -1;
	dp[0] = 0;
	queue<int> que;
	que.push(0);

	// BFS
	while (!que.empty()) {
		int v = que.front();
		que.pop();

		for (int pow6 = 1; v + pow6 <= N; pow6 *= 6) {
			if (dp[v + pow6] == -1) {
				dp[v + pow6] = dp[v] + 1;
				que.push(v + pow6);
			}
		}
		for (int pow9 = 1; v + pow9 <= N; pow9 *= 9) {
			if (dp[v + pow9] == -1) {
				dp[v + pow9] = dp[v] + 1;
				que.push(v + pow9);
			}
		}
	}

	cout << dp[N] << endl;
}

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

const int N = 8;
char mark[2] = {'o', 'x'};

bool inrange(int x, int y) {
    return 0 <= x && x < N && 0 <= y && y < N;
}

int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
pii select(vector<string> &board, int turn) {
    char opp = mark[turn ^ 1];

    pii ret = {-1, -1};
    int mx = 0;
    rep(y, 0, N) {
        rep(x, 0, N) {
            int i = 0, j = 0;
            if (turn) {
                i = N - 1 - y;
                j = N - 1 - x;
            } else {
                i = y;
                j = x;
            }
            if (board[i][j] != '.') continue;

            int sum = 0;
            rep(dir, 0, 8) {
                pii tmp = {-1, -1};
                int cnt = 0;
                rep(k, 1, 9) {
                    int ii = i + dy[dir] * k;
                    int jj = j + dx[dir] * k;
                    if (!inrange(jj, ii)) break;
                    if (board[ii][jj] == opp) {
                        cnt++;
                        continue;
                    }
                    if(board[ii][jj]=='.'){
                        break;
                    }
                    tmp = {ii, jj};
                    break;
                }
                if (tmp.first != -1) {
                    sum += cnt;
                }
            }

            if (sum != 0) {
                // cerr<<"sum: "<<sum<<", "<<"j: "<<j<<", i:"<<i<<endl;
                if (mx < sum) {
                    mx = sum;
                    ret = {i, j};
                }
            }
        }
    }
    return ret;
}

void update(vector<string> &board, int turn, pii pos) {
    char opp = mark[turn ^ 1];
    int y, x;
    tie(y, x) = pos;
    rep(dir, 0, 8) {
        int cnt = 0;
        rep(k, 1, 9) {
            int yy = y + dy[dir] * k;
            int xx = x + dx[dir] * k;
            if (!inrange(xx, yy)) break;
            if (board[yy][xx] == opp) {
                continue;
            }
            if(board[yy][xx]=='.'){
                break;
            }
            cnt = k;
            break;
        }
        rep(k, 0, cnt) {
            int yy = y + dy[dir] * k;
            int xx = x + dx[dir] * k;
            board[yy][xx] = mark[turn];
        }
    }
}

signed main() {
    vector<string> board(N);
    rep(i, 0, N) cin >> board[i];

    int turn = 0;
    bool skipped = false;
    // int loop=3;
    while (1) {
        pii pos = select(board, turn);
        // cerr << pos.first << ", " << pos.second << endl;
        if (pos.first == -1) {
            if (skipped) {
                break;
            }
            skipped = true;
            turn ^= 1;
            continue;
        }
        skipped = false;

        // 更新
        update(board, turn, pos);
        turn ^= 1;

        // rep(i, 0, N) {
        //     cerr << board[i] << endl;
        // }
        // cerr << endl;
    }

    rep(i, 0, N) {
        cout << board[i] << endl;
    }
}


Measured memory_bytes: 3196
/**    epsileer 18 August 2019  17:38:07  **/    
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> PII;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define TEST int t = 1; while(t--) solve()

void solve(){
    int n; cin>>n;
    vector<LD> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(), a.end());
    LD ans = a[0];
    for(int i=1;i<n;i++){
        ans = (ans + a[i])/2.0;
    }
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000


int main(){

	string s,t;
	cin>>s>>t;
	
	vector<vector<int>> ind(26,vector<int>(0));
	
	for(int i=0;i<s.size();i++){
		ind[s[i]-'a'].push_back(i);
	}
	
	long long now = 0;
	long long ans = 0;
	for(int i=0;i<t.size();i++){
		int c = (int)t[i]-'a';
		if(ind[c].size()==0){
			cout<<-1<<endl;
			return 0;
		}
		A:
		auto it = lower_bound(ind[c].begin(),ind[c].end(),now);
		if(it==ind[c].end()){
			ans++;
			now=0;
			goto A;
		}
		now = (*it)+1;
		
		
	}
	
	cout<<(long long)ans*s.size()+(long long)now<<endl;
	
	return 0;
}


Measured memory_bytes: 1216
#include <stdio.h>

int main()
{
  int x, y;

  while (1) {
    scanf("%d%d", &x, &y);

    if (x == 0 && y == 0) {
      return 0;
    }

    if (x < y) {
      printf("%d %d\n", x, y);
    } else {
      printf("%d %d\n", y, x);
    }
  }
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-
import math

# スペース区切りの整数の入力
n,d = map(int, input().split())
list_x = [[0 for i in range(d)] for j in range(n)]

ans = 0
tmp_targ = 0

for k in range(n):
    list_x[k] = list(map(int, input().split()))

# print(list_x)

for l in range(n-1):
    for m in range(l+1,n):
        tmp_targ = 0
        for i1 in range(d):
            tmp_targ += (list_x[l][i1] - list_x[m][i1]) ** 2
        # print("targ:{},sqrt:{}".format(tmp_targ,math.sqrt(tmp_targ)))
        if isinstance(math.sqrt(tmp_targ), int) or math.sqrt(tmp_targ).is_integer():
            ans += 1
# 出力
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;

	vector<lint> height(N);
	vector<int> pos_x(N);
	vector<int> pos_y(N);
	int set;
	bool flag;

	for (int i = 0; i < N; i++)
	{
		cin >> pos_x[i] >> pos_y[i] >> height[i];
		if (0 < height[i])
			set = i;
	}

	for (int i = 0; i <= 100; i++)
	{
		for (int j = 0; j <= 100; j++)
		{
			lint pivot = height[set] + abs(pos_x[set] - i) + abs(pos_y[set] - j);

			flag = true;
			for (int k = 0; k < N; k++)
			{
				if (height[k] != max(pivot - abs(pos_x[k] - i) - abs(pos_y[k] - j), (lint)0))
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				cout << i << " " << j << " " << pivot << endl;
				return;
			}
		}
	}
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int main(){ //11-b-Harshad_Namber
  std::string a;
  cin>>a;
  int v=std::stoi(a);
  int f=v;
  int s=1;
  int sum=0;
  for(int i=1;i<a.size();i++){
    s=s*10;
  }
  for(int i=0;i<a.size();i++){
    sum+=v/s;
    v-=v/s*s;
    s=s/10;
  }
  if(f%sum==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define ll long long
    #define INF 1e9 + 7
    #define fast_io ios_base::sync_with_stdio(false)
    #define cine cin.tie(NULL)
    #define in(x) cin>>x
    #define op(x) cout<<x<<"\n"
    #define pb(x) push_back(x);
    using namespace std;
    int main()
    {
       //fast_io;
       //cine;
       //code
       ll n;
       cin>>n;
       ll a[n][3],b[n][3];
       for(ll i=0;i<n;i++)
       {
         for(ll j=0;j<3;j++)
          {
            cin>>a[i][j];
           }
        }
        b[n-1][0]=a[n-1][0];
        b[n-1][1]=a[n-1][1];
        b[n-1][2]=a[n-1][2];

        for(ll i=n-2;i>=0;i--)
        {
          for(ll j=0;j<3;j++)
           {
                b[i][j]=a[i][j]+max(b[i+1][(j+1)%3],b[i+1][(j+2)%3]);
            }
         }
        /* for(ll i=0;i<3;i++)
         {
           for(ll j=0;j<3;j++)
            {
                 cout<<b[i][j]<<" ";
             }
             cout<<"\n";
         }*/
         cout<<max(max(b[0][0],b[0][1]),b[0][2]);
     }


Measured memory_bytes: 4864