akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define pi 3.14159265358979323846
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--) 
  
long long fact(long long a, long long b){
    int r= max(a, b);
    int v= min(a, b);
    int l=1;
    // if(v==0)
    for(int i=r+1; i<=a+b; i++){
        l*=i;
    }
    for(int i=v; i>=2; i--){
        l/=i;
    }
    return l;
}

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

int powr(int a) { 
    int var=1;
    for(int i=0; i<a; i++){
        var*=2;
    }
    return var;
}

signed main(){    
    fast;
    int a, b, c,d ,e;
    cin >>a>>b>>c>>d>>e;
    if(a==0)
        cout << "1";
        if(b==0)
        cout << "2";
     if(c==0)
        cout << "3";
        if(d==0)
        cout << "4";
        if(e==0)
        cout << "5";
       
}

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


int main() {
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int diff = (H2 * 60 + M2) - (H1 * 60 + M1);
	cout << diff - K << endl;
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> i_i;

vector<ll> p(100000);

void era(){
    for (int i=2; i<100000; i++) {
        if(p[i]==0)continue;
        int j=i;
        while (j<100000) {
            j+=i;
            if(j>=100000)break;
            p[j]=0;
        }
    }
}

int main(){
    rep(i, 100000) p[i]=i;
    era();
    for (;;) {
        int m,a,b;
        cin >> m >> a >> b;
        if(!m) break;
        int ans = 0, pp = 0, qq = 0;
        for (int i=m; i>1; i--) {
            if(p[i]==0 or i == 1)continue;
            for (int j=min(m/i,i); j>=i*a/b; j--) {
                if (i*j<ans) break;
                if (p[j]!=0 and i!=1 and i*j <= m and i*a <= j*b) {
                    if(ans < i*j){
                        ans = i*j;
                        pp = j;
                        qq = i;
                    }
                }
            }
        }
        cout << pp<<" "<<qq << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	ll n,k;
	cin>>n>>k;

	ll ans=0;
	ans+=(n/k)*(n/k)*(n/k);
	if(k%2==0){
		ll count=0,i=k/2;
		while(i<=n){
			count++;
			i+=k;
		}
		ans+=count*count*count;
	}
	cout<<ans<<endl;

	return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> x(N+1);
    for(int i=1; i<=N; i++) cin >> x[i];
    
    int sum=0;
    for(int i=1; i<=N; i++){
        if((x[i]) <= (abs(K-x[i])))
            sum += x[i]*2;
        else
            sum += abs(K-x[i])*2;
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = INT_MIN;
	for (int i = 1; i < N; i++) {
		int n = 0;
		string s, t;
		s = S.substr(0, i);
		t = S.substr(i, N - i);
		map<char, int>mp;
		for (int j = 0; j < s.size(); j++) {
			mp[s[j]] = 1;
		}
		for (int j = 0; j < t.size(); j++) {
			if (mp[t[j]] == 1) {
				mp[t[j]] = 2;
			}
		}
		for (auto it = mp.begin(); it != mp.end(); ++it) {
			if (it->second == 2) {
				n++;
			}
		}
		chmax(ans, n);
	}
	cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    int cnt = 0;
    while(1){
        bool flag = 0;
        for(int i=0;i<n;i++){
            if(a[i]%2==0){
                a[i]/=2;
            }else{
                flag = 1;
            }
        }
        if(flag){
            cout << cnt << endl;
            return 0;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m; cin >> n >> m;
  vector<int> a(n);
  double vote = 0;
  int cnt = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    vote += a.at(i);
  }
  vote = vote /(4 * m);
  
  for(int i = 0; i < n; i++){
    if(a.at(i) >= vote){
      cnt++;
      if(cnt == m){
    	cout << "Yes";
        return 0;
      }
    }
  }
    cout << "No";
}


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

  public static void main(String[] args) {
  
  Scanner sc=new Scanner(System.in);
  int a[]=new int[3];
  a[0]=sc.nextInt();
  a[1]=sc.nextInt();



  System.out.println(-(a[1]-a[0]-1));
  }
  
}

Measured memory_bytes: 21204
n = int(input())
AB = [[] * 2 for _ in range(n - 1)]
graph = [[] for _ in range(n + 1)]

for i in range(n - 1):
	a, b = map(int, input().split())
	AB[i].append(a)
	AB[i].append(b)
	graph[a].append(b)
	graph[b].append(a)

root = 1
parent = [0] * (n + 1)
order = []
stack = [root] # 根を stack に入れる

while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)

color = [-1] * (n + 1)
for x in order:
	ng = color[x]
	c = 1
	for y in graph[x]:
		if y == parent[x]:
			continue
		if c == ng:
			c += 1
		color[y] = c
		c += 1

res = []
for a, b in AB:
	if parent[a] == b:
		res.append(color[a])
	else:
		res.append(color[b])

print(max(res)) # root
print('\n'.join(map(str, res)))

Measured memory_bytes: 84256
#include <stdio.h>
#include <string.h>

int main() {
    int a, b, c;
    int digit;
    for (int i = 0;i < 200; i++) {
        if (scanf("%d %d", &a, &b) != 2) {
            break;
        }
        c = a + b;
        digit = 0;
        for (;;){
            if (c % 10 != 0) {
                digit++;
                c = c / 10;
            } else if (c / 10 != 0) {
                digit++;
                c = c / 10;
            } else {
                break;
            }
        }
        printf("%d\n", digit);
    }
    return 0;
}



Measured memory_bytes: 2060
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;


void solve(){
	int n; cin>>n;
	int k=2;// cin>>k;
	int a[n]; f(i,0,n) cin>>a[i];
	int cost[n];
	cost[0]=0;
	f(i,1,n){
		int mn=LLONG_MAX;
		for(int j=i-1;j>=0 && (i-j) <= k;--j){
			mn=min(mn,cost[j]+abs(a[i]-a[j]));
		}
		cost[i]=mn;
	}
	cout<<cost[n-1];
}

signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!


Measured memory_bytes: 5180
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない



int main() {

	string s;
	cin >> s;

	vector<string> ss(4);

	ss[0] = "resare"; ss[2] = "esare";
	ss[1] = "remaerd"; ss[3] = "maerd";

	bool key = true;

	reverse(s.begin(), s.end());

	int i = 0;

	while (i < s.size()) {
		bool key2 = false;
		rep(j, 0, 4) {
			string s1 = s.substr(i, ss[j].size());
			if (s1 == ss[j]) {
				key2 = true; i += ss[j].size(); break;
			}
		}
		if (!key2) { key = false; break; }
	}

	if (key) {
		YES;
	}
	else {
		NO;
	}

	return 0;
}


Measured memory_bytes: 512
# coding: utf-8
# Your code here!
import sys
import itertools


N, M, Q = map(int, input().split())
nums_list = []
A = [] # 最大M
for m in range(M):
    A.append(m+1)
run_list = []
for v in itertools.combinations_with_replacement(A, N):
    count = 0 
    for i in range(N-1):
        if v[i] <= v[i+1]:
            count += 1
    if count == N-1:
        run_list.append(v)

for q in range(Q):
    nums = [int(x.strip()) for x in input().split(' ') ]
    nums_list.append(nums)
ans = 0

for run in run_list:
    tmp = 0
    for num in nums_list:
        if run[num[1]-1] - run[num[0]-1] == num[2]:
            tmp = tmp + num[3]
            
    if ans < tmp:
        ans = tmp
    
print(ans)

Measured memory_bytes: 21852
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

//Russian Dolls
public class Main{

	static class T implements Comparable<T>{
		int h,r;
		public T(int h, int r) {
			this.h = h;
			this.r = r;
		}
		public int compareTo(T o) {
			return h==o.h?r-o.r:h-o.h;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			List<T> l = new ArrayList<T>();
			for(int i=0;i<n;i++)l.add(new T(sc.nextInt(), sc.nextInt()));
			int m = sc.nextInt();
			for(int i=0;i<m;i++)l.add(new T(sc.nextInt(), sc.nextInt()));
			Collections.sort(l);
			int[] dp = new int[n+m];
			Arrays.fill(dp, 1);
			int max = 1;
			for(int i=1;i<n+m;i++){
				T a = l.get(i);
				for(int j=i-1;j>=0;j--){
					T b = l.get(j);
					if(b.h<a.h&&b.r<a.r)dp[i]=Math.max(dp[i], dp[j]+1);
				}
				max = Math.max(max, dp[i]);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	
  	long long n,a,b;
  	cin>>a>>b>>n;
  	cout<<max(0LL,a-n)<<" "<<max(0LL,b-(n-(a-max(0LL,a-n))))<<endl;
  
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000;
const double PI = acos(-1);
const int mod = 1000000007;
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 {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= 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 {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n) :fact(n + 1), ifact(n + 1) {
        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];
    }
};

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    map<int, int> mp;
    mp[0] = 3;
    mint ans(1);
    rep(i, n) {
        ans *= mp[a[i]];
        mp[a[i]]--;
        mp[a[i] + 1]++;
    }
    cout << ans.x << endl;
}


Measured memory_bytes: 8156
n,m = map(int, input().split())
a = [[0, 'WA'] for i in range(n)]
tmp_AC = 0
tmp_WA = 0
for i in range(m):
  l,s = map(str, input().split())
  l = int(l) - 1
  if a[l][1] == 'WA' and s == 'AC':
    a[l][1] = 'AC'
    tmp_AC += 1
    tmp_WA += a[l][0]
  elif a[l][1] == 'WA' and s == 'WA':
    a[l][0] += 1
print(tmp_AC, tmp_WA)

Measured memory_bytes: 14836
import collections
n = int(input())
a = list(map(int, input().split()))


def comb2(n):
    return (n * (n-1)) // 2


sums = [0]
for i in range(n):
    sums.append(sums[i] + a[i])

sums = sorted(sums)

counts = collections.Counter(sums)
res = 0

for i in counts:
    res += comb2(counts[i])

print(res)


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
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;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int A, B; cin >> A >> B;
	int K; cin >> K;
	vector<int>v;
	rep(i, 0, max(A, B)) {
		int j = i + 1;
		if (A%j == 0 and B%j == 0) {
			v.eb(j);
		}
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	dump(v);
	cout << v[v.size()-K] << endl;


	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> arr(n);
    F0R(i,n)
        cin >> arr[i];
    SORT(arr);
    REV(arr);
    int cnt=1;
    int ind=1;
    ll tot=arr[0];
    while(cnt<n-1) {
        if(cnt+2<n) {
            cnt+=2;
            tot+=arr[ind]+arr[ind];
        }
        else {
            cnt++;
            tot+=arr[ind];
        }
        ind++;
    }
    cout << tot;

    return 0;
}


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

public class Program
{
	public static void Main()
	{
		var HW = Console.ReadLine().Split().Select(int.Parse);
		for (int i = 0; i < HW.First(); i++)
		{
			var C = Console.ReadLine();
			for (int j = 0; j < 2; j++)
			{
				Console.WriteLine(C);
			}
		}
	}
}

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

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

string s, t;
int S, T;

bool match (int k) {
  REP(i,T) {
    if (t[i] != s[i+k] && s[i+k] != '?') {
      return false;
    }
  }
  return true;
}

string construct (int k) {
  string ans = s;
  REP(i,T) {
    ans[k+i] = t[i];
  }
  REP(i,S) {
    if (ans[i] == '?') {
      ans[i] = 'a';
    }
  }
  return ans;
}

int main () {
  cin >> s >> t;
  S = SZ(s);
  T = SZ(t);

  int k = -1;
  REP(i,S-T+1) {
    if (match(i)) {
      k = i;
    }
  }

  if (k == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  cout << construct(k) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100
void BubbleSort(int x[],int n);

int main(){
	int i,N;
	int x[MAX] = {0} ;
	
	cin >> N ;

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

	BubbleSort(x,N);
	return 0;

}

void BubbleSort(int x[],int n){
	int i,j,tmp,count=0;

	for(i=1;i<n;i++){
		for(j=(n-1);j>(i-1);j--){
			if(x[j] < x[j-1]){
				tmp = x[j] ;
				x[j] = x[j-1] ;
				x[j-1] = tmp ;
				count++;
			}
		}
	}

	for(i=0;i<n;i++){

	if(i<(n-1))cout << x[i] << ' ' ;
	if(i == (n-1))cout << x[i] << endl ;

	}
	
	cout << count << endl ;
}

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

int main(){
    int N; cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        A[i]--;
    }
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 0; i < N - 1; i++) cin >> C[i];

    int ans = 0;
    for(int i = 0; i < N - 1; i++){
        if(A[i + 1] == A[i] + 1){
            ans += B[A[i]] + C[A[i]];
        }else{
            ans += B[A[i]];
        }
    }
    ans += B[A[N - 1]];

    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
f = [[] for i in range(3*n)]
for i in range(m):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    f[u].append(v+n)
    f[u+n].append(v+2*n)
    f[u+2*n].append(v)

s,t = map(int,input().split())
s -= 1
t -= 1

stack = [s]
stack_new = []
used = [-1 for i in range(3*n)]

time = 0
while len(stack) > 0:
    now = stack.pop()
    if used[now] == -1:
        used[now] = time
        if now == t:
            print(time//3)
            exit()
        stack_new+=f[now]
    if len(stack) == 0:
        stack = stack_new
        stack_new = []
        time += 1

print(-1)

Measured memory_bytes: 101516
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		
		int b = scan.nextInt();
		
		
		
		System.out.println(a * b + " " + (a*2 + b*2));
	}

}


Measured memory_bytes: 26016
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
import math
import string
import fractions
import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop

# from itertools import accumulate
# from collections import deque
import random




def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def main():
    n = int(input())
    if n==1:
        print("Hello World")
    else:
        a = int(input())
        b = int(input())
        print(a+b)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 65260
# coding: utf-8
# Your code here!
S = input()
flag1 = False
flag2 = False

num1 = int(S[0] + S[1])
num2 = int(S[2] + S[3])

if num1 >= 0 and (num2 >= 1 and num2 <= 12):
    flag1 = True

if (num1 >= 1 and num1 <= 12) and num2 >= 0:
    flag2 = True
    


if flag1 == True and flag2 == False:
    print("YYMM")
elif flag1 == False and flag2 == True:
    print("MMYY")
elif flag1 == True and flag2 == True:
    print("AMBIGUOUS")
else:
    print("NA")


Measured memory_bytes: 38420
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int m;
    for(int i=1;i<n;i++){
        m=s[i-1].length();
        if(s[i][0]!=s[i-1][m-1]){
            cout << "No"<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j]){
                cout << "No"<<endl;
                return 0;
            }
        }
    }
    cout << "Yes"<<endl;
    return 0;
}



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

int main(){
  string S;
  cin >> S;
  int year, month;
  year = atoi(S.substr(5, 6).c_str());
  if(year >= 5){
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

void solve(){
	
	int n, m; cin >> n >> m;	
	vi H;
	int ans = 0;
	for(int i = 0, tmp; i < n; ++i){
		cin >> tmp;
		H.push_back(tmp);
	}
	vector<vi> adj(n);
	for(int i = 0, tmp1, tmp2; i < m; ++i){
		cin >> tmp1 >> tmp2; tmp1--; tmp2--;
		adj[tmp1].push_back(tmp2);
		adj[tmp2].push_back(tmp1);
	}
	for(int i = 0; i < n; ++i){
		int ok = 1;
		for(int j = 0; j < adj[i].size(); ++j){
			if(H[i] <= H[adj[i][j]]){
				ok = 0;
			}
		}
		ans += ok;
	}
	cout << ans << "\n";	
	
			
}

int main(){
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	
	solve();
		
	return 0;
}


Measured memory_bytes: 8772
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        List<Integer> totalList = new ArrayList<Integer>();
        for(int i=0; i<= n; i++) {
            int sum = gettotal(i);

            if (a <= sum && b >= sum) {
                totalList.add(i);
            }
        }

        int res = 0;
        for (int i=0; i < totalList.size(); i++) {
            res = res + totalList.get(i);
        }
        System.out.print(res);
    }

    private static int gettotal(int i) {
        int sum = 0;
        while(i !=0) {
            sum += i % 10;
            i /= 10;
        }
        return sum;
    }
}



Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
long long a, b;
void solve()
{
    cin >> a >> b;
    if((a+b)%2==0) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;
    return;
}
int main ()
{
   // FasterIO;
    #ifdef _online
    input
    //output
    #endif // _online
    solve();
}


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

int main() {
    int x; cin >> x;
    set<int> nums;
    nums.insert(1);
    for (int i = 2; i*i <= x; ++i) {
        int num = i;
        for (int j = 0; num <= x; ++j) {
            num *= i;
            if (num <= x) nums.insert(num);
        }
    }
    cout << *rbegin(nums) << endl;
}

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

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int64_t dp[4010][4010];

struct V {
	int64_t a;
	int i;
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t n; cin >> n;
	vector<V> vs(n);
	FOR_LT(i, 0, n) {
		int a; cin >> a;
		vs[i] = { a,i };
	}
	sort(vs.begin(), vs.end(), [](const auto& lhs, const auto& rhs) {
		return lhs.a > rhs.a;
	});

	FOR_LT(i, 0, n) {
		int x = i + 1;
		int y = 0;

		int pl = vs[i].i;
		int pr = n - 1 - vs[i].i;
		while (0 <= x) {
			int64_t v = 0;
			if (x != 0) {
				v = max(v, dp[x - 1][y] + vs[i].a * (pl - x + 1));
			}
			if (y != 0) {
				v = max(v, dp[x][y - 1] + vs[i].a * (pr - y + 1));
			}

			dp[x][y] = v;
			x--;
			y++;
		}

	}

	int64_t ans = 0;
	FOR_LE(x, 0, n) {
		int y = n - x;
		ans = max(ans, dp[x][y]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 27304
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<int,int>
#define mp make_pair
using namespace std;
int n;
ll memo[101][100005];
ll a[105];
ll w[105];
ll solve(int i,int sum)
{
    if(i == n)
    {
        return 0;
    }
    ll &ret = memo[i][sum];
    if(ret != -1)
        return ret;
    ret = 0;
    if(sum >= w[i])
    {
        ret = max(ret , a[i]+solve(i+1,sum-w[i]));
    }
    ret = max(ret , solve(i+1,sum));
    return ret;
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int x;
   cin>>n>>x;
   for(int i=0;i<n;i++)
   {
       cin>>w[i]>>a[i];
   }
   cout<<solve(0,x);
}


Measured memory_bytes: 79104
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define fr first
#define sd second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
map<string,int>ma;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read();
	while(n--)
	{
		string s;
		cin>>s;ma[s]++;
	}
	cout<<"AC"<<" x "<<ma["AC"]<<endl;
	cout<<"WA"<<" x "<<ma["WA"]<<endl;
	cout<<"TLE"<<" x "<<ma["TLE"]<<endl;
	cout<<"RE"<<" x "<<ma["RE"]<<endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;
import java.lang.*;

public class Main {
	static long mod = 998244353;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		int count = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			if (a[i] < 0) {
				count++;
			}
		}
		long ans = 0;
		if (count % 2 == 0) {
			for (int i = 0; i < n; i++) {
				ans += Math.abs(a[i]);
			}
		} else {
			long min = 1000000001;
			for (int i = 0; i < n; i++) {
				if (Math.abs(a[i]) < min) {
					min = Math.abs(a[i]);
				}
			}
			for (int i = 0; i < n; i++) {
				ans += Math.abs(a[i]);
			}
			ans -= min * 2;
		}
		System.out.println(ans);
	}
}

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

int main()
{
  int n,m;
  cin >> n >> m;
  
  int x[m];
  rep(i,m) cin >> x[i];
  
  sort(x,x+m);
  
  int dis[m-1];
  rep(i,m-1) dis[i] = x[i+1] - x[i];
  
  sort(dis,dis+(m-1));
  
  ll ans = 0;
  for(int i = 0; i < m-1-(n-1); i++)
  {
    ans += dis[i];
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 4416
def resolve():
    N = int(input())
    K = int(input())
    x = list(map(int, input().split()))
    
    sum = 0
    for i in range(N):
        if K-x[i] > x[i]:
            sum += x[i]*2
        else:
            sum += (K-x[i])*2
    print(sum)
resolve()


Measured memory_bytes: 38256
#include<iostream>
#include<queue>
#include<map>
#include<cstdio>
#include<algorithm>
#define INF 1000000
using namespace std;
typedef pair<int,int> P;
int main(){
  int n,m;
  cin>>n>>m;
  int a,b,c,d;
  int x1,x2,y1,y2;
  int cost[22][22];
  int dcost[22];
  int ans;
  for(int i=0;i<22;i++){
    for(int j=0;j<22;j++){
      cost[i][j]=INF;
    }
    dcost[i]=INF;
  }
  for(int i=0;i<m;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    cost[a][b]=c;
    cost[b][a]=d;
  }
  scanf("%d,%d,%d,%d",&x1,&x2,&y1,&y2);
  ans=y1-y2;
  // ダイクストラ
  dcost[x1]=0;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,x1));
  
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    int nc=p.first;
    for(int i=0;i<=n;i++){
      if(cost[v][i]!=INF && cost[v][i]+nc<dcost[i]){
	dcost[i]=cost[v][i]+nc;
	que.push(P(dcost[i],i));
      }
    }
  }
  ans-=dcost[x2];
  for(int i=0;i<22;i++){
    dcost[i]=INF;
  }
  
  dcost[x2]=0;
  
  que.push(P(0,x2));
  
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    int nc=p.first;
    for(int i=0;i<=n;i++){
      if(cost[v][i]!=INF && cost[v][i]+nc<dcost[i]){
	dcost[i]=cost[v][i]+nc;
	que.push(P(dcost[i],i));
      }
    }
  }
  ans-=dcost[x1];
  cout<<ans<<endl;
}

