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

int n, m;
vector<long long> a;
long long ans;
typedef pair<int, int> P;
vector<P> v;
vector<long long> w;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	a.resize(n);
	for(auto &i:a) cin >> i;
	sort(a.begin(), a.end());
	for(int i=0; i<m; ++i){
		int b, c;
		cin >> b >> c;
		v.push_back(P(c, b));
	}
	sort(v.begin(), v.end());
	for(int i=m-1; i>=0; --i){
		bool f = false;
		for(int j=0; j<v[i].second; ++j){
			w.push_back(v[i].first);
			if(w.size() == n){
				f = true;
				break;
			}
		}
		if(f) break;
	}
	for(int i=1; i<n; ++i)
		a[i] += a[i-1];
	for(int i=1; i<w.size(); ++i)
		w[i] += w[i-1];
	ans = a[n-1];
	for(int i=0; i<w.size(); ++i){
		ans = max(ans, w[i] + a[n-1] - a[i]);
	}
/*	for(int i=0; i<n; ++i)
		cout << i << " " << a[i] << "\n";
	for(int i=0; i<w.size(); ++i)
		cout << i << " " << w[i] << "\n";
*/	cout << ans << "\n";
}

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

int dp[1024][100001],v[323456],w[323456],n,q,a,l;
int f(int a,int l){
  if(l<0)return -1e9;
  if(!a)return 0;
  if(a>1023)return max(f(a/2,l),f(a/2,l-w[a])+v[a]);
  if(~dp[a][l])return dp[a][l];
  return dp[a][l]=max({f(a/2,l),f(a,l-1),f(a/2,l-w[a])+v[a]});
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin>>n;
  for(int i=1;i<=n;i++)cin>>v[i]>>w[i];
  cin>>q;
  while(q--){
    cin>>a>>l;
    cout<<f(a,l)<<endl;
  }
}


Measured memory_bytes: 413272
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <vector>

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

    std::vector<int> lnk[200000];

    for (int i = 0; i < M; i++) {
        int a, b;
        std::cin >> a >> b;
        a--; b--;
        lnk[a].push_back(b);
        lnk[b].push_back(a);
    }

    for (auto mid : lnk[0]) {
        for (auto dst : lnk[mid]) {
            if (dst == N-1) {
                std::cout << "POSSIBLE" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "IMPOSSIBLE" << std::endl;
    
    return 0;
}

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

int main()
{
  int n,i;
  int a[3];
  cin>>n;
    for(i=0;i<n;i++){
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	  if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]){
	       cout<<"YES\n";}
	  else{cout<<"NO\n";}

    }
 return 0;
}

Measured memory_bytes: 1136
use num::integer::gcd;
use proconio::input;

fn main() {
    input! {
        k: usize
    }

    let mut s = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                s += gcd(gcd(a, b), c);
            }
        }
    }

    println!("{}", s);
}


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

using namespace std;

int main(){
	int N;
  	cin>>N;
  	int nmin = 9999999;
  	for(int i=0;i<N;i++){
    	int tmp,d;
      	d = 0;
      	cin>>tmp;
      	while(tmp%2==0){
          d++;
          tmp /=2;
        }
        nmin = min(nmin,d);
    }
  	cout<<nmin<<endl;
}

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


int pow(int A, int P){
	int a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	int adash = a * a;
	if(p % 2) return pow(adash, p / 2) * a;
	else return pow(adash, p / 2);
}

