akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const int INF = 100000000;

int dp[2003][2003];
int chw[2003][2003], chb[2003][2003];

int main()
{
    int n;
    cin >> n;
    char c[4003];
    int a[4003];
    for(int i = 0; i < n * 2; i++) cin >> c[i] >> a[i];
    int leftw[2003] {0}, leftb[2003] {0};
    for(int i = 0; i < n * 2; i++){
        for(int j = 0; j < i; j++){
            if(c[i] == 'W' && c[j] == 'W' && a[j] > a[i]) leftw[a[i]]++;
            if(c[i] == 'B' && c[j] == 'B' && a[j] > a[i]) leftb[a[i]]++;
            if(c[i] == 'W' && c[j] == 'B') chw[a[i]][a[j] - 1] = 1;
            if(c[i] == 'B' && c[j] == 'W') chb[a[i]][a[j] - 1] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = n - 1; j >= 0; j--){
            chw[i][j] += chw[i][j + 1];
            chb[i][j] += chb[i][j + 1];
        }
    }
    for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = INF;
    dp[0][0] = 0;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + leftw[i] + chw[i][j]);
            if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + leftb[j] + chb[j][i]);
        }
    }
    cout << dp[n][n] << endl;
}

Measured memory_bytes: 47232
S = input()

a = int(S[:2])
b = int(S[2:])

s = 1 <= b <= 12
f = 1 <= a <= 12
if f and s:
    print("AMBIGUOUS")
elif f:
    print("MMYY")
elif s:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N;
	cin >> N;
	int W[N];
	int SUM = 0;

	for(int i=0; i<N; i++) {
		int w;
		cin >> w;
		W[i] = w;
		SUM += w;
	}

	int n=0;
	int ans = 1000000;
	for(int i=0; i<N; i++) {
		n += W[i];
		int left = SUM - n;

		ans = min(ans, abs(left-n));
	}

	cout << ans;
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
X,Y, A,B, C = list(map(int , input().split()))
P = list(map(int , input().split()))
Q = list(map(int , input().split()))
R = list(map(int , input().split()))
s = X + Y
R.sort(reverse=True)
P.sort(reverse=True)
Q.sort(reverse=True)

Z = P[:X]+Q[:Y]+R
Z.sort(reverse=True)
w = 0
for i in range(s):
    w += Z[i]
print(w)

Measured memory_bytes: 110828
import sys
 
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
 
 
def resolve():
    s = input()
    if s.isupper():
        print("A")
    else:
        print("a")
 
 
 
if __name__ == '__main__':
    resolve()

Measured memory_bytes: 8868
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, vis[51];
vector <int> a, b, ans;

bool dfs(int node, int tnode){
    if(node == tnode) return 1;
    if(vis[node]) return 0;
    vis[node] = 1;
    for(auto &i : ans)
        if(dfs(node % i, tnode))
            return 1;
    return 0;
}
bool check(){
    for(int i = 0 ; i < n ; i++){
        memset(vis, 0, sizeof vis);
        if(dfs(a[i], b[i]) == 0) return 0;
    }
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0, x ; i < n && cin >> x ; i++)
        a.push_back(x);
    for(int i = 0, x ; i < n && cin >> x ; i++)
        b.push_back(x);
    for(int i = 1 ; i <= 50 ; i++)
        ans.push_back(i);
    if(check() == 0) finish(-1);
    ll res = 0;
    for(int i = 49 ; i >= 0 ; i--){
        ans.erase(ans.begin() + i);
        if(!check()){
            ans.insert(ans.begin() + i, i + 1);
            res += 1LL << ans[i];
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
n = int(input())
testimony = [[] for _ in range(n)]

for i in range(n):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])

honest = 0
for i in range(1, 2**n):
    flag = 0
    for j in range(n):
        if (i>>j)&1 == 1:
            for x, y in testimony[j]:
                if (i>>x)&1 != y:
                    flag = 1
    if flag == 0:
        honest = max(honest, bin(i)[2:].count('1'))

