akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
/*
ll n, k;
vl a;
*/
ll N, W;
vl w, v;
/******* define variable end *******/

ll solve()
{
    /*
    cin >> n >> k;
    a.resize(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    vl wa(n + 1);
    wa[0] = 0;
    REP(i, n)
    {
        wa[i + 1] = wa[i] + a[i];
    }
    REP(i, n)
    {
        for (ll j = i + 1; j < n + 1; ++j)
        {
        }
    }
    */
    cin >> N >> W;
    w.resize(N);
    v.resize(N);
    vl w1v, w2v, w3v, w4v;
    ll w1 = 0, w2 = 0, w3 = 0, w4 = 0;
    REP(i, N)
    {
        cin >> w[i] >> v[i];
        if (w[i] == w[0])
        {
            w1++;
            w1v.push_back(v[i]);
        }
        else if (w[i] == w[0] + 1)
        {
            w2++;
            w2v.push_back(v[i]);
        }
        else if (w[i] == w[0] + 2)
        {
            w3++;
            w3v.push_back(v[i]);
        }
        else
        {
            w4++;
            w4v.push_back(v[i]);
        }
    }
    sort(w1v.begin(), w1v.end(), greater<ll>());
    sort(w2v.begin(), w2v.end(), greater<ll>());
    sort(w3v.begin(), w3v.end(), greater<ll>());
    sort(w4v.begin(), w4v.end(), greater<ll>());
    ll ans = 0;
    REP(i, w1 + 1)
    {
        REP(j, w2 + 1)
        {
            REP(k, w3 + 1)
            {
                REP(l, w4 + 1)
                {
                    if ((i)*w[0] + (j) * (w[0] + 1) + k * (w[0] + 2) + (l) * (w[0] + 3) <= W)
                    {
                        ll anstmp = 0;
                        REP(w1c, i)
                        {
                            anstmp += w1v[w1c];
                        }
                        REP(w2c, j)
                        {
                            anstmp += w2v[w2c];
                        }
                        REP(w3c, k)
                        {
                            anstmp += w3v[w3c];
                        }
                        REP(w4c, l)
                        {
                            anstmp += w4v[w4c];
                        }
                        if (anstmp > ans)
                        {
                            ans = anstmp;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
main(){
  int i,j;
  int n,m;
  cin>>n;
  while(n!=0){
    char t[n][2];
    for(i=0;i<n;i++)
      cin>>t[i][0]>>t[i][1];
  
    cin>>m;
 
    char ans[m+1];
  
    for(i=0;i<m;i++){
      cin>>ans[i];
      for(j=0;j<n;j++){
	if(t[j][0]==ans[i]){
	  ans[i]=t[j][1];
	  break;
	}
      }
    }
    ans[i]='\0';

    cout<<ans<<endl;
    cin>>n;  
  }

  return 0;
}

Measured memory_bytes: 1252
#include<stdio.h>
int main () {
int a,b,c,d;
scanf("%d %d %d",&a,&b,&c);
if (a > b) {
d = a;
a = b;
b = d;
}
if (b > c) {
d = b;
b = c;
c = d;
}
if (a > b) {
d = a;
a = b;
b = d;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  int K, S;
  cin >> K >> S;
  
  ll res;
  rep(i, K+1){
    rep(j, K+1){
      if(0 <= S-i-j && S-i-j <= K) res++;
      else if (S-i-j < 0) break;
    }
  }
  
  
  cout << res;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
_P = list(map(int, input().split()))

## 期待値を事前に計算しておく
P = []
for p in _P:
  if p == 1:
    P.append(1)
  elif p%2 == 0:
    P.append(p//2+0.5)
  else:
    P.append(p//2+1)

## 最初に求められるところを求めたのち、一個ずつずらしていく
ans = sum(P[:K])
_ = ans
for x in range(1,N-K+1,1):
  ## 1個ずらして計算
  _ -= P[x-1]
  _ += P[x+K-1]
  
  ## 今までの最大値との比較
  ans = max(ans, _)
      
      
print(ans)

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

int main() {
    int N; cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; ++i) {
        cin >> H.at(i);
    }

    bool flg = true;
    int minN = INT_MAX;
    for (int i = N-1; i > 0 ; --i) {
        minN = min(minN, H.at(i));
        if(H.at(i) >= H.at(i-1)){
            continue;
        } else {
            H.at(i-1)--;
            minN = min(minN, H.at(i-1));
            if(minN < H.at(i-1)){
                flg = false;
                break;
            }
        }
    }
    if(flg){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	boolean check(TreeSet<int[]> C, int[] S) {
		int[] Sl = C.lower(S);
		if (Sl != null && Sl[1] < S[1]) {
			return true;
		} else {
			return false;
		}
	}

	@SuppressWarnings("unchecked")
	void solve(int N, int[][] S) {
		TreeSet<int[]>[] C = new TreeSet[N];
		for (int i = 0; i < N; ++i) {
			C[i] = new TreeSet<>(new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0]) {
						return Integer.compare(o1[0], o2[0]);
					} else {
						return -Integer.compare(o1[1], o2[1]);
					}
				}
			});
		}
		C[0].add(S[0]);
		int maxLen = 1;
		for (int i = 1; i < N; ++i) {
			int left = -1;
			int right = maxLen;
			while (right - left > 1) {
				int middle = (right + left) / 2;
				if (check(C[middle], S[i])) {
					left = middle;
				} else {
					right = middle;
				}
			}

			if (left + 1 == maxLen) {
				C[left + 1].add(S[i]);
				++maxLen;
				continue;
			} else {
				int[] tmp = C[left + 1].floor(S[i]);
				if (tmp != null && tmp[1] == S[i][1])
					continue;
				tmp = C[left + 1].higher(S[i]);
				while (tmp != null && S[i][1] <= tmp[1]) {
					C[left + 1].remove(tmp);
					tmp = C[left + 1].higher(S[i]);
				}
				C[left + 1].add(S[i]);
			}
		}
		System.out.println(maxLen);
	}

	int nextA(int a, int M) {
		return 36969 * (a & M) + (a >> 16);
	}

	int nextB(int b, int M) {
		return 18000 * (b & M) + (b >> 16);
	}

	int nextVal(int a, int b, int C) {
		return (C & ((a << 16) + b)) % 1000000;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			int A = sc.nextInt();
			int B = sc.nextInt();
			if (m == 0 && n == 0 && A == 0 && B == 0)
				break;
			int[][] S = new int[m + n][3];
			for (int i = 0; i < m; ++i) {
				S[i][0] = sc.nextInt();
				S[i][1] = sc.nextInt();
				S[i][2] = sc.nextInt();
			}
			int a = A, b = B, C = ~(1 << 31), M = (1 << 16) - 1;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < 3; ++j) {
					a = nextA(a, M);
					b = nextB(b, M);
					S[i + m][j] = nextVal(a, b, C);
				}
			}
			Arrays.sort(S, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0])
						return Integer.compare(o1[0], o2[0]);
					else if (o1[1] != o2[1]) {
						return -Integer.compare(o1[1], o2[1]);
					} else {
						return -Integer.compare(o1[2], o2[2]);
					}
				}
			});

			int[][] tmp = new int[m + n][2];
			for (int i = 0; i < m + n; ++i) {
				tmp[i][0] = S[i][1];
				tmp[i][1] = S[i][2];
			}
			solve(m + n, tmp);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 491140
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int main()
    {
        ll n{},k{};
        cin>>n>>k;
        ll x = (ll)pow((k-1),(n-1));
        cout<<x*k<<endl;
        return 0;
    }

Measured memory_bytes: 256
# 全探索に終了条件を追加することで計算量を削減させるやり方
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


X, Y, Z, K = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ABC = []
for a in range(X):
    if a + 1 > K:
        break
    for b in range(Y):
        if (a + 1) * (b + 1) > K:
            break
        for c in range(Z):
            # a,b,cはA,B,Cの上から何番目に大きいか
            if (a + 1) * (b + 1) * (c + 1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])


ABC.sort(reverse=True)
ABC = ABC[:K]
print(*ABC, sep='\n')


Measured memory_bytes: 8708
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;
int main(){
    int a[MAX],n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    int maxv=-2000000000;
    int minv=a[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,a[i]-minv);
        minv=min(minv,a[i]);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3860
using System;
using System.Linq;

namespace ABC133_D___Rain_Flows_into_Dams
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ai = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            var sumRainfall = Ai.Sum();
            var rainFall = new long[N];

            rainFall[0] = sumRainfall;
            for (int i = 1; i < N; i += 2)
                rainFall[0] -= Ai[i] * 2;


            for (int i = 1; i < N; i++)
                rainFall[i] = 2 * Ai[i - 1] - rainFall[i - 1];

            Console.WriteLine(string.Join(" ", rainFall));
        }
    }
}


