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

#define SIZE 100
#define FORWARD 0
#define BACKWORD 1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1


int graph[SIZE][SIZE];
int color[SIZE];
int nextnum[SIZE];
int timestamp[2][SIZE];
int time;

typedef struct _node {
	int val;
	struct _node *next;
} node;

node *allocNode(int val) {
	node *p = (node *)malloc(sizeof(node));
	p->val = val;
	p->next = NULL;
	return p;
}

void push(node **top, node *p) {
	if (p == NULL) return;
	p->next = *top;
	*top = p;
}

void pop(node **top) {
	if (*top == NULL) return;
	node *tmp = *top;
	*top = (*top)->next;
	free(tmp);
}

int nextVertex(int u, int n) {
	int i, nv = NIL;
	for (i = nextnum[u]; i < n; i++) {
		if (graph[u][i] == 1 && color[i] == WHITE) {
			nv = i;
			break;
		}
	}

	if (nv != NIL) nextnum[u] = nv + 1;
	else nextnum[u] = n;

	return nv;

}

void dfs(int u, node **top, int n) {
	int i, v;
	node *p;
	for (i = 0; i < n; i++) nextnum[i] = 0;

	p = allocNode(u);
	push(top, p);
	color[u] = GRAY;
	timestamp[FORWARD][u] = ++time;

	while (*top != NULL) {
		u = (*top)->val;
		v = nextVertex(u, n);
		if (v != NIL) {
			p = allocNode(v);
			push(top, p);
			color[v] = GRAY;
			timestamp[FORWARD][v] = ++time;
		}
		else {
			pop(top);
			color[u] = BLACK;
			timestamp[BACKWORD][u] = ++time;
		}
	}
}

int main()
{
	int i, j, n, u, k, v;
	node *top;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			graph[i][j] = 0;

	for (i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			graph[u - 1][v - 1] = 1;
		}
	}

	for (i = 0; i < n; i++)	color[i] = WHITE;

	time = 0;
	top = NULL;
	for (i = 0; i < n; i++) {
		if (color[i] == WHITE) dfs(i,&top,n);
	}

	for (i = 0; i < n; i++) {
		printf("%d %d %d\n", i + 1, timestamp[FORWARD][i], timestamp[BACKWORD][i]);
	}
	return 0;
}


Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    long A[N],B[N];
    vector<long> C(N);
    long result=0;
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
        C[i]=A[i]+B[i];
        result-=B[i];
    }
    sort(C.begin(),C.end());
    reverse(C.begin(),C.end());
    for(int j=0;j<N;j=j+2){
        result+=C.at(j);
    }
  cout<<result<<endl;
}


Measured memory_bytes: 2560
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long N = sc.nextLong();
    	long M = sc.nextLong();
    	if (N != 1 && M != 1) {
    		System.out.println((N*M)%2 == 0 ? N*M/2 : N*M/2+1);
    	} else {
    		System.out.println(1);
    	}
    }
}

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

using namespace std;

typedef long long int ll;

