akhauriyash/Code-Regression huggingface dataset:
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=5000+10;
int N,K;
int P[MX],C[MX];
const int LOG=30;

int memo[MX][LOG+2],memo2[MX][LOG+2];

int jump(int u, int k){
	if(memo[u][k]!=-1) return memo[u][k];
	if(k==0) return memo[u][0]= P[u];
	return memo[u][k]=jump(jump(u,k-1),k-1);
}

int jumpV(int u, int k){
	if(memo2[u][k]!=-1) return memo2[u][k];
	if(k==0) return memo2[u][k]=C[P[u]];
	return memo2[u][k]=jumpV(u,k-1)+jumpV(jump(u,k-1),k-1);
}

int32_t main(){
   boost;
   IO();
	
	for(int i=0; i<MX; i++)for(int j=0; j<=LOG; j++) memo[i][j]=memo2[i][j]=-1;	

	cin>>N>>K;
	for(int i=1; i<=N; i++) cin>>P[i];
	for(int i=1; i<=N; i++) cin>>C[i];

	int res=-INF;
	for(int i=1; i<=N; i++){
		int ans=-INF;

		int sum=0;

		int ii=i;
		

		for(int j=1; j<=min(K,N+10); j++){
			sum+=jumpV(ii,0);
			ii=P[ii];
			ans=max(ans,sum);
		}

		int s=0;
		ii=i;

		int KK=max((ll)0,K-N-10);
		int KKK=KK;

		for(int j=LOG; j>=0; j--)if(((1)<<(j))<=KK){
			s+=jumpV(ii,j);
			ii=jump(ii,j);
			KK-=((1)<<(j));
			ans=max(ans,s);
		}

		for(int j=1; j<=K-KKK; j++){
			s+=jumpV(ii,0);
			ii=jump(ii,0);
			ans=max(ans,s);
		}
		ans=max(ans,s);

		res=max(res,ans);
	}

	cout << res << endl;


   return 0;
}



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

constexpr double EPS = 1e-10;
bool equals(double a, double b) { return (abs(a - b) < EPS); }

struct V2 {
	double x, y;
	V2(double x = 0, double y = 0) : x(x), y(y) {}
	
	V2 operator + (V2 p) const { return (V2(x + p.x, y + p.y)); }
	V2 operator - (V2 p) const { return (V2(x - p.x, y - p.y)); }
	V2 operator * (double r) const { return (V2(x * r, y * r)); }
	V2 operator / (double r) const { return (V2(x / r, y / r)); }
	
	double norm() const { return (sqrt(sqrNorm())); }
	double sqrNorm() const { return (x*x + y*y); }
	
	bool operator < (const V2 &p) const { 
		return (x != p.x ? x < p.x : y < p.y); 
	}
	bool operator == (const V2 &p) const {
		return (equals(x, p.x) && equals(y, p.y));
	}

	V2 rotate90() const { return (V2(y, -x)); }
	V2 normalized() const { return (*this / norm()); }

	double dot(const V2 &p) const { return (x*p.x + y*p.y); }
	double cross(const V2 &p) const { return (x*p.y - y*p.x); }
	double arg() const { return (atan2(y, x)); }
};
V2 polar(double r, double a) { return (V2(cos(a) * r, sin(a) * r)); }

using Polygon = vector<V2>;
struct Segment {
	V2 p1, p2;
	Segment() {}
	Segment(V2 p1, V2 p2) : p1(p1), p2(p2) {}
};

using Line = Segment;
struct Circle {
	V2 o;
	double r;
	Circle() {}
	Circle(V2 o, double r) : o(o), r(r) {}

	int intersects(const Circle &c) {
		double d = (o-c.o).norm();
		if (d + c.r < r) return (0);
		if (d + r < c.r) return (0);
		if (equals(d + c.r, r)) return (1);
		if (equals(d + r, c.r)) return (-1);
		if (r + c.r < d) return (4);
		if (equals(r + c.r, d)) return (3);
		return (2);
	}

	vector<V2> crossPoints(const Circle &c) {
		int inter = intersects(c);
		if (inter != 2 && inter != 3) return (vector<V2>());
		double d = (c.o-o).norm();
		double t = (c.o-o).arg();
		if (inter == 3) return ((vector<V2>){o + (c.o-o).normalized() * r});

		double a = acos((r*r + d*d - c.r*c.r) / (2*r*d));
		return ((vector<V2>){o + polar(r, t+a), o + polar(r, t-a)});
	}
};

