akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll  long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}


int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
        

fast();
//ll t;cin>>t;while(t--)
{
    ll X,f=0,a=0,b=0;
    cin>>X;
    for(int i=-120;i<=120;i++)
    {
        for(int j=-120;j<=120;j++)
        {
            if(1ll*i*i*i*i*i-1ll*j*j*j*j*j==X)
            {
                a=i,b=j;
                  f=1;
                  break;
                break;
            }
        }
        if(f)
            break;

    }

    cout<<a<<" "<<b<<endl;
}
return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>

using namespace std;

int main() {
    int N, q, time;
    string name;
    queue<pair<string, int> > Q;
    
    cin >> N >> q;
    for (int i = 0; i < N; i++) {
        cin >> name >> time;
        Q.push(make_pair(name, time));
    }
    
    pair<string, int> u;
    int elps = 0, a;

    while (!Q.empty()) {
        u = Q.front(); Q.pop();
        a = min(u.second, q);
        u.second -= a;
        elps += a;
        if (u.second > 0) {
            Q.push(u);
        } else {
            cout << u.first << " " << elps << endl;
        }
    }   

    return 0;
}


Measured memory_bytes: 6304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}



ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int L,R,d;cin>>L>>R>>d;
	int ans = 0;
	for(int i = L; i <= R; i++) if(i%d==0) ans++;
	out(ans);
}

Measured memory_bytes: 3584
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(b % a == 0){
            System.out.println(a + b);
        } else {
            System.out.println(b - a);
        }

    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tc() ll T;cin>>T;while(T--)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    /*-----------------Code Begins Here------------------*/
    
    ll n,k; cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    for(ll i=k,j=0;i<n;i++,j++){
        if(a[i]>a[j]) cout<<"Yes\n";
        else cout<<"No\n";
    }
    
    /*------------------Code Ends Here-------------------*/
    
    return 0;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    int N;
    cin >> N;
    vector<bool[10]> F(N);
    vector<int[11]> P(N);
    // int num[10];

    rep(i, N)
    {
        rep(j, 10)
        {
            cin >> F[i][j];
        }
    }
    rep(i, N)
    {
        rep(j, 11)
        {
            cin >> P[i][j];
        }
    }
    ll Max = LONG_LONG_MIN;
    for (int bit = 1; bit < (1 << 10); bit++)
    {
        ll tmp = 0;
        int c[N];
        rep(i, N)
        {
            c[i] = 0;
        }
        rep(j, 10)
        {
            if (bit & (1 << j))
            {
                rep(i, N)
                {
                    c[i] += F[i][j];
                }
            }
        }
        rep(i, N)
        {
            tmp += P[i][c[i]];
        }
        Max = max(Max, tmp);
    }
    cout << Max;
    return 0;
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.println(Main.calc(s.nextInt()));
	}

	public static int calc(int n) {
		int res = n;
		for (int a = 1; a < n; a++) {			
			int b = n - a;
			int cal = Main.calcKeta(a) + Main.calcKeta(b);
			res = Math.min(cal, res);
		}

		return res;
	}

	private static int calcKeta(int n) {
		return (n == 0) ? 0 : n % 10 + Main.calcKeta(n / 10);
	}
}