print(honest)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstring>
#define ll long long
#define next fuck
#define fi first
#define se second
using namespace std;
int main()
{

    string s;
    cin>>s;
    int mn = INT_MAX;
    for(int i = 0;i<=s.length()-3;i++)
    {
        int y = (s[i] - '0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        //cout<<y<<endl;
        mn = min(mn,abs(y-753));
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int g[12];
int main()
{
    std::ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;

    for(int i=1; i<=k; i++)
    {
        int x;
        cin>>x;
        g[x]=1;
    }
    for(n;; n++)
    {
        int t=n,flag=0;
        while(t)
        {
            int c=t%10;
            if(g[c])
            {
                flag=1;
                break;
            }
            t/=10;
        }
        if(!flag)
            break;
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//D
int main() {
	ll M;
	scanf("%lld", &M);
	vector<ll> d(M);
	vector<ll> c(M);
	for (ll i = 0; i < M; i++) {
		scanf("%lld %lld", &d[i], &c[i]);
	}

	ll keta = 0;
	ll sum = 0;
	for (ll i = 0; i < M; i++) {
		sum += d[i] * c[i];
		keta += c[i];
	}

	ll result = keta - 1 + ((sum - 1) / 9);

	printf("%lld\n", result);
}


//C
/*
int main() {
	ll H;
	scanf("%lld", &H);
	ll W;
	scanf("%lld", &W);
	ll K;
	scanf("%lld", &K);
	vector<vector<char>> arr(H, vector<char>(W, 0));
	for (ll j = 0; j < H; j++) {
		char s[400];
		scanf("%s", s);

		for (ll i = 0; i < W; i++) {
			arr[j][i] = s[i];
		}
	}

	int currNo = 0;

	vector<vector<int>> result(H, vector<int>(W, 0));

	for (ll j = 0; j < H; j++) {
		int count = 0;
		for (ll i = 0; i < W; i++) {
			if (arr[j][i] == '#') {
				count++;
				break;
			}
		}

		if (count > 0) {
			currNo++;
		}
		else {
			continue;
		}

		count = 0;
		for (ll i = 0; i < W; i++) {
			if (arr[j][i] == '#') {
				count++;
				if (count >= 2) {
					currNo++;
				}
			}

			result[j][i] = currNo;
		}
	}

	//��
	for (ll j = 1; j < H; j++) {
		if (result[j][0] > 0) {
			continue;
		}

		for (ll i = 0; i < W; i++) {
			result[j][i] = result[j - 1][i];
		}
	}

	//��
	for (ll j = H - 2; j >= 0; j--) {
		if (result[j][0] > 0) {
			continue;
		}

		for (ll i = 0; i < W; i++) {
			result[j][i] = result[j + 1][i];
		}
	}

	for (ll j = 0; j < H; j++) {
		for (ll i = 0; i < W; i++) {
			printf("%d ", result[j][i]);
		}
		printf("\n"); 
	}
}
*/

//B
/*
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> A(N);
	ll total = 0;
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		total += A[i];
	}

	ll result = INF;
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		sum += A[i];

		if (sum * 2 == total) {
			result = 0;
		}
		else if (sum * 2 <= total) {
			result = min(result, abs(total - 2 * sum));
		}
		else {
			result = min(result, abs(2 * sum - total));
		}
	}



	printf("%lld\n", result);
}
*/

//A
/*
int main() {
	ll X;
	scanf("%lld", &X);
	ll Y;
	scanf("%lld", &Y);

	ll result = 0;

	if (X == 3) {
		result += 100000;
	}
	else if (X == 2) {
		result += 200000;
	}
	else if (X == 1) {
		result += 300000;
	}

	if (Y == 3) {
		result += 100000;
	}
	else if (Y == 2) {
		result += 200000;
	}
	else if (Y == 1) {
		result += 300000;
	}

	if (X == 1 && Y == 1) {
		result += 400000;
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 3328
#include<stdio.h>

int main()
{
	int A,B,C,D;
	while(scanf("%d %d %d %d",&A,&B,&C,&D)!=EOF)
	while(A>0 && B>0)
	{
		C=C-B;
		if(C<=0)
		{
			printf("Yes\n");
			break;
		}
		A=A-D;
		if(A<=0)
		{
			printf("No\n");
			break;
		} 
	}	
	return 0;
 } 

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,a[102],k=0,l=0,cnt=0,x,n,m,c,b[102][102];
    cin>>n>>m>>c;
    for(i=0;i<m;i++){cin>>a[i];}
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){cin>>b[i][j];}
    }
    for(i=0;i<n;i++){
            l=0;
        for(j=0;j<m;j++){
            l+=b[i][j]*a[j];
        }
        if(l+c>0){cnt++;}
    }
  cout<<cnt<<endl;




}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();

		boolean result = false;
		if (n % 2 == 0 && s.substring(0, n / 2).equals(s.substring(n / 2))) {
			result = true;
		}
		System.out.println(result ? "Yes" : "No");
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll solve()
{
    ll N;
    std::cin >> N;

    return N * N * N;
}

int main()
{
    std::cout << solve() << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#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 mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main(){
	string s; getline(cin, s);
	rep(i, s.size()) if (isalpha(s[i])) s[i] = toupper(s[i]);
	cout << s << endl;
	
	return 0;
}

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

#define f(i, a, b, c) for(int i = a ; i < b ; i += c)
#define fr(i, a, b, c) for(int i = a ; i >= b ; i -= c)
#define fit(it, v) for(auto it = v.begin() ; it != v.end() ; ++it)
#define frit(it, v) for(auto it = v.rbegin() ; it != v.rend() ; ++it)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define NL '\n'
#define modn 1000000007
#define EPS 1e-9

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< lli > vli;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< char > vc;
typedef vector< string > vs;
typedef vector< bool > vb;
typedef set< int > si;
typedef set< ii > sii;

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

	#ifdef LOCAL_TEST
		ifstream h("in");
		ofstream g("out");
		clock_t z = clock();
	#else
		#define h cin
		#define g cout
	#endif//LOCAL_TEST

	int n, x, t;
	h >> n >> x >> t;
	g << ((n + x - 1) / x) * t;

	#ifdef LOCAL_TEST
		cerr << "Time taken is: " << double(clock() - z) / CLOCKS_PER_SEC << NL;
		h.close();
		g.close();
	#endif//LOCAL_TEST
}


Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
long long f[500];
int main()
{
    scanf("%d",&n);
    f[0]=2;
    for(int i=1;i<=n;i++) f[i]=f[i-1]*2+2;
    printf("%lld\n",f[n]);
    return 0;
}


Measured memory_bytes: 128
class Block
  def initialize(color)
    @color = color
    @size = 1
  end

  def add
    @size += 1
  end

  def sz
    return @size
  end

  def col
    return @color
  end
end

N, K = gets.chomp.split.map(&:to_i)
S = gets.chomp

cur = Block.new(2)
blocks = []
N.times do |i|
  if i == 0 or cur.col != S[i].to_i
    blocks << cur
    cur = Block.new(S[i].to_i)
  else
    cur.add
  end

  blocks << cur if i == N - 1
end
blocks = blocks[1..-1]
b_size = blocks.length

block0_num = 0
blocks.each do |b|
  block0_num += 1 if b.col == 0
end

if block0_num <= K
  puts N
else
  ans = 0
  (0...2*K).each do |i|
    ans += blocks[i].sz
  end
  ans += blocks[2*K].sz if 2*K < b_size and blocks[2*K].col == 1

  canditate = ans
  (1..(b_size - 2*K)).each do |i|
    canditate -= blocks[i - 1].sz  
    canditate += blocks[i - 1 + 2*K].sz if blocks[i - 1 + 2*K].col == 0
    canditate += blocks[i + 2*K].sz if i + 2*K < b_size and blocks[i + 2*K].col == 1
    ans = [ans, canditate].max
  end

  puts ans
end

Measured memory_bytes: 10236
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right

bool check(ll num){
    ll cnt = 0 ;
    while (num != 0) {
        num /= 10;
        cnt ++;
    }
    if(cnt % 2  == 1) return true;
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin >> N ;
    
    ll ans = 0 ;
    rep(i, N){
        ll num = i + 1;
        
        if(check(num)) ans ++;
    }
    
    cout << ans << endl;


    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main() {
  int n;
  while(cin >> n, n) {
    int ab, am = 0, y;
    cin >> y;
    for(int i = 0; i < n; i++) {
      int b, r, t, m;
      cin >> b >> r >> t;
      if(t == 1) m = 10000*(1+y*(double)r/100);
      else {
	double d = 1 + (double)r/100;
	for(int j = 1; j < y; j++) {
	  d *= 1 + (double)r/100;
	}
	m = 10000*d;
      }

      if(m > am) {
	ab = b;
	am = m;
      }
    }
    cout << ab << endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void)
{
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if(a == b || b == c || c == a)
                {
                        if(a == b && b == c){printf("%d",1);}
                        else{printf("%d",2);}
                }
        else{printf("%d",3);}
        return 0;
}


Measured memory_bytes: 128
import sys


def inpl():
    return list(map(int, input().split()))


def set_depth(i):
    for e in edge[i]:
        if depth[e] != -1:
            continue
        depth[e] = depth[i] + 1
        parent[e] = i
        set_depth(e)
    return


def get_root_v(can_depth, u):
    if depth[u] == can_depth:
        return u
    else:
        return get_root_v(can_depth, parent[u])


def find_max_depth(v):
    if len(edge[v]) == 1 and parent[v] == edge[0]:
        return depth[v]

    tmp = depth[v]
    for e in edge[v]:
        if parent[v] == e:
            continue
        else:
            tmp = max(tmp, find_max_depth(e))
    return tmp


sys.setrecursionlimit(2 * 10**6)

N, u, v = inpl()
AB = [inpl() for _ in range(N - 1)]
edge = [[] for i in range(N + 1)]
for a, b in AB:
    edge[a].append(b)
    edge[b].append(a)

depth = [-1 for i in range(N + 1)]
depth[v] = 0

parent = [-1 for i in range(N + 1)]

set_depth(v)

can_depth = depth[u] - (depth[u] - 1) // 2
root_v = get_root_v(can_depth, u)

print(find_max_depth(root_v) - 1)


Measured memory_bytes: 111916
import sys
sys.setrecursionlimit(2000000)
input = sys.stdin.readline
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents = [i for i in range(n+1)]
        self.size = [1]*(n+1)

    def find(self,x):
        if self.parents[x]==x:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        xRoot = self.find(x)
        yRoot = self.find(y)
        if xRoot == yRoot:
            return
        if self.size[xRoot]>self.size[yRoot]:
            self.parents[yRoot] = xRoot
        else:
            self.parents[xRoot] = yRoot
            if self.size[xRoot] == self.size[yRoot]:
                self.size[yRoot]+=1

N,M = map(int,input().split())
tree = UnionFind(N)
P = list(map(int,input().split()))
for _ in range(M):
    x,y = map(int,input().split())
    tree.union(x,y)

indeces = {}
indeces2 = {}
for i in range(N):
    indeces[P[i]]=i+1
    indeces2[i+1]=P[i]

group = {}
group2 = {}
for i in range(1,N+1):
    r = tree.find(i)
    if r not in group:
        group[r]=set()
    group[r].add(i)
    group2[i]=r

ans = 0
for n,index in indeces.items():
    if n == index:
        ans += 1
    else:
        groupNum = group2[index]
        if n in group[groupNum]:
            ans += 1
            a = indeces2[n] #n番目に現在君臨している数字
            indeces2[n] = n
            indeces2[index] = a
            indeces[a] = index
            indeces[n] = n

print(ans)




Measured memory_bytes: 72404
A,B,Q = map(int,input().split())
S = [-float("inf")]+[int(input()) for _ in range(A)]+[float("inf")]
T = [-float("inf")]+[int(input()) for _ in range(B)]+[float("inf")]
X = [int(input()) for _ in range(Q)]

from bisect import bisect_left

for x in X:
    Si,Ti = bisect_left(S,x),bisect_left(T,x)
    Sw,Se = abs(x-S[Si-1]),abs(x-S[Si])
    Tw,Te = abs(x-T[Ti-1]),abs(x-T[Ti])
    print(min(max(Sw,Tw),max(Se,Te),2*min(Sw,Te)+max(Sw,Te),2*min(Tw,Se)+max(Tw,Se)))

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

#define ll long long int
#define pb push_back
#define f(i,x,y) for(i=x;i<y;i++)
#define vll vector<ll>
#define fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}

void addEdge(vll adj[], ll u, ll v) 
{ 
    adj[u].push_back(v); 
    adj[v].push_back(u); 
}
void DFSE(vll adj[],vector<bool> &visited,ll u)
{
    ll i;
    visited[u] = true;
    cout<<u<<" ";
    f(i,0,adj[u].size())
    {
        if(visited[adj[u][i]]==false)
        {
            DFSE(adj,visited,adj[u][i]);
        }
    }
    
}
void DFS(vll adj[],ll u,ll v)
{
    ll i;
    vector<bool> visited(v,false);
    f(i,0,v)
    {
        if(visited[i]==false)
        {
            DFSE(adj,visited,i);
        }
    }
}
bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 

int main()
{
    fast;
    string s,t;
    cin>>s>>t;
    ll mn,n=s.length(),m=t.length(),i;
    mn=m;
    
    f(i,0,n-m+1)
    {
        ll c=0;
        ll j=0;
        while(j<m)
        {
            if(s[i+j]!=t[j])    
                c++;
            j++;
        }
        mn=min(mn,c);
    }
    cout<<mn<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,s=0,t;
	cin>>n;
	t=n;
	while(t!=0)
	{
		s+=t%10;
		t/=10;
	}
	t=n%s;
	if(t==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}



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

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int n, k;
    cin >> n >> k;

    vector<int> A(n);
    int mn = 1 << 29;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        mn = min(mn, x);
        A[i] = x;
    }

    int p = 0;
    for (int i = 0; i < n; ++i) {
        if (A[i] == mn) {
            p = i;
            break;
        }
    }

    int res = n + 1234;
    for (int i = max(0, p - k + 1); i <= min(n - k, p); ++i) {
        int ans = 1 + (i + k - 2) / (k - 1) + (max(0, n - 1 - (i + k - 1)) + k - 2) / (k - 1);
        res = min(res, ans);
        // cout << i << " " << ans << endl;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=305;
int f[2][N][N];
ll l[N*2],r[N*2],n,mo;
int d[N*2];
void move(int &a,ll b){
	a=(a+b)%mo;
}
int main(){
	cin>>n>>mo;
	for (int i=0;i<2*n;i++){
		l[i]=2*n;
		for (int j=0;j<2*n;j++){
			if (n*n<=i*i+j*j&&i*i+j*j<=4*n*n){
				l[i]=min(l[i],(ll)j);
				r[i]=max(r[i],(ll)j);
			}
		}
	}
	int p=n-1,q=2*n-1;
	for (int i=1;i<=2*n;i++){
		if (q<n||p>=0&&l[p]<=r[q])d[i]=p--;
		else d[i]=q--;
	}
	for (int i=0;i<=n;i++)f[0][0][i]=i&1?-1:1;
	int _=0,cnt=0;
	for (int i=1;i<=2*n;i++){
		int x=d[i];_^=1;
		memset(f[_],0,sizeof f[_]);
		for (int j=0;j<=n;j++)
			for (int k=0;j+k<=n;k++){
				if (x>=n)
					move(f[_][j][k],f[!_][j][k]*(r[x]+1-j-cnt));
				else {
					move(f[_][j][k],f[!_][j][k]*(r[x]+1-(i-1+k+n-cnt)));
					if (k)move(f[_][j+1][k-1],f[!_][j][k]*(l[x]-j-cnt));
				}
			}
		cnt+=x>=n;
	}
	int ans=0;
	for (int i=0;i<=n;i++)move(ans,f[_][i][0]);
	cout<<(ans%mo+mo)%mo<<endl;
}

Measured memory_bytes: 1024
/***********************
*  Date: 2018.11.28    *
*  Problem:            *
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,q,appe[100010][20],coap[100010],len=0;//appe:appearance
int list_top[100010],val[200010],nxt[200010];

void add(int x,int y)
{
	val[++len]=y;
	nxt[len]=list_top[x];
	list_top[x]=len;
}

int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	cin>>q;
	repn(i,q)
	{
		int x,y;
		scanf("%d%d%d",&x,&y,&coap[i]);
		appe[x][y]=i;
	}
	for(int i=9;i>=0;i--)//算能不能覆盖appe[j][i]之前要先算出appe[p][i+1]会不会被覆盖，所以i要倒着循环 
	{
		repn(p,n)
		{
			for(int k=list_top[p];k!=0;k=nxt[k])//i在这里代表可以控制的范围
			{
				int j=val[k];
				appe[j][i]=max(appe[j][i],appe[p][i+1]);/*远一条边距离就要加1，这里是看后者可不可以覆盖前者，
				可以说是一种dp，一个类似递归的过程，如果再之前的点把后者覆盖了，也会在前者上体现出来*/
			}	
		}	
	} 
	repn(i,n)
	{
		int lst=0;
		rep(j,11) lst=max(lst,appe[i][j]);
		cout<<coap[lst]<<endl;
	}
	rt0;
}

Measured memory_bytes: 10752
n=int(input())
S=[0,0,0,0]
for i in range(n):
    now=str(input())
    if now=='AC':
        S[0]+=1
    elif now=='WA':
        S[1]+=1
    elif now=='TLE':
        S[2]+=1
    else:
        S[3]+=1
    
print('AC x {0}'.format(S[0]))
print('WA x {0}'.format(S[1]))
print('TLE x {0}'.format(S[2]))
print('RE x {0}'.format(S[3]))


Measured memory_bytes: 9216
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n, ans=0, len, c;
    string s, name[110], t;
    cin>>n>>s;
    for (int i=0; i<n; i++) cin>>name[i];
    for (int i=0; i<n; i++)
    {
        len=name[i].size();
        for (int j=1; j<51; j++)
        {
            for (int k=0; k<len; k++)
            {
                t=""; c=0;
                for (int l=k; l<len && c<s.size(); l+=j)
                {
                    if (l<len) { t+=name[i][l]; c++; }
                }
                if (t==s) { ans++; k=200; j=60; }
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}



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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;
ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) return mod_pow(x * x % MOD, n / 2) % MOD;
    else return x * mod_pow(x, (n - 1)) % MOD;
}
ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;
    ll ret = 1;
    while (n) if (n & 1) ret = ret * x % MOD; x = x * x % MOD; n /= 2;
    return ret;
}
ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) ret *= (i + 1); ret %= MOD;
    return ret;
}
ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);
    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    ll x; cin >> x;
    ll count = 0;
    ll value = 100;
    while(true) {
        value += value / 100;
        count++;
        if (value >= x) break;
    }
    cout << count;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3644
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