int main() {
	Circle c1, c2;
	double x1, y1, r1;
	double x2, y2, r2;
	cin >> x1 >> y1 >> r1;
	cin >> x2 >> y2 >> r2;
	c1 = Circle(V2(x1, y1), r1);
	c2 = Circle(V2(x2, y2), r2);
	
	cout << abs(c1.intersects(c2)) << endl;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s.length()==1)
    {
        cout<<"0"<<'\n';
        return 0;
    }
    char c = s[0];
    ll cnt=0;
    for(ll i=1;s[i]!='\0';i++)
    {
        if(s[i]==c && s[i]=='0')
        {
            cnt++;
            s[i]='1';
            c = '1';
        }
        else if(s[i]==c && s[i]=='1')
        {
            cnt++;
            s[i]='0';
            c = '0';
        }
        else
        {
            c = s[i];
        }
    }
    cout<<cnt<<'\n';
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,T,flag=0;cin>>N>>T;
  vector<pair<int,int>> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i).first>>a.at(i).second;
  sort(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(a.at(i).second<=T){
      cout<<a.at(i).first;
      flag++;
      break;
    }
  }
  if(flag==0)cout<<"TLE"<<endl;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    sx, sy, tx, ty = [int(x) for x in input().split()]

    print("R" * (tx - sx) + "U" * (ty - sy) + "L" * (tx - sx) + "D" * (ty - sy), end ="")
    print("D" + "R" * (tx - sx + 1) + "U" * (ty - sy + 1) + "L", end="")
    print("U" + "L" * (tx - sx + 1) + "D" * (ty - sy + 1) + "R")


if __name__ == '__main__':
    main()


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

int main()
{
  int sort[3] = {};
  int temp, i, n, t;
  temp = t = n = 0;
  
  while(cin >> temp){
    if(n++ == 10) break;
    for(i = 0; i < 3; i++){
      if(sort[i] < temp){
	t = sort[i];
	sort[i] = temp;
	temp = t;
      }
    }
  }
  
  for(i = 0; i < 3; i++){
    cout << sort[i] << "\n";
  }

  return 0;
}

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

public class Main {

    static char[] abc = { 'A', 'B', 'C' };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        sc.nextInt();
        char[] S = sc.next().toCharArray();

        int count = 0;
        for (int i = 0; i < S.length - 2; i++) {
            char[] sub = Arrays.copyOfRange(S, i, i + 3);

            if (Arrays.equals(sub, abc)) {
                count++;
            }
        }

        System.out.println(count);

    }

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>

