akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

long test () {
  int n;
  readf (" %d", &n);
  if (n == 1) return 0;
  auto a = new int[n];
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
  }
  //y = x
  //1 * x - y = 0
  auto d = new Tuple!(int,int)[n];
  foreach (i; 0 .. n) {
    d[i] = tuple ((i + 1) - a[i], i);
  }
  long res = long.max;
  
  long f (int i) {
    topN (d, i);
    immutable w = d[i][0];// + (d[i][1] + 1);
    long r;
    foreach (k; 0 .. n) {
      r += abs ( (k + 1) - a[k] - w); 
    }
    return r;
  }
  if (n & 1) {
    return f (n >> 1);
  } else {
    immutable m = n >> 1;
    return min (f (m - 1), f (m));
  }
}

void main() {
  writeln (test ());
}


Measured memory_bytes: 3580
import sys,math,copy,queue,itertools
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
N,M = LI()
ans = N * (N-1) //2 + M * (M-1) // 2
print (ans)


Measured memory_bytes: 40556
import numpy as np

mod = 998244353
N = int(input())
a = np.array([int(input()) for i in range(N)])
sum_a = np.sum(a)
dp = np.zeros((N+1, sum_a+1))
dp[0,0] = 1

for i in range(1, N+1):
    a_i = a[i-1]
    dp[i,a_i:] += dp[i-1,:-a_i]
    dp[i,:] += dp[i-1,:] * 2
    dp[i,:] %= mod