Measured memory_bytes: 22228
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  int K;
  cin >> K;
  string S;
  cin >> S;
  const int N = K + S.length();
  constexpr long long kMod = 1000000007;
  auto modpow = [&](long long a, int b) {
  	long long r = 1;
  	for (; b > 0; b /= 2) {
  		if (b % 2) r = r * a % kMod;
  		a = a * a % kMod;
  	}
  	return r;
  };
  auto inv = [&](int a) { return modpow(a, kMod - 2); };
  vector<long long> fact(N + 1, 1);
  for (int i = 0; i < N; ++i) fact[i + 1] = fact[i] * (i + 1) % kMod;
  vector<long long> inv_fact(N + 1);
  inv_fact[N] = inv(fact[N]);
  for (int i = N; i > 0; --i) inv_fact[i-1] = inv_fact[i] * i % kMod;
  auto c = [&](int n, int r){
  	return fact[n] * inv_fact[n-r] % kMod * inv_fact[r] % kMod;
  };
  long long m25 = 1;
  long long ans = 1;
  for (int i = 1; i <= K; ++i) {
  	m25 = m25 * 25 % kMod;
  	ans += c(N, i) % kMod * m25 % kMod;
  	if (ans > kMod) ans -= kMod;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 35588
from collections import deque
K = int(input())
E = [[((i + 1) % K, 1)] for i in range(K)]
for i in range(1, K):
	E[i].append((i * 10 % K, 0))
Q = deque([(1, 1)])
reached = set()
while 1:
	tmp_node, tmp_cost = Q.popleft()
	if tmp_node == 0:
		ans = tmp_cost
		break
	if tmp_node in reached:
		continue
	reached.add(tmp_node)
	for nxt, dist in E[tmp_node]:
		if dist == 0:
			Q.appendleft((nxt, tmp_cost))
		else:
			Q.append((nxt, tmp_cost + 1))
print(ans)


Measured memory_bytes: 46572
#include<stdio.h>

int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if (a < b){
    printf("a < b\n");
      } else if (a == b){
    printf("a == b\n");
      } else if (a > b){
    printf("a > b\n");
      };
  return 0;
}

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

int main(){
  string s;
  int left,right;
  int kekka;
  
  cin >> s;
  
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 'A'){
      left = i;
      break;
    }
  }
  
  for(int i = s.size()-1; i > 0; i--){
    if(s.at(i) == 'Z'){
      right = i;
      break;
    }
  }
  
  kekka = s.size() - left - (s.size() - right - 1);
  cout << kekka;
}

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

#define INF 1000000000000
#define MOD 1000000007

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

    ll n, ans=0;
    cin>>n;
    
    for(int i=1; i<n; i++){
        ans+=n/i;
        if(n%i==0){
            ans--;
        }
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
k,s=map(int,input().split())
cnt=0
for z in range(0,min(k+1,s+1)):
  s_=s-z
  if s_<=k:
    cnt+=(s_+1)
  else:
    v=s_-k
    if v<=k:
      cnt+=(k-v+1)
print(cnt)

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

int main() {
   int x;
   cin >> x;
   if(x >= 400 && x <= 599) cout << 8 << endl;
   if(x >= 600 && x <= 799) cout << 7 << endl;
   if(x >= 800 && x <= 999) cout << 6 << endl;
   if(x >= 1000 && x <= 1199) cout << 5 << endl;
   if(x >= 1200 && x <= 1399) cout << 4 << endl;
   if(x >= 1400 && x <= 1599) cout << 3 << endl;
   if(x >= 1600 && x <= 1799) cout << 2 << endl;
   if(x >= 1800& x <= 1999) cout << 1 << endl;
}

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

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

const int INF = 1001001001;
vector<int> A(100100);
vector<int> dp(100100);

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

  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < 100100; ++i) dp.at(i) = INF;
  
  dp.at(0) = 0;
  dp.at(1) = abs(A.at(1) - A.at(0));
  
  for (int i = 0; i < N; i++){
    chmin(dp.at(i + 1), dp.at(i) + abs(A.at(i) - A.at(i + 1)));
    chmin(dp.at(i + 2), dp.at(i) + abs(A.at(i) - A.at(i + 2)));
  }

  cout << dp.at(N-1) << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  int sum=0;
  for(int i=0;i<k;i++)
    sum+=a[i];
  cout<<sum;
return 0;
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


int query(int a, int b, int c, int d) {
  cout << "? " << a << " " << b << " " << c << " " << d << "\n";
  int r;
  cin >> r;
  return r;
}

int main(void){
  ios::sync_with_stdio(false);
  int h, w, n;
  ll k;
  cin >> h >> w >> n >> k;
  ll sum = 0;
  ll cur = 1;
  REP(i, 0, h) {
    REP(j, 0, w) {
      int res = query(i, j, i, j);
      sum = (sum + res * cur) % k;
      cur = cur * 2 % k;
    }
  }
  cout << "! " << sum << "\n";
}