template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<ll>> &v) //v{n][k] == nCk
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = v[k - 1][j - 1] + v[k - 1][j];
		}
	}
}
string RunLengthEncoding(string str)
{
	int itr = 0;
	std::string res;
	while (itr < int(str.size()))
	{
		char tmp = str[itr++];
		int length = 1;
		while (itr < int(str.size()) && str[itr] == tmp)
		{
			++itr;
			++length;
		}
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
int main()
{
	str s;
	cin >> s;
	if(s=="ABC"){
		cout << "ARC" << endl;
	}
	else{
		cout << "ABC" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static class Pair implements Comparable<Pair>{
        int start;
        int end;
        
        void Pair(int x,int y){
            this.start=x;
            this.end=y;
        }
        
        public int compareTo(Pair p){
            return -p.end+this.end;
        }
    }
    
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        Pair[] allpair=new Pair[M];
        
        for(int i=0;i<M;i++){
            int tmp_start=sc.nextInt();
            int tmp_end=sc.nextInt();
            Pair tmp=new Pair();
            tmp.Pair(tmp_start,tmp_end);
            allpair[i]=tmp;
        }
        
        Arrays.sort(allpair);
        int ANS=0;

        int x=0;
        
        for(int i=0;i<M;i++){
            int tmp=allpair[i].end;
            if(x<allpair[i].start){
                ANS++;
                x=tmp-1;
            }else{
            }
        }
        
        System.out.println(ANS);
    }
}


Measured memory_bytes: 87924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
int x,a,b;
int main(){
  cin >> x;
  a = x/100;
  b = x-a*100;
  for (size_t i = 0; i < a; i++) {
    if(b <= 0)break;
    if(b >= 5)b -= 5;
    else b -= b;
  }
  cout << (b<=0 ? 1:0) << endl;
}


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

int main( void ) {
    int n, m;
    while( cin >> n >> m && n + m > 0 ) {
    for( int i = 0; i < n; ++i ) {
        for( int j = 0; j < m; ++j ) {
            cout << '#';
        }
        cout << '\n';
    }
    cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 3008
import numpy as np

N = int(input())

AB = []
for i in range(N):
    ab = list( map(int,input().split()) )
    AB.append(ab)

AB = np.array(AB)

A = AB[:,0]
B = AB[:,1]

m_min = np.median(A)
m_max = np.median(B)

if N%2==0:
    ans = (int(m_max*10) - int(m_min*10)) //5 +1
else:
    ans = int(m_max) - int(m_min) + 1

print(ans)

Measured memory_bytes: 66564
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def pos(a, x, k):
    res = 0
    for i in a:
        res += (i-1)//x
    return res <= k

for _ in range(int(input()) if not True else 1):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    alpha = 1
    omega = 10**9
    while alpha < omega:
        mid = (alpha+omega) // 2
        if pos(a, mid, k):
            omega = mid
        else:
            alpha = mid+1
    print(omega)


Measured memory_bytes: 95284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
int h[10] = {0,2,5,5,4,5,6,3,7,6};

int main(){
    int n,m;
    cin >> n >> m;
    ve<char> a(m);
    rep(i,m){
        cin >> a[i];
    }
    ve<string> dp(n+10);
    dp[0] = "";
    rep(i,m){
        dp[h[a[i]-'0']] = max(dp[h[a[i]-'0']],(string)""+a[i]);
    }
    rep(i,n+1){
        rep(j,m){
            if(dp[i] == "") continue;
            if(i+h[a[j]-'0'] >= n+1) continue;
            if(dp[i + h[a[j]-'0']].size() > dp[i].size()+1) continue;
            if(dp[i + h[a[j]-'0']].size() < dp[i].size()+1){
                dp[i+h[a[j]-'0']] = dp[i] + a[j];
                continue;
            }
            dp[i+h[a[j]-'0']] = max(dp[i+h[a[j]-'0']], dp[i] + a[j]);
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

using namespace std;

vector<int>v;

int dp[100050];

int main(){
    int n,k,br;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>br;
        v.push_back(br);
    }

    dp[0]=v[0];
    dp[1]=abs(v[0]-v[1]);
    for(int i=2;i<=k;i++){
        if(i>=n)continue;
        int minn=abs(v[0]-v[i]);
        for(int j=1;j<i;j++)minn=min(minn,dp[j]+abs(v[j]-v[i]));
        dp[i]=minn;
    }

    for(int i=k+1;i<n;i++){
        int minn=1000000000;
        for(int j=i-k;j<i;j++)minn=min(minn,dp[j]+abs(v[j]-v[i]));
        dp[i]=minn;
    }

    cout<<dp[n-1];




    return 0;
}


Measured memory_bytes: 1144
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //値を取得
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] str = s.split("");
        int count = 0;
        int countStart = 0;
        int countEnd = 0;
        
        //文字列を一文字ずつ取り出し、条件に合えばカウント
        //条件に合わないときは何もしない
        for (int i = 0; i < str.length; ++i){
            if (str[i].equals("A")){    //始まり
                countStart = 1;
            }
            if (countStart == 1){  //部分文字列のカウント
                ++count;
                if (str[i].equals("Z")){  //終わり
                    countEnd = count;
                }
            }
        }
        
        //出力
        System.out.println(countEnd);
        
    }
}

Measured memory_bytes: 66008
from sys import stdin
import collections
N = int(stdin.readline().rstrip())

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table
prime = prime_decomposition(N)

c = collections.Counter(prime)
p = c.values()
cnt = 0
for i in p:
    t=1
    while True:
        i = i-t
        if i<=t:
            cnt += t
            break
        t+=1
print(cnt)

Measured memory_bytes: 9532
#include<iostream>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int ans[n];
    // rep(i,n){
    //     rep(j,n){
    //         if(a[j] == i + 1){
    //             ans[j] << j + 1;
    //         }
    //     }
    // }
    rep(i,n) ans[a[i]-1] = i+1;
    rep(i,n) cout << ans[i] << " ";
    return 0;
}

Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

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


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] as = new long[N];
			HashMap<Long, Integer> counts = new HashMap<Long, Integer>();
			
			for(int i = 0; i < N; i++) {
				as[i] = sc.nextLong() - i;
				
				if(!counts.containsKey(as[i])) {
					counts.put(as[i], 0);
				}
				counts.put(as[i], counts.get(as[i]) + 1);
			}
			
			long answer = 0;
			for(int i = 0; i < N; i++) {
				final long purpose = -as[i] - 2 * i;
				
				if(counts.containsKey(purpose)) {
					answer += counts.get(purpose);
				}
				
				counts.put(as[i], counts.get(as[i]) - 1);
			}
			
			System.out.println(answer);
		}
	}

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

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

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

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

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

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

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

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

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

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

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