int main(){
    int n ;
    cin>>n;
    ll arr[n];
    for(int i= 0;i< n;i++)cin>>arr[i];
    sort(arr, arr+n);
    int flag = 0;
    for(int i = 0;i< n-1;i++)
    {
        if(arr[i] == arr[i+1])flag =1;
    }
    if(flag == 1)cout<<"NO";
    else cout<<"YES";
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;

int main(void) {
	string s, t;
	int n;
	int count = 0;
	cin >> n >> s >> t;
	FOR(i, 0, n - 1) {
		FOR(p, 0, n-i-1) {
			if (s[i + p] != t[p]) {
				break;
			}
			if (p == n-i-1) {
				count = n + i;
				goto warp;
			}
		}
	}
	warp:
	if (count == 0) {
		cout << 2*n << endl;
	}
	else {
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define REP(i,n) for(LL i=0, i##_len=(n); i<i##_len; ++i)

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

template <LL MOD=1000000007> class MODLL {
public:
  LL x;
  MODLL(const LL _x) : x(_x % MOD) {};
  MODLL operator+(const MODLL rhs) const { return MODLL(*this) += rhs; }
  MODLL operator-(const MODLL rhs) const { return MODLL(*this) -= rhs; }
  MODLL operator*(const MODLL rhs) const { return MODLL(*this) *= rhs; }
  MODLL operator/(const MODLL rhs) const { return MODLL(*this) /= rhs; }
  MODLL& operator+=(const MODLL rhs) { x += rhs.x; x %= MOD; return *this; }
  MODLL& operator-=(const MODLL rhs) { x -= rhs.x; x %= MOD; if(x<0) x += MOD; return *this; }
  MODLL& operator*=(const MODLL rhs) { x *= rhs.x; x %= MOD; return *this; }
  MODLL inv() const {
    if(x == 0) { throw "does not have inverse"; }
    LL a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return MODLL(u);
  }
  MODLL& operator/=(const MODLL rhs) { (*this) *= rhs.inv(); return *this; }
  MODLL pow(ULL n) const {
    MODLL res = 1;
    MODLL a = x;
    while (n > 0) {
      if (n & 1) res *= a;
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef MODLL<> ML;

void test() {
  {
    ML x = 3;
    assert(x.pow(45).x == 644897553);
  }
  {
    for(int i=1; i<13; i++) {
      MODLL<13> x = i;
      assert( (x.inv().x * i) % 13 == 1 );
    }
  }
}


int main() {
  LL N,K;
  std::cin >> N >> K;
  std::vector<LL> A(N);
  for(LL i=0; i<N; i++) {
    std::cin >> A[i];
  }

  LL cnt = 0;
  for(LL i=0; i<N; i++) {
    for(LL j=N-1; j>i; j--) {
      if(A[j] < A[j-1]) {
        cnt++;
        LL tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
      }
    }
  }

  ML ans = 0;
  LL small = A[0];
  LL n_small = 0;
  for(LL i=0; i<N; i++) {
    if(A[i] > small) {
      small = A[i];
      n_small = i;
    }
    ans += n_small;
  }
  ans *= K*(K-1)/2;
  ans += cnt * K;
  std::cout << ans.x << std::endl;

  return 0;
}



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

int main(){
 int N,M;
  cin>>N>>M;
  vector<int> tenbou(N,0);
  vector<int> t_check(N,1);
for(int i=0;i<N;i++){
  int a=0;
  cin>>a;
  tenbou[i]=a;
}
for(int j=0;j<M;j++){
 int b,c;
  cin>>b>>c;
  if(tenbou[b-1]>=tenbou[c-1]){
    t_check[c-1]=0;
    //tenbou[c-1]=tenbou[b-1];
  }
  if(tenbou[c-1]>=tenbou[b-1]){
    t_check[b-1]=0;
    //tenbou[b-1]=tenbou[c-1];
  }
}

 /* for(int j=0;j<N;j++){
  cout<<t_check[j]<<" ";
  }*/
int count=accumulate(t_check.begin(),t_check.end(),0);
 cout<<count<<endl;
  
}

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

using namespace std;

void init(){

}

int n;
int A[22];

void solve(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    int ans = 0;
    int arr[3];
    for(int i = 1; i < n-1; i++){
        arr[0] = A[i-1];
        arr[1] = A[i];
        arr[2] = A[i+1];
        sort(arr, arr+3);
        if(A[i] == arr[1]) ans++;
    }
    printf("%d\n", ans);
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}


Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))

L = sorted(L,reverse=True)

#print(L)
t = 0
a = 0
for i in range(1,n):
    t += L[i-1]
    a += (t * L[i]) #% (10**9 + 7)
#    print(t,a)

print(a % (10**9 + 7))    


Measured memory_bytes: 31620
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    string s;
    cin >> s;

    int n = s.length();

    vector<int> o(n);
    for (int i = 0; i < n; i++) {
      o[i]=0;
    }

    int left, center, right = 0;
    int i = 1;
    while (i < n) {
      left = right;
      while(s[i]=='R'){
        if(++i == n) break;
      }
      center = i;
      while(s[i]=='L'){
        if(++i == n) break;
      }
      right = i;
      // cout << left << center << right << endl;
      o[center-1] = (center-left+1)/2 + (right-center  )/2;
      o[center  ] = (center-left  )/2 + (right-center+1)/2;
    }

    for (int i = 0; i < n; i++) {
      cout << (i?" ":"") << o[i];
    }
    cout << endl;

    return 0;
}


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

using namespace std;


int n, k, A[4005][4005];
int rangesum(int a, int b, int c, int d){
	return A[c][d]-A[a-1][d]-A[c][b-1]+A[a-1][b-1];
}
int query(int x, int y){
	// query box x,y, to x+k-1, y+k-1, and x+k,y+k, to x+2k-1,y+2k-1
	return rangesum(x,y,x+k-1,y+k-1)+rangesum(x+k,y+k,x+2*k-1,y+2*k-1);
}
int main(){
	cin >> n >> k;
	for(int i = 0; i<n; i++){
		int a,b; char c;
		cin >> a >> b >> c;
		if(c == 'W') b+=k; // white -> black
		A[a%(2*k)+1][b%(2*k)+1]++;
		A[a%(2*k)+1][b%(2*k)+1+2*k]++;
		A[a%(2*k)+1+2*k][b%(2*k)+1]++;
		A[a%(2*k)+1+2*k][b%(2*k)+1+2*k]++;
	}
//	for(int i = 1; i<=4*k; i++){ for(int j = 1; j<=4*k; j++) printf("%d ", A[i][j]); printf("\n"); }
	for(int i = 1; i<=4*k; i++) for(int j = 1; j<=4*k; j++) A[i][j]+=A[i-1][j]+A[i][j-1]-A[i-1][j-1];
	// how many blacks can we have?
	int ans = 0;
	for(int i = 1; i<=2*k; i++){
		for(int j = 1; j<=2*k; j++){
			ans = max(ans, query(i,j));
		}
	}
	cout << ans;
}


Measured memory_bytes: 62848
inputs = gets.to_s.split(" ")
number = inputs.length
array = []
desult = 0
for i in 0..number-1 do
  input = inputs[i]

  if input.match(/\+|\-|\/|\*/) == nil
    array << input.to_i
  end

  if input.match(/\+/) != nil
    desult = array.pop + array.pop
    array << desult
  end

  if input.match(/\-/) != nil
    desult = -1 * (array.pop - array.pop)
    array << desult
  end

  if input.match(/\//) != nil
    desult = 1 / (array.pop / array.pop)
    array << desult
  end

  if input.match(/\*/) != nil
    desult = array.pop * array.pop
    array << desult
  end
end

puts array[0]



Measured memory_bytes: 6896
# coding:utf-8
array = map(int, raw_input().split())
W = array[0]
H = array[1]
x = array[2]
y = array[3]
r = array[4]
if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    ll n;
    cin >> n;
    vector<string> s(n);
    for (ll i = 0;i < n;i++){
        cin >> s[i];
    }
    ll m = 0,a = 0,r = 0,c = 0,h = 0;
 
    for (ll i = 0; i < n; i++){
        if (s[i][0] == 'M'){
            m++;
            continue;
        }
        if (s[i][0] == 'A'){
            a++;
            continue;
        }
        if (s[i][0] == 'R'){
            r++;
            continue;
        }
        if (s[i][0] == 'C'){
            c++;
            continue;
        }
        if (s[i][0] == 'H'){
            h++;
            continue;
        }
    }
 
    ll ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
    cout << ans << endl;
    
}


Measured memory_bytes: 6268
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int n;
cin>>n;
int num[1000];
for(int i = 0;i<n;i++)cin>>num[i];
int all = 1;
int bad = 1;
for(int i =0;i<n;i++){
    all*=3;
if(num[i]%2==0)bad*=2;

}
cout<<all-bad<<endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<string> vs;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int main() {
	while(true) {
		int n;
		cin >> n;
		if(n == 0) break;

		vector<pii> vp;
		rep(i,0,n) {
			int h,m,s;
			scanf("%d:%d:%d", &h, &m, &s);
			vp.push_back(pii(h*3600 + m*60 + s, 1));
			scanf("%d:%d:%d", &h, &m, &s);
			vp.push_back(pii(h*3600 + m*60 + s, -1));
		}

		sort(vp.begin(), vp.end());

		int ans = 0, tmp = 0;
		rep(i,0,vp.size()) {
			tmp += vp[i].second;
			ans = max(ans, tmp);
		}
		cout << ans << endl;
	}
}

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

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int adj[n][n] = {};

  for (int i = 0; i < n; i++) {
    int u, k; cin >> u >> k;
    
    for (int j = 0; j < k; j++) {
      int v; cin >> v;
      adj[u-1][v-1] = 1;
    }
  }

  int d[n] = {};
  int f[n] = {};
  int t = 1;

  stack<int> st;
  st.push(0);

  while (!st.empty()) {
    int v = st.top();

    if(d[v] == 0) {
      d[v] = t;
    }

    for (int i = 0; i < n; i++) {
      if(adj[v][i] == 1 && d[i] == 0) {
        st.push(i);
        break;
      }
    }

    if(st.top() == v) {
      f[v] = t+1;
      st.pop();
    }

    if(st.empty()) {
      t++;
      for (int i = 0; i < n; i++) {
        if(d[i] == 0) {
          st.push(i);
          break;
        }
      }
    }

    t++;
  }

  for (int i = 0; i < n; i++) {
    cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
  }

}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  int n;
  cin >> n;
  int ans = n*800 - n/15*200;
  cout << ans << endl;
}


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

ll mod_pow(ll n, ll p, ll mod) {
    n %= mod;
    if (p == 0)
        return 1;
    ll res = mod_pow(n * n % mod, p / 2, mod);
    if (p % 2 == 1)
        res = res * n % mod;
    return res;
}

struct combination {
    combination(ll Nmax, ll mod) {
        (this->MOD) = mod;
        (this->Nmax) = Nmax;
        factorial.resize(Nmax + 1, 1);
        inverse_factorial.resize(Nmax + 1, 1);
        init_factorial();
    }

    ll calc(ll n, ll r) {
        if (r < 0 || r > n)
            return 0;
        ll ret = (factorial[n] * inverse_factorial[r]) % MOD;
        ret = (ret * inverse_factorial[n - r]) % MOD;
        return ret;
    }

private:
    ll MOD, Nmax;
    vector<ll> factorial;
    vector<ll> inverse_factorial;

    void init_factorial() {
        for (ll i = 1; i <= Nmax; i++) {
            factorial[i] = (factorial[i - 1] * i) % MOD;
        }
        inverse_factorial[Nmax] = mod_pow(factorial[Nmax], MOD - 2, MOD);
        for (ll i = Nmax - 1; i >= 1; i--) {
            inverse_factorial[i] = (inverse_factorial[i + 1] * (i + 1)) % MOD;
        }
    }
};

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll ans = 0;
    ll mod = 1e9 + 7;
    combination comb(N, mod);
    for (int i = K - 1; i < N; i++) {
        ans = (ans + A[i] * comb.calc(i, K - 1) % mod) % mod;
    }
    for (int i = 0; i + K - 1 < N; i++) {
        ans -= A[i] * comb.calc(N - i - 1, K - 1) % mod;
        while (ans < 0) {
            ans += mod;
        }
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2176
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return Counter(a)

def check(j):
    if j <= 2:
        return 1
    else:
        tmp = int((j * 2) ** 0.5)
        while 1:
            if tmp * (tmp + 1) <= j * 2:
                return tmp
            else:
                tmp -= 1
        # return int((j * 2) ** 0.5)


N = int(input())
ans = 0
for i, j in prime_factorize(N).items():
    ans += check(j)
print(ans)




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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

std::vector<std::string> split(const std::string &str, char delim) {
  std::istringstream stream(str);
  std::string element;
  std::vector<std::string> result;
  while(std::getline(stream, element, delim)) {
    result.push_back(element);
  }
  return result;
}

int main() {
  //const int x_max = 100000;

  uint n;
  string str;
  scanf("%u", &n);
  vector<int> nums;
  int a;
  REP(i, n) {
    scanf("%d", &a);
    nums.push_back(a);
  }
  /*
  getchar();
  getline(cin, str);
  vector<string> strnums = split(str, ' ');
  //REP(i, strnums.size()) { cout<<strnums[i]<<endl; }
  vector<int> nums;
  REP(i, strnums.size()) {
    nums.push_back(atoi(strnums[i].c_str()));    
  }
  */
  //REP(i, nums.size()) { cout<<nums[i]<<endl; }
  
  map<int, int> m;

  for(auto &x : nums) {
    m[x-1]++;
    m[x+1]++;
    m[x]++;
  }
  int ans = 0;
  for(auto &x : m) {
    ans = max(ans, x.second);
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 5112
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int Z = 210;
const int N = 500;
vector<int> g[N];
int deg[N];
bool used[N];

void dfs(int v)
{
    used[v] = 1;
    for (int u : g[v])
        if (!used[u])
            dfs(u);
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int n, m;
    scanf("%d%d", &n, &m);
    while(n--) {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        a += c;
        b += d;
        int v, u;
        if (c == 0) {
            v = Z + a;   
        } else {
            v = Z - c;
        }
        if (d == 0) {
            u = Z - b;
        } else {
            u = Z + d;
        }
        g[v].push_back(u);
        deg[v]++;
        deg[u]--;
    }
    for (int v = 0; v < N; v++) {
        if (deg[v] == 0) continue;
        /*
        if (abs(deg[v]) != 1) {
            printf("NO\n");
            return 0;
        }
        */
        if (deg[v] < 0) {
            if (v >= Z) {
                printf("NO\n");
                return 0;
            }
        } else {
            if (v <= Z) {
                printf("NO\n");
                return 0;
            }
            if (!used[v]) dfs(v);
        }
    }
    for (int v = 0; v < N; v++) {
        if (!used[v] && !g[v].empty()) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define emb emplace_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define N  99999
#define f first 
#define em emplace
#define s second
using lint=long long int;

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

 
#define fori(n) for(int i=0; i<int(n); i++)
 
#define cins(s) string s; cin>>s;
#define cini(i) lint i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }
#define z 1000000007 


void solve(){
  
  cini(n);
  vector<int>dp(3);


  for(int i=0;i<n;i++){
     vector<int>v(3);

     for(int j=0;j<3;j++){
           cin>>v[j];
            int m=0;
           for(int k=0;k<3;k++){

              if(j!=k){
                m=max(dp[k],m);
              }
           }
           v[j]+=m;
     }
    
    dp=move(v);
  }
     
     int a=*max_element(dp.begin(),dp.end());
     cout<<a<<endl;




}
 
 
int main()
{ 
  fast;
 



  solve();
 }

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

#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define skip continue

int n;
string s, t;

int main(){
	cin >> n;
	cin >> s;
	cin >> t;
	int len = n + n;
	forn(i, 0, n - 1){
		bool ok = 1;
		for(int j = 0; j + i < n; ++ j){
			if(s[i + j] == t[j]) skip;
			ok = 0;
			break;
		}
		if(ok){
        	len = min(len, i + n);
        }
	}
	cout << len;        
	return 0;
}

Measured memory_bytes: 256
N, K = [ int(n) for n in input().split() ]
S = input()

happy = 0
LR = 0
RL = 0
for i in range(N-1):
    s = S[i:i+2]
    if s == "LR":
        LR += 1
    elif s == "RL":
        RL += 1
    else:
        happy += 1

m = min(LR,RL)
M = max(LR,RL)
if M <= K:
    print(N-1)
elif m >= K:
    print(happy + 2*K)
else:
    print(N-2)

Measured memory_bytes: 39920
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
  #define pb push_back
#define f first
#define s second
  #define MAXN 100005
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	string s;
	cin>>s;
	ll b=0;
	ll ans=0;
	for(int i=0; i<s.length(); i++) {
		if(s[i]=='B') {
			b++;
		}
		else  {
			ans+=b;
		
		}
	}
	cout<<ans<<endl;

	return 0;
}


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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 1e5+100;
const ll inf = 1e15;
const ll mod = 1e9+7;



int main(){
	fastio;
	ld a,b,n,x;
	cin >> a >> b >> x;
	ld ang ;
	if(a*a*b <= 2*x){
		x = a*a*b -x;
		ld h = 2*x/(a*a);
		ang =  atan(a/h)*180.0/acos(-1) ; 
	}
	else{
		ld h = 2*x/(a*b);
		ang =  atan(h/b)*180.0/acos(-1) ;
	}
	cout << fixed<< setprecision(12)<< 90.0 - ang << endl;
}

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

int main(){
  string s;
  unsigned long k;
  cin >> s >> k;
  
  for(int i=0; i < k; i++){
    if(s[i] != '1'){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
a = input()
n, y = a.split()
N = int(n)
y = int(y)
Y = y / 1000

n1, n2, n3 = -1, -1, -1
for z in range(N+1):
    x = (Y - 5*N + 4*z)/5
    y = (10*N - 9*z - Y)/5
    if x.is_integer() and y.is_integer() and x >= 0 and y >= 0:
        n1, n2, n3 = x, y, z

n1 = int(n1)
n2 = int(n2)
n3 = int(n3)
print('{} {} {}'.format(n1, n2, n3))


Measured memory_bytes: 3064
import math
import copy

neko = 0
nuko = 0
a,b = map(int,input().split())
for i in range(a,b+1):
    s1 = i//10000
    s2 = (i%10000)//1000
    s3 = (i%100)//10
    s4 = i%10
    if (s1 == s4)and(s2 == s3):
        neko += 1
print(neko)

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
typedef long long ll;

using namespace std;

struct Problem {
    int num;
    string ans;
};

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<Problem> v(m);
    vector<bool> isCollect(n, false);
    for(int i = 0; i < m; i++) {
        cin >> v[i].num >> v[i].ans;
        if(v[i].ans == "AC") {
            isCollect[v[i].num - 1] = true;
        }
    }
    
    vector<bool> flag(n, false);
    int collect = 0;
    int wa = 0;
    for(int i = 0; i < m; i++) {
        if(flag[v[i].num - 1] == false) {
            if(v[i].ans == "WA" && isCollect[v[i].num - 1]) {
                wa++;
            }
            else if(v[i].ans == "AC"){
                collect++;
                flag[v[i].num - 1] = true;
            }
        }
    }
    
    cout << collect << " " << wa << endl;
    
    return 0;
}


Measured memory_bytes: 6528
N,K = map(int,input().split())
list_x = list(map(int,input().split()))

loop_cnt = N - K + 1
ans = []

for i in range(loop_cnt):
  diff_between_0 = min(abs(list_x[i]), abs(list_x[i+K-1]))
  diff_between_max_min = abs(list_x[i+K-1] - list_x[i])
  _ = diff_between_0 + diff_between_max_min
  ans.append(_)

print(min(ans))

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

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

  string S;
  cin >> S;

  int num = 0;
  int count = 0;
  rep(i, S.size()) if (S[i] == 'R') num++;
  rep(i, num) if (S[i] == 'R') count++;

  cout << num - count << endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
	cout<<setprecision(12);
	int n;
	cin>>n;
	double a,b=0;
	while(n--){
		cin>>a;
		b+=(1/a);
	}
	cout<<(1/b)<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type city struct {
	o  int
	p  int
	y  int
	id int
}

type cities []city

func (cs cities) Len() int           { return len(cs) }
func (cs cities) Swap(i, j int)      { cs[i], cs[j] = cs[j], cs[i] }
func (cs cities) Less(i, j int) bool { return cs[i].y < cs[j].y }

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	cs := make(cities, m)
	for i := 0; i < m; i++ {
		cs[i].o = i
		fmt.Scan(&cs[i].p, &cs[i].y)
	}

	sort.Sort(cs)
	mp := make(map[int]int)
	ans := make([]string, m)
	for i := 0; i < m; i++ {
		mp[cs[i].p]++
		cs[i].id = mp[cs[i].p]
		ans[cs[i].o] = fmt.Sprintf("%06d%06d", cs[i].p, cs[i].id)
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}


Measured memory_bytes: 15744
import java.util.*;

public class Main {
	static class Node {
		int id;
		int depth = -1;
		Node parent = null;
		Set<Node> parents = new HashSet<>();
		List<Node> children = new ArrayList<>();

		Node(int id) {
			this.id = id;
		}

		void setDepth(Node from) {
			if (from == null) {
				this.depth = 0;
			} else {
				if (this.depth <= from.depth + 1) {
					this.parent = from;
					this.depth = from.depth + 1;
				}
				this.parents.remove(from);
			}
			if (this.parents.isEmpty()) {
				for (Node child : children) {
					child.setDepth(this);
				}
			}
		}
	}

	int N, M;
	int[] A, B;
	Node[] nodes;
	Node root;

	Main() {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		A = new int[N - 1 + M];
		B = new int[N - 1 + M];
		for (int i = 0; i < N - 1 + M; ++i) {
			tokens = in.nextLine().split(" ");
			A[i] = Integer.parseInt(tokens[0]);
			B[i] = Integer.parseInt(tokens[1]);
		}
		in.close();

		this.nodes = genTree();
		this.root = findRoot(this.nodes);
		this.root.setDepth(null);
	}

	Node findRoot(Node[] nodes) {
		for (Node node : nodes) {
			if (node.parents.isEmpty()) {
				return node;
			}
		}
		return null;
	}

	Node[] genTree() {
		Node[] tree = new Node[N];
		for (int i = 0; i < N; ++i) {
			tree[i] = new Node(i);
		}
		// edgeの追加
		for (int i = 0; i < N - 1 + M; ++i) {
			Node src = tree[A[i] - 1];
			Node dst = tree[B[i] - 1];
			src.children.add(dst);
			dst.parents.add(src);
		}
		return tree;
	}

	void show() {
		for (int i = 0; i < N; ++i) {
			if (nodes[i].parent == null) {
				System.out.println(0);
			} else {
				System.out.println((nodes[i].parent.id + 1));
			}
		}
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.show();
	}
}

Measured memory_bytes: 189260
import math
N,M=map(int,input().split())
if abs(N-M)>=2:
    print(0)
else:
    if N==M:
        a=math.factorial(N)
        print(2*a**2%(10**9+7))
    else:
        a=math.factorial(N)
        b=math.factorial(M)
        print(a*b%(10**9+7))
        

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main() {
    string k;
    int d;
    cin>>k>>d;
    // dp[i][0] - #integers with sum_digits p*d + i using curr digit m as [0..9]
    // dp[i][1] - #integers with sum_digits p*d + i using curr digit m as [0..m]
    vector<vector<int>> prev(d, vector<int> (2, 0));
    prev[0][0] = prev[0][1] = 1;
    for(int i = k.size()-1; i>=0; i--) {
        vector<vector<int>> curr(d, vector<int> (2, 0));
        int m = (int) (k[i] - '0');
        for(int j=0; j<d; j++) {
            for(int k=0; k<10; k++) {
                curr[j][0] = (curr[j][0] + prev[(j - k + 9*d) % d][0]) % mod;
                if(k < m) curr[j][1] = (curr[j][1] + prev[(j - k + 9*d) % d][0]) % mod;
            }
            curr[j][1] = (curr[j][1] + prev[(j - m + 9*d) % d][1]) % mod;
        }
        prev = curr;
    }
    cout<<(prev[0][1] - 1 + mod) % mod<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    string s;

    cin >> s;

    bool is_odd = s.length() % 2 == 1 ? true : false;
    bool is_same = s[0] == s[s.length() - 1];

    if((is_odd^is_same) == false)
    {
        cout << "Second" << endl;
    }
    else
    {
        cout << "First" << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX_V = 10000;
const ll MAX_E = 100000;
struct edge{
  ll u,v,cost;
  bool operator<(const edge &o) const {return cost < o.cost;}
  bool operator>(const edge &o) const {return cost > o.cost;}
};
ll V,E,Par[MAX_V],Rank[MAX_V] = {};edge G[MAX_E];
void init(ll n){
  for(ll i=0;i<n;i++) Par[i] = i;
}
ll find(ll x){
  if(x == Par[x]) return x;
  else return Par[x] = find(Par[x]);
}
void unite(ll x,ll y){
  x = find(x);y = find(y);
  if(x == y) return;
  if(Rank[x] < Rank[y]) swap(x,y);
  Par[y] = x;
  if(Rank[x] == Rank[y]) Rank[x]++;
}
bool same(ll x,ll y){
  return find(x) == find(y);
}
ll Kruskal(){
  sort(G,G+E);ll ans = 0,i;edge e;
  init(V);
  for(i=0;i<E;i++){
    e = G[i];
    if(!same(e.u,e.v)){
      ans += e.cost;
      unite(e.u,e.v);
    }
  }
  return ans;
}
int main(){
  ll i;scanf("%lld%lld",&V,&E);
  for(i=0;i<E;i++) scanf("%lld%lld%lld",&G[i].u,&G[i].v,&G[i].cost);
  printf("%lld\n",Kruskal());
}


Measured memory_bytes: 5720
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
mod = 10 ** 9 + 7


def p(x, y):
    ret = 1
    for i in range(y):
        ret *= x - i
        ret %= mod

    return ret


adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


def dfs(s):
    d = [-1] * n
    d[s] = 0
    child = [0] * n
    stack = [s]
    while stack:
        u = stack.pop()
        for v in adj[u]:
            if d[v] == -1:
                child[u] += 1
                d[v] = d[u] + 1
                stack.append(v)

    return child


c = dfs(0)
ans = 1
for i, e in enumerate(c):
    if i == 0:
        ans *= k * p(k - 1, e)
    else:
        ans *= p(k - 2, e)

    ans %= mod

print(ans)


Measured memory_bytes: 45708
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>

double charToDouble(char *c)
{
	return atof(c);
}

std::string doubleToString(double x)
{
	char c[256] = {'\0'};
	sprintf(c, "%.0f", x);

	return c;
}

int main()
{
	int x;
    std::cin >> x;
	double y = pow(double(x), 3);
    std::cout << doubleToString(y) << std::endl;
}

Measured memory_bytes: 1304
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define INFINITE 100000000
// Maximum number of nodes
#define NODENUM 1000
// 隣接行列
int dist[NODENUM][NODENUM];
int cost[NODENUM];
int nearest[NODENUM];

int prim(int n)
{
    int i;
    int totalWeight = 0;
    bool visited[NODENUM];
    for (i = 0; i < NODENUM; i++)
        visited[i] = false;
    visited[0] = true;
    for (i = 0; i < n; i++) {
        cost[i] = dist[0][i];
        nearest[i] = 0;
    }
    while (1) {
        int min = INFINITE;
        int minID;
        for (i = 0; i < n; i++) {
            if (visited[i]) continue;
            if (min > cost[i]) {
                min = cost[i];
                minID = i;
            }
        }
        if (min == INFINITE) break;
        visited[minID] = true;
        totalWeight += dist[minID][nearest[minID]];
        for (i = 0; i < n; i++) {
            if (dist[minID][i] < cost[i]) {
                cost[i] = dist[minID][i];
                nearest[i] = minID;
            }
        }
    }
    return totalWeight;
}

int main (int argc, char *argv[])
{
    int c, r;
    for (c = 0; c < NODENUM; c++)
        for (r = 0; r < NODENUM; r++)
            dist[c][r] = (c == r)? 0 : INFINITE;
    int n, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            scanf("%d", &dist[i][j]);
            if (dist[i][j] == -1)
                dist[i][j] = INFINITE;
        }
    }
    printf("%d\n", prim(n));
    return 0;
}


Measured memory_bytes: 5684
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

int A[109];

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

	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N, greater<int>());
	int score1 = 0, score2 = 0;
	for (int i = 0; i < N; i += 2) {
		score1 += A[i];
	}
	for (int i = 1; i < N; i += 2) {
		score2 += A[i];
	}
	cout << score1 - score2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
bool f(vector<int> &A) {
    int N = A.size();
    int even = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) even++;
    }
    if (even % 2 == 1) return false;
    if (even == N - 1) {
        for (int i = 0; i < N; i++) if (A[i] % 2 && A[i] >= 2) {
            A[i]--;
            int t = A[0];
            for (auto a : A) t = __gcd(t, a);
            for (auto &a : A) a /= t;
            bool ok = false;
            if (f(A)) ok = true;
            for (auto &a : A) a *= t;
            A[i]++;
            if (ok) return false;
        }
    }
    return true;
}
int main() {
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    cout << (!f(A) ? "First" : "Second") << '\n';
    return 0;
}


Measured memory_bytes: 640
a = [int(s) for s in input().split(' ')]

i = 0
foo = 0.0

arr = []

for n in range(a[0]):
    x = a[0] - n
    while (x * 2 ** i < a[1]):
        i += 1
    arr.append(i)

for i in arr:
    foo += 0.5 ** i

result = foo * (1 / a[0])

print(result)


Measured memory_bytes: 3864
N = int(input())
s = input()
w = [0] * (N + 1)
e = [0] * (N + 1)
for i in range(N):
    if s[i] == 'W':
        w[i + 1] = w[i] + 1
    else:
        w[i + 1] = w[i]
for i in range(N - 1, -1, -1):
    if s[i] == 'E':
        e[i] = e[i + 1] + 1
    else:
        e[i] = e[i + 1]
ans = float('inf')
for i in range(1, N + 1):
    ans = min(ans, w[i - 1] + e[i])
print(ans)

Measured memory_bytes: 17628
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0); 
	long long r,d,x;
	cin>>r>>d>>x;
	for(int i=0;i<10;i++)
	{
		x=r*x-d;
		cout<<x<<'\n';
	}
	
	
}
	
	

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char N[3];
    scanf("%s", N);
    if((N[0] == N[1] && N[1] < N[2])|| N[0] < N[1]){
            N[0] += 1;
        }
    N[1] = N[0];
    N[2] = N[0];
    printf("%s\n", N);
    return 0; 
}

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

/*int minimum(int &a,int &b,int &c,int &d){
  int x = max((b - a),(c - b));
  return (d - x);
}
*/
int main(){
  int k,n;
  cin >> k >> n;
  vector<int> A(n);
  
  for(int i=0;i<n;++i){
    cin >> A.at(i);
  }
  
  int answer=min((A.at(n-1) - A.at(0)),(k - A.at(1) + A.at(0)));

  for(int j=1;j<n;++j){
    
    if(answer > (k - A[j+1] + A[j])){
      answer = k - A[j+1] + A[j];
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  std::vector< ll > vsum(N, 0LL);

  std::cin >> va[0];
  vsum[0] = va[0];
  for (ll i = 1; i < N; i++) {
    std::cin >> va[i];
    vsum[i] = vsum[i-1] + va[i];
  }

  ll ans = INF;
  for (ll i = 0; i < N-1; i++) {
    ll x = vsum[i];
    ll y = vsum[N-1] - vsum[i];
    ll calc = std::abs(x - y);
    ans = std::min(ans, calc);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define ll long long int
#define inf 1e9 + 10
using namespace std;
//unordered_map<ll,vector<ll>> ma;
vector<ll> ma[100005];
ll dp[100005];
ll sol(ll src)
{
    if(dp[src]!=-1)
        return dp[src];
    ll maxlen=0;
    bool child=false;
    for(auto i:ma[src])
    {
        child=true;
        maxlen=max(maxlen,sol(i));
    }
    if(child==false)
        dp[src]=0;
    else
    {
        dp[src]=1+maxlen;
    }
    return dp[src];
}
int main()
{
    ll n,m;
    cin>>n>>m;

    for(ll i=0;i<m;i++)
    {
      ll x,y;
      cin>>x>>y;
      ma[x].push_back(y);
    }
      for(ll i=0;i<=n;i++)
        dp[i]=-1;
        ll ans=0;
      for(ll i=1;i<=n;i++)
      {
          ans=max(ans,sol(i));
      }
      cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 11836
from numpy import*
N,K=map(int,input().split())
m=zeros((3*K,3*K),dtype=int)
L=2*K
o=0
for _ in [0]*N:
 x,y,c=input().split()
 x,y=int(x)%L,int(y)%L
 t=c=='W'
 m[x,y]+=2*t-1
 o+=t
for _ in [0,0]:
 m[L:]=m[:K]
 m=cumsum(m,axis=0)
 m[:L]-=m[K:]
 m=m.T
m=m[:L,:L]
print(o-int((m+roll(roll(m,K,axis=0),K,axis=1)).min()))

Measured memory_bytes: 153100
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int mod=1000000007;
    int teep=120*60;
    int t,h,s;
    for (;;) {
        scanf("%d %d %d",&t,&h,&s);
        if (t==-1) break;
        int hyojun=teep-(t*3600+h*60+s);
        printf("%02d:%02d:%02d\n",hyojun/3600,(hyojun%3600)/60,hyojun%60);
        hyojun*=3;
        printf("%02d:%02d:%02d\n",hyojun/3600,(hyojun%3600)/60,hyojun%60);
    }
    return 0;
}

Measured memory_bytes: 3144
#include<stdio.h>
char a[]={'A','B','C','D','E','F'};
char b[2];
int main()
{
    int i=0,j=0;
    scanf("%c %c",&b[0],&b[1]);
    getchar();
    while(a[i]!='\0')
    {
        if(b[0]==a[i])
        {
            break;
        }
        i++;
    }
    i=i+1;
    while(a[j]!='\0')
    {
        if(b[1]==a[j])
        {
            break;
        }
        j++;
    }
    j=j+1;
    if(i>j)
    {
        printf(">\n");
    }
    else if(i==j)
    {
        printf("=\n");
    }
    else
    {
        printf("<\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c;
    char d,e;
  	string s;
  	cin>>a>>b;
  
    cout<<a*b-a-b+1<<endl;
 
 
 /* else if(a==23)
    cout<<"Christmas Eve Eve"<<endl;
  else
    cout<<"Christmas Eve Eve Eve"<<endl;
  */

  return 0;
}

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

typedef long long ll;

int N;
vector<int> L, T, R, B;
vector<int> X, Y;
vector<vector<ll>> field;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void compress(vector<int> &X){
    sort(X.begin(), X.end());
    X.erase(unique(X.begin(), X.end()), X.end());
}

void dfs(int x, int y){
    ll val = field[x][y];
    field[x][y] = -1;
    
    for(int i=0; i<4; i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(0<=nx && nx<X.size() && 0<=ny && ny<Y.size() && field[nx][ny] == val){
            dfs(nx, ny);
        }
    }
}

int main(){
    while(cin >> N, N){
        L.resize(N); T.resize(N); R.resize(N); B.resize(N);
        
        X.clear(); Y.clear();
        for(int i=0; i<N; i++){
            cin >> L[i] >> T[i] >> R[i] >> B[i];
            for(int j=-1; j<=1; j++){
                X.push_back(L[i] + j);
                X.push_back(R[i] + j);
                Y.push_back(T[i] + j);
                Y.push_back(B[i] + j);
            }
        }
        compress(X); compress(Y);
        
        field = vector<vector<ll>>(X.size(), vector<ll>(Y.size()));
        for(int i=0; i<X.size(); i++){
            for(int j=0; j<Y.size(); j++){
                ll t = 0;
                for(int k=0; k<N; k++){
                    if(L[k]<=X[i] && X[i]<R[k] && B[k]<=Y[j] && Y[j]<T[k])
                        t |= 1LL<<k;
                }
                field[i][j] = t;
            }
        }
        
        int ans = 0;
        for(int i=0; i<X.size(); i++){
            for(int j=0; j<Y.size(); j++) if(field[i][j] >= 0){
                dfs(i, j);
                ans++;
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define inf 1e18
#define pi acos(-1.0)
#define mod 1000000007

bitset<4000005>b;

int main(void)
{
    fastio;

    int n,a,s=0,i;
    cin >> n;
    b[0]=1;
    for(i=0;i<n;i++)
    {
        cin >> a;
        s=s+a;
        b=b|(b<<a);
    }
    for(i=(s+1)/2;i<=s;i++)
    {
        if(b[i])break;
    }
    cout << i ;

    return 0;
}



Measured memory_bytes: 5084
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Process struct {
	Name string
	Time int
}

type Queue struct {
	xs [200000]*Process
	i  int
	n  int
}

func (q *Queue) enqueue(x *Process) {
	q.xs[q.n] = x
	q.n++
}

func (q *Queue) dequeue() *Process {
	x := q.xs[q.i]
	if q.i >= len(q.xs)-1 {
		q.i = 0
	} else {
		q.i++
	}
	return x
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func nextStr(sc *bufio.Scanner) string {
	sc.Scan()
	s := sc.Text()
	return s
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	q := nextInt(sc)

	var queue Queue
	for i := 0; i < n; i++ {
		queue.enqueue(&Process{
			Name: nextStr(sc),
			Time: nextInt(sc),
		})
	}

	sum := 0
	for n > 0 {
		p := queue.dequeue()
		if p.Time > q {
			sum = sum + q
			p.Time = p.Time - q
			queue.enqueue(p)
		} else {
			sum = sum + p.Time
			n--
			fmt.Print(p.Name)
			fmt.Print(" ")
			fmt.Println(sum)
		}
	}
}



Measured memory_bytes: 5980