akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node {
	struct node *right;
	struct node *left;
	struct node *parent;
	int key;
};

typedef struct node * Node;

Node root;

Node treeMinimum(Node x) {
	while (x->left != NULL) x = x->left;
	return x;
}

Node treeMaximum(Node x) {
	while (x->right != NULL) x = x->right;
	return x;
}

Node treeSearch(Node u, int k) {
	while (u != NULL && k != u->key) {
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

Node treeSuccessor(Node x) {
	if (x->right != NULL) return treeMinimum(x->right);
	Node y = x->parent;
	while (y != NULL && x == y->right) {
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node z) {
	Node y; // node to be deleted
	Node x; // child of y

	if (z->left == NULL || z->right == NULL) y = z;
	else y = treeSuccessor(z);

	if (y->left != NULL) x = y->left;
	else x = y->right;

	if (x != NULL) x->parent = y->parent;

	if (y->parent == NULL) root = x;
	else {
		if (y == y->parent->left) y->parent->left = x;
		else y->parent->right = x;
	}

	if (y != z) z->key = y->key;

	free(y);
}

void insert(int k) {
	Node y = NULL;
	Node x = root;
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = NULL;
	z->right = NULL;

	while (x != NULL) {
		y = x;
		if (z->key < x->key) x = x->left;
		else x = x->right;
	}

	z->parent = y;
	if (y == NULL) root = z;
	else {
		if (z->key < y->key) y->left = z;
		else y->right = z;
	}
}

void inorder(Node u) {
	if (u == NULL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node u) {
	if (u == NULL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}


int main() {
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s", com);
		if (com[0] == 'f') {
			scanf("%d", &x);
			Node t = treeSearch(root, x);
			if (t != NULL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'i') {
			scanf("%d", &x);
			insert(x);
		}
		else if (com[0] == 'p') {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com[0] == 'd') {
			scanf("%d", &x);
			treeDelete(treeSearch(root, x));
		}
	}

	return 0;
}


Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,a,q,b,e;
    cin >> n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin >> a;
        deq.emplace_back(a);
    }
    cin >> q;
    for (int j=0;j<q;j++) {
        cin >> b >> e;
        reverse(deq.begin()+b,deq.begin()+e);
    }
    for (int k=0;k<n;k++) {
        if (k==n-1) {
            cout << deq[k] << endl;
        } else {
            cout << deq[k] << " ";
        }
        
    }
}



Measured memory_bytes: 3128
import java.io.*;
public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());


        int[] arr = new int[10001];
        for(int i=1;i<=100;i++){
            for(int j=1;j<=100;j++){
                for(int k=1;k<=100;k++){

                    int num = i*i + j*j + k*k + i*j + i*k + j*k;
                    if(num > 10000)break;
                    else{
                        arr[num]++;
                    }
                }
            }
        }

        for(int i=1;i<=n;i++){
            System.out.println(arr[i]);
        }
    }
}


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

using namespace std;

int64_t mod_pow(int64_t x, int64_t n, int64_t mod) {
  int64_t ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}


int main() {
  int M, N;
  cin >> M >> N;
  cout << mod_pow(M, N, (int) (1e9 + 7)) << endl;
}



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

typedef long long s64;