Measured memory_bytes: 70576
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vll data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());
    ll ans = 0;
    for (int i = 0; i < N - 1; i++) {
        if (i % 2 == 0) {
            ans += data.at(i / 2);
        }
        else {
            ans += data.at((i + 1)/ 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4740
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
ans=[[0 for i in range(w)] for j in range(h) ]

v=0
d=0
df=0
for i in range(n):
    t=i+1
    f=0
    while f<a[i]:
        if df==0:
            ans[v][d]=t

        elif df==1:

            ans[v][w-1-d]=t
        f+=1
        d+=1
        if df==0 and d==w:
            v+=1
            df^=1
            d=0
        if df==1 and w-d==0:
            v += 1
            df ^= 1
            d = 0
for h in ans:
    print(*h)

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

int main(){
    int N, min, buf, res=1;
    cin >> N;
    cin >> min;
    REP(i,N-1){
        cin >> buf;
        if(min>buf){
            min = buf;
            res++;
        }
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>		//提出用
using namespace std;
int main(){
	int t;
	cin >> t;
	int loop,loop2;
	int n,k,x1,x2,needs;
	int ans;
	vector<int> xdist;
	for(loop=0;loop<t;loop++){
		cin >> n >> k;
		k=min(n,k);
		xdist.resize(n-1);
		k--;
		x1=0;
		for(loop2=0;loop2<n;loop2++){
			cin >> x2;
			if(loop2){
				xdist[loop2-1]=x2-x1;
			}
			x1=x2;
		}
		sort(xdist.begin(),xdist.end());		//昇順ソート  降順にしようと考えたがpop_backした方が早くね？という結論に
		needs=n-1;
		for(;k>0;k--){
			xdist.pop_back();
			needs--;
		}
		ans=0;
		for(loop2=0;loop2<needs;loop2++){
			ans+=xdist[loop2];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,K;
	int eq;
	cin>>N>>K;
	
	int A[N+2]={0},S[N+2]={0},B[N+2]={0};
	int now=0;
	for(int i=1;i<=N;i++)cin>>A[i];
	
	for(int j=0;j<K;j++){
		now=0;
		eq=0;
		for(int i=1;i<=N;i++){
			S[min(i+A[i]+1,N+1)]--;
			S[max(i-A[i],1)]++;
		}
		for(int i=1;i<=N;i++){
			now+=S[i];
			A[i]=now;
			S[i]=0;
		}
		for(int i=1;i<N;i++){
			if(A[i]==A[i+1])eq++;
		}
		if(eq==N-1 && A[1]==N)break;
	}
	for(int i=1;i<=N;i++)cout<<A[i]<<" ";
	return 0;
}

Measured memory_bytes: 5976
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+7;
int w[N],v[N],dp[N];
main()
{
    int n,W;
    scanf("%lld%lld",&n,&W);
    for(int i=0;i<n;i++)
        scanf("%lld%lld",&w[i],&v[i]);
    for(int i=0;i<n;i++)
    {
        for(int j=W-w[i];j>=0;j--)
            dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
    }
    int ans=0;
    for(int i=0;i<=W+1;i++)
        ans=max(ans,dp[i]);
    printf("%lld\n",ans);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;
int main()
{ 
    fast;
    ll n,m,s,t;
     cin>>n>>m;
   vector<ll> adj[3*n];

   for(ll i=0;i<m;i++)
   { 
    ll x,y;
    cin>>x>>y;
    x--,y--;
    adj[x].pb(y+n);
    adj[x+n].pb(y+2*n);
    adj[x+2*n].pb(y);
   }

   cin>>s>>t;
   s--,t--;

   queue<ll> q;
   vector<bool> vis(3*n,false);
   q.push(s);
   vis[s]=1;
   vector<ll> d(3*n,-1);
   d[s]=0;

   while(!q.empty())
   {
    ll v=q.front();
    q.pop();

    for(auto u:adj[v])
    {
      if(!vis[u])
      {
        vis[u]=1;
        d[u]=d[v]+1;
        q.push(u);
      }
    }
   }

   if(d[t]==-1)
    cout<<-1<<endl;
  else cout<<d[t]/3<<endl;
  }

Measured memory_bytes: 19072
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
txy = [LIST() for _ in range(N)]

def dist(p1, p2):
	return abs(p1[0]-p2[0])+abs(p1[1]-p2[1])

now = [0, 0]
time = 0
for t, x, y in txy:
	if (t-time) < dist(now, [x, y]) or ((t-time) - dist(now, [x, y]))%2!=0:
		print("No")
		break
	time = t
	now[0] = x
	now[1] = y
else:
	print("Yes")


Measured memory_bytes: 29392
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <fstream>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

/*
  ifstream in("test.txt");
  cin.rdbuf(in.rdbuf());
*/

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  VI pt(N);
  ll tmp = 0;
  REP(i, N)
  {
    int A, B;
    cin >> A >> B;
    pt[i] = A+B;
    tmp -= B;
  }
  SORTG(pt);
  ll ans = 0;
  REP(i, N) if (i % 2 == 0) ans += pt[i];

  cout << ans + tmp << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int N, K;
	cin >> N >> K;
	vector<Int> a(N + 1, 0);
	for (int i = 1; i <= N; ++i) { cin >> a[i]; }

	if (K == 1) { 
		cout << 0 << endl;
		return 0;
	}

	vector<Int> S(N + 1, 0);
	for (int i = 1; i <= N; ++i) { S[i] = S[i - 1] + a[i]; }

	map<Int, Int> mp;
	int l = 0, r = 1;
	mp[0] = 1;
	Int ans = 0;
	while (r <= N && l < r) {
		Int idx = (S[r] - r + K) % K;
		ans += mp[idx];
		mp[idx] += 1;

		++r;
		while (r - l >= K) {
			mp[(S[l] - l + K) % K] -= 1;
			++l;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 15872
package main
import (
    "fmt"
    "bufio"
    "os"
)

var stdin = bufio.NewScanner(os.Stdin)

func sI() string {
	stdin.Scan()
	return stdin.Text()
}

func main() {
    c := sI()
    fmt.Println(string(c[0] + 1))
}


Measured memory_bytes: 640
let () =
  let a, b = Scanf.scanf "%d %d" (fun x y -> (x, y)) in
  ( if a mod 3 = 0 || b mod 3 = 0 || (a + b) mod 3 = 0 then "Possible"
    else "Impossible" )
  |> Printf.printf "%s\n"

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct

int main(void){
    int n,i,j,k[100];
    char s[101];
    while(1){
        n=in();
        if(!n)break;
        rep(i,n)k[i]=in();
        chin(s);
        rep(i,strlen(s)){
            rep(j,k[i%n]){
                if(s[i]=='A')s[i]='z';
                else if(s[i]=='a')s[i]='Z';
                else s[i]--;
            }
        }
        puts(s);
    }
    return 0;
}



Measured memory_bytes: 2108
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
	int a, b, c, d, e, f;	
	cin >> a >> b >> c >> d >> e >> f;
	int sugar = 0, water = 100 * a;
	for (int na = 0; 100 * a * na <= f; na++) {
		for (int nb = 0; 100 * (a * na + b * nb) <= f; nb++) {
			for (int nc = 0; nc * c <= e * (a * na + b * nb)
					&& (100 * (a * na + b * nb) + nc * c <= f); nc++) {
				for (int nd = 0; nc * c + nd * d <= e * (a * na + b * nb)
						&& (100 * (a * na + b * nb) + nd * d + nc * c) <= f; nd++) {
					int s = nc * c + nd * d, w = 100 * (na * a + nb * b);		
					if (s * (sugar + water) > sugar * (s + w)) {
						sugar = s;
						water = w;
					}
				}
			}
		}
	}
	cout << sugar + water << " " << sugar << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
using ll = long long;
using ld = long double;

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

    vector<int> X( M );
    for ( int i = 0; i < M; ++i ) cin >> X[ i ];
    sort( X.begin(), X.end() );

    vector<int> d;
    for ( int i = 1; i < M; ++i ) d.push_back( X[ i ] - X[ i - 1 ] );
    sort( d.begin(), d.end() );

    ll result = 0;
    for ( int i = 0; i < M - N; ++i ) result += d[i];
    cout << result << endl;

    return 0;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    while(cin>>n, n) {
        bool table[101][101];
        fill((bool*)table, (bool*)table+101*101, false);
        for(int i=0; i<n; ++i) {
            int m;
            cin >> m;
            for(int j=0; j<m; ++j) {
                int x;
                cin >> x;
                table[i][x] = true;
            }
        }
        int k;
        cin >> k;
        vector<int> target(k);
        for(int i=0; i<k; ++i) cin >> target[i];

        int ans = -1;
        for(int i=0; i<n; ++i) {
            int j;
            for(j=0; j<k; ++j)
                if(!table[i][target[j]]) break;
            if(j == k) {
                if(ans != -1) {
                    ans = -1;
                    break;
                }
                else ans = i + 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long	
using namespace std;
int n;
ll a[100];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	cout << a[n - 1] - a[0];
	return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
H = [10**5]*K+list(map(int,input().split()))
L = [0]*(N+K)
for i in range(K+1,N+K):
    #print(i)
    res = abs(H[i]-H[i-1])+L[i-1]
    for j in range(i-1,i-K-1,-1):
        #print('j={}'.format(j))
        res = min(res,abs(H[j]-H[i])+L[j])
    L[i] = res
print(L[N+K-1])

Measured memory_bytes: 53216
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
	int H, W;
	cin >> H >> W;
	char a[H][W];

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> a[i][j];
		}
	}
	int L[H][W];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++) L[i][j] = 0;
	}


	for(int i=0;i<H;i++){
		int j=0;
		while(j<W){
			if(a[i][j]=='.'){
				int left = j;
				int cnt = 0;
				while(j<W && a[i][j]=='.'){
					cnt++;
					j++;
				}
				for(int l=left;l<j;l++){
					L[i][l] += cnt;
				}
			}
			j++;
		}
	}

	for(int j=0;j<W;j++){
		int i=0;
		while(i<H){
			if(a[i][j]=='.'){
				int top = i;
				int cnt = 0;
				while(i<H && a[i][j]=='.'){
					cnt++;
					i++;
				}
				for(int l=top;l<i;l++){
					L[l][j] += cnt;
				}
			}
			i++;
		}
	}


	int ans = 0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			ans = max(ans, L[i][j]-1);
		}
	}
	cout << ans <<endl;
  	

    
  	return 0;
}


Measured memory_bytes: 19840
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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


int main(){
    int H, W;
    cin >> H >> W;
    string s[H+2];
    for(int i = 0; i < H+2; i++){
        s[i] = "";
        for(int j = 0; j < W+2; j++){
            s[i] += "#";
        }
    }
    string a;
    for(int i = 1; i <= H; ++i){
        cin >> a;
        s[i].replace(1, W, a);
    }

    for(int i = 0; i < H+2; ++i){
        cout << s[i] << endl;
    }
    return 0;
}


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

int main(){
  string s;
  cin >>s;
  int cnt = 0;
  rep(i,s.size()){
    if(s[i]=='1') cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:break
    for i in range(a):
    	for j in range(b):
    		if (i + j)%2 == 0:print('#',end="")
    		else:print(".",end="")
    	print("")
    print("")


Measured memory_bytes: 7008
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    long h,w;
    cin>>h>>w;
    if(h==1||w==1){
        cout<<1<<endl;
        return 0;
    }
    if(h*w%2==0){
        cout<<(h*w)/2<<endl;
    }
    else{
        cout<<((h*w)/2)+1<<endl;
    }
}

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

int formula(string &s, int P, int Q, int R, int &i) {
    if(s[i] == '-') {
        i++;
        return 2-formula(s, P, Q, R, i);
    } else if(s[i] == '(') {
        int X, Y;
        i++;
        X = formula(s, P, Q, R, i);
        if(s[i] == '*') {
            i++;
            Y = formula(s, P, Q, R, i);
            i++;
            if(X == 0) return 0;
            if(X == 1) {
                if(Y == 0) return 0;
                else return 1;
            } else {
                return Y;
            }
        } else {
            i++;
            Y = formula(s, P, Q, R, i);
            i++;
            if(X == 0) return Y;
            if(X == 1) {
                if(Y == 0) return 1;
                else return Y;
            } else {
                return 2;
            }
        }
    } else {
        int ret;
        if(s[i] >= '0' && s[i] <= '2') ret = s[i]-'0';
        else if(s[i] == 'P') ret = P;
        else if(s[i] == 'Q') ret = Q;
        else if(s[i] == 'R') ret = R;
        i++;
        return ret;
    }
}

int main(void){
    string s;
    while(cin >> s && s != ".") {
        int cnt = 0;
        rep(i, 3) rep(j, 3) {
            rep(k, 3) {
                int index = 0;
                if(formula(s, i, j, k, index) == 2) cnt++;
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,v[3003][3003],K;
ll dp[3003][3003][4];
int main(){
	cin>>n>>m>>K;
	for(int i=1;i<=K;i++){
		int r,c,V;cin>>r>>c>>V;
		v[r][c]=V; 
	}
	dp[1][1][0]=0;if(v[1][1]>0)dp[1][1][1]=v[1][1];
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(i>1||j>1){
		if(j>1){
			for(int k=0;k<4;k++)dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
			if(v[i][j]>0)for(int k=0;k<3;k++)dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j-1][k]+v[i][j]);
		}
		if(i>1){
			for(int k=0;k<4;k++)dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
			if(v[i][j]>0)for(int k=0;k<4;k++)dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+v[i][j]);
		}
	}
	ll ans=0;
	for(int i=0;i<4;i++)ans=max(ans,dp[n][m][i]);
	cout<<ans;
}

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

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char dc[] = "RDLU";

int main() {
	int g[11][11] = {};
	char c;
	for (int i=1; i<10; ++i) {
		for (int j=1+i%2; j<=9; j+=2) {
			cin >> c;
			g[i][j] |= c - '0';
		}
	}
	int x=1, y=1, d=0;
	do {
		for (int t=d+3; ; ++t) {
			if (g[y + dy[t%4]][x + dx[t%4]]) {
				d = t%4;
				break;
			}
		}
		x += dx[d] * 2;
		y += dy[d] * 2;
		cout << dc[d];
	} while (x != 1 || y != 1);
	cout << endl;
	return 0;
}

Measured memory_bytes: 1132
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {

    long long sum = 0;
    int n, t;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        sum += t;
    }
    printf("%lld\n", (sum / n));
    return 0;
}


Measured memory_bytes: 2576
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=3500;i++){
		for(int j=1;j<=3500;j++){
			ll val=(ll)n*i*j;
			ll val2=(ll)4*i*j-n*i-n*j;
			if(val2<=0)continue;
			if(val%val2==0 && val/val2<=3500){
				printf("%d %d %d\n",i,j,val/val2);
				return 0;
			}
		}
	}
	return 0;
}

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

using namespace std;

#define f first
#define s second
#define ll long long
#define pb push_back

const ll M = 998244353;

ll a[300005], n, x, y, k, ans;

int main (){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    n -= k;

    if (k == 1){
        cout << 0;
        return 0;
    }
    cout << n;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() 
{
	string a;
	cin>>a;
	int t=a.length()-1;
	if(a[t]=='2'||a[t]=='4'||a[t]=='7'||a[t]=='5'||a[t]=='9')cout<<"hon";
	if(a[t]=='0'||a[t]=='1'||a[t]=='6'||a[t]=='8')cout<<"pon";
	if(a[t]=='3')cout<<"bon";
	return 0;
}

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

int main() {
  int X,K,n,m,a;
  cin >> K >> X;
  n=X-K+1;
  m=X+K-1;
  if(n<-1000000){
    n=-1000000;
  }
  if(m>1000000){
    m=1000000;
  }
  int i=n;
  while(i<=m){
    cout << i;
    i++;
    if(i<=m){
      cout << " ";
    }
  }
cout << endl;
}







Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a <= b) {
            if (b <= c) {
                System.out.println(a + b + c * 10);
            } else {
                System.out.println(a + b * 10 + c);
            }
        } else {
            if (a <= c) {
                System.out.println(a + b + c * 10);
            } else {
                System.out.println(a * 10 + b + c);
            }
        }

    }
}







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

int main () {

    int N, M;
    scanf("%d %d", &N, &M);

    int num[N];
    bool red[N];

    for (int i = 0; i < N; i++) {
        num[i] = 1;
        red[i] = false;
    }
    red[0] = true;

    for (int i = 0; i < M; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        x--; y--;

        if (red[x]) {
            red[y] = true;
        }
        num[x]--;
        num[y]++;
        if (num[x] == 0) {
            red[x] = false;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (red[i]) ans++;
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 768
k,n = map(int,input().split())
a = list(map(int,input().split()))
kyori=[]
for i in range(n):
    if i<=n-2:
        kyori.append(a[i+1]-a[i])
    else:
        kyori.append(k-a[i]+a[0])
m_ky=max(kyori)
print(k-m_ky)


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

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

  string ans = "Yay!";
  if (e - a > k) ans = ":(";

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int N = 200006;
const ll INF = 1e18;
map<pair<int,int>, int> h;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;

    ll mx_1 = -2e18, mn_1 = 2e18, mn_2 = 2e18, mx_2 = -2e18;   
    for(int i = 1; i <= n; i++) {
        ll x, y;
        cin >> x >> y;
        mx_1 = max(mx_1, x + y);
        mn_1 = min(mn_1, x + y);
        mn_2 = min(mn_2, x - y);
        mx_2 = max(mx_2, x - y);
    }
    cout << max(abs(mx_1 - mn_1), abs(mx_2 - mn_2)) << '\n';
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define int long long int
using namespace std;
int DP[101][100001];
#define rep(i,n) for(int i=0;i<=n;i++)
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,w;
    
    cin>>n>>w;
    int val[n];
    int wei[n];
    //exit(0);
    for(int i=0;i<n;i++)
    cin>>wei[i]>>val[i];

    
    //exit(0);
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0 || j==0)
            {
                DP[i][j]=0;
                continue;
            }
            //exit(0);
            if(wei[i-1]<=j)
            {
                //cout<<"ent"<<endl;
                DP[i][j] = max(val[i - 1] + DP[i - 1][j - wei[i - 1]],DP[i - 1][j]); 
            }else
            DP[i][j] = DP[i-1][j];
            
            
        }
    }

    
    cout<<DP[n][w];
    return 0;
}

Measured memory_bytes: 79232
#!/usr/bin/env pypy3


def solve(n, s):
    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    res_len = 0
    idx = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if s[i - 1] == s[j - 1] and dp[i - 1][j - 1] < j - i:
                dp[i][j] = dp[i - 1][j - 1] + 1
                if dp[i][j] > res_len:
                    res_len = dp[i][j]
                    idx = max(i, idx)
            else:
                dp[i][j] = 0
    return res_len


def main():
    n = int(input())
    s = input()
    res_len = solve(n, s)
    print(res_len)


if __name__ == "__main__":
    main()


Measured memory_bytes: 247304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

struct Employee
{
    int id;
    int boss;
};

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> data(n, 0);

    for(int i= 0; i < n -1; i++)
    {
        int a;
        std::cin >> a;
        data[a-1]++;
    }

    for(auto x : data)
    {
        std::cout << x << std::endl;
    }

    return EXIT_SUCCESS;
} 

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+2;
string s,p;
int dp[N][N];
void LCS(int n,int m)
{
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(s[i-1]==p[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans;
    while(dp[n][m]!=0)
    {
        if(dp[n][m]==dp[n-1][m])
        {
            n--;
        }
        else if(dp[n][m]==dp[n][m-1])
        {
            m--;
        }
        else
        {
            ans+=s[n-1];
            n--,m--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,i,j,n,m,l,r,k;
    cin>>s>>p;
    LCS((int)s.size(),(int)p.size());
    return 0;
}

Measured memory_bytes: 35456