printList [a] = print a
printList (a:as) = putStr ( show a ) >> putChar ' ' >> printList as

main = readInt >>= print . ( 1 - )

Measured memory_bytes: 3880
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

void rectangle(int h, int w) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if ((i + j) % 2 == 0) {
        cout << '#';
      } else {
        cout << '.';
      }
    }
    cout << '\n';
  }
}

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

  while (1) {
    int h, w; cin >> h >> w;
    if (h == 0 && w == 0) {
      break;
    }
    rectangle(h, w);
    cout << '\n';
  }

  return 0;
}


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

// int 3E4
// long 2E9
// long long 9E18
int main() {
  int N, M;
  vector<int> A;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    {
      int Ai;
      cin >> Ai;
      A.emplace_back(Ai);
    }

  sort(A.rbegin(), A.rend());
  if (A[M - 1] >= (double)accumulate(A.begin(), A.end(), 0LL) / (4 * M))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int,int> pii;
const int N=500005;

int n,m;
int c[N],pos[N],ans[N];
vector<pii> q[N];
int tr[N];

void add(int x,int c)
{
    for(;x<=n;x+=x&-x)tr[x]+=c;
}

int sum(int x)
{
    int res=0;
    for(;x;x&=x-1)res+=tr[x];
    return res;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",c+i);
    for(int i=0;i<m;i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        q[r].push_back(make_pair(l,i));
    }
    for(int i=1;i<=n;i++)
    {
        if(pos[c[i]]>0)add(pos[c[i]],-1);
        add(i,1);
        pos[c[i]]=i;
        for(int j=0;j<q[i].size();j++)
        {
            pii it=q[i][j];
            int l=q[i][j].first,id=q[i][j].second;
            ans[id]=sum(i)-sum(l-1);
        }
    }
    for(int i=0;i<m;i++)
        printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 33168
#include<stdio.h>
#include<stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int INFTY=(1<<21);
int n,M[MAX][MAX];

void  str(){
  int i,v,minv;
  int d[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
d[0]=0;
color[0]=GRAY;
while(1){
  minv=INFTY;
  int u=-1;
  for(i=0;i<n;i++){
    if(minv>d[i]&&color[i]!=BLACK){
      u=i;
      minv=d[i];
    }
  }
if(u==-1)break;
color[u]=BLACK;
for(v=0;v<n;v++){
  if(color[v]!=BLACK&&M[u][v]!=INFTY){
    if(d[v]>d[u]+M[u][v]){
      d[v]=d[u]+M[u][v];
      color[v]=GRAY;
    }
  }
}
}
for(i=0;i<n;i++){
  printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
}
}

int main(){
scanf("%d",&n);
int i,j;
for(i=0;i<n;i++){
  for(j=0;j<n;j++){
    M[i][j]=INFTY;
  }
}
int k,c,u,v;
for(i=0;i<n;i++){
  scanf("%d%d",&u,&k);
  for(j=0;j<k;j++){
    scanf("%d%d",&v,&c);
    M[u][v]=c;
  }
}
str();
return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define inf 1000000007
#define for(i, a, b) for(int i=a; i<b; i++)
int dp[1000001] = {0};

void solve(){
	int n, res=0;
	cin>>n;
	int a[n], b[n], c[n-1];
	for(i, 0, n)cin>>a[i];
	for(i, 0, n) cin>>b[i];
	for(i, 0, n-1)cin>>c[i];
	res+=b[a[0]-1];

	for(i, 1, n){
		res+=b[a[i]-1];
		if(a[i]-1==a[i-1]){
			res+=c[a[i-1]-1];
		}
	}
	cout<<res;
}
signed main(){	
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 

typedef unsigned long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

const int DIM = 320;

int dx[DIM * DIM];
int dy[DIM * DIM];

int s[DIM * DIM];

main()
{
	int n, m, d;
	cin >> n >> m >> d;
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			int x;
			cin >> x;
			
			dx[x] = i, dy[x] = j;
		}
	}
    
	for(int i = d + 1; i <= n * m; i++)
		s[i] = s[i - d] + abs(dx[i] - dx[i - d]) + abs(dy[i] - dy[i - d]);
	
	int q;
	cin >> q;
	
	while(q--)
	{
		int l, r;
		cin >> l >> r;
		
		cout << s[r] - s[l] << '\n';
	}
}

Measured memory_bytes: 2176
# Union Find
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


def same(x, y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]


import sys

input = sys.stdin.readline
n, m = map(int, input().split())
a = set()
for _ in range(m):
    ab = sorted(map(int, input().split()))
    a.add((ab[0], ab[1]))
par = [-1] * n

for x, y in a:
    unite(x - 1, y - 1)

d = {}
for i in range(n):
    i = find(i)
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
print(max(d.values()))

Measured memory_bytes: 47156
function main()
	N=parse.(Int, readline())
	str=""
	for x=1:N
		if x==1
			str=chomp(readline())
		else
			str = string(str," ",chomp(readline()))
		end
		
	end
	
	println(length(sort(unique(parse.(Int,split(str))))))
end

main()

Measured memory_bytes: 186740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

int n;
int A[100100];
int B[100100];
int C[100100];
int mem[100100][3];
ll dp(int at, int l){
    if(at >= n) return 0;
    ll ans = -100000000;
    if(mem[at][l] != -1) return mem[at][l];
    if(l != 0){ // gerdi A
        ans = max(ans, A[at]+dp(at+1,0));
    }
    if(l != 1){
        ans = max(ans, B[at]+dp(at+1,1));
    }
    if(l != 2){
        ans = max(ans, C[at]+dp(at+1,2));
    }
    return mem[at][l] = ans;
}

int main()
{
    cin.sync_with_stdio(false);
    cin >> n;
    memset(mem,-1,sizeof(mem));
    rep(i,0,n) cin >> A[i] >> B[i] >> C[i];
    ll ans = -100000000;
    ans = max(ans, A[0]+dp(1,0));
    ans = max(ans, B[0]+dp(1,1));
    ans = max(ans, C[0]+dp(1,2));
    cout << ans << endl;
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#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(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N;
	int32 K;
	vector<int64> a, sum, l, r;
	cin >> N >> K;
	a.resize(N);
	sum.resize(N+1, 0);
	l.resize(N+1, 0);
	r.resize(N+1, 0);
	REP(i, N) cin >> a[i];
	REP(i, N){
		sum[i+1] += sum[i]+a[i];
		l[i+1] += l[i]+max((int64)0, a[i]);
	}
	for(int32 i = N-1;i >= 0;i--){
		r[i] += r[i+1]+max((int64)0, a[i]);
	}
	int64 res = -INF_LL;
	REP(i, N-K+1){
		chmax(res, l[i]+max((int64)0, sum[i+K]-sum[i])+r[i+K]);
	}
	cout << res << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll>> 
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define rep(i,start,end) for(int i=start;i<end;i++)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()  
#define sz(x) (ll)(x).size()
//////////////////////////////////////////////////////////////////////////////////////////////////

#define N 100005
ll dp[N][2][2], v[N];
ll n;
ll func(ll idx, bool curr_flipped, bool next_flipped)
{
	if(idx == n-2)
		return (curr_flipped?-1*v[idx]:v[idx])+(next_flipped?-1*v[idx+1]:v[idx+1]);
	if(dp[idx][curr_flipped][next_flipped] != -1)
		return dp[idx][curr_flipped][next_flipped];
	return dp[idx][curr_flipped][next_flipped] = (curr_flipped?-1*v[idx]:v[idx]) + max(func(idx+1,!next_flipped,true),func(idx+1,next_flipped,false));
}
int main()
{
	cin>>n;
	for(ll i=0;i<n;i++)
		cin>>v[i];
	memset(dp,-1,sizeof(dp));
	ll ans = max(func(0,0,0),func(0,1,1));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11904
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define LL(x) ll x; scanf("%lld",&x)
#define INPUT(x) cin >> x
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF_INT 2147483647
#define INF_LL 9223372036854775807

typedef long long ll;

int main(){
    //?????????????????¨?????´??°???????????§???????????¢??????A[N][N]??????
    //???????????¢
    int A[100][100];
    
    //?????°
    INT(N);INT(E);
    
    //?????????
    REP1(i,N){
        REP1(j,N){
            if(i != j){
                A[i][j] = INF_INT;
            }else{
                A[i][j] = 0;
            }
        }
    }
    
    //??\???
    REP1(i,E){
        INT(s);INT(t);INT(d);
        //A^0??¨??????????????????
        A[s][t] = d;
        //A[t][s] = d;
    }
    
    REP1(k,N){
        REP1(i,N){
            if (A[i][k] == INF_INT) continue;
            REP1(j,N){
                if (A[k][j] == INF_INT) continue;
                A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
            }
        }
    }
    
    REP1(i,N){
        if(A[i][i] < 0){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    
    REP1(i,N){
        REP1(j,N){
            if (A[i][j] == INF_INT) {
                cout << "INF";
            }else{
                cout << A[i][j];
            }
            if (j+1 != N)cout << " ";
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3240
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (true) {
			int R = in.nextInt();
			int C = in.nextInt();
			if (R == 0 && C == 0) {
				break;
			}
			boolean[][] a = new boolean[R][C];
			for (int i = 0; i < R; i++) {
				for (int j = 0; j < C; j++) {
					a[i][j] = (in.nextInt() == 1);
				}
			}
			
			int max = 0;
			for (int b = 0; b < (1 << R); b++) {
				boolean[] turn = new boolean[R];
				for (int i = 0; i < R; i++) {
					turn[i] = ((b & (1 << i)) != 0);
				}
				int sum = 0;
				for (int j = 0; j < C; j++) {
					int k = 0;
					for (int i = 0; i < R; i++) {
						if (a[i][j] ^ turn[i]) {
							k++;
						}
					}
					sum += Math.max(k, R - k);
				}
				if (sum > max) {
					max = sum;
				}
			}
			
			System.out.println(max);
		}
	}
}

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

using namespace std;
int n,i;
string s;
int main()
{
    cin>>n>>s;
    if(n>=s.size())
        for(i=0; i<s.size(); i++)
            cout<<s[i];

    else
    {
        for(i=0; i<n; i++)
            cout<<s[i];
        cout<<"...";
    }

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
  int c[7];
  int a[7];
  int b[7];
  for(int i = 0;i < 7;i++){
    cin >> a[i] >> b[i];
    c[i] = a[i] - b[i];
  }
  for(int i = 0;i < 7;i++){
    cout << c[i] << endl;
  }
  return(0);
}



Measured memory_bytes: 3104
//
//AtCoder Beginner Contest 142
//C - Go to School
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n;

    cin >> n;

    pair<int, int> a[n];
    REP(i, n) {
        cin >> a[i].first;
        a[i].second = i+1;
    }
    sort(a, a+n);
    REP(i, n) {
        cout << a[i].second;
        if (i<n-1) cout << " ";
    }
    cout << endl;
    return 0;
}


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

typedef long long ll;



int main()
{
    int n;
    cin>>n;
    vector<ll> arr(n);
    int i;
    for(i=0;i<n;++i){
        cin>>arr[i];
    }
    ll ans=0;
    for(i=0;i<n-1;++i){
        if(arr[i]>arr[i+1]){
            ans+=arr[i]-arr[i+1];
            arr[i+1]=arr[i];
        }
    }
    cout<<ans;
}

Measured memory_bytes: 4760
/*
 * author Puneet;
 */
import java.io.*;

public class Main{
    public static void main(String agrs[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream, true);
        StringBuilder builder = new StringBuilder();

        String a[]=br.readLine().trim().split(" ");
        builder.append(a[0]);
        builder.append(a[1]);
//        out.println(builder);
        int n=Integer.parseInt(builder.toString());
        int p=(int)Math.sqrt(n);
        if((p*p)==n)
            out.println("Yes");
        else
            out.println("No");

    }

}


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

bool prime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    for (int i = 3; i * i <= num; i += 2) {
        if (num % i == 0) return false;
    }

    return true;
}

int main() {
    int ans[1000000], n;
    ans[0] = 0;
    for (int i = 1; i <= 999999; ++i) {
        if (prime(i)) ans[i] = ans[i - 1] + 1;
        else ans[i] = ans[i - 1];
    }

    while (cin >> n) {
        cout << ans[n] << endl;
    }
    
    return 0;
}


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

typedef long long ll;

ll S;

int main()
{
    cin >> S;

    cout << 0 << " " << 0 << " ";
    ll x1 = 1000000000, y1 = 1, x2 = (1000000000 - S % 1000000000) % 1000000000, y2 = (S + 1000000000 - 1) / 1000000000;
    cout << x1 << " " << y1 << " ";
    cout << x2 << " " << y2 << endl;

    return 0;
}


Measured memory_bytes: 256