Measured memory_bytes: 1244
import bisect
n,m = map(int,input().split())
p = [0]*(n+1)
mod = 10**9+7

a = [int(input()) for i in range(m)]

p[0]=1

for i in range(1,n+1):
  k = bisect.bisect_left(a,i)
  k2 = bisect.bisect_right(a,i)
  if k == k2:
    p[i] += p[i-1]
    if i >= 2:
      p[i] += p[i-2]
    p[i] = p[i]%mod
#print(p)
print(p[-1]%mod)


Measured memory_bytes: 54232
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int N, K;
	cin >> N >> K;

	int ans = 1;
	for (int i = 0; i < N; i++)
	{
		ans = min(ans + K, 2 * ans);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
var arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var id = arr[0]; var gate = arr[1];
var array = Array(count:arr[0], repeatedValue: 0 )

var min = 0
var max = id - 1
var o = 0
//arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
while let line = readLine() {
  arr=line.characters.split{$0==" "}.map{Int(String($0))!}
  
  if( arr[0] - 1 > min ) {
    min = arr[0] - 1
  }
  
  if( max > arr[1] - 1 ) {
    max = arr[1] - 1
  }
      
}

let newArray = array.filter { $0 == gate }
if( (max - min)  < 0 )  {
  print( 0 )
}
else {
  print( (max - min) + 1 )
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

//-----------------------------------------

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

  ll s;
  cin >> s;
  vll dp(s + 1, 1);
  dp[0] = dp[1] = dp[2] = 0;

  for(ll i = 3; i <= s; i++){
    for(ll j = 3; j <= i - 3; j++){
      dp[i] += dp[j];
      dp[i] %= MOD;
    }
  }
  cout << dp[s] << endl;
    
    
  return 0;
}



Measured memory_bytes: 3660
import math
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    a, b, x = map(int, input().split())
    v = a ** 2 * b
    if v / 2 > x:
        alpha = 2 * x / (a * b)
        ans = math.degrees(math.atan(b / alpha))
    else:
        alpha = 2 * b - 2 * x / (a ** 2)
        ans = math.degrees(math.atan(alpha / a))
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int A, B, K; cin >> A >> B >> K;
	for (int i = 100; i > 0; --i) {
		if (!(A % i) && !(B % i)) K--;
		if (K == 0) {cout << i << endl; return 0;}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <set>

int n, k;
int P[200000];


int main(){
  int i, r;
  std::set<int> s;
  scanf("%d%d", &n, &k);
  for(i=0;i<n;i++) scanf("%d", P+i);
  int sort = 0;
  for(i=0;i<k;i++){
    s.insert(P[i]);
    sort += (i!=0&&P[i] > P[i-1]);
  }
  r = 1;
  int m = sort == k-1;
  for(i=k;i<n;i++){
    if(P[i-k] == *s.begin() && P[i] > *s.rbegin()) ;
    else r++;
    int nsort = sort - (P[i-k+1] > P[i-k]) + (P[i] > P[i-1]);
    m += sort != k-1 && nsort == k-1;
    sort = nsort;

    s.erase(P[i-k]);
    s.insert(P[i]);
  }
  printf("%d\n", r - (m?m-1:0));

  return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=0,h,w,n;
    cin>>h>>w>>n;

    ans=min(n/h+((n%h>0)?(1):(0)),n/w+((n%w>0)?(1):(0)));

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A, B, C, X, Y;
int main(){
    cin >> A >> B >> C >> X >> Y;
    int ans = 1e9;
    for(int i = 0; i <= X; i++){
        int s = i * A + 2 * C * (X - i);
        int br = max(0, Y - (X - i));
        s += br * B;
        ans = min(ans, s);
    }
    for(int i = 0; i <= Y; i++){
        int s = i * B + 2 * C * (Y - i);
        int br = max(0, X - (Y - i));
        s += br * A;
        ans = min(ans, s);
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

typedef long long Int;
const int MOD = 1000000007;

Int dp[201][201];

int main()
{
    int N;
    char s[256];

    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%s", &s[i]);

    dp[0][0] = 1;

    for (int i = 0; i < N; i++){
        for (int j = 0; j <= N; j++){
            if (s[i] == '-'){
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
            }
            if (s[i] == 'U'){
                dp[i + 1][j] += dp[i][j] * j;
                dp[i + 1][j] %= MOD;
                if (j < N){
                    dp[i + 1][j + 1] += dp[i][j];
                    dp[i + 1][j + 1] %= MOD;
                }
            }
            if (s[i] == 'D'){
                dp[i + 1][j] += dp[i][j] * j;
                dp[i + 1][j] %= MOD;
                if (j > 0){
                    dp[i + 1][j - 1] += dp[i][j] * j * j;
                    dp[i + 1][j - 1] %= MOD;
                }
            }
        }
    }

    printf("%lld\n", dp[N][0]);

    return (0);
}

Measured memory_bytes: 1504
#include<bits/stdc++.h>
#define int long long
using namespace std;


signed main(){
    
    int n;  cin >> n;
    int a[n+2] = {0};
    for(int x=1;x<=n;x++)   cin >> a[x];

    int pref[n+2] = {0} , suff[n+2] = {0};

    for(int x=1;x<=n;x++) pref[x] = __gcd(pref[x-1] , a[x]);
    for(int x=n;x>=0;x--) suff[x] = __gcd(suff[x+1] , a[x]);

    int ans = 0;

    for(int x=1;x<=n;x++){

        // int ahead, back;
        int num = __gcd(pref[x-1] , suff[x+1]);
        int total = __gcd(num , __gcd(pref[x-1] , suff[x+1]));

        ans = max(ans , total);

        // if(x == 1){
        //     ahead = suff[x+1];
        //     back = a[x];

        //     ans = max(ans , __gcd(back , ahead));
        // }else if(x == n){
        //     ahead = a[x];
        //     back = pref[x-1];

        //     ans = max(ans , __gcd(ahead, back));
        // }else{

        //     ahead = suff[x+1];
        //     back = pref[x-1];
        //     int num = lcm(ahead, back);

        //     ans = max(ans , __gcd(ahead , __gcd(back , num)));


        // }


    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>

#define SIZE 200005
#define MOD 1000000007

using namespace std;
typedef long long int ll;

char str[SIZE];
bool black[SIZE];

int main() {
	
	int n;
	cin >> n >> str;

	for (int i = 0; i < 2 * n; i++)
	{
		// 奇数番目
		if (i % 2)
		{
			black[i] = str[i] == 'B';
		}
		// 偶数番目
		else
		{
			black[i] = str[i] == 'W';
		}
	}
	ll ret = 1;
	int stack = 0;
	for (int i = 0; i < 2 * n; i++)
	{
		// white
		if (black[i] == false)
		{
			stack++;
			//cout << stack << endl;
		}
		// black
		else
		{
			// 組み合わせなし
			if (stack == 0)
			{
				cout << 0;
				return 0;
			}
			ret = ret * (ll)stack % MOD;
			stack--;
			//cout << stack << " : " << ret << endl;
		}
	}
	if (stack > 0)
	{
		cout << 0;
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		ret = ret * (ll)i % MOD;
	}
	cout << ret;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

int main() {
    char a = 'a', A = 'A', z = 'z', Z = 'Z';
    char tmp;

    std::cin >> tmp;

    if(tmp >= a && tmp <= z) {
        std::cout << a << std::endl;
    }
    else {
        std::cout << A << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3608
// AOJ 1345: Bit String Reordering
// 2017.12.4 bal4u@uu

#include <stdio.h>

#define INF 1000

int b[16];
int zero[16], one[16];

int swap(int *a, int goal, int fr, int to)
{
	int i;

	for (i = fr+1; i < to; i++) {
		if (a[i] == goal) { a[i] = a[fr], a[fr] = goal; return i - fr; }
	}
	return INF;
}

int main()
{
	int n, m, p, i, j, bit, cnt0, cnt1;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) scanf("%d", b+i);
	for (bit = 0, j = i = 0; i < m; i++, bit = !bit) {
		scanf("%d", &p);
		while (p--) zero[j] = bit, one[j++] = !bit;
	}

	for (cnt0 = cnt1 = 0, i = 0; i < n; i++) {
		if (zero[i] != b[i]) cnt0 += swap(zero, b[i], i, n);
		if ( one[i] != b[i]) cnt1 += swap( one, b[i], i, n);
	}
	if (cnt0 > cnt1) cnt0 = cnt1;
	printf("%d\n", cnt0);
	return 0;
}

Measured memory_bytes: 1828
#include <iostream>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 5e6+17;
int main(int argc ,char const *argv[])
{
	#ifdef noob
	freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
	#endif
	string str;
	int a[26]={0};
	cin>>str;
	for (int i = 0; i < str.length(); ++i)
	{
		a[str[i]-'a']++;
	}
	for (int i = 0; i < 26; ++i)
	{
		if(a[i]==0)
		{
			str.push_back(i+'a');
			return cout<<str<<endl,0;
		}
	}
	for (int i = str.length()-1; i > -1; --i)
	{
		for (int j = str[i]-'a'+1; j < 26; ++j)
		{
			if(str[i]=='w')
			{
				debug(j);
				debug(a[j]);
			}
			if(a[j]==0)
			{
				str[i] = j+'a';
				return cout<<str<<endl,0;
			}
		}
		a[str[i]-'a']--;
		str.pop_back();
	}
	cout<<-1<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<long long int > v(n);
    REP(i,n){
        cin>>v[i];

    }
    long long int result=0,tmp=0;
    FOR(i,1,n){
        
        if(v[i-1]>=v[i]){
            tmp++;
            result=max(result,tmp);
        }else{
            result=max(result,tmp);
            tmp = 0;
        }
    }
cout<<result<<endl;
    return 0;
}


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

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;	
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}
string str;
bool can (string s) {
	int ptr = 0;
	for (int i = 0; i < (int) str.size(); i += 1) {
		if (str[i] == s[ptr]) {
			++ptr;
		}
		if (ptr == 3)
			return true;
	}
	return false;
}
int n;
string tostr (int n) {
	string lol = to_string(n);
	while ((int) lol.size() < 3)
		lol = '0' + lol;
	return lol;
}
void solve() {
	cin >> n;
	cin >> str;
	int ans = 0;
	for (int i = 0; i <= 999; i += 1) {
		if (can(tostr(i)))
			++ans;
	}
	cout << ans;
}     	

Measured memory_bytes: 512
N = int(input())
W = [int(x) for x in input().split()]

min = abs(sum(W))
for i in range(1, N+1):
    n1 = sum(W[0:i])
    n2 = sum(W[i:N])
    if abs(n1 - n2) < min:
        min = abs(n1 - n2)

print(min)

Measured memory_bytes: 3060