Measured memory_bytes: 31452
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int s = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        long mod = 998244353;
        long[][] dp = new long[n+1][s+1];
        dp[0][0] = 1;
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= s; j++){
                dp[i+1][j] += 2 * dp[i][j];
                dp[i+1][j] %= mod;
                if(j <= s-a[i]){
                    dp[i+1][j+a[i]] += dp[i][j];
                    dp[i+1][j+a[i]] %= mod;
                }
            }
        }
        System.out.println(dp[n][s]);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 96848
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0030().doIt();
	}
	class AOJ0030{
		int n,s;
		int dfs(int index,int sum,int cost){
			int result = 0;
			if(cost==n){
				if(sum==s)return 1;
				else return 0;
			}
			if(index>9)return 0;
			if(sum>s)return 0;
			result+=dfs(index+1,sum+index,cost+1);//indexをとる場合。
			result+=dfs(index+1, sum, cost);//indexを取らない場合。
			return result;
		}
		
		void doIt() {
			while(true){
				n = in.nextInt();
				s = in.nextInt();
				if(n+s==0)break;
				System.out.println(dfs(0,0,0));
			}
		}
	}
}

Measured memory_bytes: 18084
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("input.txt");ofstream coutt("output.txt");

int n,m,q,ans=0;
vvi v;
vi ass;