int main()
{
	//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	s64 l,r;
	cin>>l>>r;
	if(l==r){puts("1");exit(0);}
	s64 ans=r-l+1;
	int i=60;
	while((l>>i)==(r>>i))--i;
	l&=(1LL<<i)-1;
	r&=(1LL<<i)-1;
	for(int j=i;--j>=0;)
	if(!((r>>j)&1))
	{
		s64 base=(r>>j)+1;
		if(base!=1){ans+=1LL<<j;continue;}
		s64 _l=l>>j;
		if(base<_l)continue;
		if(base>_l)ans+=1LL<<j; 
		else ans+=(1LL<<j)-(l&(1LL<<j)-1);
	}
	cout<<ans;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 1;
  for(int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  for(int i = 1; i < n; i++) {
    if(s.at(i) != s.at(i - 1)) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 9548
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    if b < c or d < a:
        print(0)
    else:
        print(min(b, d) - max(a, c))


if __name__ == '__main__':
    slove()


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

ll mp[33];

int main(){
	
	int n;cin >> n;
	string str;cin >> str;
	REP(i, n){
		mp[str[i] - 'a']++;
	}
	
	ll ans = 1;
	REP(i, 26){
		ans = (ans * (mp[i]+ 1)) % MOD;
	}
	
	cout << ans - 1 << endl;
		
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S,T;
  cin>>N>>S>>T;
  int count=0;
  for(int i=0;i<N;i++){
    bool flag=true;
    for(int j=i;j<N;j++){
      if(S.at(j)!=T.at(j-i)){
        flag=false;
      }
    }
    if(flag){
      count=i;
      break;
    }
    if(i==N-1){
      count=N;
    }
  }
  cout<<N+count<<endl;
}
    

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

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n); 
    rep(i, n) cin >> a.at(i);

    int sum = accumulate(a.begin(), a.end(), 0);
    sort(a.rbegin(), a.rend());
    int b = 4 *m;
    bool flg = true;
    //cout << sum << endl;
    rep(i, m) {
        if (a.at(i) * b < sum) {
            flg = false;
            break;
        }
    }

    if (flg)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

const long long mod=1e9+7;

int main(){

    string d[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

    string s;
    cin>>s;

    for(int i=0;i<7;i++){
        if(s==d[i]){
            cout<<7-i<<endl;
            break;
        }
    }

    return 0;
}

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

int main() {
  int64_t n;
  array<int64_t, 3> abc;
  cin >> n >> abc[0] >> abc[1] >> abc[2];
  string out, s[n];
  for (int i = 0; cin >> s[i]; ++i) {}
  function<bool(int)> solve = [&](int i) {
    if (i == n) {
      return true;
    }
    --abc[s[i].front() - 'A'];
    ++abc[s[i].back() - 'A'];
    if (abc[s[i].front() - 'A'] >= 0 && solve(i + 1)) {
      out.push_back(s[i].back());
      out.push_back('\n');
      return true;
    }
    abc[s[i].front() - 'A'] += 2;
    abc[s[i].back() - 'A'] -= 2;
    if (abc[s[i].back() - 'A'] >= 0 && solve(i + 1)) {
      out.push_back(s[i].front());
      out.push_back('\n');
      return true;
    }
    --abc[s[i].front() - 'A'];
    ++abc[s[i].back() - 'A'];
    return false;
  };
  if (solve(0)) {
    reverse(begin(out), end(out));
    cout << "Yes" << out;
  } else {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 10452
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N (1<<17)
#define G 2147483647
class RUQ{
private:
    #define D 17
    ll dat[2*N],laz[2*N];
    ll eval(int k){
	if(laz[k]!=G){
	    dat[k]=laz[k]*(1<<(D-(ll)log2(k)));
	    if(k<N){
		laz[k*2]=laz[k];
		laz[k*2+1]=laz[k];
	    }
	}
	laz[k]=G;
	return dat[k];
    }
public:
    void Init(){
	lol(i,2*N)dat[i]=0,laz[i]=G;
    }
    void Upd(int l,int r,ll x){
	l+=N,r+=N+1;
	for(int i=D;i>=0;i--){
	    eval(l>>i);eval(r>>i);
	}
	for(int a=l,b=r;a<b;a>>=1,b>>=1){
	    if(a&1)laz[a++]=x;
	    if(b&1)laz[--b]=x;
	}
	for(int a=l,b=r;a;a>>=1,b>>=1){
	    dat[a/2]=eval(a)+eval(a^1);
	    dat[b/2]=eval(b)+eval(b^1);
	}
    }
    ll Sum(int l,int r){
	l+=N,r+=N+1;
	for(int i=D;i>=0;i--){
	    eval(l>>i);eval(r>>i);
	}
	ll res=0;
	for(int a=l,b=r;a<b;a>>=1,b>>=1){
	    if(a&1)res+=eval(a++);
	    if(b&1)res+=eval(--b);
	}
	return res;
    }
};
int main(){
    int n,q;cin>>n>>q;
    RUQ seg;seg.Init();
    while(q--){
	ll a,b,c;cin>>a;
	if(a==0){
	    cin>>a>>b>>c;
	    seg.Upd(a,b,c);
	}
	else{
	    cin>>a>>b;
	    cout<<seg.Sum(a,b)<<endl;
	}
    }
    return 0;
}



Measured memory_bytes: 7348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderE
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextInt();
        long h = sc.NextInt();
        long[] a = new long[n];
        long[] b = new long[n];

        for (int i = 0; i < n; i++)
        {
            a[i] = sc.NextLong();
            b[i] = sc.NextLong();
        }

        b = b.OrderByDescending(i => i).ToArray();
        long[] sumB = new long[n + 1];
        sumB[0] = 0;
        for (int i = 1; i <= n; i++)
        {
            sumB[i] = sumB[i - 1] + b[i - 1];
        }

        long maxA = a.Max();

        long answer = long.MaxValue;

        for (int i = 0; i <= n; i++)
        {
            long count = i;
            long hit = h;
            hit = hit - sumB[i];
            if (hit > 0)
            {
                count += (hit + maxA - 1) / maxA;
            }
            answer = Math.Min(answer, count);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 24396
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffor(i,a,b) for(ll i=a;i<=b;i++)
#define rfor(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//functions: set.insert(val), *(set.find_by_order(order-1)), set.order_of_key(val)

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e6 + 6;
const ll maxN = 1e5 + 6;

ll power(ll x, ll y, ll M = MOD) // default argument
{ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	ll x;
	FOR(i, 5) {
		cin >> x;
		if (x == 0) { cout << i + 1 << endl;	}
	}
	return 0;
}


Measured memory_bytes: 3608
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
const int N = 3e5+10; // 不开大点都对不起1024MB。。。 
inline int read()
{
	register int x = 0 , f = 0; register char c = getchar();
	while(c < '0' || c > '9') f |= c == '-' , c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
	return f ? -x : x;
}
int n , tot , S , T , cnt = 1;
int p[N] , q[N] , id[2][N] , head[N] , d[N] , cur[N];
struct edge{ int v , nex , c; }e[N << 3];
inline void add(int u , int v , int c)
{
	e[++cnt].v = v; e[cnt].nex = head[u]; e[cnt].c = c; head[u] = cnt;
	e[++cnt].v = u; e[cnt].nex = head[v]; e[cnt].c = 0; head[v] = cnt;
}
void col(int x , int *p , int *id , int c)
{
	id[x] = c;
	if(!id[p[x]]) col(p[x] , p , id , c);
}

bool bfs()
{
	queue<int> q;
	for(int i = 1 ; i <= T ; ++i) cur[i] = head[i];
	for(int i = 1 ; i <= T ; ++i) d[i] = 0; d[S] = 1; q.push(S);
	while(q.size())
	{
		int x = q.front(); q.pop();
		for(int i = head[x] ; i ; i = e[i].nex) if(e[i].c && !d[e[i].v]) d[e[i].v] = d[x] + 1 , q.push(e[i].v);
	}
	return d[T] != 0;
}

int dfs(int x , int flow)
{
	if(x == T || flow == 0) return flow;
	int res = 0 , k;
	for(int &i = cur[x] , v; i ; i = e[i].nex)
	{
		v = e[i].v;
		if(e[i].c && d[v] == d[x] + 1)
		{
			k = dfs(v , min(flow , e[i].c));
			if(k) { e[i].c -= k; e[i^1].c += k; res += k; flow -= k; if(flow == 0) return res; }
			else d[v] = 0;
		}
	}
	return res;
}

inline int Dinic() { int ans = 0; while(bfs()) ans += dfs(S , 1e8); return ans; }

int main()
{
	n = read();
	for(int i = 1 ; i <= n ; ++i) p[i] = read() + 1;
	for(int i = 1 ; i <= n ; ++i) q[i] = read() + 1;
	for(int i = 1 ; i <= n ; ++i) if(!id[0][i]) col(i , p , id[0] , ++tot);
	for(int i = 1 ; i <= n ; ++i) if(!id[1][i]) col(i , q , id[1] , ++tot);
	S = tot + 1; T = tot + 2; int ans = n;
	for(int i = 1 ; i <= n ; ++i)
	{
		if(p[i] == i && q[i] == i) ans--;
		else
		if(p[i] == i) add(id[1][i] , T , 1); // q 不动 
		else
		if(q[i] == i) add(S , id[0][i] , 1); // 
		else
		if(p[i] != q[i])
			add(id[1][i] , id[0][i] , 1);
		else
			add(id[1][i] , id[0][i] , 1) , add(id[0][i] , id[1][i] , 1);
	}
	cout << ans - Dinic() << '\n';
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, t;
  cin >> n >> t;

  int mini = INF;
  int dis = 0;
  int ans = 0;
  REP(_, n) {
    int a;
    cin >> a;
    mini = min(mini, a);
    if (a - mini > dis) {
      ans = 0;
      dis = a - mini;
    }
    if (dis == a - mini) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

int64* calc(const int *a,const int n){
  const int f=16;
  int64 *now=(int64 *)calloc(f,sizeof(int64));
  int64 *next=(int64 *)calloc(f,sizeof(int64));
  int64 *dp=(int64 *)calloc(n,sizeof(int64));
  int i,j;
  for(i=0;i<f;i++) now[i]=2*i;
  dp[n-1]=now[0];
  for(i=n-2;i>=0;i--){
    int64 t=a[i];
    int64 v=a[i+1];
    int k=0;
    for(j=0;j<f;j++,t*=4){
      for(;t>v;k++,v*=4);
      if(k<f){
	next[j]=2*j+now[k];
      } else {
	next[j]=2*j+now[f-1]+2*(k-f+1)*(n-i-1);
      }
    }
    dp[i]=next[0];
    int64 *swap=now;
    now=next;
    next=swap;
  }
  free(now);
  free(next);
  return dp;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int64 *dp1=calc(a,n);
  for(i=0;i<n-1-i;i++){
    int swap=a[i];
    a[i]=a[n-1-i];
    a[n-1-i]=swap;
  }
  int64 *dp2=calc(a,n);
  int64 min=dp1[0];
  for(i=1;i<n;i++){
    int64 t=dp1[i]+dp2[n-i]+i;
    if(t<min) min=t;
  }
  printf("%lld\n",min);
  free(a);
  free(dp1);
  free(dp2);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 4096
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int C,D,W,X;
int E_table[16][30],F_table[16][30],G_table[16][30];
int dp[31][51][6];

bool rangeCheck(int area){
	if(area >= 0 && area <= C-1){
		return true;
	}else{
		return false;
	}
}


void func(){

	for(int area = 1; area <= C; area++){
		for(int day = 0; day < D; day++){
			scanf("%d",&E_table[area][day]);
			if(E_table[area][day] == 0){
				G_table[area][day] = 0;
			}else{
				G_table[area][day] = 1;
			}
		}
	}

	for(int area = 1; area <= C; area++){
		for(int day = 0; day < D; day++)scanf("%d",&F_table[area][day]);
	}

	for(int day = 0; day <= D-1; day++){
		for(int area = 1; area <= C; area++){
			E_table[area][day] += E_table[area-1][day];
			F_table[area][day] += F_table[area-1][day];
			G_table[area][day] += G_table[area-1][day];
		}
	}

	for(int day = 0; day <= D; day++){
		for(int futan = 0; futan <= W; futan++){
			for(int num = 0; num <= X; num++){
				dp[day][futan][num] = -1;
			}
		}
	}

	dp[0][0][0] = 0;

	int ans = 0;
	int tmp_futan,tmp_E,tmp_G;

	for(int day = 0; day <= D-1; day++){
		for(int futan = 0; futan <= W; futan++){
			for(int num = 0; num <= X; num++){
				if(dp[day][futan][num] == -1)continue;

				dp[day+1][futan][num] = max(dp[day+1][futan][num],dp[day][futan][num]);

				for(int area = 1; area <= C; area++){
					tmp_E = E_table[area][day]-E_table[area-1][day];
					tmp_futan = F_table[area][day]-F_table[area-1][day];

					if(tmp_E == 0 || futan+tmp_futan > W)continue;

					dp[day+1][futan+tmp_futan][num] = max(dp[day+1][futan+tmp_futan][num],dp[day][futan][num]+tmp_E);
					ans = max(ans,dp[day+1][futan+tmp_futan][num]);

					if(num == X)continue;

					for(int count = 2; area+count <= C+1; count++){
						tmp_G = G_table[area+count-1][day]-G_table[area-1][day];
						if(tmp_G != count)break;

						tmp_futan = F_table[area+count-1][day]-F_table[area-1][day];
						if(futan+tmp_futan > W)break;;

						tmp_E = E_table[area+count-1][day]-E_table[area-1][day];

						dp[day+1][futan+tmp_futan][num+1] = max(dp[day+1][futan+tmp_futan][num+1],dp[day][futan][num]+tmp_E);
						ans = max(ans,dp[day+1][futan+tmp_futan][num+1]);
					}
				}
			}
		}
	}

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

int main(){

	for(int day = 0; day <= 29; day++){
		E_table[0][day] = 0;
		F_table[0][day] = 0;
		G_table[0][day] = 0;
	}

	while(true){
		scanf("%d %d %d %d",&C,&D,&W,&X);
		if(C == 0 && D == 0 && W == 0 && X == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3172
import sys
import itertools
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = in_nl()

    asum = list(itertools.accumulate([0] + A))
    count = Counter(asum)

    ans = 0
    for k, v in count.items():
        ans += v * (v - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44800
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi v={0,111,222,333,444,555,666,777,888,999};
    rep(i,9) {
        if(v[i]<N&&N<=v[i+1]) cout<<v[i+1]<<endl;
    }
}

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

vector<int> topoSort;
bitset<100005> seen;
int tr[100005];
void topo(int s,vector<vector<int>> &graph){
    if(seen[s])return;
    for(int i = 0; i < graph[s].size();++i)
        topo(graph[s][i],graph);
    seen[s] = 1;
    tr[s] = (int)topoSort.size();
    topoSort.push_back(s);
}

int dp[100005];

int main(){
    int n,m;
    scanf(" %d %d",&n,&m);
    vector<vector<int>> graph(n);
    for(int i = 0; i < m;++i){
        int x,y;
        scanf(" %d %d",&x,&y);
        --x,--y;
        graph[x].push_back(y);
    }
    for(int i = 0; i < n;++i)
        topo(i,graph);
    int ans = 0;
    for(auto va:topoSort){
        for(auto ve:graph[va])
            dp[tr[va]] = max(dp[tr[va]],1+dp[tr[ve]]);
        ans = max(ans,dp[tr[va]]);
        //printf("who:%d ans:%d\n",va,dp[tr[va]]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 9080
#include<stdio.h>
#include<stack>
#include<cstdio>

using namespace std;

int main(void){

	int inp;
	stack<int> train;

	while(scanf("%d",&inp)!=EOF){
		if(inp!=0){
			train.push(inp);
		}else{
			printf("%d\n",train.top());
			train.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct xxx{
    int B, C;
}oper[111111];
priority_queue<int, vector<int>, greater<int> > q;
int N, M, A[111111], cnt;
bool cmp(struct xxx x, struct xxx y){
    return x.C > y.C;
}
int main(){
    cin>>N>>M;
    for(int i = 1;i <= N; i++){
        scanf("%d", &A[i]);
        q.push(A[i]);
    }
    for(int i = 1;i <= M; i++){
        int B, C;
        scanf("%d%d", &B, &C);
        oper[i].B = B;
        oper[i].C = C;
    }
    sort(oper + 1, oper + 1 + M, cmp);
    for(int i = 1;i <= M; i++){
        for(int j = 1;j <= oper[i].B; j++){
            if(q.top() < oper[i].C){
                q.pop();
                q.push(oper[i].C);
            }
            else break;
        }
    }
    long long ans = 0;
    while(!q.empty()){
        ans += 1LL * q.top();
        q.pop();
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  
  string s;
  cin >> s;
  
  
  char b = s.at(1);
  
  
  int num = 0;
  
  for (int i = 0; i < 3; i++){
    if (s.at(i) == 'S'){
      num = num + 1;
    }
  }
  
  if (num == 3){
    cout << 0 << endl;
  }
  else if (num == 2){
    cout << 1 << endl;
  }
  else if (num == 0){
    cout << 3 << endl;
  } //こっからしたはS = 1だけ
  else if (b == 'S'){
    cout << 1 << endl;
  }
  else if (b != 'S'){
    cout << 2 << endl;
  }
  
}

Measured memory_bytes: 3592
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long[] H) {
    return zip(H, H.fold!max).count!"a[0] == a[1]";
}


auto fold(alias f, R)(R range) {
    alias T = ElementType!R;
    
    static struct Result {
    private:
        R source;
        T state;

        this(R range) {
            source = range;
            if (source.empty)
                return;

            state = source.front;
        }

    public:
        @property bool empty() {
            return source.empty;
        }

        @property T front() {
            assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
            return state;
        }

        void popFront() {
            assert(!empty, "Attempting to popFront an empty cumulativeFold.");
            source.popFront;

            if (source.empty)
                return;

            state = f(state, source.front);
        }

        static if (isForwardRange!R) {
            @property auto save()
            {
                auto result = this;
                result.source = source.save;
                return result;
            }
        }

        static if (hasLength!R) {
            @property size_t length()
            {
                return source.length;
            }
        }
    }

    return Result(range);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] H = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        H[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, H);
    else
        solve(N, H).writeln;
}


Measured memory_bytes: 256
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      a[i][j] = "o"
for i in range(3):
  if a[i][0] == a[i][1] == a[i][2]:
    print("Yes")
    exit()
  elif a[0][i] == a[1][i] == a[2][i]:
    print("Yes")
    exit()
  elif a[0][0] == a[1][1] == a[2][2]:
    print("Yes")
    exit()
  elif a[0][2] == a[1][1] == a[2][0]:
    print("Yes")
    exit()
  elif i == 2:
    print("No")

Measured memory_bytes: 9220
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
	int n;
	
	scanf("%d",&n);
	
	long long a[n],b[n],push_all=0;
	
	int i,j;
	
	long long push_temp=0;

	for(i=0;i<n;i++){
		scanf("%lld %lld",a+i,b+i);
	}
	
	for(i=n-1;i>=0;i--){
		a[i]+=push_temp;
		if(a[i]%b[i]!=0){
			push_temp+=(b[i]-a[i]%b[i]);
		}
	}

	
	printf("%lld\n",push_temp);
	
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int ans = 0;
    for(int x=0; x*r<=n; ++x){
        for(int y=0; x*r+y*g<=n; ++y){
            if((n-x*r-y*g) % b == 0)
                ++ ans;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = input()
N = int(N)
a = list(map(int,input().split()))
m = lcm(*a)
x = 0
for j in range(N):
  x += (m-1) % a[j]
print(x)

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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& x : a) {
		cin >> x;
	}
	long long mx = a[0], ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] < mx)
			ans += (mx-a[i]);
		else
			mx = a[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

ll x[120000];

int main(){
    int N;  cin >> N;
    int s[310000];
    int l_e = 0, r_e = 0;
    for(int i = 0; i < N; i++){
        char c; cin >> c;
        if(c == 'E'){
            r_e += 1;
            s[i] =  1;
        }
        else{
            s[i] = -1;
        }
    }

    int res = INT32_MAX;
    for(int i = 0; i < N; i++){
        int ad = 0;
        if(s[i] == 1){
            ad = -1;
        }
        res = min((i - l_e) + r_e + ad, res);
        if(s[i] == 1) {
            l_e += 1;
            r_e -= 1;
        }
    }

    cout << res << endl;

    return 0;

}



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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto S=vecin(N);

	int M=in();
	REP(i,M){
		int u=in(),m=in(),v=in();
		rotate(S.begin()+u,S.begin()+m,S.begin()+v);
	}

	REP(i,N-1){
		cout << S[i] << ' ';
	}
	out(S[N-1]);
	return 0;
}


Measured memory_bytes: 3124
N=int(input())

A=list(map(int,input().split()))
A=[0]+A+[0]

S=0
tujyo=0
for i in range(N+2):
    
            
    tujyo+=abs(A[i]-S)
    S=A[i]
          


for k in range(1,N+1):
    mae=A[k-1]
    usiro=A[k+1]
    if mae<= A[k]<=usiro or usiro<= A[k]<=mae:
        print(tujyo)
    else:
        print(tujyo-abs(A[k]-mae)-abs(usiro-A[k])+abs(usiro-mae))
        

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

int main() {
    int N, M;
    cin >> N >> M;
    if (M == N)
    {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    
    
  return 0;
}


Measured memory_bytes: 256
template<class T> inline void chmin(T & a, const T b) { if (a > b) a = b; }
template<class T> inline void chmax(T & a, const T b) { if (a < b) a = b; }
typedef long long llong;

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

int countDigits(llong num) {
	int digit = 0;
	while (num) {
		num /= 10;
		digit++;
	}
	return digit;
}

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

	int res = countDigits(N);
	for (llong A = 1LL; A*A <= N; A++) {
		if (N%A != 0) continue;
		const llong B = N / A;
		chmin(res, max(countDigits(A), countDigits(B)));
	}

	cout << res << endl;
	
	return 0;
}

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

//dp[i][j] represents cost from i to j


signed main()
{
	long long int n;
	cin>>n;
	
	vector<long long int> x(n);
	
	for(long long int i=0;i<n;i++)
	cin>>x[i];

	vector<long long int> ab(n+2,0);
	vector<vector<long long int> > dp(n+2,ab);
	vector<long long int> prefix(n+1);
	long long int count=0;

	for(long long int i=1;i<=n;i++)
		{
			for(long long int j=1;j<=n;j++)
				dp[i][j]=(long long int)(1e20);
				// dp[i][j]=INT_MAX;
		}
	for(long long int i=0;i<n;i++)
	{
		count+=x[i];
		prefix[i+1]=count;
	}
	for(long long int i=1;i<n;i++)
	{
		dp[i][i+1]=x[i]+x[i-1];
		dp[i][i]=0;
	}
	dp[n][n]=0;

	for(long long int len=2;len<=n-1;len++)
	{
		for(long long int i=1;i<=n-len;i++)
		{
			long long int j=i+len;
			// dp[i][j]=long long int_MAX;
			
			for(long long int k=i;k<j;k++)
			{
			
			
			long long int sum2=prefix[j],sum1=0;
			
			
			if(i-1>=1)
				sum1=prefix[i-1];
			
			dp[i][j]=min(dp[i][j],(dp[i][k]+dp[k+1][j]) - sum1+ sum2);
			
			}
		}
	}

	cout<<dp[1][n];

	return 0;


}

Measured memory_bytes: 1536
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[i]<=b[i]:
        cnt+=a[i]
        b[i]-=a[i]
        if b[i]<=a[i+1]:
            cnt+=b[i]
            a[i+1]-=b[i]
        else:
            cnt+=a[i+1]
            a[i+1]=0
    else:
        cnt+=b[i]
print(cnt)

Measured memory_bytes: 19156
N,K = list(map(int, input().split()))
H = []
for i in range(N):
  H.append(int(input()))
H.sort()
min = H[K-1] - H[0]
for i in range(K, N):    
  t = H[i] - H[i-K+1]
  if min > t:
    min = t
print(min)


Measured memory_bytes: 7384
#include <bits/stdc++.h>
#define MAX_N 100000
#define INF 0x3f3f3f3f
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-48);
}
int n, rt, tot, mx; bool mrk[MAX_N+5];
int c[MAX_N+5], d[MAX_N+5], f[MAX_N+5];
char s[MAX_N+5]; vector <int> G[MAX_N+5];
void DFS(int u, int fa) {
	mrk[u] = c[u];
	for (int v : G[u]) if (v ^ fa)
		DFS(v, u), mrk[u] |= mrk[v], 
		d[u] += mrk[v], d[v] += mrk[v];
}
void DP(int u, int fa) {
	int w = ((d[u]&1)^c[u]) ? 2 : 0;
	f[u] = w, tot += d[u]+((d[u]&1)^c[u]);
	for (int v : G[u]) if ((v ^ fa) && mrk[v])
		DP(v, u), mx = max(mx, f[u]+f[v]), f[u] = max(f[u], f[v]+w);
}
int main() {
	read(n);
	for (int i = 1, u, v; i < n; i++)
		read(u), read(v), G[u].push_back(v), G[v].push_back(u);
	scanf("%s", s+1);
	for (int i = 1; i <= n; i++) c[i] = s[i] == 'W';
	for (int i = 1; !rt && i <= n; i++) if (c[i]) rt = i;
	return DFS(rt, 0), DP(rt, 0), printf("%d\n", tot-mx), 0;
}


Measured memory_bytes: 14848
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int[][] map;
    static int[][] label;


    static ArrayList<String> list;

    static int M;
    static int N;
    static int T;
    static int P;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String a = scanner.nextLine();
        String b = scanner.nextLine();

        BigInteger aa = new BigInteger(a);
        BigInteger bb = new BigInteger(b);

        if(aa.compareTo(bb) == 1){
            System.out.println("GREATER");
        }else if(aa.compareTo(bb) == -1){
            System.out.println("LESS");
        }else{
            System.out.println("EQUAL");
        }

    }



}


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

int main(){
    int n;

    cin >> n;

    int sn = 0;
    int number = n;
    for(unsigned int i = 0; i < 10; i++) {
        sn += number % 10;
        number /= 10;
    }

    if(n % sn == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll a,b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) {
        cout << "Zero" << endl;
    }else if(a > 0){
        cout << "Positive" << endl;
    }else{
        if((a - b - 1) % 2 == 0){
            cout << "Positive" << endl;
        }else{
            cout << "Negative" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
#define MAXN 111111
#define ll long long
using namespace std;

int V[22];


int main() {
    int A,B,T;
    cin>>A>>B>>T;
    cout << (T/A)*B << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){

    int a = 0;
    int b = 0;
    int c = 0;
    int k = 0;
    int sum = 0;

    std::cin >> a >> b >> c >> k;

    while (k > 0){
        if(a > k){
            sum = sum + k*1;
            k = k - k;
        }
        else if(a <= k){
            sum = sum + a*1;
            k = k - a;
            
            if(b > k){
                sum = sum + k*0;
                k = k - k;
            }
            else if(b <= k){
                sum = sum + b*0;
                k = k - b;
                sum = sum + k*(-1);
                k = k - k;
            }
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int a, b; cin >> a >> b;
    if(a>0) cout << "Positive" << endl;
    else if(a<=0 && b>=0) cout << "Zero" << endl;
    else {
        if((b-a)%2==0) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int k,n;

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

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

    cout << n - k<< endl;

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
MOD = 10**9 + 7

primeCount = defaultdict(int)

def primeList(n):
    p = 2
    primeList = defaultdict(int)
    while n > 1:
        if n % p == 0:
            while n % p == 0:
                primeList[p] += 1
                n //= p
        p += 1
    if n >= 2:
        primeList[n] = 1
    return primeList

for i in range(1, N + 1):
    for prime, count in primeList(i).items():
        primeCount[prime] += count

ans = 1
for _, count in primeCount.items():
    ans *= (count + 1)
    ans %= MOD

print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[200000];
int dp[200000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dp[i] = Inf;
	}
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  unordered_map<string,int> mp; 
  
  vector<string> ans(N,"zzzzzzzzzzz");
  vector<string> S(N);
  rep(i,N){
    cin>>S[i];
    ++mp[S[i]];
  }
  
  int M=0;
  rep(i,N){
    if(mp[S[i]]>M)
      M=mp[S[i]];
  }
  
  rep(i,N){
    if(mp[S[i]]==M){
      ans[i]=S[i];
    }
  }
  
  sort(ans.begin(),ans.end());
  cout<<ans[0]<<endl;
  
  for(int i=1;i<N;++i){
    if(ans[i]!=ans[i-1] && ans[i]!="zzzzzzzzzzz")
      cout<<ans[i]<<endl;
  }
  
}


Measured memory_bytes: 27208
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		String result = "2018" + s.substring(4);
		
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23380
def union(x, y, t):
    x, t_x = findSet(x)
    y, t_y = findSet(y)
    link(x, t_x, y, t_y, t)


def link(x, d_x, y, d_y, t):
    #print('', 'x', 'y')
    #print('', x, y)
    #print('', d_x, d_y, t)
    if r[x] > r[y]:
        p[y] = x
        d[y] = d_x - d_y - t
        #print('', y, '->', p[y], '=', d[y], '\n')

    else:
        p[x] = y
        d[x] = d_y - d_x + t
        if r[x] == r[y]: r[y] = r[y] + 1
        #print('', x, '->', p[x], '=', d[x], '\n')


def findSet(x):
    if x != p[x]:
        p[x], t = findSet(p[x])
        d[x] += t
    return p[x], d[x]


def diff(x, y):
    x, d_x = findSet(x)
    y, d_y = findSet(y)
    if x == y:
        return d_x - d_y

    else:
        return '?'




if __name__ == '__main__':

    p, r, d = [], [], []

    n_set, n_quare = map(int, input().split())

    for i in range(n_set):
        p.append(i)
        r.append(0)
        d.append(0)


    for i in range(n_quare):
        l = input().split()

        if len(l) == 4:
            _, x, y, t = map(int, l)
            union(x, y, t)

        else:
            _, x, y = map(int, l)
            print(diff(x, y))



Measured memory_bytes: 11400
N = int(input())
S = list(input())
r = []
c = 0
for x in range(N):
  a = S[:x]
  b = S[x:]
  if len(a) >= 1 and len(b) >= 1:
    for y in set(a):
      if y in b:
        c += 1
    r.append(c)
  c = 0
print(max(r))

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(l);
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int index1 = Math.max(j + 1, search1(l, l[j] - l[i]));
				int index2 = search2(l, l[j] + l[i]);
				if (index1 <= index2) {
					count += (index2 - index1 + 1);
				}
			}
		}
		System.out.println(count);
	}

	public static int search1(int[] l, int a) {
		int min = 0;
		int max = l.length;
		while (max - min > 1) {
			int mid = min + (max - min) / 2;
			if (l[mid] > a) {
				max = mid;
			} else {
				min = mid;
			}
		}
		return max;
	}

	public static int search2(int[] l, int a) {
		int min = 0;
		int max = l.length;
		while (max - min > 1) {
			int mid = min + (max - min) / 2;
			if (l[mid] < a) {
				min = mid;
			} else {
				max = mid;
			}
		}
		return min;
	}
}


Measured memory_bytes: 28016
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		scan.useDelimiter("?\?\r?\?\n");
		// ??\???
		String s = scan.next();
		// ??????????????????
		int s1 = s.length();
		
		String S = "";
		for(int i=0; i<s1; i++){
			String s2 = s.substring(i, i+1);
			String s3;
			if( s2.matches( "[a-z]+" ) ){
				String upper_s2 = s2.toUpperCase();
				S = S + upper_s2;
			}
			/*
			else if (s2 == a){
				
				S = S + s3;
			}
			*/
			else {
				String lower_s2 = s2.toLowerCase();
				S = S + lower_s2;
			}
		}
		
		System.out.print(S);

	}

}

Measured memory_bytes: 34252