int main(){
	int N, M;
	cin >> N >> M;
	int s[M], c[M];
	for(int i=0;i<M;i++){
		cin >> s[i] >> c[i];
	}
	int MA = pow(10, N);
	int MI = pow(10, N-1);
	int ans = -1;
	if(MI == 1)MI = 0;
	for(int i=MI;i<MA;i++){
		bool chk = true;
		for(int j=0;j<M;j++){
			int tmp = i;
			for(int k=1;k<N + 1-s[j];k++){
				tmp /= 10;
			}
			tmp %= 10;
			if(tmp != c[j]){
				chk = false;
				break;
			}
		}
		if(chk){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n;
	cin>>n;
	vector<int>v(n);
	for(auto& p:v){
		cin>>p;
	}
	sort(v.begin(),v.end());
	int ans=v[v.size()/2]-v[v.size()/2-1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    ll n, m; cin >> n >> m;
    if (n > m)
        swap(n,m);
    if (n == 1 && m == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (n == 1) {
        cout << m - 2 << endl;
        return 0;
    }

    cout << (n-2) * (m-2) << endl;
    return 0;
}


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

#define ll long long
#define scl(n) scanf("%lld",&n)
#define scd(n) scanf("%d",&n)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second


int main()
{

    ll n,m,i,j,k,a,b,c;
    cin>>n>>m;
    for(i=1,c=0;i<=m;i++)
    {
        scl(a);
        c+=a;
    }
    if(c>=n){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int w[400], n, W, dp[20005];
int main() {
	cin >> n >> W;
	for (int i = 0; i < n; i++)cin >> w[i];
	sort(w, w + n);
	int sum = 0;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= W; j++)dp[j] = 0; dp[cnt] = 1;
		for (int j = i + 1; j < n; j++) {
			for (int k = W - w[j]; k >= cnt; k--) {
				dp[k + w[j]] += dp[k]; dp[k + w[j]] %= 1000000007;
			}
		}
		for (int j = W - w[i] + 1; j <= W; j++) { sum += dp[j]; sum %= 1000000007; }
		cnt += w[i]; if (cnt > W)break;
	}
	if (cnt <= W)sum++;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3212
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

vector<int> h;
int cost(int i, int j){
	return abs(h[i] - h[j]);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	h.push_back(0);
	int t;
	for(int i=0;i<n; i++){
		cin>>t;
		h.push_back(t);
	}

	vector<int> DP(n+1, 0);

	DP[0] = 0;
	DP[1] = 0;
	DP[2] = cost(1, 2);
	int j = 0;
	for(int i=3; i<=n; i++){
		j=i;
		DP[j] = min(DP[j-1]+ cost(j-1, j), DP[j-2] + cost(j-2, j));
	}

	cout<<DP[n];




	return 0;
}

Measured memory_bytes: 1144
#include "bits/stdc++.h"
#include <queue>

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;



void solve() {
	VI v(3);
	int k;
	rep(i, 3) cin >> v[i];
	cin >> k;
	sort(all(v));


	cout << (v[2] << k) + v[1] + v[0] << endl;
}


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

	solve(); 
	return 0;
}

Measured memory_bytes: 256
n, s = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
mod = 998244353

sum = Array.new(s, 0)
ans = 0

a.each_with_index do |e, idx|
    sum[0] += 1
    next if e > s
    ans = (ans + sum[s - e] * (n - idx)) % mod

    (s - e - 1).downto(1) do |i|
        sum[i + e] = (sum[i + e] + sum[i]) % mod
    end

    sum[e] = (sum[e] + idx + 1) % mod if e != s
end
#p sum
puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int P,Q,R;
  cin >>P>>Q>>R;
  cout << P+Q+R-max(P,max(Q,R));
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		char[] s = sc.nextLine().toCharArray();
		char[] t = sc.nextLine().toCharArray();
		
		Map<Character, List<Integer>> sMap = new HashMap<>();
		for (int i=0; i<s.length; i++) {
			List<Integer> l = sMap.get(s[i]);
			if (l == null) {
				l = new ArrayList<>();
				sMap.put(s[i], l);
			}
			l.add(i);
		}
		
		boolean contain = true;
		for (char c : t) {
			if (!sMap.containsKey(c)) {
				contain = false;
				break;
			}
		}
		
		if (!contain) {
			System.out.println(-1);
		}
		else {
			long cnt = 0;
			int length = s.length;
			for (char c : t) {
				List<Integer> l = sMap.get(c);
				cnt += getCnt(l, length, c);
			}
			System.out.println(cnt);
		}
	}
	
	private static int now = -1;
	private static Map<Character, Integer> nowMap = new HashMap<>();
	
	private static int getCnt(List<Integer> l, int length, char c) {
		int start = nowMap.containsKey(c) ? nowMap.get(c) + 1 : 0;
		for (int i=start; i<l.size(); i++) {
			int idx = l.get(i);
			if (idx > now) {
				int ret = now == -1 ? idx + 1 : idx - now;
				now  = idx;
				nowMap.put(c, i);
				return ret;
			}
		}
		int ret = now == -1 ? length : length - now - 1;
		now = -1;
		nowMap.clear();
		return getCnt(l, length, c) + ret;
	}
}

Measured memory_bytes: 34468
#include <iostream>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c,d;
  cin >> c;
  cin >>a;
  cin >>b;
  if(a-b>=0){
	cout <<"delicious" <<endl;
  }else if(b-a<=c){
	cout << "safe" <<endl;
  }else{
    cout <<"dangerous" <<endl;
  }
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vi a(n); rep(i,n) cin >> a[i];

    i32 Xor = 0;
    for(auto val : a) Xor ^= val;

    vi ans;
    for(auto val : a) ans.push_back(Xor ^ val);

    rep(i,n) cout << ans[i] << (i == n-1 ? '\n' : ' ');

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 6840
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	long long int n,c = 0,d = 0,a[10005],b[10005];
	cin >> n;
	for(int i = 1;i <= n; i++)
		cin >> a[i];
		for(int i = 1;i <= n; i++)
			cin >> b[i];
			for(int i = 1;i <= n; i++)
			{
				if(a[i] > b[i])
					c += a[i] - b[i];
					else
						d += (b[i] - a[i]) / 2;
			}
			if(c > d)
				cout << "No" << endl;
				else
					cout << "Yes" << endl;
					return 0;
}

Measured memory_bytes: 384
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<int,int>
#define ti3 tuple<ll,ll,ll>

ll x[100010];

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
    }
    ll c = x[0];
    ll cost = 0;
    for(int i = 1;i < n;i++)
    {
        ll s = (x[i] - c) * a;
        cost += min(s, b);
        c = x[i];
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

b = [0] * (N + 1)
half = N // 2
b[half + 1:] = A[half:]
for i in range(half, 1, -1):
    s = sum([b[j] for j in range(i * 2, N + 1, i)]) % 2
    if s != A[i - 1]:
        b[i] = 1
s = sum(b)
if s % 2 != A[0]:
    b[1] = 1
    s += 1
print(s)
for i, b_ in enumerate(b[:]):
    if b_ == 1:
        print(i, end=" ")

Measured memory_bytes: 8784
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=0;i<n;i++){
			int[] x=new int[3];
			x[0]=sc.nextInt();
			x[1]=sc.nextInt();
			x[2]=sc.nextInt();
			Arrays.sort(x);
			if(x[0%3]*x[0%3]+x[1%3]*x[1%3]==x[2%3]*x[2%3]){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 23380
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll h,w; cin >> h >> w;
    vector<string> c(h);
    rep(i,0,h){
        cin >> c[i];
    }

    auto calc = [&](ll a, ll b) {
        vector dp(h + 1, vector<ll>(h + 1, INF));
        vector cost(h + 1, vector<ll>(h + 1));
        rrep(i, h, 0)rrep(j,h,0){
            cost[i][j] =
                cost[i + 1][j + 1] + (c[h - i - 1][a] == c[h - j - 1][b]);
        }
        debug(a, b, cost);
        dp[0][1] = dp[1][0] = cost[0][0];
        rep(i, 0, h+1) rep(j, 0, h+1) {
            if (i) chmin(dp[i][j], dp[i - 1][j] + cost[i - 1][j]);
            if (j) chmin(dp[i][j], dp[i][j - 1] + cost[i][j - 1]);
        }
        debug(dp);
        return dp[h][h];
    };

    ll ans = 0;
    rep(i,0,w-1){
        ans += calc(i, i+1);
    }

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

Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  string s;
  int k;
  cin >> s >> k;

  set<string> se;
  for (char c = 'a'; c <= 'z'; c++) {
    int loc = 0;
    while (true) {
      auto pos = s.find(c, loc);
      if (pos == s.npos) break;
      rep(i, 5) se.insert(s.substr(pos, i + 1));
      loc = pos + 1;
    }
    if (se.size() > 5) break;
  }
  auto itr = se.begin();
  rep(i, k - 1) itr++;
  cout << *itr << endl;
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	sort(a.begin(), a.end());
	const int h = (k + 1) / 2;
	int answer = 0;
	if(a.back() > h){
		const int x = a.back();
		if(k % 2 == 1){
			answer = (x - h) * 2;
		}else{
			answer = (x - h) * 2 - 1;
		}
	}
	cout << answer << endl;
	return 0;
}



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

int main()
{
  int n, x; cin >> n >> x;
  vector<int> l(n+1, 0);
  rep(i, n) {
    int a; cin >> a;
    l[i+1] = a + l[i];
  }
  int ans = upper_bound(l.begin(), l.end(), x) - l.begin();
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		double ans = 0;
		for(int i = 1; i <= n; i++) {
			double tmp = 0.5;
			double pow  = 0d;
			int j = i;
			while(j < k) {
				pow += 1;
				j *= 2;
			}
			ans += Math.pow(tmp, pow) * 1/n ;
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21588
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 2019;

int H, W;
int rows[MAX_N][MAX_N];
int columns[MAX_N][MAX_N];
char grid[MAX_N][MAX_N];
bool visited_r[MAX_N][MAX_N];
bool visited_c[MAX_N][MAX_N];

int dfs_r(int y, int x, int cnt) {
  visited_r[y][x] = true;

  if (x < W - 1 && grid[y][x + 1] == '.') {
    cnt = dfs_r(y, x + 1, cnt + 1);
  }

  rows[y][x] = cnt;

  return cnt;
}

int dfs_c(int y, int x, int cnt) {
  visited_c[y][x] = true;

  if (y < H - 1 && grid[y + 1][x] == '.') {
    cnt = dfs_c(y + 1, x, cnt + 1);
  }

  columns[y][x] = cnt;

  return cnt;
}

int main() {
  cin >> H >> W;
  string s;

  for (int y = 0; y < H; y++) {
    cin >> s;

    for (int x = 0; x < W; ++x) {
      grid[y][x] = s[x];
    }
  }

  memset(visited_r, false, sizeof(visited_r));
  memset(visited_c, false, sizeof(visited_c));

  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      if (grid[y][x] == '#') continue;

      if (!visited_r[y][x]) {
        dfs_r(y, x, 1);
      }
      if (!visited_c[y][x]) {
        dfs_c(y, x, 1);
      }
    }
  }

  int ans = 0;

  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      if (grid[y][x] == '#') continue;

      int n = rows[y][x] + columns[y][x] - 1;

      if (ans < n) {
        ans = n;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 43904
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    int lower = 0;
    int upper = N;
    int center = (lower + upper) / 2;
    while(lower + 1 < upper){
        bool isOk = true;

        vector<int> color(center, -1);
        for(int i = 0; i < N; i++){
            int temp = A[i];
            auto place = lower_bound(color.begin(), color.end(), temp);

            if(place == color.begin()){
                isOk = false;
                break;
            }
            else{
                place--;
                *place = temp;
            }
        }

        if(isOk){
            upper = center;
        }
        else{
            lower = center;
        }
        center = (upper + lower) / 2;
    }

    cout << upper << endl;

    return 0;
}

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

int main()
{
    int A, B;
    cin >> A >> B;

    int C = 3;

    if ((A * B * C) % 2 == 1)
    {
        printf("Yes\n");
    }
    else if ((A * B * C) % 2 == 0)
    {
        printf("No\n");
    }
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> cnt(8, 0);
	int tot = 0;
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		for(int i = 0; i < 8; i++){
			if(x < 400*i + 400){
				cnt[i]++;
				break;
			}
		}
		if(x >= 3200)tot++;
	}
	int tmp = 0;
	for(auto x : cnt){
		if(x)tmp++;
	}
	if(tmp == 0){
		cout<<1<<" "<<tot<<endl;
	}else{
		cout<<tmp<<" "<<tmp + tot<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, a[4] = { };
  cin >> n;
  string s;
  rep(i,n)
  {
    cin >> s;
    if (s[0] == 'A') {
      a[0]++;
    } else if (s[0] == 'W') {
      a[1]++;
    } else if (s[0] == 'T') {
      a[2]++;
    } else if (s[0] == 'R') {
      a[3]++;
    }
  }
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;
  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        for (int i=1; i<= 9; i++) {
            for (int k=1; k<= 9; k++) {
                if (N == (i*k)) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }

}

Measured memory_bytes: 22100
<?php
  fscanf(STDIN, "%d %d %d %d", $A, $B, $C, $D);
  if (abs($A - $C) <= $D){
    $ans = "Yes";
  } elseif (abs($A - $B) <= $D && abs($B - $C) <= $D){
    $ans = "Yes";
  } else {
    $ans = "No";
  }
  echo $ans;
 ?>


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;


typedef long long ll;
#define CIN_I(a) ll a;cin>>a;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)

int main() {
  string s, t;
  cin >> s >> t;
  ll count = 0;
  REP(i,s.size()) {
    if(s[i] != t[i]) count++;
  }
  cout << count << endl;
}

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

int main() {
	int n,k,i,j;
	cin>>n>>k;
	int a[n];
	int dp[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	dp[0]=0;
	dp[1] = abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{
	    dp[i] = INT_MAX;
	    for(j=i-1;j>=max(i-k,0);j--)
	    {
	        dp[i] = min(dp[i],dp[j]+abs(a[i]-a[j]));
	    }
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>

ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll n;
	cin>>n;
	if(n==0)
		cout<<1<<endl;
	else
		cout<<0<<endl;

	
	
	


	
	return 0;
}

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

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


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

	vector<pair<double, string>> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i].first >> x[i].second;
		if (x[i].second == "BTC") {
			x[i].first *= 380000.0;
		}
	}

	double answer = 0;
	for (int i = 0; i < N; i++) {
		answer += x[i].first;
	}

	cout << answer << endl;
}

Measured memory_bytes: 256
#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, k; cin >> n >> m >> k;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i*(m-j) + j*(n-i) == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    system("pause");
}

Measured memory_bytes: 504
<?php
list($h, $w) = ints();
for ($i = 0; $i < $h; ++$i) {
    list($a) = strs();
    for ($j = 0; $j < $w; ++$j) {
        if (isset($cnt[$a[$j]])) ++$cnt[$a[$j]];
        else $cnt[$a[$j]] = 1;
    }
}

$g1 = $h % 2 && $w % 2 ? 1 : 0;
$g2 = ($w % 2) * intdiv($h, 2) + ($h % 2) * intdiv($w, 2);
$g4 = intdiv($h, 2) * intdiv($w, 2);

for ($i = 1; $i <= $g1; ++$i) {
    foreach ($cnt as $k => $v) {
        if ($v % 4 === 1 || $v % 4 === 3) {
            $cnt[$k] -= 1;
            continue 2;
        }
    }
    exit('No');
}

for ($i = 1; $i <= $g2; ++$i) {
    foreach ($cnt as $k => $v) {
        if ($v % 4 === 2) {
            $cnt[$k] -= 2;
            continue 2;
        }
    }
    foreach ($cnt as $k => $v) {
        if ($v > 0 && $v % 4 === 0) {
            $cnt[$k] -= 2;
            continue 2;
        }
    }
    exit('No');
}

for ($i = 1; $i <= $g4; ++$i) {
    foreach ($cnt as $k => $v) {
        if ($v > 0 && $v % 4 === 0) {
            $cnt[$k] -= 4;
            continue 2;
        }
    }
    exit('No');
}

echo 'Yes';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16300
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        String s = in.ns();
        if(s.length()==2) out.println(s);
        else out.println(new StringBuffer(s).reverse().toString());
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21204
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;



public class Main{
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int n=sc.nextInt();
	 Set<Integer> S=new HashSet<Integer>();
	 for(int i=0;i<n;i++) {
		 Integer temp=sc.nextInt();
		 S.add(temp);
	 }
	 int q=sc.nextInt();
	 Set<Integer> T=new HashSet<Integer>();
	 for(int i=0;i<q;i++) {
		 Integer temp2=sc.nextInt();
		 T.add(temp2);
	 }
	 
	 int result = 0;
	 
	 for (Iterator<Integer> it = T.iterator(); it.hasNext(); ) {
	        Integer f = it.next();
	        if(S.contains(f)) {
	        	result++;
	        }
	    }
	 
	 System.out.println(result);
	 
	 
	
	 
	 
	 
 }
	


}