void f(int i,int lst){
    if(i==n){
        //cout<<ass<<"\n";
        int lolo=0;
        for(int j=0;j<q;j++){
            if(ass[v[j][1]-1]-ass[v[j][0]-1]==v[j][2]){
                lolo+=v[j][3];
            }
        }
        ans=max(ans,lolo);
        return;
    }
    
    for(int j=lst;j<=m;j++){
        ass.push_back(j);
        f(i+1,j);
        ass.pop_back();
    }
    
}

signed main(){
    FASTER;
    cin>>n>>m>>q;
    v=vvi(q,vi(4));cin>>v; 
    f(0,1);
    cout<<ans;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N;
ll L[100];

int main() {
  cin >> N;
  L[0] = 2;
  L[1] = 1;
  repe(i, 2, 86) { L[i] = L[i - 1] + L[i - 2]; }
  cout << L[N];
}


Measured memory_bytes: 3636
import math
N, K = map(int,input().split())
ans = 0
ans += (N//K)**3

if K%2 == 0:
    cnt = 0
    for i in range(1,N+1):
        if i%K == int(K/2):
            cnt += 1
    ans += cnt**3
    #ans += (math.ceil(N/K))**3
print(ans)

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

using namespace std;

/********************************MACROS********************************/

#define int long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define vt vector
#define pb push_back
#define F first
#define S second
#define u_s unordered_set
#define u_m unordered_map
#define p_q priority_queue

/*******************************DEBUGGER*******************************/

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

/******************************ALGORITHMS******************************/

int __pow(int x, int y, int M) {int res = 1;while(y>0){if(y&1) res = (res*x)%M; y>>=1; x = (x*x)%M;}return res%M;}
int gcd(int a, int b) {if(b==0) return a; return gcd(b, a % b);}

/******************************MAIN**CODE******************************/

const int N = 3e5+2, inf = 1e18, M = 1e9+7;

int test, n, m, k, query;

void test_case(){
    cin>>n;
    vt<int> a(n);
    for(auto &x:a) cin>>x;
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2; i<n; i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;
}
int32_t main(){
    test = 1;
    //cin>>test;
    while(test--)
        test_case();
#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}


Measured memory_bytes: 4824
N,M=(int(x) for x in input().split())
a=list(map(int, input().split()))
b=0
c=0
for i in range(N):
    b+=a[i]
    #print(i)
for i in range(N):
    if(a[i]>=b/(4*M)):c+=1
    #print(i)
if(c>=M):print('Yes')
else:print('No')


Measured memory_bytes: 3060
#include <stdio.h>
int	main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);
	int i = 13;
	while (i < 12625)
	{
		if (((i*8)/100) == a && ((i*10)/100) == b)
		{
			break;
		}
		i++;
	}
	if (i == 12625)
	{
		printf("-1");
		return (0);
	}
	printf("%d", i);
	return (0);
}


Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;

int main(){
  char S[4];
  int i;

  cin >> S;


  if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll x, y, z;
  if (a >= b){
    x = a - b;
  }
  else if(a<b){
    x = b - a;
  }
  if(b>=c){
    y = b - c;
  }
  else if(b<c){
    y = c - b;
  }
  if(a>=c){
    z = a - c;
  }
  else if(a<c){
    z = c - a;
  }
  bool ans = false;
  if(z<=d){
    ans = true;
  }
  else if(z>d){
    if(y<=d&& x<=d){
      ans = true;
    }
  }
  if(ans){
    print("Yes");
  }
  else{
    print("No");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int pt[3][5]={{0,1,3,1,0},{0,3,3,3,0},{1,3,5,3,1}};
int ax[12],ay[12],az[12];

int seach(int n,int (*da)[10]) {
	int i,j,k,x,y,x2,y2,z,f,d[10][10];
	f=0;
	for (i=0;i<10;i++) for (j=0;j<10;j++) {
		d[i][j]=da[i][j];
		if (f==0 && d[i][j]>0) { x=j; y=i; f=1; }
	}
	if (x==9 || y>8) return 0;
	if (n==-1) {
		f=0;
        for (i=0;i<10;i++) for (j=0;j<10;j++) if (d[i][j]>0) f=1;
		if (f==0) return 1; else return 0;
	}

	for (k=0;k<3;k++) {
		if (k==0) if (x==0) continue; else { x2=x; y2=y+1;}
		if (k==1) if (x>7) continue; else {x2=x+1;y2=y+1;}
		if (k==2) if (x<2 || x>7 || y>5) continue; else { x2=x; y2=y+2; }
        z=k+1; f=0;
		for (i=-(z+1)/2;i<=(z+1)/2;i++) for (j=-(pt[z-1][2+i])/2;j<=(pt[z-1][2+i])/2;j++) if (d[y2+j][x2+i]==0) f=1;
		if (f==0) {
			for (i=-(z+1)/2;i<=(z+1)/2;i++) for (j=-(pt[z-1][2+i])/2;j<=(pt[z-1][2+i])/2;j++) d[y2+j][x2+i]--;
			ax[n]=x2; ay[n]=y2; az[n]=z ; if (seach(n-1,d)==1) return 1;
            for (i=-(z+1)/2;i<=(z+1)/2;i++) for (j=-(pt[z-1][2+i])/2;j<=(pt[z-1][2+i])/2;j++) d[y2+j][x2+i]++;
		}
	}
    return 0;
}

int main() {
    int i,j,n,da[10][10];
	cin >> n;
	for (i=0;i<10;i++) for (j=0;j<10;j++) cin >> da[i][j];
	seach(n-1,da);
    for (i=0;i<n;i++) cout << ax[i] << " " << ay[i] << " " << az[i] << endl;
	return 0;
}

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

int main () {
    int n;
    int k;
    cin >> n >> k;
    int L[n];
    for (int i =0; i <n; i++){
        cin >> L[i];
    }
    sort(L,L+n);

    int ans = 0;
    for (int i=n-1; i>=n-k; i--){
        ans += L[i];
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    string s, t;
    cin >> s >> t;
    if(t.substr(0, s.size()) == s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;;
    return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
//using namespace __gnu_pbds;
//using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
const int mod=1e9+7;
int n,m;
int fact[500010],finv[500010];
ll modpow(ll a,ll n,ll mod) {
	ll r=1,b=a;
	while(n>0) {
		if(n&1)r=r*b%mod;
		b=b*b%mod;
		n>>=1;
	}
	return r;
}
int nCr(int n,int r) {
	if(r<0||r>n)return 0;
	return (ll)fact[n]*finv[r]%mod*finv[n-r]%mod;
}
void MAIN() {
	cin>>n>>m;
	fact[0]=finv[0]=1;
	rng(i,1,m){
		fact[i]=(ll)fact[i-1]*i%mod;
	}
	finv[m]=modpow(fact[m],mod-2,mod);
	gnr(i,m-1,1){
		finv[i]=(ll)finv[i+1]*(i+1)%mod;
	}
	ll ans=(ll)nCr(m,n)*nCr(m,n)%mod*fact[n]%mod*fact[n]%mod;
	rng(i,1,n) {
		ll val=(ll)nCr(n,i)*nCr(m,i)%mod*fact[i]%mod*nCr(m-i,n-i)%mod*nCr(m-i,n-i)%mod*fact[n-i]%mod*fact[n-i]%mod;
		if(i%2)ans=(ans+mod-val)%mod;
		else ans=(ans+val)%mod;
	}
	cout<<ans;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 7468
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll d[100000], r[100000];
int main()
{
	ll num;
	scanf("%lld", &num);
	ll s = 0;
	for (int i = 0; i < num; i++)scanf("%lld", &d[i]), s += d[i];
	bool f = true;
	if (s % (num*(num + 1) / 2) != 0)f = false;
	s /= (num*(num + 1) / 2);
	ll t = 0;
	for (int i = 0; i < num; i++)
	{
		int p = (i + num - 1) % num;
		if ((d[p] + s - d[i]) % num != 0)f = false;
		r[i] = (d[p] + s - d[i]) / num;
		if (r[i] < 0)f = false;
		t += r[i];
	}
	if (s != t)f = false;
	printf(f ? "YES\n" : "NO\n");
}

Measured memory_bytes: 1664
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

  ll a, b, k;
  cin >> a >> b >> k;

  ll a1, b1;
  if (a >= k) {
    a1 = a - k;
    b1 = b;
  } else {
    a1 = 0;
    b1 = b - (k - a);
    if (b1 < 0) b1 = 0;
  }

  cout << a1 << " " << b1 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

using P = pair<int, int>;

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

constexpr int64 INF = 1000000;

inline int mod2(int x) { return abs(x)%2; }

struct state {
    int x, y, t, c;
    state() {}
    ~state() {}
    state(int a, int b, int d, int e): x(a), y(b), t(d), c(e) {}
};

int Sx, Sy, Gx, Gy, N, X[1000], Y[1000], Lx, Ly;

int memo[201][201][6];
inline int set_memo(int x, int y, int t, int v) { return memo[x+100][y+100][t] = v; }
inline int get_memo(int x, int y, int t) { return memo[x+100][y+100][t]; }

int solve() {
    for (int j = 0; j < 201; ++j) for (int k = 0; k < 201; ++k)
        fill(memo[j][k], memo[j][k]+6, INF);
    set_memo(Sx, Sy, 0, 0);

    for (int j = 0; j < N; ++j) {
        set_memo(X[j], Y[j], 0, INF*2);
    }

    queue<state> que;
    que.emplace(Sx, Sy, 0, 0);
    while (!que.empty()) {
        state st = que.front(); que.pop();
        if (st.c > get_memo(st.x, st.y, st.t)) { continue; }
        int fd = abs(st.t * st.x * st.y) % 6;
        for (int d = 0; d < 7; ++d) {
            int nx = st.x + dx[mod2(st.x)][d], ny = st.y + dy[mod2(st.x)][d];
            if (abs(nx) > Lx || abs(ny) > Ly || get_memo(nx, ny, 0) > INF) continue;

            int nc = get_memo(st.x, st.y, st.t) + (fd == d ? 0 : 1);
            if (nc < get_memo(nx, ny, (st.t+1)%6)) {
                set_memo(nx, ny, (st.t+1)%6, nc);
                que.emplace(nx, ny, (st.t+1)%6, nc);
            }
        }
    }

    int ans = INF;
    for (int t = 0; t < 6; ++t) {
        ans = min(ans, get_memo(Gx, Gy, t));
    }
    return ans == INF ? -1 : ans;
}

int main() {
    cin >> Sx >> Sy >> Gx >> Gy >> N;
    for (int j = 0; j < N; ++j) {
        cin >> X[j] >> Y[j];
    }
    cin >> Lx >> Ly;
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 4236
#include<stdio.h>

int par[100000];
int rank[100000];

void init(int n){
		int i;
		for(i=0;i<n;i++){
				par[i]=i;
				rank[i]=0;
		}
}

int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
}

void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y])par[x]=y;
		else{
				par[y]=x;
				if(rank[x]==rank[y])rank[x]++;
		}
}

int same(int x,int y){
		if(find(x)==find(y))return 1;
		else return 0;
}


int main(){
		int n,m,i;
		int p[100000];
		int xy[100000][2];
		scanf("%d%d",&n,&m);
		for(i=0;i<n;i++){
				scanf("%d",&p[i]);
				p[i]--;
		}for(i=0;i<m;i++){
				scanf("%d%d",&xy[i][0],&xy[i][1]);
				xy[i][0]--;
				xy[i][1]--;
		}
		init(n);
		for(i=0;i<m;i++)unite(xy[i][0],xy[i][1]);
		int ans=0;
		for(i=0;i<n;i++)ans+=same(p[i],i);
		printf("%d\n",ans);
		return 0;
}


Measured memory_bytes: 2048
n1,n2 = gets.chomp.split(" ").map(&:to_i)
count = n1
ans = 0
count2 = 0
while count > 1
  if n2 >= 2**(count+1) - 1 + count2
    n2 -= 2**(count+1) - 1 + count2
    ans += 2**count
    count2 = 0
  else
    count2 += 1
  end
  count -= 1
end
if n2 - count2 >= 4
  ans += 3
elsif n2 - count2 == 3
  ans += 2
elsif n2 - count2 == 2
  ans += 1
end
p ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
string s;
long long r,k;
int main(){
cin>>s;
for(int i=0;i<3;i++){
    if(s[i]=='R')k++;
}
if(k==3)cout<<k;
else{


for(int i=0;i<3;i++){
if(s[i]==s[i+1]&&s[i]=='R'){
                r+=2;break;}
        else if(s[i]=='R'&&s[i+1]!='R'){
                r++;break;
        }

}
 cout<<r;}

    return 0;}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, k;
    cin >> n >> k;
    if ((n+1)/2 >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B,C,D;
  cin >> N;
  A = N / 1000;
  B = (N % 1000) /100 ;
  C = (N % 100)/10;
  D = (N % 10);
  
  if (A == B && B == C) cout << "Yes" << endl;
  else if (B == C && C == D) cout << "Yes" << endl;
  else if (A == B && B == C && C == D ) cout << "Yes" << endl;
  else cout << "No" << endl;
  

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K; cin >> N >> K;
  vector<int> h;
  for (int i = 0; i < N; i++) {
    int x; cin >> x; h.push_back(x);
  }
  sort(h.begin(), h.end());
  int res = 1e9;
  for (int i = 0; i < N-K+1; i++) {
    res = min(res, h[i+K-1]-h[i]);
  }
  cout << res << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll a[1010],b[1010],dp[10100],n;
const ll Inf = 1e18;

ll Rec(ll h){

    if(h <= 0)   return 0;

    if(dp[h] != -1)  return dp[h];

    ll Res = Inf;

    for(int i = 0;i<n;i++){
        Res = min(Res , b[i] + Rec(h - a[i]));
    }
    return dp[h] = Res;
}

int main()
{
    memset(dp , -1 , sizeof(dp));
    ll h;  cin >> h >> n;
    for(int i = 0;i<n;i++)  cin >> a[i] >> b[i];
    cout << Rec(h);
    return 0;
}


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

int main(){

    #ifndef ONLINE_JUDGE
    freopen( "input.txt", "r", stdin);
    #endif

    int a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k<=a) cout << k;
    else if(k>a && k<=a+b) cout << a;
    else cout << a-(k-(a+b));

    return 0;
}

Measured memory_bytes: 3636
while True:
    s = input().split()
    n = int(s[0])
    x = int(s[1])

    if n==0 and x==0:
        break

    sum = 0
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                #print("i:",i+1,"j:",j+1,"k:",k+1)
                if i+j+k+3==x:
                    sum+=1

    print(sum)




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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	ll ans = 0;
	vi v;
	REP(i, 0, n){
		if(i >= k && t[i] == t[i-k] && v[i-k] > 0) v.PB(0);
		else{
			if(t[i] == 's') v.PB(r);
			else if(t[i] == 'r') v.PB(p);
			else v.PB(s);
		}
		ans += v[i];
	}
	cout<< ans;

}


Measured memory_bytes: 1020
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	int z = min(n, m);
	rep(i, max(n,m)) {
		cout << z;
	}
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);
    
    while (in.hasNext()) {
      double T = in.nextDouble();
      double X = in.nextDouble();
      
      System.out.println(T / X);
    }
  }   
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF LLONG_MAX
int n,k;

int main()
{
    cin>>n>>k;
    ll h[n];
    
    for(ll i=0;i<n;i++)
    {
        cin>>h[i];
    }
    
    ll t[n];

     for(ll i=1;i<n;i++)
    {
        t[i]=INF;
    }
        t[0]=0;
    
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k && i+j<n;j++)
        {
            
            t[i+j]=min(t[i+j],t[i]+abs(h[i]-h[i+j]));
        }
    }
    
    cout<<t[n-1]<<"\n";
    
    return 0;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  sort(all(b));
  int c=0;
  rep(i,a-1)
    c+=b[i];
  c+=b[a-1]/2;
  out(c);
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	fmt.Fprintln(writer, (n+1)/2)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;    
#define int long long        
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar) for(int pen=0;pen<sizeof(ar)/8;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rt return 0;
#define mod 1000000007
const int N= 8*1e5+ 10;
int st[N]={0};
void update(int ss, int se, int i, int diff, int si)  
{  
    // Base Case: If the input index lies outside the range of  
    // this segment  
    if (i < ss || i > se)  
        return;  
  
    // If the input index is in range of this node, then update  
    // the value of the node and its children  
    st[si] = st[si] + diff;  
    if (se != ss)  
    {  
        int mid = (ss+se)/2;  
        update(ss, mid, i, diff, 2*si);  
        update(mid+1, se, i, diff, 2*si + 1);  
    }  
}  
int get_sum(int ss, int se, int qs, int qe, int si)  
{  
    // If segment of this node is a part of given range, then return  
    // the sum of the segment  
    if (qs <= ss && qe >= se)  
        return st[si];  
  
    // If segment of this node is outside the given range  
    if (se < qs || ss > qe)  
        return 0;  
  
    // If a part of this segment overlaps with the given range  
    int mid = (ss+se)/2;
    return get_sum(ss, mid, qs, qe, 2*si) +  
        get_sum(mid+1, se, qs, qe, 2*si+1);  
} 
signed main()
{
    int n,k;
    cin>>n>>k;
    int ar[n];
    sc(ar,n);
    int dp[n]={0};
    dp[0]=0;
    dp[1]=abs(ar[1]-ar[0]);
    for(int i=2;i<n;i++){
        int mn=1000000000000;
        for(int j=1;j<=k;j++){
            if(( i-j )>=0)
            mn=min(dp[i-j]+abs( ar[i]-ar[i-j] ),mn);
        }
        dp[i]=mn;
    }
    cout<<dp[n-1]<<endl;
}

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

int main(){
    int n,fl_ab = 0,first_b = 0,last_a = 0,ab = 0;
    cin >> n;
    vector<string> s(n);
    for(int i = 0;i < n;i++){
        cin >> s[i];
        for(int j = 1;j < (int)s[i].size();j++){
            if(s[i][j - 1] == 'A' && s[i][j] == 'B')ab++;
        }
        if(s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A')fl_ab++;
        else if(s[i][0] == 'B')first_b++;
        else if(s[i][s[i].size() - 1] == 'A')last_a++;
    }
    if(fl_ab > 0){
        ab += fl_ab - 1;
        if(first_b > 0){
            ab++;
            first_b--;
        }
        if(last_a > 0){
            ab++;
            last_a--;
        }
    }
    ab += min(first_b,last_a);

    cout << ab << endl;
}

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

int main() {
  int x,n;
  cin>>x>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  map<int,int>mp;
  for(int i=0;i<n;i++){
    if(mp.count(a[i]))mp.at(a[i])++;
    else mp[a[i]]=1;
  }
  int shou=-100;
  int dai=200;
  int sa_shou=1000,sa_dai=1000;
  for(int i=x;i>=-100;i--){
    int tmp=x-i;
    if(sa_shou>tmp){
      bool hantei=true;
      for(int j=0;j<n;j++){
        if(i==a[j]){
          hantei=false;
          break;
        }
      }
      if(hantei){
        sa_shou=tmp;
        shou=i;
      }
    }
  }
  for(int i=x;i<200;i++){
    int tmp=i-x;
    if(sa_dai>tmp){
      bool hantei=true;
      for(int j=0;j<n;j++){
        if(i==a[j]){
          hantei=false;
          break;
        }
      }
      if(hantei){
        sa_dai=tmp;
        dai=i;
      }
    }
  }
  if(sa_shou<=sa_dai)cout<<shou<<endl;
  else cout<<dai<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
typedef vector<pairs> p;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    ll t[n];
    for(ll i=0;i<n;++i){
        cin>>t[i];
    }
    ll ans = 1;
    for(ll i=0;i<n;++i){
        ans = lcm(ans, t[i]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	int T;cin>>T;
	while(T--){
		llint n,A,B,C,D,ans=0;cin>>n>>A>>B>>C>>D;
		//逆方向に操作する
		priority_queue<pair<llint,llint>,vector<pair<llint,llint>>,greater<pair<llint,llint>>>que;
		que.push(mp(-inf,n));
		map<llint,llint> dist;
		while(que.size()){
			llint c,K,S;tie(c,K)=que.top();que.pop();
			if(dist[K]<c){continue;}
			if(1.0*K*D<1e18){chmin(ans,c+K*D);}//VS overflow 
			if(K==0){break;}
			
			S=(K-K%2)/2;
			if(chmin(dist[S],c+ D*(K%2) +A)){que.push(mp(c+ D*(K%2) +A,S));}
			
			S=(K+2-K%2)/2;
			if(chmin(dist[S],c+ D*(2-K%2) +A)){que.push(mp(c+ D*(2-K%2) +A,S));}
			
			S=(K-K%3)/3;
			if(chmin(dist[S],c+ D*(K%3) +B)){que.push(mp(c+ D*(K%3) +B,S));}
			
			S=(K+3-K%3)/3;
			if(chmin(dist[S],c+ D*(3-K%3) +B)){que.push(mp(c+ D*(3-K%3) +B,S));}
			
			S=(K-K%5)/5;
			if(chmin(dist[S],c+ D*(K%5) +C)){que.push(mp(c+ D*(K%5) +C,S));}
			
			S=(K+5-K%5)/5;
			if(chmin(dist[S],c+ D*(5-K%5) +C)){que.push(mp(c+ D*(5-K%5) +C,S));}
			
			//cerr<<"K="<<K<<"c="<<c<<endl;
		}
		cout<<ans+inf<<endl;
	}
	
	return 0;
}


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

int main(){
	string str[3];
	int num,count = 0,i;
	cin >> str[0] >> num;
	for(i = 0;i < num; i++){
		cin >> str[1];
		str[2] = str[1];
		str[2] += str[1];
		if(str[2].find(str[0]) != string::npos){
			count++;
		} 
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1212
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}

int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int Max =X;
	int p;
	for (int i = 0; i < N; i++) {
		cin >> p;
		Max = max(p, Max);
	}
	int Min = Y;
	for (int i = 0; i < M; i++) {
		cin >> p;
		Min = min(Min, p);
	}
	if (Max < Min) {
		cout << "No War" << endl;
	} else {
		cout << "War" << endl;
	}
}



Measured memory_bytes: 256