exc = np.sum(dp[N, (sum_a+1)//2:]) % mod
res = 3**N % mod - exc * 3

if sum_a % 2 == 0:
    dp = np.zeros((N+1, sum_a+1))
    dp[0,0] = 1
    for i in range(1, N+1):
        a_i = a[i-1]
        dp[i,a_i:] += dp[i-1,:-a_i]
        dp[i,:] += dp[i-1,:]
        dp[i,:] %= mod
    res += dp[N, sum_a//2] * 3

print(int(res % mod))

Measured memory_bytes: 224024
#include<iostream>
#include<algorithm>
using namespace std;
int a[233];
int main()
{
	int i,n,k,s=0;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(i=n;i>n-k;i--)
	{
		s+=a[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main(int argc, char *argv[]) {
  int a,b,k,i;
  cin>>a>>b>>k;
  vector<int> x;
  for(i=1;i<=a;i++)
    if(a%i==0 && b%i==0)
      x.push_back(i);
  sort(x.begin(),x.end(),greater<int>());
  cout<<x[k-1]<<endl;
}


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


int main(){
  
  string S,T,Z;
  cin >> S;
  cin >> T;
  
  int lengthS, lengthT;
  lengthS = S.size();
  lengthT = T.size();
  
  Z = T.substr(0,lengthT-1);
  
  if(S == Z){
    cout << "Yes";
  }else{
    cout << "No";
  }
             
}

Measured memory_bytes: 3600
import sys
import numpy as np
import collections as cl
import itertools as it
# import more_itertools as mit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(100000)

n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))
cnt = 0
for i, j in  it.combinations(x, 2):
    di = 0
    for k in range(d):
        di += (i[k]-j[k])**2
    di = di**(1/2)
    if di.is_integer():
        cnt += 1
print(cnt)

Measured memory_bytes: 27060
a,b,c,d = map(int,input().split())
import math
g = c*d//math.gcd(c,d)

num1=b//c
num2=b//d
num3=b//g
num4=(a-1)//c
num5=(a-1)//d
num6=(a-1)//g


print(b-a+1-(num1+num2-num3-num4-num5+num6))


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

typedef long long LL;
const int N = 604;
const double INF = 1e100;
vector<int> out[N];
double dp[N];

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


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

    for (int i=1; i<=m; i++) {
        int u, v;
        cin>>u>>v;
        out[u].push_back(v);
    }

    dp[n] = 0;
    double ans = INF;
    for (int i=n-1; i>0; i--) {
        double sum = 0;
        int id = 0;

        for (int x: out[i]) {
            if (dp[x] > dp[id])
                id = x;
            sum += dp[x];
        }
        int k = out[i].size();

        dp[i] = k > 1 ? 1 + (sum-dp[id])/(k-1) : INF;

        for (int j=i-1; j>0; j--) {
            double sum = 0;
            int k = out[j].size();
            for (int x: out[j])
                sum += dp[x];
            dp[j] = 1 + sum/k;
        }
        ans = min(ans, dp[1]);
        dp[i] = 1 + sum/k;
    }
    ans = min(ans, dp[1]);
    cout<<setprecision(10)<<fixed<<ans<<endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
    int x=0,y=0,temp;
    while(x>=0&&y>=0)
    {
        scanf("%d %d",&x,&y);
        if(x>y)
        {
            temp = x;
            x = y;
            y = temp;
            printf("%d %d\n",x,y);
        }
        else if(x==0&&y==0)
        {
            return 0;
        }
        else
        {
            printf("%d %d\n",x,y);
        }

    }
    return 0;
}



Measured memory_bytes: 1972
N = int(input())
*H,=map(int, input().split())

dp = [0]*N

for i in range(1, N, 1):
    if i==1:
        dp[i] = abs(H[i-1]-H[i])
        continue
    cost1 = dp[i-1]+abs(H[i-1]-H[i])
    cost2 = dp[i-2]+abs(H[i-2]-H[i])
    dp[i] = min(cost1, cost2)

   
print(dp[N-1])

Measured memory_bytes: 13928
n,c=map(int, input().split())
a=[[0,0]]+[list(map(int, input().split())) for i in range(n)]+[[c,0]]
m=[0]
h=[0]
mb=[0]
hb=[0]
for i in range(n+1):
    m.append(m[-1]-a[i+1][0]+a[i][0]+a[i+1][1])
    mb.append(m[-2]-a[i+1][0]+a[i][0]+a[i+1][1]-a[i+1][0])
    h.append(h[-1]-a[-i-1][0]+a[-i-2][0]+a[-i-2][1])
    hb.append(h[-2]-a[-i-1][0]+a[-i-2][0]+a[-i-2][1]-c+a[-i-2][0])

mm=[0]
for i in range(n):
    mm.append(max(mm[-1],m[i+1]))
hm=[0]
for i in range(n):
    hm.append(max(hm[-1],h[i+1]))
    
ans=max(hm[-1],mm[-1])
for i in range(1,n):
    ans=max(hb[i]+mm[-i-1], mb[i]+hm[-i-1],ans)
print(ans)

Measured memory_bytes: 48808
#include <iostream>
#include<string>
#include <math.h>
using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	
	int n, ans;

	cin >> n;

	cout << ((n%2==0) ? (n/2)-1:floor(n/2)) << endl;
	return 0;
}

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

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

int main(){
    ll n,q; cin >> n;
    vector<ll> a(100100);
    rep(i,n){
        int x; cin >> x;
        a[x]++;
    }
    cin >> q;
    ll sum=0;
    rep(i,100100){
        sum+=a[i]*i;
    }
    vector<int> B(q),C(q);
    rep(i,q) cin >> B[i] >> C[i];
    rep(i,q){
        int b=B[i],c=C[i];
        sum+=c*a[b]-b*a[b];
        a[c]+=a[b];
        a[b]=0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<ll>a;
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	ll ans=0;
	for(ll i=0;i<n-2;i++){
		for(ll j=i+1;j<n-1;j++){
			for(ll k=j+1;k<n;k++){
				ll A=a[i];
				ll B=a[j];
				ll C=a[k];
				if(C<A+B&&A<B+C&&B<A+C){
					ans++;
				}
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

struct status {
	int nx;
	int ny;
	int way;
	
};
bool operator<(const status&b, const status&a) {
	return b.nx * 100 + b.ny * 10000 + b.way < a.nx * 100 + a.ny * 10000 + a.way;
}

const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
int main() {
	int N, X0, Y0, T; cin >> N >> X0 >> Y0 >> T;
	vector<vector<vector<int>>>lines(60, vector < vector<int>>(60, vector<int>(4)));
	for (int i = 0; i < N; ++i) {
		int xs, ys, xe, ye; cin >> xs >> ys >> xe >> ye;
		if (xs > xe)swap(xs, xe);
		if (ys > ye)swap(ys, ye);
		if (xs == xe) {
			for (int y = ys; y < ye; ++y) {
				lines[y][xs][1] = true;
				lines[y + 1][xs][3] = true;
			}
		}
		else {
			for (int x = xs; x < xe; ++x) {
				lines[ys][x][2] = true;
				lines[ys][x + 1][0] = true;
			}
		}
	}
	vector<int>tways(1001,-1);
	map<char, int>mp;
	mp[N] = 3;
	mp['W'] = 0;
	mp['S'] = 3;
	mp['E'] = 2;
	mp['N'] = 1;
	int nt = 0;
	for (int i = 0; i < T; ++i) {
		int a;char b; cin >> a >> b;
		nt += a;
		tways[nt-1] = mp[b];
	}
	set<status>aset;
	for (int way = 0; way < 4; ++way) {
		if (lines[Y0][X0][way]) {
			aset.emplace(status{ X0,Y0,way });
		}
	}
	for (int t = 0; t < nt; ++t) {
		set<status>newset;
		for (auto sta : aset) {
			const int nowx = sta.nx;
			const int nowy = sta.ny;
			const int nowway = sta.way;
			const int nexx = nowx + dx[nowway];
			const int nexy = nowy + dy[nowway];
			for (int way = 0; way < 4; ++way) {
				if (tways[t] != -1) {
					if (nowway != tways[t] && way != tways[t])continue;
				}
				if ((nowway + 4 - way) % 4 == 2)continue;
				else if (lines[nexy][nexx][way]) {
					newset.emplace(status{ nexx,nexy,way });
				}
			}
		}
		aset = newset;
	}
	set<pair<int, int>>ansset;
	for (auto sta : aset) {
		ansset.emplace(sta.nx, sta.ny);
	}
	for (auto sta : ansset) {
		cout << sta.first << " " << sta.second << endl;
	}
	return 0;
}

Measured memory_bytes: 3512
(let ((n (read))
      (maxz 1)
      (minz 2000000001)
      (maxw -1000000000)
      (minw 1000000000))
  (loop :for i :from 1 :to n
        :for x := (read)
        :for y := (read)
        :for z := (+ x y)
        :for w := (- x y)
        :do (setf maxz (max maxz z))
        :do (setf minz (min minz z))
        :do (setf maxw (max maxw w))
        :do (setf minw (min minw w)))
  (format t "~A~%" (max (- maxz minz) (- maxw minw))))


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

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

    int n = s.length();
    int count = 0;
    rep(i, n){
        if(s.at(i)!=t.at(i)){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3916
#include <stdio.h>
#include<string.h>
int main(void){
int a[150]={};
while(1){
    int x;
    x=getchar();
    
    if(x==-1)
    break;
    
    a[x]++;
}
for(int i=97;i<=122;i++){
    printf("%c : %d\n",i,a[i]+a[i-32]);
}


    return 0;
}

Measured memory_bytes: 2604
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		List<Long> l1 = insu(a);
		List<Long> l2 = insu(b);
		HashSet<Long> h = new HashSet<Long>(l1);
		l1.clear();
		l1.addAll(h);
		h = new HashSet<Long>(l2);
		l2.clear();
		l2.addAll(h);
		int ans = 0;
		for(long i: l1){
			if(l2.contains(i)) {
				ans++;
			}
		}
		System.out.println(ans+1);
	}

	public static List<Long> insu(long n){
		List<Long> list = new ArrayList<>();
		if(n==1) return list;
		for(int i=2; i<=Math.sqrt(n); i++){
			if(n%i == 0){
				list.add((long)i);
				n = n/i;
				i = 1;
			}
		}
		list.add(n);
		return list;
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int maze[10][10];
void MakeMaze(int n){
  memset(maze,0,sizeof(maze));
  maze[0][0] = 1;
  bool ret = false;
  int x = 1 ;
  int y = -1;
  int line = 1;
  int cnt = 1;
  for(int i = 0 ; i < 2 * (n - 1) ; i ++){
    if(i % 2){
      //odd
      if(i < n - 1){
	//right low
	x = 0;
	//cout<<"rl"<<x<<"\t"<<y<<endl;
      }else{
	//right mid
	x += 2;
	y --;
	//cout<<"rm"<<x<<"\t"<<y<<endl;
      }
      while(((0 <= x && x < n ) && (0 <= y && y < n ))){
	//cout<<"odd\t"<<i<<"\t"<<x<<"\t"<<y<<endl;
	maze[x][y] = ++cnt;
	x++;y--;
      } 
    }else{
      //even
      if(i < n - 1){
	//top low
	y = 0;
	//cout<<"tl"<<x<<"\t"<<y<<endl;
      }else{
	//top mid

	y +=2;
	x --;
	//cout<<"tm"<<x<<"\t"<<y<<endl;
      }
      while(((0 <= x && x < n ) && (0 <= y && y < n ))){
	//cout<<"even\t"<<n<<" "<<i<<"\t"<<x<<"\t"<<y<<endl;
	maze[x][y] = ++cnt;
	x--;y++;
      }
    }
  }
  
}

int main(void){
  int n,cnt = 0;
  while(cin>>n,n){
    
    cout<<"Case "<<++cnt<<":"<<endl;
    MakeMaze(n);
    rep(i,n){
      rep(j,n){
	printf("%3d",maze[j][i]);
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 1204
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    i64 a, b, c;
    char _;
    std::cin >> a >> b >> _ >> c;
    std::cout << (a * (b * 100 + c)) / 100 << '\n';
}


Measured memory_bytes: 3652
from collections import deque


def reachable(field, h2, w2, k):
    # 各マスから上下左右にどこまで行けるか
    hw = h2 * w2
    up, dw, lf, rg = [-1] * hw, [-1] * hw, [-1] * hw, [-1] * hw
    lf_tmp = -1
    for i in range(w2, hw - w2):
        if field[i] == '.':
            if lf_tmp == -1:
                lf_tmp = i
            lf[i] = max(lf_tmp, i - k)
        else:
            lf_tmp = -1
    rg_tmp = -1
    for i in range(hw - w2, w2 - 1, -1):
        if field[i] == '.':
            if rg_tmp == -1:
                rg_tmp = i
            rg[i] = min(rg_tmp, i + k)
        else:
            rg_tmp = -1
    wk = w2 * k
    for j in range(1, w2):
        up_tmp = -1
        for i in range(j, hw, w2):
            if field[i] == '.':
                if up_tmp == -1:
                    up_tmp = i
                up[i] = max(up_tmp, i - wk)
            else:
                up_tmp = -1
        dw_tmp = 0
        for i in range(hw - w2 + j, w2 - 1, -w2):
            if field[i] == '.':
                if dw_tmp == -1:
                    dw_tmp = i
                dw[i] = min(dw_tmp, i + wk)
            else:
                dw_tmp = -1
    return up, dw, lf, rg


def solve(h2, w2, k, field, x1, y1, x2, y2):
    s = x1 * w2 + y1
    t = x2 * w2 + y2
    up, dw, lf, rg = reachable(field, h2, w2, k)
    # print(up)
    # print(dw)
    # print(lf)
    # print(rg)

    INF = 10 ** 18
    ans = [[INF, INF] for _ in field]
    ans[s][0] = ans[s][1] = 0

    q = deque([(0, s)])
    while q:
        cost, v = q.popleft()
        if v == t:
            return cost
        nc = cost + 1

        for u in range(up[v], v, w2):
            if ans[u][0] <= nc:
                break
            ans[u][0] = nc
            q.append((nc, u))

        for u in range(dw[v], v, -w2):
            if ans[u][0] <= nc:
                break
            ans[u][0] = nc
            q.append((nc, u))

        for u in range(lf[v], v, 1):
            if ans[u][1] <= nc:
                break
            ans[u][1] = nc
            q.append((nc, u))

        for u in range(rg[v], v, -1):
            if ans[u][1] <= nc:
                break
            ans[u][1] = nc
            q.append((nc, u))

        # print(cost, divmod(v, w2), q)
        # print([divmod(lim[v], w2) for lim in (up, dw, lf, rg)])

    return -1


h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
h2 = h + 2
w2 = w + 2

field_tmp = [input() for _ in range(h)]
field = ['@' * w2]
for row in field_tmp:
    field.append('@' + row + '@')
field.append('@' * w2)
field = ''.join(field)
print(solve(h2, w2, k, field, x1, y1, x2, y2))


Measured memory_bytes: 508876
#include <stdio.h>

int main()
{
        char str[51];
        int i, j;

        while ( scanf( "%s", str ) != EOF ) {
                i = 0;
                while ( str[i] != '\0' ) {
                        if ( str[i] == '@' ) {
                                j = 0;
                                while ( j < str[i+1]-'0' ) {
                                        printf( "%c", str[i+2] );
                                        j++;
                                }
                                i += 3;
                        } else {
                                printf( "%c", str[i] );
                                i++;
                        }
                }
                printf( "\n" );
        }
        return 0;
}



Measured memory_bytes: 2032
#include <stdio.h>

int main(void) {
	char ch[2], now = 'A';
	
	
	while(scanf("%c", &ch[0]) != EOF){
		scanf("%c", &ch[1]);
		scanf("%c", &ch[1]);
		
		if(ch[0] == now){
			now = ch[1];
		}
		else if(ch[1] == now){
			now = ch[0];
		}
		
		scanf("%c", &ch[1]);
	}
	
	printf("%c\n", now);
	return 0;
}

Measured memory_bytes: 968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  int sum = 0;
  rep(i,N){
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(),A.end());
  if(A.at(N - M)*4*M >= sum){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   int x,t;
   cin >> x >> t;
   cout << max(x-t,0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    int n; 
    string s;
    cin >> n >> s;
    if(n%2 != 0) cout << "No" << endl;
    else{
        if(s.substr(0,n/2) == s.substr(n/2, n/2)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    //cout << s.substr(0,n/2) << endl;
    //cout << s.substr(n/2, n/2) << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    cin >> N >> M;
    pair<int, int> ba[M];
    rep(i, 0, M)
    {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        ba[i] = make_pair(tmp2, tmp1);
    }
    sort(&ba[0], &ba[M]);
    int ans = 0;
    int i = 0;
    while (i < M)
    {
        int j = 1;
        while (ba[i].first > ba[i + j].second && i + j < M)
            ++j;
        ++ans;
        i += j;
    }
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vector<string> vs(n);
    rep(i,0,n)cin>>vs[i];
    unordered_map<string,int> mp;
    ll ans=0;
    rep(i,0,n){
        if(mp.count(vs[i])==0)ans++;
        mp[vs[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 23956
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int size=1e6+5;
vector <int> g[size];
int in[size];
int enc(int x,int y)
{
    return min(x,y)*1000+max(x,y);
}
int dec_u(int x)
{
    return x/1000;
}
int dec_v(int x)
{
    return x%1000;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        int from = enc(i,x);
        for(int j=0,v;j<n-2;j++)
        {
            cin>>v;
            int to = enc(i,v);
            g[from].push_back(to);
            in[to]++;
            from = to;
        }
    }
    int total=0,ans=0;
    queue <int> q;
    for(int i=0;i<size;i++)
        if(in[i]==0)
        q.push(i);
    while(!q.empty())
    {
        total += q.size();
        ans++;
        int p = q.size();
        for(int i=0;i<p;i++)
        {
            int t = q.front();
            q.pop();
            for(auto v:g[t])
            {
//                cout<<dec_u(v)<<" "<<dec_v(v)<<endl;
                in[v]--;
                if(in[v]==0)
                    q.push(v);
            }
        }
    }
    if(total!=size)
        cout<<"-1\n";
    else
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 45224
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  long long int in;
  while(cin>>in,in){
    string ans="";
    long long int t=1;
    int i=0;
    while(in!=0){
      i++;
      t*=10;
      if(i%2){
	int co=0;
	while((double)in/t!=in/t){co++;in-=t/10;}
	ans=(char)(co+'0')+ans;
      }else{
	int co=0;
	while((double)in/t!=in/t){co++;in+=t/10;}
	ans=(char)(co+'0')+ans;
      }
      //cout<<in<<endl;
    }
    cout<<ans<<endl;
  }


}

Measured memory_bytes: 1204
#include <stdio.h>

void swap(int *A1, int *A2) {
	int tmp;
	tmp = *A1;
	*A1 = *A2;
	*A2 = tmp;
}

int bubbleSort(int A[], int N) {
	int i, j;
	int sw = 0;
	int flag = 1;
	for ( i = 0; flag; i++ ) {
		flag = 0;
		for ( j = N - 1; j >= i + 1; j-- ) {
			if ( A[j] < A[j - 1] ) {
				swap(&A[j], &A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void) {
	int N;
	int A[100];
	int sw;
	int i;
	
	scanf("%d", &N);
	
	for ( i = 0; i < N; i++ ) {
		scanf("%d", &A[i]);
	}
	
	sw = bubbleSort(A, N);
	
	for ( i = 0; i < N; i++ ) {
		if (i) {
			printf(" ");
		}
		printf("%d", A[i]);
	}
	
	printf("\n");
	printf("%d\n", sw);
	

	return 0;
}

Measured memory_bytes: 604
N = int(input())

A = [0,0,0,0]

for i in range (0, N):
    S = str(input())
    if S == 'AC':
        A[0]+=1
    if S == 'WA':
        A[1]+=1
    if S == 'TLE':
        A[2]+=1
    if S == 'RE':
        A[3]+=1

print(str('AC x ')+str(A[0]))
print(str('WA x ')+str(A[1]))
print(str('TLE x ')+str(A[2]))
print(str('RE x ')+str(A[3]))

Measured memory_bytes: 9160
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;

int main(){
    int n,m; cin >> n >> m;
    vector<P> ab(m);
    rep(i,m){
        int a,b;cin >> a >> b;
        ab[i] = P(a,b);
    }
    sort(ab.begin(),ab.end());
    vector<P> minmax;
    int count = 0;
    minmax.pb(ab[0]);
    rep(i,m){
        int ta,tb;ta = ab[i].first;tb = ab[i].second;
        int ca = minmax[count].first,cb = minmax[count].second;
        if(ta > ca && ta < cb ) minmax[count].first = ta;
        if(tb < cb && tb > ca) minmax[count].second = tb;
        if(ta >= cb){
            count++;
            minmax.pb(P(ta,tb));
        }
    }
    int ans = minmax.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
# B
import numpy as np
N, K = map(int, input().split())
h = np.array(input().split(), dtype="int32")
dp = np.zeros(N, dtype="int32")
 
for i in range(1, N):
    if i < K:
        dp[i] = np.min(dp[:i] + np.abs(h[i]-h[:i]))
    else:
        dp[i] = np.min(dp[i-K:i] + np.abs(h[i]-h[i-K:i]))
print(dp[-1])

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

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

  vector<int> s(3);
  s[0] = ss/100;
  s[1] = (ss%100)/10;
  s[2] = ss%10;

  int count=0;
  for(int i=0;i<3;i++){
    if(s[i]) count++;
  }

  cout <<count <<endl;
}


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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef long double ld;
typedef vector <ll> vi;

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n, x;
int a[N];
bool u[N];

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> x;
    forn(i, 1, n)
        cin >> a[i];
    ll ans = 0;
    forn(i, 1, n) ans += a[i];

    forn(it, 1, n) {
        vi b(n + 1);
        forn(i, 1, n)
            b[i] = min(a[i], a[i == 1 ? n : i - 1]);
        forn(i, 1, n)
            a[i] = b[i];
        ll cur = 0;
        forn(i, 1, n) cur += a[i];
        ans = min(ans, cur + 1ll * x * it);
    }
    cout << ans << "\n";

    return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		




int main() {

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

	int a = 0;
	int b = 0;
	REP(i, n) {
		if (i % 2) {
			if (s[i] == '0')a++;
			else b++;
		}
		else {
			if (s[i] == '0')b++;
			else a++;
		}
	}

	cout << n-max(a, b) << endl;

	return 0;
}

Measured memory_bytes: 512
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
const int MAX_V = 201;
void DubiousDocument2() {
	string s,t;
	cin >> s >> t;
	vector<string> oklist;
	for (size_t i = 0; i < s.size() - t.size() + 1; i++)
	{
		bool ok = true;
		string tm = s;
		for (size_t j = 0; j < t.size(); j++)
		{
			if (tm[i + j] == t[j]) continue;
			if (tm[i + j] == '?') {
				tm[i + j] = t[j];
				continue;
			}
			ok = false;
			break;
		}
		if (!ok) continue;
		for (size_t j = 0; j < s.size(); j++)
		{
			if (tm[j] == '?') tm[j] = 'a';
		}
		oklist.push_back(tm);
	}
	sort(oklist.begin(), oklist.end());
	if (oklist.size() == 0) {
		cout << "UNRESTORABLE" << endl;
	}else
		cout << oklist[0] << endl;
}

int main() {
	DubiousDocument2();
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b;
	scanf("%d %d", &a, &b);
	if(a%b==0){
		printf("%d", a/b);
	} else if(a<=b){
		printf("%d", 1);
	} else{
		printf("%d", a/b + 1);
	}
	return 0;
}

Measured memory_bytes: 3184
#include <stdio.h>
#include <math.h>
int main(void){
    // Your code here
    int n,i;
    double  d1=0,di=0,xy;
    double d2=0,d3=0;
    scanf("%d",&n);
    int x[101],y;
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&y);
        xy=abs(y-x[i]);
        d1+=xy;
        d2+=xy*xy;
        d3+=xy*xy*xy;
        if (di<xy) di=xy;
        
    }
    printf("%lf\n%lf\n%lf\n%lf\n",d1,sqrt(d2),pow(d3,1.0/3.0),di);
    return 0;
}



Measured memory_bytes: 2108
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  long long N, C, K, T[200000];
  cin >> N >> C >> K;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  sort(T, T + N);

  int ans = 0, away = -1, cnt = 0;
  for (int i = 0; i < N; i++) {
    if (cnt == C || away < T[i]) {
      ans++;
      cnt = 1;
      away = T[i] + K;
    } else {
      cnt++;
    }
  }

  printf("%d\n", ans);
  return 0;
}


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


using namespace std;





int main(){
 int s; cin >> s;
 int ans = 0;
 vector<int> A(1000000);
	A.at(0)=s;
	for(int i = 1; i<1000000;i++){
	if(0==s%2){
		s=s/2;
		A.at(i)=s;
	  }
	  else{
		  s=3*s+1;
		}
		for(int k = 0 ; k < i-1;k++){
		if(s==A.at(k)){
			ans = i+1;
			break;
		  }
		}
	  if(ans != 0){
		  break;
		}
	}
	cout << ans <<endl;

}



Measured memory_bytes: 4096
#include<stdio.h>

int main(){
  int ans, d, i;
  while(scanf("%d", &d) != EOF){
    ans = 0;
    for(i = d;i != 600;i += d){
      ans += i * i * d; 
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  while(cin>>n,n){
    Int cnt=n/2,i;
    for(i=1;i*i<n/2;i++) cnt+=(n/2+i-1)/i;
    cnt=cnt*2-i*i;
    cnt+=n;
    cout<<cnt*8<<endl;
  }
  return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  vi a(N);
  int sum=0;
  rep(i,N) {
    cin >> a[i];
    sum += a[i];
  }
  auto solve = [&](int k) -> bool {
    vi b(N);
    rep(i,N) {
      b[i]=a[i]%k;
    }
    sort(rng(b));
    reverse(rng(b));
    vi acc(N+1,0);
    rep(i,N) {
      acc[i+1]=acc[i]+b[i];
    }
    // [0,i)
    auto getL = [&](int i) {
      if(i<=0) return 0;
      return i*k-acc[i];
    };
    // [i,N)
    auto getR = [&](int i) {
      if(i>=N) return 0;
      return acc[N]-acc[i];
    };
    rep(d,N+1) {
      int lc = getL(d);
      int rc = getR(d);
      if(lc==rc&&lc<=K) return true;
    }

    return false;
  };
  int ans = 0;
  for(int k=1;k*k<=sum;k++) {
    if(sum%k!=0) continue;
    if(solve(k)) {
      chmax(ans,k);
    }
    if(solve(sum/k)) {
      chmax(ans,sum/k);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b<c+d)
    cout << "Right" << endl;
  else if(a+b > c+d)
    cout << "Left" << endl;
  else
    cout << "Balanced" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define NIL -1
void depth(int,int);
int height(int);
int info_sibling(int);
void print(int);

typedef struct{
    int parent;
    int left;
    int right;
} Node;

Node node_all[N];
int n;
int node_depth[N],node_height[N];

int main(){
    int i,id,l,r,root;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        node_all[i].parent = NIL;
    }
    for(i=0;i<n;i++){
        scanf("%d%d%d",&id,&l,&r);
        node_all[id].left = l;
        node_all[id].right = r;
        if(l != NIL) node_all[l].parent = id;
        if(r != NIL) node_all[r].parent = id;
    }
    for(i=0;i<n;i++){
        if(node_all[i].parent == NIL){
            root = i;
        }
    }
    depth(root,0);
    height(root);
    for(i=0;i<n;i++){
        print(i);
    }
    return 0;
}

void depth(int k,int dn){
    if(k == NIL) return;
    node_depth[k] = dn;
    depth(node_all[k].left,dn+1);
    depth(node_all[k].right,dn+1);
}

int height(int k){
    int a = 0,b = 0,max;

    if(node_all[k].left != NIL){
        a = height(node_all[k].left) + 1;
    }
    if(node_all[k].right != NIL){
        b = height(node_all[k].right) + 1;
    }
    max = a;
    if(b > max){
        max = b;
    }
    node_height[k] = max;
    return node_height[k];
}

int info_sibling(int k){
    if(node_all[k].parent == NIL){
        return NIL;
    }
    if(node_all[node_all[k].parent].left != k && node_all[node_all[k].parent].left != NIL){
        return node_all[node_all[k].parent].left;
    }
    if(node_all[node_all[k].parent].right != k && node_all[node_all[k].parent].right != NIL){
        return node_all[node_all[k].parent].right;
    }
    return NIL;
}

void print(int k){
    int count = 0;
    
    printf("node %d: ",k);
    printf("parent = %d, ",node_all[k].parent);
    printf("sibling = %d, ",info_sibling(k));
    if(node_all[k].left != NIL){
        count++;
    }
    if(node_all[k].right != NIL){
        count++;
    }
    printf("degree = %d, ",count);
    printf("depth = %d, ",node_depth[k]);
    printf("height = %d, ",node_height[k]);

    if(node_all[k].parent == NIL){
        printf("root\n");
    }
    else if(node_all[k].left == NIL && node_all[k].right == NIL){
        printf("leaf\n");
    }
    else printf("internal node\n");
}


Measured memory_bytes: 2044
/*
***************************************************************************
 name  : ITP1_10_C.cpp
 title : Standard Deviation
 make  : 2018/09/12 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object
#include <cmath>    // mathematical function

main(void){
  int n;         // number
  float a[1000]; // integers
  bool judge;    // parameters to determine
  float sum;     // sum
  float ave;     // average
  float dev;     // deviation
  int i;         // index

  std::cin >> n; // input "n"

  // initialized judge = 0
  // continue judge == 0
  // input n at loop update
  for(judge = 0;judge == 0;std::cin >> n){
    if(n == 0){
      break;
    }
    else{
      // initialized i = 0 and sum = 0
      // continue i < n
      // increment i at loop update
      for(i = 0,sum = 0;i < n;i++){
        std::cin >> a[i]; // input "a[i]"
        sum += a[i];
      }
      ave = sum/n;

      // initialized i = 0 and sum = 0
      // continue i < n
      // increment i at loop update
      for(i = 0,sum = 0;i < n;i++){
        a[i] -= ave;  // deviation
        a[i] *= a[i]; // deviation squared
        sum += a[i];  // deviation sum of squares
      }
      dev = sum/n;
      dev = std::sqrt(dev);
      std::cout << dev << std::endl; // output "dev"
    }
  }

}



Measured memory_bytes: 3300
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  s <- getLine
  t <- getLine
  let s' = zip [1..length s] s
  putStrLn $ rotation s' t
  
rotation s' t
  |rots==t   = "Yes"
  |rotn==1   = "No"
  |otherwise = rotation rot t
    where rot = last s' : init s'
          rots = map snd rot
          rotn = fst $ head rot

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


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

Measured memory_bytes: 1024
f = lambda: map(int,input().split())
n = int(input())
a1 = list(f())
a2 = list(f())
ans = sum(a1)+a2[-1]
for i in range(1,n):
    b = a1[:i]+a2[i-1:]
    ans = max(ans,sum(b))
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int a, b, ans;
    scanf("%d %d", &a, &b);
    ans = a * b;
    if (ans%2 == 0)
    {
        puts("Even");
    }
    else
    {
        puts("Odd");
    }
    return 0;
}

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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  int sum = 0;
  if(k > a){
    sum += a;
    k -= a;
    if(k > b){
      k -= b;
      sum -= k;
    }
  }
  else sum += k;
  
  cout << sum << endl;
}

Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var sum = 0
    for (line in 1..n) {
        val list = readLine()!!.split(" ").map { it.toInt() }
        sum += list[1] - list[0] + 1
    }
    println(sum)
}

Measured memory_bytes: 35984
#include <bits/stdc++.h>
#define nl endl
#define dbg(a) cout << #a << "=" << a << endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define md 1000000007

using namespace std;

int solve()
{
    ll n;
    cin>>n;
    ll ct=0;
    ll f=0;
    while(n--)
    {
        ll a, b;
        cin>>a>>b;
        if(a==b) ct++;
        else ct=0;
        if(ct>=3) f=1;
    }
    if(f)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

int main()
{
    fast;
    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

#define pb push_back
const ll mod = 1e9 + 7;

signed main() {
    int h, n;
    cin >> h >> n;
    int sum = 0;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum < h)cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,aa,b,bb,c,cc,d,x,z;
  	cin >> x;
  	a=x/1000;
  	aa=x%1000;
  	b=aa/100;
  	bb=aa%100;
  	c=bb/10;
  	cc=bb%10;
  	d=cc/10;
  	if(a==b&&b==c||b==c&&c==d){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
  	
}

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



int main(void){
    long long T;
    int N;
    cin >> N >>T;
    long long ans = 0;
    long long a,b;

    for(int i = 0; i < N ;i++){
        cin >> a;
        if(i>0){
            if(a-b<T)ans += a-b;
            else ans += T;
        }
        b = a;
        
    }
    
    cout << ans + T << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db              double
#define ll              long long int
#define ld              long long double
//#define int           long long int
#define ull             unsigned long long
#define fi              first
#define se              second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl            '\n'
#define mem(a,b)        memset(a, b, sizeof a)
#define mkp             make_pair
#define pb              push_back
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)          a.begin(), a.end()
#define sz(a)           int((a).size())
#define dbg(x)          cerr << #x << " = " << x << endl;
//Bitwise 
#define isOn(S, j)      (S & (1<<j))
#define setBit(S, j)    (S |= (1<<j))
#define clearBit(S, j)  (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S)       (S & (-S))
#define setAll(S, n)    (S = (1<<n)-1)
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
//Can use tuples in C++17
using namespace std;
typedef map < int, int > mii;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
const db PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =          0.000001;
ll mod       =          998244353;   //(1e9+7)
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=2000008;
bool judge(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}
int main(){ 
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  cout.tie(NULL);
//  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
	char ch;
	cin>>ch;
	if(ch>='A' && ch<='Z') cout<<"A"<<endl;
	else cout<<"a"<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    for(ll i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3600
/* 
  Krishnakant Tiwari
  Problem Link:
  
 */
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _cin                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
#define endl "\n"
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define repd(i, a, b) for (ll i = a; i >= b; --i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define mll map<ll, ll>
#define sz(x) (ll) x.size()
#define sll set<ll>
#define pll pair<ll, ll>
#define F first
#define S second
#define eb emplace_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define precise(x) cout << fixed << setprecision(x)
const ll MAX = 1000004;
const ll INF = 1e18L + 5;
template <typename Arg1>
void pn(Arg1 &&arg1)
{
    cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1 &&arg1, Args &&... args)
{
    cout << arg1 << "\n";
    pn(args...);
}
template <typename Arg1>
void ps(Arg1 &&arg1)
{
    cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void ps(Arg1 &&arg1, Args &&... args)
{
    cout << arg1 << " ";
    ps(args...);
}
template <typename Arg1>
void read(Arg1 &&arg1)
{
    cin >> arg1;
}
template <typename Arg1, typename... Args>
void read(Arg1 &&arg1, Args &&... args)
{
    cin >> arg1;
    read(args...);
}

ll g[MAX];
ll a[MAX];

void solve()
{
    ll n, k;
    read(n, k);
    ll p[n], c[n];
    rep(i, 0, n)
    {
        read(p[i]);
        p[i]--;
    }
    rep(i, 0, n) read(c[i]);
    ll ans = -INF;
    rep(i, 0, n)
    {
        ll cur_i = i;
        ll c_s = 0;
        ll c_l = 0;
        while (true)
        {
            c_s += c[p[cur_i]];
            c_l++;
            cur_i = p[cur_i];
            if (cur_i == i)
                break;
        }

        ll path = 0;
        ll cnt = 0;
        while (true)
        {
            cnt++;
            path += c[p[cur_i]];
            if (cnt > k)
                break;
            ll num = (k - cnt) / c_l;
            ll val = path + max(0ll,c_s) * num;
            ans = max(ans, val);

            cur_i = p[cur_i];
            if (cur_i == i)
                break;
        }
    }
    pn(ans);
}

int main()
{

    _cin
    // ll tc;
    // cin>>tc;
    // while(tc--){
    solve();
    // }
}

Measured memory_bytes: 3700
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, l;
	cin >> n >> l;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = l + i;
	}
	int sum = accumulate(a.begin(), a.end(), 0);
	int ans, diff = 1 << 30;
	for (int i = 0; i < n; ++i) {
		int s = sum - (l + i);
		int d = abs(sum - s);
		if (d < diff) {
			diff = d;
			ans = s;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256