Measured memory_bytes: 92628
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL unsigned long long
#define MOD 1000000007
#define inf 1999999999



int main() {
	LL n, mn = 10000000000000;
	cin >> n;
	for (LL i = 1; i < 10000000; i++){
		if (n%i == 0) {
			mn = min(mn, (i-1) + (n / i - 1));
		}
	}
	cout << mn << endl;
	return 0;
}


Measured memory_bytes: 384
//file_name:ABC51_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int k,s;
    scanf("%d%d",&k,&s);
    ll ans = 0;

    rep(i,k+1){
        rep(j,k+1){
            if(s-i-j>=0&&s-i-j<=k){
                ans++;
            }
        }
    }

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



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import collections
n,k,q = list(map(int,input().split()))
# print(n,k,q)
a = [] 
for i in range(q):
    a.append(input())

c = collections.Counter(a)
for i in range(1,n+1):
    if k+c[str(i)] > q:
        print('Yes')
    else: 
        print('No')

Measured memory_bytes: 14332
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll INF = 1e18L+5;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  ll W;
  cin>>n>>W;
  int val[n];
  ll wt[n];
  for(int idx = 0;idx<n;idx++)
    cin>>wt[idx]>>val[idx];
    
  int sum_val = 0;
  
  for(int idx = 0;idx<n;idx++)
    sum_val+=val[idx];
    
  vector<ll>dp(sum_val+1,INF);
  dp[0]=0;
  for(int item = 0;item<n;item++){
    for(int val_al =sum_val - val[item];val_al>=0;--val_al){
       dp[val_al+val[item]]=min(dp[val_al+val[item]],wt[item]+dp[val_al]);
       }
      /* for(int i = 0;i<=sum_val;i++)
         cout<<"("<<i<<","<<dp[i]<<") ";
         cout<<endl;*/
    }
    ll ans =0;
          for(int i = 0;i<=sum_val;i++)
            if(dp[i]<=W)
               ans = max(ans,(ll)i);
     cout<<ans;
    return 0;
    }
  