Measured memory_bytes: 596
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in range(n):
    dic[a[i]]+=1
ans = 0
for j in dic:
    ans += dic[j]*j

Q= int(input())
for q in range(Q):
    b, c = map(int, input().split())
    s= dic[b]*(c-b)
    ans += s
    
    dic[c]+=dic[b]
    dic[b]=0
    
    print(ans)

Measured memory_bytes: 89664
n = int(input())
l = list(map(int, input().split()))
l.sort()
a = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]+l[j] > l[k] and l[i] != l[j] and l[j] != l[k]:
                a += 1
print(a)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++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; }
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<long long> h(100010);
    rep(i,n) {
     cin >> h[i];
    }
    
    
   const long long INF = 1LL << 60;
   long long dp[100010];
   
    
    for(int i = 0;i < 100010;i++) {
     dp[i] = INF;
    }
    dp[0] = 0;
    
    for(int i = 0;i<n;i++) {
     chmin(dp[i+1], dp[i]+abs(h[i] - h[i+1]));
     chmin(dp[i+2], dp[i]+abs(h[i] - h[i+2]));
     }
    
    cout << dp[n-1];
}

Measured memory_bytes: 4844
using System;

namespace ABC135
{
    class A
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            if ((A + B) % 2 == 0)
            {
                Console.WriteLine((A + B) / 2);
            }
            else
            {
                Console.WriteLine("IMPOSSIBLE");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n, k;
  while (scanf("%d %d", &n, &k) != EOF)
  {
    int fruits[n]; for (int i = 0; i < n; i++) scanf("%d", &fruits[i]);
    sort(fruits, fruits+n);
    int ans = 0;
    for (int i = 0; i < k; i++) ans += fruits[i];
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int ans = 0;
  
  vector<vector<int>> data(K, vector<int>(N));
  

  for (int i = 0; i < K; i++) {
    
    int d;
    cin >> d;
    
    for (int j = 0; j < d; j++) {
      
        cin >> data.at(i).at(j);
      
    }
  }
  
  for (int i = 0; i < N; i++) {
    int x = 0;
    for (int j = 0; j < K; j++) {
      
      for (int k = 0; k < data.at(j).size(); k++) {
        if (data.at(j).at(k) == i + 1){
          x = 1;
        }
      }
    }
      if (x == 0){
        ans++;
      }
      
   
  }
  
 cout << ans;
 
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;






int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int r;
	cin >> r;
	r*=r;
	c(r);
	ed;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
const int MAX_V = 10000; // 1??????????????°??´???°??¨?????????
int prime[10000]; // 1???????´???°,0???????´???°????????°???????
int main(){
	int i, k, n;
	int border[10];
	for( i = 2; i <= MAX_V; i++) {
		prime[i] = 1; // 2??\?????°??´???°??¨??????
	}
	for(i = 2; i*i <= MAX_V; i++){
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i){
				prime[k] = 0; // ?´???°??°?2?????\?????°??????°??°??´???°????????°???????
			}
		}
	}
	while(1){
		scanf("%d", &n);
		if( n == 0) break;
		int max;
		for( i = n; i >= 2; i--){
			if( prime[i]){
				if( prime[i - 2]){
					max = i;
					break;
				}
			}
		}
		printf("%d %d\n", max -2, max);
	}
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	ll n; cin >>n;
	vector<int> a(n);
	cinf(n,a);
	int cnt2=0;
	int cnt4=0;
    int max=-1;
	for(int i=0;i<n;i++){
		if(a[i]%2 ==0 &&a[i]%4!=0)cnt2++;
		if(a[i]%4==0)cnt4++;
	}
	if(cnt4>0 && cnt2==0){
		max=cnt4*2+1;
	}
	if(cnt4>0 && cnt2>0){
		max=cnt4*2+cnt2;
	}
	if(cnt4==0 && cnt2>0){
		if(cnt2==n)max=n;
		else max=-1;
	}
	cout << (max>=n?"Yes":"No")<< endl;
}

Measured memory_bytes: 640
import numpy as np
n,k = map(int,input().split())

p = np.array(input().split(),np.int)


fs = p[:k]
f = sum(fs)
m = n - k + 1
qs = np.zeros(m)
qs[0] = f
if n == k:
    ans = (f + k)/2
    print(ans)
else:
    for i in range(k,n):
        a = qs[i-k] - p[i-k] + p[i]
        qs[i-k+1] = a
    ans = (max(qs)+k) / 2
    print(ans)
    


Measured memory_bytes: 32212
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

n = 0
ans = []
for i in range(h):
    for j in range(w-1):
        if a[i][j] % 2 == 1:
            a[i][j+1] += 1
            a[i][j] -= 1
            n += 1
            ans.append([i+1, j+1, i+1, j+2])

for i in range(h-1):
    if a[i][w-1] % 2 == 1:
        a[i+1][w-1] += 1
        a[i][w-1] -= 1
        n += 1
        ans.append([i+1, w, i+2, w])

print(n)
for i in ans:
    print(*i)

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

int main(){
  int n;
  cin>>n;
  int amt;
  cin>>amt;
  int a[n];
  for(int i=0;i<n;++i)cin>>a[i];
  sort(a,a+n);
  int ans=0;
  for(int i=0;i<n-1;++i){
    if(a[i]<=amt){
        amt-=a[i];
        ans++;
    }
  }
  if(a[n-1]==amt)ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n;
  while(cin >> n,n){
    int dp[301][301]={};
    int num[n];
    REP(i,n){
      cin>>num[i];
      if(i!=0&&abs(num[i]-num[i-1])<2){
	dp[i-1][i]=2;
      }
    }
    for(int i=2;i<n;i++){
      for(int j=0;j<n-i;j++){
	for(int k=0;k<i;k++){
	  dp[j][j+i]=max(dp[j][j+i],dp[j][j+k]+dp[j+k+1][j+i]);
	  if(dp[j+1][j+i-1]==i-1){
	    if(abs(num[j]-num[j+i])<2)
	      dp[j][j+i]=i+1;
	    else
	      dp[j][j+i]=max(i-1,dp[j][j+i]);
	  }
	}
      }
    }
    cout<<dp[0][n-1]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3364
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<long long int, P> Q;

int main() {
    long long int n, m;
    cin >> n >> m;
    long long int x, y, z;
    vector< vector<P> > mp(n);
    for (long long int i = 0; i < m; i++) {
        cin >> x >> y >> z;
        if (z % 2 == 0) {
            mp[x-1].push_back(P(y-1, 0));
            mp[y-1].push_back(P(x-1, 0));
        } else {
            mp[x-1].push_back(P(y-1, 1));
            mp[y-1].push_back(P(x-1, 1));
        }
    }
    vector<long long int> ans(n, 0);
    long long int count = 0;

    priority_queue<P, vector<P>, less<P> > pq;

    for (long long int i = 0; i < n; i++) {
        long long int sz = mp[i].size();
        pq.push(P(sz, i));
    }
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        if (ans[p.second] == 0) {
            count++;
            ans[p.second] = 2;
            queue<long long int> q;
            q.push(p.second);
            while (!q.empty()) {
                long long int qq = q.front();
                q.pop();
                for (long long int i = 0; i < mp[qq].size(); i++) {
                    P pp = mp[qq][i];
                    if (ans[pp.first] == 0) {
                        if (pp.second == 1) {
                            ans[pp.first] = 3 - ans[qq];
                        } else {
                            ans[pp.first] = ans[qq];
                        }
                        q.push(pp.first);
                    }
                } 
            }
        }
        //cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << endl;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<='9'); c = getchar());  register long long a=c-'0';
    for(c = getchar(); c>='0' && c<='9'; c = getchar())
        a = (a<<3)+(a<<1)+c-'0';
    return a;
}
const ll N = 59;
string a;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a;
    cout<<((a[1] == a[2] and (a[0] == a[1] or a[2] == a[3])) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
n = int(input())
X = input()
x = int(X,2)
bitx = bin(x).count('1')
 
ans = [0]*(bitx+2)
for i in range(1,bitx+2):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
bitp = bitx + 1
bitm = bitx - 1
xmp = 0
xmm = 0


if bitx != 1:
    for i in range(n):
        if X[i] == '1':
            xmp += pow(2, n-(i+1), bitp)
            xmm += pow(2, n-(i+1), bitm)
    for i in range(n):
        if X[i] == '1':
            xm = (xmm - pow(2,n-i-1,bitm)) % bitm
            l.append(str(1+ans[xm]))
        else:
            xm = (xmp + pow(2,n-i-1,bitp))%bitp
            l.append(str(1+ans[xm]))
 
else:
    for i in range(n):
        if X[i] == '1':
            xmp += pow(2, n-(i+1), bitp)
    for i in range(n):
        if X[i] == '1':
            l.append(str(0))
        else:
            xm = (xmp + pow(2,n-i-1,bitp))%bitp
            l.append(str(1+ans[xm]))
 
print('\n'.join(l))


Measured memory_bytes: 89692
/* ex9_2
   nabe9393 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100001
//キュー内の各データの定義
typedef struct node{
  int elem;
  struct node *next;
}node;

//データを追加
void push(node **first, char elem){
  //追加する分の領域を確保
  node *new = calloc(1, sizeof(node));
  if(new == NULL) exit(1);
  new->elem = elem;
  //追加
  new->next = *first;
  //追加したものを先頭に
  *first = new;
}
 
//スタックからデータを取り出す
char pop(node **first){
  char elem;
  node *tmp = *first;
  if(tmp == NULL) exit(1);
  elem = tmp->elem;
  *first = tmp->next;
  //取り出したノードのメモリを解放
  free(tmp);
}
 
 
int main(void){
  //最終的な答え
  int count=0, i;
  char cube[SIZE];
  //ノードの先頭
  node *first=NULL;
  scanf("%s",cube);

  for(i=0;i<strlen(cube);i++){
    if(first==NULL || cube[i]==first->elem){
      //スタックにノードを追加
      push(&first,cube[i]);
    }
    else{
      //スタックからデータを取り出す
      pop(&first);
      //2追加
      count=count+2;
    }
  }
  //答えの出力
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 4900
from itertools import tee,count
N = int(input())
H0,H1,H2 = tee(map(int,input().split()), 3)
next(H2)

dp = [0, abs(next(H2)-next(H1))]

for i,h0,h1,h2 in zip(count(1), H0,H1,H2):
  dp.append(min(dp[i]+abs(h2-h1), dp[i-1] + abs(h2-h0)))

print(dp[-1])


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

using namespace std;

#define topper top //XDDDDDDD

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

const ld EPS = 1e-9;
const ld PI = acos(-1);

const int N = 3e2+5;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

int n;
char grid[N][N];
char aux[N][N];

bool check(int k) {
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      aux[i][j] = grid[(i+k)%n][j];
    }
  }

  for(int i=0; i<n; i++) {
    for(int j=i; j<n; j++) {
      if(aux[i][j] != aux[j][i]) return false;
    }
  }

  return true;
}

int main(){
  //freopen("in", "r", stdin);
  //freopen("out", "w", stdout);

  scanf("%d", &n);
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      scanf(" %c", &grid[i][j]);
    }
  }

  int ans = 0;
  for(int i=0; i<n; i++) if(check(i)){
    ans += n;
  }

  printf("%d\n", ans);

	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr int inv(LL x, int m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr int mpow(LL a, LL k, int m) { int r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }


const int Mod = 998244353;
int main() {
    int n;
    scanf("%d", &n);
    vector<int> A(n + 1);
    FI(i, 1, n) scanf("%d", &A[i]);
    sort(A.begin() + 1, A.end());
    int ans = A[1] % Mod;
    FI(i, 2, n) ans = 1LL * ans * __gcd(A[i], i - 1) % Mod;
    cout << ans << endl;
}


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

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

class Prime {
private:
	void Eratos(lint N) {
		for (lint i = 2; i * i < N; i++) {
			if (Ptb[i]) {
				for (int j = 0; i * (j + 2) < N; j++) {
					Ptb[i *(j + 2)] = 0;
				}
			}
		}
	}
public:
	vector<int> Ptb;
	
	Prime(lint N = 10000) : Ptb(N + 1, 1) { Eratos(N + 1); }
	
	vector<pair<lint,int>> Pfact(lint num) {
		vector<pair<lint, int>> res;
		for (lint i = 2; i * i <= num; i++) {
				int cnt = 0;
				while (num % i == 0) {
					cnt++;
					num /= i;
				}
				if(cnt) res.emplace_back(i, cnt);
		}
		if (num != 1) res.emplace_back(make_pair(num, 1));
		return res;
	}

	bool isPrime(lint num) {
		if (num < 2) return false;
		else if (num == 2 || num == 3) return true;
		else if (num % 2 == 0 || num % 3 == 0) return false;
		else if (num % 6 != 1 && num % 6 != 5) return false;
		for (lint i = 5; i * i <= num; i += 6) {
			if (num % i == 0) return false;
			if (num % (i + 2) == 0) return false;
		}
		return true;
	}
};

lint gcd(lint a, lint b) { return b ? gcd(b, a%b) : a; }

int main() {
	
	cin.tie(0);

	int N;
	cin >> N;

	vector<lint> a(N + 1), ans;
	FOR(i, 0, N + 1) cin >> a[i];

	Prime p(N);

	for (int prime = 2; prime <= N; prime++) {

		if (p.Ptb[prime]) {

			vector<lint> mod(prime);
			FOR(i, 0, N + 1) mod[i % (prime - 1)] += a[i];

			bool flag = !(a[N] % prime);
			FOR(i, 0, prime) {
				if (mod[i] % prime) {
					flag = false;
					break;
				}
			}

			if (flag) ans.emplace_back(prime);
		}
	}

	lint a_gcd = 0;
	FOR(i, 0, N + 1) a_gcd = gcd(a_gcd, abs(a[i]));

	auto pfac = p.Pfact(a_gcd);
	for (const auto &elem : pfac) ans.emplace_back(elem.first);

	sort(ans.begin(), ans.end());
	unique(ans.begin(), ans.end());
	for (const auto& elem : ans) cout << elem << "\n" ;

	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include <cassert>
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int N,M,K;
const int mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){} //コンストラクタ
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {//前計算O(n)
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>M>>K;
    mint ans = 0;
    mint m = M;
    rep(k,K+1){

        ans+= (m*c(N-1,k)*(m-1).pow(N-1-k));
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int N = 1e6;
    vector<int> isprime(N + 5, 1);
    vector<int> primes;
    vector<int> SPF(N + 5);
    isprime[0] = isprime[1] = 0;
    for (int i = 2; i < N; i++)
    {
        if (isprime[i])
            primes.push_back(i), SPF[i] = i;
        for (int j = 0; j < primes.size() && i * primes[j] < N && primes[j] <= SPF[i]; j++)
            isprime[i * primes[j]] = 0, SPF[i * primes[j]] = primes[j];
    }
    int x;
    cin >> x;
    for (int i = x;; i++)
        if (isprime[i])
            return cout << i, 0;
}

Measured memory_bytes: 8700
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
ll h[100000];
ll dp[100001];

int main() {
    cin >> n;
    rep(i,n) cin >> h[i];
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        if (i == 1) dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        else dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
}



Measured memory_bytes: 1792
//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	ll N, M;cin >> N >> M;
	vector<ll> L(M), R(M);
	rep(i,M) cin >> L[i] >> R[i];

	sort(ALL(L));
	sort(ALL(R));


	if(R[0] - L[M-1] + 1 < 0) cout << 0 << endl;
	else cout << R[0] - L[M-1] + 1 << endl; 
}	

Measured memory_bytes: 12776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
int main(){
    int N,M;
    cin >> N >> M;
    int maxid = INF;
    int minid = 0;
    rep(i,M){
        int l,r;
        cin >> l >> r;
        minid = max(minid,l);
        maxid = min(maxid,r);
    }
    if(maxid >= minid){
        cout << maxid - minid +1 << endl;
    }else{
        puts("0");
    }
    return 0;
}

Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

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

int main()
{
    int k,n;
    cin>>k>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int max=0;
    for(int i=1;i<n;i++)
    {
        if(arr[i]-arr[i-1]>max)
        max=arr[i]-arr[i-1];
    }
    int temp=k-arr[n-1]+arr[0];
    if(temp>max)
    max=temp;
    cout<<(k-max);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  for(int i = 0; i < 100; i++) for(int j = 0; j < 100; j++){
    if(i*4 + j*7 == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>

#define ll long long
#define vl vector<ll>
#define vll vector<vl>

const int INF = 1e9;

ll mod=1000000007;

int edge[210][210];

int col[210];

bool muri=false;

int n;

bool dfs(int from, int co)
{
	col[from]=co;
	rep(to, n)
	{
		if(edge[from][to])
		{
			if(col[to]==co)
			{
				return false;
			}
			if(col[to]==0)
			{
				if(!dfs(to, -co))
				{
					return false;
				}
			}
		}
	}
	return true;
}

int main() {
	cin >> n;
	rep(i, n)rep(j, n)
	{
		char dum;
		cin >> dum;
		if(dum=='1') edge[i][j]=1;
	}
	//rep(i, n)rep(j, n) cout << edge[i][j];
	if(!dfs(0, 1))
	{
		cout << "-1" << endl;
		return 0;
	}
	rep(i, n)rep(j, n)
	{
		if(i!=j && edge[i][j]==0) edge[i][j]=10000; 
	}
	rep(i, n)rep(j, n)rep(k, n)
	{
		edge[j][k]=min(edge[j][k], edge[j][i]+edge[i][k]);
	}
	int ans=0;
	rep(i, n)rep(j, n)
	{
		ans=max(ans, edge[i][j]);
	}
	cout << ans+1 << endl;
	return 0;
}

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

int main() {
  
  int N,A = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    
    int j,b = 0;
    cin >> j;
    
    for (; j >= 1; j /= 2) {
      if(j%2 == 0) b++;
      else break;
    }
    if ( b == 0 ) break;
    else if ( A == 0 || A > b) A = b;
  }
  cout << A << endl;
}


Measured memory_bytes: 256
import numpy as np

n = int(input())
x = np.array([int(i) for i in input().split()])

mins = x.min()
maxs = x.max()

dis = np.inf
for p in range(mins, maxs+1):
  temp = np.sum((x - p) ** 2)
  if dis > temp:
    dis = temp
    
print(dis)

Measured memory_bytes: 12404
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    int n, m;
    cin >> n >> m;
    
    if (m == 1) {
        cout << 0 << endl;
        return 0;
    }
        
    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    
    vector<int> a(m);
    repeat (i, m) cin >> a[i];
    sort(a.begin(), a.end());
    
    int sum = a[m-1] - a[0];
    
    priority_queue<int> pq;
    repeat (i, m-1) pq.push(a[i+1] - a[i]);
    
    rep (n-1) {
        sum -= pq.top();
        pq.pop();
    }
    cout << sum << endl;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s ; cin>>s ; int k=0,ans=0 ;
    s=" "+s ;
    for(int i = 1 ; i < s.size() ; i++)
    {
        if(s[i]!=s[i-1])
        {
            //cout<<k<<endl ;
            if(k) ans++ ; k=1 ;
        }
        else k++ ;
    }
    if(k) ans++ ;
    cout<<ans-1<<endl ;
}


Measured memory_bytes: 3788
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */
 
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007
 
const long double PI = 3.141592653589793236L;
 
typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{   
    string s;
    string t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();

    vector<vector<int>> dp(n + 1, vector<int> (m + 1));

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(s[i - 1] == t[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 = "";
    
    int i = n, j = m;
    
    while(i && j)
    {
        if(s[i - 1] == t[j - 1])
        {
            ans += s[i - 1];
            i--;
            j--;
        }
        else 
        {
            if(dp[i][j - 1] > dp[i - 1][j])
            {
                j--;
            }
            else {
                i--;
            }
        }
    }

    reverse(all(ans));

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 38516
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int k = sc.nextInt();
    String S = sc.next();
    
    int kMinus = k - 1;
    
    System.out.println(S.substring(0, kMinus) + S.substring(kMinus, k).toLowerCase() + S.substring(k));
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    int a[n], b[n];
    int sum[MAX], sum_a[MAX], sum_b[MAX];
    memset(sum, 0, sizeof(sum));
    memset(sum_a, 0, sizeof(sum_a));
    memset(sum_b, 0, sizeof(sum_b));
    rep(i, n){
        scanf("%d%d", &a[i], &b[i]);
        ++sum[a[i]]; --sum[b[i]];
        ++sum_a[a[i]];
        ++sum_b[b[i]];
    }
    partial_sum(sum, sum+MAX, sum);
    rrep(i, MAX-1) sum_a[i] += sum_a[i+1];
    partial_sum(sum_b, sum_b+MAX, sum_b);
    int M = 0, m = 0;
    rep(i, n){
        chmax(M, n - sum_a[b[i]] - sum_b[a[i]]);
        chmax(m, sum[a[i]]);
    }
    printf("%d %d\n", M, m);
}


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

int main(){
  int n;
  cin >> n;
  rep(i, n){
    cout << "ACL";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    int n, m; ll x; cin >> n >> m >> x;
    vector<int> c(n);
    ll ans = 1e10;
    vector<vector<int>> v(n, vector<int>(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> v[i][j];
        }
    }
    for(int bit = 0; bit < (1 << n); bit++){
        vector<ll> temp(m, 0);
        ll sum = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                sum += c[i];
                for(int j = 0; j < m; j++){
                    temp[j] += v[i][j];
                }
            }
        }
        bool f = true;
        for(int i = 0; i < m; i++){
            if(temp[i] < x){
                f = false;
                break;
            }
        }
        if(f)ans = min(ans, sum);
    }
    if(ans == 1e10){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
    
    system("pause");
}


Measured memory_bytes: 3696
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
const int INF = 1000000007;

int main(){
   int k;
   cin >> k;
   queue<ll> lun;
   for(int i = 1; i <= 9; i++){
      lun.push(i);
   }
   for(int i = 0; i < k-1; i++){
      ll x = lun.front(); lun.pop();
      for(int j = -1; j <= 1; j++){
         int d = x%10+j;
         if(d < 0 || d > 9) continue;
         lun.push(10*x+d); 
      }
   }
   cout << lun.front() << endl;
}
 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define endl "\n"



int32_t main() {
	FAST
	//ofstream fout ("test.out");
    //ifstream fin ("test.in");
 	int x;
 	cin >> x;
 	REP(i, -120, 130) {
 		REP(j, -120, 130) {
 			int a = i*i*i*i*i - j*j*j*j*j;
 			if(a != x)
 				continue;
 			cout << i << " " << j << endl;
 			return 0;
 		}
 	}
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
int main(){
    string s;cin>>s;
    int n=s.size();
    int ans=0,sum=0;
    rep(i,n+1){
        if(i==n){
            chmax(ans,sum);
            break;
        }
        if(s[i]=='A'||s[i]=='G'||s[i]=='T'||s[i]=='C'){
            sum++;
        }
        else{
            chmax(ans,sum);
            sum=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())

hour_rad = ((2 * math.pi) / 720) * ((60 * h) + m)
min_rad =  ((2 * math.pi) / 60) * m
rad_ = abs(hour_rad - min_rad)
hour_sin = b * math.cos(rad_)
hour_cos = b * math.sin(rad_)

length_1 = a - hour_sin
length_2 = hour_cos

if rad_ == math.pi:
    ans = abs(length_1) + abs(length_2)
else:
    ans = math.sqrt((length_1 ** 2) + (length_2 ** 2))
print(ans)

Measured memory_bytes: 9548