Measured memory_bytes: 1024
import java.util.*;
public class Main{

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

      int[][] costs = new int[10][10];
      for(int i = 0; i <= 9; i++) {
        for(int j = 0; j <= 9; j++)
          costs[i][j] = sc.nextInt();
      }

      int[][] matrix = new int[h][w];
      for(int i = 0; i < h; i++) {
          for(int j = 0; j < w; j++) {
            matrix[i][j] = sc.nextInt();
          }
      }
      
      Map<Integer, Long> memo = new HashMap<>();
      long cost = 0;
      for(int i = 0; i < h; i++) {
          for(int j = 0; j < w; j++) {
              int num = matrix[i][j]; // 8
              if(num == -1) continue; //       8            9
              long minCost = 0;
              if(memo.containsKey(num))
                minCost = memo.get(num);
              else{
                minCost = dfs(memo, costs, matrix, num, 0, costs[num][1]);
                memo.put(num, minCost);
              }
              cost += minCost;
          }
      }
      System.out.println(cost);
  }

  private static long dfs(Map<Integer, Long> memo, int[][] costs, int[][] matrix, int n, long curCost, long minCost) {
      
      if(curCost >= minCost) return minCost;
      if(n == 1) {
        return curCost;
      }

      for(int i = 0; i <= 9; i++) {
        if(i == n) continue;
        minCost = Math.min(minCost, dfs(memo, costs, matrix, i, curCost + costs[n][i], minCost));
      }
      //memo.put(n, minCost);
      return minCost;
  }
}



Measured memory_bytes: 46976
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;



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

char c;
cin >> c;
int a = int(c);
a += 1;
if (a == 123)
	cout << 'a';
else 
	cout << char (a);


return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  long long n,A[200000],ans=0,a,b=1e9,x=0;
  cin>>n;
  rep(i,n){
    cin>>A[i],a=abs(A[i]),ans+=a,b=min(a,b);
    if(A[i]<0)x++;
  }
  if(x%2==0) cout<<ans;
  else cout<<ans-b*2;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
	long long x,ans;
	while(~scanf("%lld",&x))
	{
		ans=0;
	   ans+=x/500*1000;
	   x=x%500;
	   ans+=x/5*5;
	   printf("%lld\n",ans); 
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  cout << (n == 0 ? 1 : n == 1 ? 2 : n == 2 ? 1 : 0) << endl;

  return 0;
}


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

//INSERT ABOVE HERE
signed main(){
  Int n,d;
  cin>>n>>d;
  vector< vector<Int> > xs(n,vector<Int>(d));
  for(Int i=0;i<n;i++)
    for(Int k=0;k<d;k++)
      cin>>xs[i][k];

  set<Int> ss;
  for(Int i=1;i<=10000;i++) ss.emplace(i*i);

  Int ans=0;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<i;j++){
      Int val=0;
      for(Int k=0;k<d;k++)
        val+=(xs[i][k]-xs[j][k])*(xs[i][k]-xs[j][k]);
      if(ss.count(val)) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 768
from collections import deque

s = deque( list(input()) )
q = int(input())

l_q = []
for i in range(q):
  l_q.append( list(input().split())  ) 

#クエリ処理
c = 0
for i in l_q:

  if i[0] == "1":
    c = (c+1)%2

  else:
    if (c+int(i[1]))%2 ==1:
      s.appendleft(i[2])
    else:
      s.append(i[2])

s=list(s)

if c == 1:
  s.reverse()

s = ''.join(s)
print(s)

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int dp[n + 1];
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for (int i = 3; i <= n; i++) {
        dp[i] = abs(a[i - 1] - a[i]) + dp[i - 1];
        for (int j = 2; j <= k and (i - j) >= 1; j++) {
                dp[i] = std::min(abs(a[i - j] - a[i]) + dp[i - j], dp[i]);

        }
    }
    //for (int i = 1; i <= n; i++) {
     //   std::cout << dp[i] << " ";
   // }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))

sunuke=a[0]
kuma=sum(a[1:])
ans=abs(sunuke-kuma)

for i in range(1, n-1):
    sunuke+=a[i]
    kuma-=a[i]
    ans=min(ans, abs(sunuke-kuma))

print(ans)

Measured memory_bytes: 24832
N=int(input())
T=list(map(int, input().split()))
M=int(input())
PX=[]
time=T[0]
for i in range(1,N):
  time+=T[i] 
[PX.append(list(map(int, input().split()))) for i in range(M)] 
for m in range(M): 
  print(time- T[PX[m][0]-1]+PX[m][1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,n,k,i,j,m,a,b;
    cin>>n;
    ll ans=(n/500)*1000;
    n%=500;
    ans+=(n/5)*5;
    cout<<ans;
    
    return 0;
 
    
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long  a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int flag=0;
    int co=0;
    for(int i=0; i<n; i++){
          if (a[i]==0){
              flag=1;
          }
          else if (a[i]<0){
              co++;
          }
        }

    if (flag==1 or co%2==0){
        long long su=0;
        for(int i=0; i<n; i++){
            su+=abs(a[i]);
        }
        cout<<su<<endl;
    }
    else{
        long long su=0;
        long long mi=1e+10;
        for(int i=0; i<n; i++){
            su+=abs(a[i]);
            mi=min(abs(a[i]),mi);
        }
        cout<<su-2*mi<<endl;
    }
}

Measured memory_bytes: 1024
n,l = map(int,input().split())
azi = (l-1)*n + (n*(n+1))//2
x = []
y = []
for i in range(1,n+1):
    x.append(l+i-1)
    y.append(abs(l+i-1))
print (azi-x[y.index(min(y))])


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

ll mod=pow(10,9)+7;
ll fac[210000];

ll mul(ll a, ll b){ //mul,power, div2はセット
    return ((a % mod) * (b % mod))%mod;
}

ll power(ll x, ll y){ //mul,power, div2はセット
    if(y == 0) return 1;
    else if(y == 1) return x%mod;
    else if(y % 2 == 0) return (power(x, y/2)*power(x, y/2))%mod;
    else return (power(x, y/2)*power(x, y/2))%mod*x%mod;
}

ll div2(ll a, ll b){ //mul,power, div2はセット
    return mul(a, power(b, mod-2));
}

signed main(){
    ll n,m;
    cin >> n >> m;
    vector<int> v;
    fac[1]=1;
    fac[0]=1;

    for(int i=2;i<210000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }

    ll c=2;
    ll now = m;
    ll d = -1;
    while(1){
        if(now%c==0){
            d++;
            v.push_back(0);
            while(1){
                if(now%c==0) v[d]++;
                else break;
                now=now/c;
            }
        }
        c++;
        if(now==1) break;
    }

    ll ans=1;
    for(int i=0;i<v.size();i++){
        ans*=div2(fac[(n-1)+v[i]],fac[n-1]%mod*fac[v[i]]%mod)%mod;
        ans%=mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1920
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
double n,m,x,y;
int main()
{
	cin>>n>>m>>x>>y;
	cout<<n*m/2<<' ';
	if(2*x==n && 2*y==m)
	{
		cout<<1<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
	return 0;
}

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

int main() {
    while (true) {
        int n, k, m;
        cin >> n >> k >> m;
        if ((n | k | m) == 0) {
            break;
        }
        vector<int> array(n);
        for (int i = 0; i < n; i++) {
            array[i] = i + 1;
        }
        size_t pos = (m - 1) % array.size();
        while (array.size() > 1) {
            array.erase(array.begin() + pos);
            pos = (pos + (k - 1) % array.size()) % array.size();
        }
        cout << array[0] << endl;
    }
}

Measured memory_bytes: 940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
auto dis(pii a,pii b){
    return (a.first - b.first)* (a.first - b.first) + (a.second - b.second)* (a.second - b.second);
}
int cal(int n){return (n == 1 ? 1 : n * cal(n - 1));}
signed main(){
    int N; cin >> N;
    vector<int>v(N); rep(i,N) v[i] = i;
    vector<pii>pos(N);
    for(auto& p : pos) cin >> p.first >>p.second;
    long double sum = 0;
    do{
        long double tsum = 0;
        for(int i = 0; i + 1 < N; ++i)
            tsum += sqrt((ld)dis(pos[v[i]],pos[v[i+1]]));
        sum += tsum;
      
    }while(next_permutation(all(v)));
    cout << setprecision(10) << fixed << sum / cal(N) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
ll sum(ll t){
  return t*(t+1)/2;
}
int main(void)
{
    ll x;cin>>x;
    ll ans = 1;
    while(sum(ans)<x) {
      ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256