akhauriyash/Code-Regression huggingface dataset:
n = int(input())
h_list = input().split(' ')

dp = [0] * n
dp[0] = 0

for i in range(n):
  if i == 0:
    continue
  elif i > 1:
    minus_one = abs(int(h_list[i]) - int(h_list[i-1])) + dp[i-1]
    minus_two = abs(int(h_list[i]) - int(h_list[i-2])) + dp[i-2]

    dp[i] = min(minus_one, minus_two)
    
  elif i == 1:
    dp[i] = abs(int(h_list[i]) - int(h_list[0]))
    
print(dp[-1])

Measured memory_bytes: 14036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
char s[N];
int n;
int main()
{
    cin >> n;
    cout << n / 500 * 1000 + n % 500 / 5 * 5 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC055_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int y = 200 * (n / 15);
            int x = 800 * n;
            Console.WriteLine(x - y);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
using ll=long long;


const int MOD=1e9+7;

int dp[2010];

int main(){
  int s;
  cin >> s;
  dp[0]=1;
  dp[1]=0;
  dp[2]=0;
  for(int i=3;i<=s;++i){
    dp[i]=dp[i-1]+dp[i-3];
    dp[i]%=MOD;
  }
  cout << dp[s] << endl;
  return 0;
}


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

const ll INF = 1e18L+7;

int main(){

int n;
cin>>n;

double p[n];
for(int i=0;i<n;i++){
	cin>>p[i];
}

double dp[n+1][n+1];
memset(dp , 0 ,sizeof dp);

dp[0][0]=1;

for(int i=1;i<=n;i++){
	dp[i][0] = (dp[i-1][0])*(1-p[i-1]);
}

for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
          dp[i][j] = (dp[i-1][j]*(1-p[i-1])) +  (dp[i-1][j-1]*(p[i-1]) );
	}
}
double ans=0;



	for(int k = n/2+1 ; k<=n ;k++){
		ans +=(dp[n][k]);
	}
cout<<fixed <<setprecision(10)<<ans;
}

Measured memory_bytes: 70528
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
int main(void){
    // Your code here!
   int N;
   cin >> N;
   int K;
   cin >> K;
   vector<int> vec(N+1);
   vec.at(0) = -1000000;
   for(int i = 0; i < N; i++)cin >> vec.at(i+1);
   vector<int> dp(N+1);
   dp.at(0) = 1000000;
   dp.at(1) = 0;
   for(int i = 2; i <= N; i++){
       dp.at(i) = dp.at(i-1) + abs(vec.at(i) - vec.at(i-1));
       for(int j = 2; j <= K; j++){
           if(i >= j){
                dp.at(i) = min(dp.at(i), dp.at(i-j) + abs(vec.at(i) - vec.at(i-j)));
           }
       }
   }
   cout << dp.at(N) << endl;
}











Measured memory_bytes: 1024
#include <iostream>

//最大公約数を求めるプログラム(m >= n)
int calcGcd(int m, int n);
//最小公倍数を求めるプログラム
inline int calcLcm(int m, int n, int gcd);

int main(){
	int gcd, lcm, x, y;
	
	while(std::cin >> x >> y){
		if(x > y) gcd = calcGcd(x, y);
		else gcd = calcGcd(y, x);
		lcm = calcLcm(x, y, gcd);
		
		std::cout << gcd << " " << lcm << std::endl;
	}
	
	return 0;
}

int calcGcd(int m, int n){
	return n == 0 ? m : calcGcd(n, m%n);
}

inline int calcLcm(int m, int n, int gcd){
	return m / gcd * n;
}

Measured memory_bytes: 1156
#include<stdio.h>
#define N 500000
#define INFTY 1000000000

int n;
int cnt=0;
int L[N/2+2], R[N/2+2];

void merge(int A[], int left,int  mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;

    int i,j=0;
    //L[0...n1], R[0...n2] を生成
    for (i=0; i<n1; i++){
         L[i]=A[left+i];
    }
    for(i=0; i<n2; i++){
        R[i]=A[mid+i];
    }
    L[n1]=INFTY;
    R[n2]=INFTY;
    i=0;j=0;
    for(int k=left; k<right; k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i];
            i++;
        }
        else{
            A[k]=R[j];
            j++;
        }
            }

}

void mergeSort(int A[],int left,int right){
    if(left+1 < right){
        int mid=(left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }


}


int main(){
    int A[N];
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        scanf("%d",&A[i]);
    }

    int left=0;
    int right=n;

    mergeSort(A, left, right);

  for(int i=0; i<n; i++){
        if(i) printf(" ");
        printf("%d",A[i]);
   }

    printf("\n%d\n",cnt);
    return 0;

}



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

int main(){
    int A,B;
    A=B=0;
    int n,a[101];
   
    cin>>n;
    for(int t=0;t<n;t++)cin>>a[t];
    sort(a,a+n,greater<int>());
  
    for(int t=0;t<n;t++){
        if(t%2==0){
            A+=a[t];
        }else{
            B+=a[t];
        }
    }
    cout<<A-B<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001

const int MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, 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);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main(){
    string s; 
    cin >> s;
    int ans = 0;
    int res = 0;
    rep(i,3){
        if(s[i] == 'R') ans++;
        else ans = 0;
        res = max(res, ans);
    }
    cout << res << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
long long n,x;
long long ans,gd;
inline long long gcd(long long x,long long y)
{
    if(y==0)return x;
    if(x<y)swap(x,y);
    long long re=gcd(y,x%y);
    ans+=2*(x-x%y);
    return re;
}
int main()
{
    scanf("%lld%lld",&n,&x);
    ans=n;gd=gcd(n-x,x);
    ans-=gd;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char *argv[])
{  char a[35];
    int i,j,t=1;
    gets(a);
    for(i=0;i<strlen(a);i++)
    {
        for(j=i+1;j<strlen(a);j++)
         if(a[i]==a[j])
         {  t=0;
            printf("no");
            break;
         }
        if(t==0)break;
    }

    if(t)
    printf("yes");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

#define Max 100

int main(){

  int i,num,j,temp,array[Max],min,count=0,flag=0;

  
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&array[i]);
  }

  for(i=0;i<num;i++){
    min=i;
    for(j=i;j<num;j++){
      if(array[j]<array[min]){
	min = j;
	flag = 1;
      }
      
    }
    if(flag == 1){count++;
      flag = 0;}
    
    temp = array[i];
    array[i]=array[min];
    array[min] = temp;
    
  }
  for(i=0;i<num-1;i++){
    printf("%d ",array[i]);

  }
  printf("%d\n",array[num-1]);
  printf("%d\n",count);
}
	

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

using namespace std;

int main(){
  string a,b;
  cin >> a >> b;
  int x = stoi(a+b);
  int n = 1;
  int n_sq = n*n;
  while (n_sq <= x) {
    if (x == n_sq) {
      cout << "Yes" << endl;
      return(0);
    }
    n++;
    n_sq = n*n;
  }
  cout << "No" << endl;
  return(0);
}


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

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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

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

  int aoki = C / B;
  if(C % B != 0) aoki++;
  int takahashi = A / D;
  if(A % D != 0) takahashi++;

  if(takahashi >= aoki) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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


void solve()
{
    ll n,x,t;
    cin>>n>>x>>t;
   ll  c=n;
    ll ans=0;
    ans+=((c/x)*t);
    n%=x;
    if(n)
    ans+=t;
    cout<<ans<<"\n";
    
    
    
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--)
	{
	    solve();
	}
 
	return 0;
}


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

int n, p;
int a[100];

long long memo[100][2];

long long solve(int i, int tmp){
  if(i == n){
    if(tmp == p) return 1;
    else return 0;
  }

  if(memo[i][tmp] != -1){
    return memo[i][tmp];
  }

  return memo[i][tmp] = solve(i+1, (tmp+a[i])%2) + solve(i+1, tmp);
}

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

  for(int i = 0;i < n;i++){
    cin >> a[i];
    a[i] = a[i] % 2;
  }

  memset(memo, -1, sizeof(memo));

  cout << solve(0, 0) << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,k=1;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",strout);
	cin>>n>>a;
	for(int i=1;i<=n;i++)
	{
		if(k>a)  k+=a;
		else    k*=2;
	}
	cout<<k;

	return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
    while b != 0:
        a, b = b, a % b
    return a

N, X = map(int, input().split())
if N == 1:
    x =int(input())
    print(abs(x - X))
else:
    x =list(map(int, input().split()))
    ans = gcd(abs(x[0] - X), abs(x[1] - X))
    if N == 2:
        print(ans)
    else:
        for i in range(2, N):
            ans = gcd(ans, abs(x[i] - X))
        print(ans)


Measured memory_bytes: 14252
// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++11 -D_GLIBCXX_DEBUG c.cpp -oc && ./c " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int LL
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fr(i,n) for(int i=(n);i--;)
#define fv(i,v) f(i,sz(v))

main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int n;
	cin>>n;
	vc<int> a(n);
	f(i,n) cin>>a[i];
	vc<int> b(n);
	int j=(n-1)/2;
	f(i,n){
		b[j]=a[i];
		if(!(i&1)) j+=i+1;
		else j-=i+1;
	}
	if(!(n&1)) reverse(all(b));
	f(i,n) cout<<b[i]<<" \n"[i+1==n];
}


Measured memory_bytes: 5376
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}


int main(int argc, char const* argv[])
{
	int x;
	cin >> x;
	vector<bool> expo(x+1);
	expo[1] = true;
	for (int i = 2; i < 34; i++) {
		for (int j = i*i; j < x+1; j *= i) {
			expo[j] = true;
		}
	}
	int v = 0;
	for (auto i = expo.rbegin(); i != expo.rend(); i++) {
		bool var = *i;
		if (var) {
			cout << x-v << endl;
			return 0;
		}
		v++;
	}
}


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

long long N,M;
vector<int> G[100010];
long long ans = 0,cnt1 = 0,cnt2 = 0,cnt3 = 0;
int res = 0;
int k[100010] = {0};

bool DFS(int v,int c)
{
    k[v] = c;
    bool res = true;
    for(int i = 0; i < G[v].size(); i++)
    {
        int ne = G[v][i];
        if(k[ne] == 0)res &= DFS(ne,-c);
        else if(k[ne] == k[v])res = false;
    }
    return res;
}

int main()
{
    scanf("%lld%lld",&N,&M);
    for(int i = 0; i < M; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for(int i = 1; i <= N; i++)
    {
        if(k[i] == 0)
        {
            if(G[i].size() == 0)cnt1++;
            else if(DFS(i,1))cnt2++;
            else cnt3++;
        }
    }

    printf("%lld\n",cnt1 * cnt1 + cnt1 * (N - cnt1) * 2LL + 2LL * cnt2 * cnt2 + 2LL * cnt2 * cnt3 + cnt3 * cnt3);
    return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long fact[20015], invfact[20015];
long long mod = 1e9 + 7;
//5^9 = (5^4)^2 * 5
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
//a^(p - 1) = 1 mod p [fermat's little theorem] so, a^(-1) = a^(p - 2) mod p
long long inverse(long long a){
    return bigmod(a, mod - 2);
}
void precalc(){
    fact[0] = 1;
    invfact[0] = inverse(fact[0]);
    for(long long i = 1; i <= 20005; i++){
        fact[i] = (fact[i - 1] * i) % mod;
        invfact[i] = inverse(fact[i]);
    }
}
//nCr = (fact[n]/(fact[r] * fact[n - r])) mod p = (fact[n] * invfact[r] * invfact[n - r]) mod p
long long nCr(long long n, long long m){
    long long ans = (fact[n] * invfact[m]) % mod;
    return (ans * invfact[n - m]) % mod;
}

int main(){
	ll m,n;
    cin>>n;
    m = bigmod(10,n) - 2*bigmod(9,n) + bigmod(8,n);
    m = (m+3*mod)%mod;
    cout<<m<<endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int dp[N][2];
vector<int> g[N];

int add(int a, int b)
{
  return (a + b) % mod;
}

int mul(int a, int b)
{
  return ((ll)a * b) % mod;
}
int solve(int node, int parent, int color)
{
  int &ans = dp[node][color];
  if(ans != -1)
    return ans;
  ans = 1;
  for(auto &x: g[node])
  {
    if(x == parent)
      continue;

    if(color == 0)
    {
      ans = mul(ans, add(solve(x, node, 0), solve(x, node, 1)));
    }
    else
    {
      ans = mul(ans, solve(x, node, 0));
    }
  }
  return ans;
}

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n - 1; i++)
  {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(dp, -1, sizeof(dp));
  cout << (solve(1, 0, 0) + solve(1, 0, 1)) % mod;
}


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

using namespace std;

vector<char> v;

int main(void) {

	
	int sx, sy, ex, ey;
	cin>>sx>>sy>>ex>>ey;

	// one
	int r = ex-sx;
	int u = ey-sy;

	for(int i = 0; i < r; ++i)
		v.push_back('R');
	for(int i = 0; i < u; ++i)
		v.push_back('U');

	for(int i = 0; i < r; ++i)
		v.push_back('L');
	for(int i = 0; i < u; ++i)
		v.push_back('D');

	v.push_back('L');
	for(int i = 0; i < u+1; ++i)
		v.push_back('U');
	for(int i = 0; i < r+1; ++i)
		v.push_back('R');
	v.push_back('D');

	v.push_back('R');
	for(int i = 0; i < u+1; ++i)
		v.push_back('D');
	for(int i = 0; i < r+1; ++i)
		v.push_back('L');
	v.push_back('U');

	for(int i = 0; i < v.size(); ++i)
		cout<<v[i];

	return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		Card[] A = new Card[n];
		for(int i=0; i<n; i++) {
			String suit = sc.next();
			int num = sc.nextInt();
			A[i] = new Card(suit, num, i);
		}
		
		quickSort(A, 0, n-1);
		
		boolean flag = true;
		for(int i=1; i<n; i++) {
			if(A[i-1].num == A[i].num && A[i-1].id > A[i].id) {
				flag = false;
				break;
			}
		}
		if(flag) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}
		
		for(int i=0; i<n; i++) {
			System.out.println(A[i].suit + " " + A[i].num);
		}
	}
	
	static void quickSort(Card[] A, int p, int r) {
		if(p < r) {
			int q = partition_num(A, p, r);
			quickSort(A, p, q-1);
			quickSort(A, q+1, r);
		}
	}
	
	static int partition_num(Card[] A, int p, int r) {
		int x = A[r].num;
		int i = p-1;
		Card temp;
		for(int j=p; j<=r-1; j++) {
			if(A[j].num <= x) {
				i++;
				temp = A[j];
				A[j] = A[i];
				A[i] = temp;
			}
		}
		temp = A[r];
		A[r] = A[i+1];
		A[i+1] = temp;
		
		return i+1;
	}
	
	static class Card {
		String suit;
		int num;
		int id;
		Card(String suit, int num, int id) {
			this.suit = suit;
			this.num = num;
			this.id = id;
		}
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 78760
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main(int argc, char *argv[])
{
	int a, b, k;
	int i;
    
	cin >> a >> b >> k;

	for (i = 0; i < k; i++) {
		if ((i % 2) == 0) {
			if (a % 2 == 1) 
				a--;
			b += a / 2;
			a -= a / 2;
		} else {
			if (b % 2 == 1)
				b--;
			a += b / 2;
			b -= b / 2;
		}
	}

	cout << a << ' ' << b << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
struct A {
	long long a,id;
}q[5]; 
int cmp(A x,A y) {
	return x.a<y.a;
}
long long n,t;
long long sum;
int main() {
	scanf("%lld%lld%lld%lld%lld",&q[1].a,&q[2].a,&q[3].a,&q[4].a,&n);
	n+=3*n;
	for(int i=1;i<=4;i++)
		q[i].id=1<<(i-1);
	q[1].a*=8,q[2].a*=4,q[3].a*=2;
	sort(q+1,q+5,cmp);
	for(int i=1;i<=4;i++) {
		q[i].a/=(8/q[i].id);
	}
	for(int i=1;i<=n;i++) {
		t=n/q[i].id;
		n-=t*q[i].id;
		sum+=t*q[i].a;
	}
	printf("%lld",sum);
}

Measured memory_bytes: 256
#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>;
using V = vector<int>;

int main(int argc, char const *argv[])
{
    int mod = 998244353;
    int n, k; cin >> n >> k;
    int l[15], r[15];
    for (int i = 0; i < k; i++) {
        cin >> l[i] >> r[i];
    }
    
    sort(l,l+k);
    sort(r,r+k);

    long long int dp[200010] = {};
    dp[1] = 1;
  	if (l[0] == 1) dp[2] = 1;
    for (int i = 3; i <= n; i++)
    {
        dp[i] = dp[i-1];
        for (int j = 0; j < k; j++)
        {
            if (i-l[j]-1 >= 0)
            {
                dp[i] += dp[i-l[j]];
                if (i-r[j]-1 >= 1) dp[i] -= dp[i-r[j]-1];
              if (dp[i] < 0) dp[i] += mod;
              dp[i] %= mod;
            }
            
        }
      //cout << dp[i] << endl;
    }
    cout << dp[n] << endl;


    

    return 0;
}


Measured memory_bytes: 5220
l=input()
n=len(l)
mod=pow(10,9)+7
import sys
sys.setrecursionlimit(10**7)
#dp1,dp2=[0]*n,[0]*n
dp1,dp2=0,1
for i in range(n):
  if l[i]=='0':
    dp1*=3
  else:
    dp1*=3
    dp1+=dp2
    dp2*=2
  dp1%=mod
  dp2%=mod
print((dp1+dp2)%mod)

Measured memory_bytes: 9216
#include <iostream>

using namespace std;

int main()
{
    string S ;
    char a , b , c , d ;
    cin >> S ;
    a = S[0] ;
    b = S[1] ;
    c = S[2] ;
    d = S[3] ;
    if((a == b && c == d && a != c) || (a == c && b == d && a != b)||(a == d && b == c && a != b))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main(void){
    // Your code here!
    ll N,M,c=0,b;
    cin>>N>>M;
    ll a[M],dp[N+1];
    rep(0,i,M){
        cin>>a[i];
    }
    b=a[0];
    dp[0]=1;
    if(b!=1)dp[1]=1;
    else{
        dp[1]=0;
        ++c;
        b=a[c];
    }
    rep(2,i,N+1){
        if(i!=b)dp[i]=(dp[i-1]+dp[i-2])%mod;
        else{
            dp[i]=0;
            ++c;
            b=a[c];
        }
    }
    cout<<dp[N]%mod<<endl;
}

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


int main(){
    int N,p,q;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    vector<int> A(N);
    rep(i,N) {
        cin >> P[i];
        A[i] = i + 1;
    }
    rep(i,N) cin >> Q[i];
    int idx = 0;
    vector<bool> flags = {false,false};
    do {
        idx++;
        if (P == A){
            p = idx;
            flags[0] = true;
        }; 
        if (Q == A){
            q = idx;
            flags[1] = true;
        }
        if (flags[0] && flags[1]) break;
    } while(next_permutation(A.begin(),A.end()));
    cout << abs(p - q) << endl;
}

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

int main() {
  int r, d, x0;
  cin >> r >> d >> x0;
  vector<int> x(11);
  x.at(0) = x0;
  rep(i, 10) {
    x.at(i + 1) = r * x.at(i) - d;
  }
  rep(i, 10) cout << x.at(i + 1) << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
  vector<ll> p(5);
  for (ll j=0; j < 5; ++j) cin >> p[j];
  ll k; cin >> k;
  bool flag = true;
  for (ll j=0; j < 4; ++j) {
    for (ll l=j+1; l < 5; ++l) {
      if (p[l] - p[j] > k) {
        flag = false;
        break;
      }
    }
  }
  cout << (flag ? "Yay!" : ":(") << endl;

  return 0;
}


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

int n,m;

class R{
public:
  string type,ad[2];
};

vector<R>vec;

class D{
public:
  string ad[2],word;
};

vector<D>res;

void input(){
  for(int i = 0 ; i < n ; i++){
    R r;
    cin >> r.type >> r.ad[0] >> r.ad[1];
    vec.push_back(r);
  }
  reverse(vec.begin(),vec.end());
}

bool check(D d){
  for(int i = 0 ; i < vec.size() ; i++){
    bool f = true;
    for(int j = 0 ; j < 2 ; j++){
      for(int k = 0 ; k < vec[i].ad[j].size() ; k++){
	if(vec[i].ad[j][k] == '?')continue;
	if(vec[i].ad[j][k] != d.ad[j][k]){f = false;break;}
      }
    }
    if(f){
      if(vec[i].type == "permit")return true;
      else return false;
    }
  }
  return false;
}

void init(){
  vec.clear();
  res.clear();
}

void solve(){
  init();
  input();
  for(int i = 0 ; i < m ; i++){
    D d;
    cin >> d.ad[0] >> d.ad[1] >> d.word;
    if(check(d))res.push_back(d);
  }
  cout << res.size() << endl;
  for(int i = 0 ; i < res.size() ; i++){
    cout << res[i].ad[0] << ' ' << res[i].ad[1] << ' ' << res[i].word << endl;
  }
}

int main(){
  while(1){
    cin >> n >> m;
    if(!n && !m)break;
    solve();
  }
  return 0;
}

Measured memory_bytes: 1456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
ll arr[105];
const ll L = 1e5 + 5;
ll dp[105][L];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll i,j,n,k;
 	cin >> n >> k;
 	for(i=0;i<n;i++)
 		cin >> arr[i];
 	dp[1][0] = 1;
 	for(i=1;i<=arr[0];i++)
 		dp[1][i] = (1 + dp[1][i-1]) % mod;
	for(i=arr[0]+1;i<k+5;i++)
		dp[1][i] = dp[1][i-1];
	for(i=2;i<n;i++)
	{
		for(j=0;j<=k;j++)
		{
			if(j == 0)
				dp[i][j] = dp[i-1][j];
			else if(j <= arr[i-1])
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
			else
				dp[i][j] = (mod + dp[i-1][j] - dp[i-1][j-arr[i-1]-1] + dp[i][j-1]) % mod;
		}
	}
	if(n == 1)
	{
		cout << dp[n][k] - dp[n][k-1] << endl;
		return 0;
	}
	if(k <= arr[n-1])
		dp[n][k] = dp[n-1][k] % mod;
	else
		dp[n][k] = (mod + dp[n-1][k] - dp[n-1][k-arr[n-1]-1]) % mod;
	cout << dp[n][k] << endl;	
	return 0;
}

Measured memory_bytes: 79360
n = int(input())
arrmon = list(map(int,input().split()))
arrhero = list(map(int,input().split()))

count = 0
i = 1
mon = arrmon[0]
hero = arrhero[0]
while i <= n:
  numin = min(mon,hero)
  count += numin
  hero -= numin
  mon = arrmon[i]
  
  numin = min(mon,hero)
  count += numin
  mon -= numin
  if i < n:
    hero = arrhero[i]
  
  i += 1
print(count)
  


Measured memory_bytes: 19116
#include <iostream>

using namespace std;

int main()
{
    int N, K;
    int a[100] = {0};
    
    cin >> N >> K;

    for (int j = 0; j < K; j++ ) { 
        int d, tmp;
        cin >> d;
        for (int k = 0; k < d; k++) {
            cin >> tmp;
            a[tmp-1]++;
        }  
    }
    int num = 0;

    for (int i = 0; i < N; i++) {
        if (a[i] == 0) {
            num++;
        }
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>

int main(){
    int a,b,c,d;
    std::cin >> a>>b >>c >>d;
    if(a+b > c+d){
        std::cout << "Left" << std::endl;
    }else if(a+b < c+d){
        std::cout << "Right" << std::endl;
    }else{
        std::cout << "Balanced" << std::endl;
    }
}



Measured memory_bytes: 3648
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

S = readline().decode('utf8').rstrip()
L = len(S)


def odd(M):
    while len(M) != L:
        if len(M) % 2 == 0:
            M += '1'
        else:
            M += '0'
    return M


def even(M):
    while len(M) != L:
        if len(M) % 2 == 0:
            M += '0'
        else:
            M += '1'
    return M


temp = ''
A = odd(temp)
B = even(temp)
na = sum(i == j for i, j in zip(S, A))
nb = sum(i == j for i, j in zip(S, B))
print(min(na, nb))


Measured memory_bytes: 3444
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char const *argv[]) {
    int N, K;
    cin >> N >> K;
    vector<int> Hs(N);
    for (int i = 0; i < N; i++) {
        cin >> Hs[i];
    }
    vector<long long int> costs(N, 0);
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            continue;
        } 
        long long int cost;
        for (int k = 1; k <= K && k <= i; k++) {
            int diff = max(Hs[i] - Hs[i - k], Hs[i - k] - Hs[i]);
            if (k == 1) {
                cost = costs[i - k] + (long long int) diff;
            } else {
                cost = min(cost, costs[i - k] + (long long int) diff);
            }
        }
        costs[i] = cost;
    }
    cout << costs[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections;
using System.Linq;
class Program
{
    static int Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int[] xs = new int[n]; //xの保存
        for (int i = 0; i < n; i++)
            xs[i] = x[i];
        Array.Sort(x);
        int left = x[(n / 2) - 1];
        int right = x[n / 2];
        for (int i = 0; i < n; i++)
        {
            if (xs[i] <= left)
                Console.WriteLine(right);
            else
                Console.WriteLine(left);
        }

        return 0;
    }
}

Measured memory_bytes: 36188
#include<stdio.h>

int main(){
  int h,w;
  while(1){
    scanf("%d %d",&h,&w);
    if ( w == 0 && h == 0 )break;
    else if ( h == 1 && w == 0)printf("#\n");
    else{
      for(int i=0;i<h;i++){
        for (int j=0;j<w;j++)
        {
          printf("#");
        }
        printf("\n");
      }
    }
    printf("\n");
  }
  

  return 0;
}


Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] l = new int[n];
		int[] d = new int[n+1];
		d[0] = 0;
		int count=0;
		if(d[0]<=x) count++;
		for (int i = 0; i <= n; i++) {
			if(i!=n)l[i] = sc.nextInt();
			if (i != 0) {
				d[i] = d[i - 1] + l[i - 1];
				if(d[i]<=x) count++;
			}
		}
		
		System.out.println(count);

	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>

//     MLE,TLE魔
//↓↓↓↓↓↓↓↓↓↓↓↓
#define int long long
//↑↑↑↑↑↑↑↑↑↑↑↑
//     MLE,TLE魔
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 5000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int a, b, q;
int s[100005], t[100005];
signed main() {
	cin >> a >> b >> q;
	rep(i, a)cin >> s[i];
	rep(i, b)cin >> t[i];
	sort(s, s + a);
	sort(t, t + b);
	rep(i, q) {
		int wh, teri, tele, shri, shle;
		cin >> wh;
		if (lower_bound(s, s + a, wh) - s != a) {
			teri = *lower_bound(s, s + a, wh);
		}
		else teri = inf;
		if (lower_bound(s, s + a, wh) - s != 0) {
			tele = s[lower_bound(s, s + a, wh) - s - 1];
		}
		else tele = -inf;
		if (lower_bound(t, t + b, wh) - t != b) {
			shri = *lower_bound(t, t + b, wh);
		}
		else shri = inf;
		if (lower_bound(t, t + b, wh) - t != 0) {
			shle = t[lower_bound(t, t + b, wh) - t - 1];
		}
		else shle = -inf;
		int ans = inf;
		if (shri != inf && teri != inf)ans = min(ans, max(shri, teri) - wh);
		if (shri != inf && tele != -inf)ans = min(ans, min(shri - wh, wh - tele) * 2 + max(shri - wh, wh - tele));
		if (shle != -inf && teri != inf)ans = min(ans, min(wh - shle, teri - wh) * 2 + max(wh - shle, teri - wh));
		if (shle != -inf && tele != -inf)ans = min(ans, wh - min(shle, tele));
		cout << ans << endl;
	}
	endre;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for(int i = 1; i <= 9; i++) {
    for(int j = 1; j <= 9; j++) {
      if(i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int N = 1e6 + 7;

void solve() {
    int k; cin >> k;
    int n = 0, lst = 7;
    loop1(i, N) {
        n = (n + lst) % k;
        lst = lst * 10 % k;
        if (n == 0) {
            cout << i; return;
        }
    }
    cout << -1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3648
import itertools
import collections
import bisect

def main():
    b = input()
    if b == 'A':
        print('T')
    elif b == 'T':
        print('A')
    elif b == 'C':
        print('G')
    elif b == 'G':
        print('C')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  long long lcm;
  map<long long, char>jud;
  string s, t;
  
  cin >> n >> m;
  cin >> s >> t;

  lcm = n * (m / __gcd(n, m));

  jud[1] = s[0];
  for(int i = 1;i <= n;i++){
    jud[i * (lcm / n) + 1] = s[i];
  }

  if(jud[1] != t[0]){
    cout << -1 << endl;
  }else{
    bool flag = true;
    for(int i = 1;i <= m && flag;i++){
      if(jud[i * (lcm / m) + 1] == 0){
	jud[i * (lcm / m) + 1] = t[i];
      }else{
	if(jud[i * (lcm / m) + 1] != t[i]){
	  flag = false;
	}
      }
    }
    
    if(flag){
      cout << lcm << endl;
    }else{
      cout << -1 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int A(int x){
    if (x == 1) return 1;
    else return  x + A(x - 1);
}
int main(){
    int N;
    cin >> N;
    cout << A(N) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int count=0;
    int N,M,h,m,k,g,i;
    int bus[24][60];

       
    for(h=0;h<=23;h++){
        for(m=0;m<=59;m++){
            bus[h][m]=0;
        }
    }
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d %d",&h,&m);
        bus[h][m]=1;
    }
    scanf("%d",&M);
    for(i=0;i<M;i++){
        scanf("%d %d",&k,&g);
        bus[k][g]=1;
    }
    for(h=0;h<=23;h++){
        for(m=0;m<=59;m++){
            if(bus[h][m]==1){
                if(count!=0)printf(" ");
                count++;
                printf("%d:%02d",h,m);
            }
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 624
#if defined(LOCAL)
#define PROBLEM_NAME "a"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ii = pair<int,int>; using lu = unsigned long long; using l = long long;
using vs = vector<string>; using vii = vector<ii>;
using vl = vector<l>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)
#define VVL(x, a, b, i) vvl x(a, vl(b, l(i)));
#define VVVL(x, a, b, c, i) vvvl x(a, vvl(b, vl(c, l(i))));

void solve(istream& cin, ostream& cout) {
  l a, b, c, k; cin >> a >> b >> c >> k;
  if (k % 2) swap(a, b);
  cout << (a - b) << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
X = [0, W]
Y = [0, H]
for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1 and X[0] < x:
    X[0] = x
  elif a == 2 and X[1] > x:
    X[1] = x
  elif a == 3 and Y[0] < y:
    Y[0] = y
  elif a == 4 and Y[1] > y:
    Y[1] = y

h = Y[1] - Y[0]
w = X[1] - X[0]
print(0 if h < 0 or w < 0 else h * w)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 5e3+5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	char c; cin>>c;
	if('a' <= c && c <= 'z') cout<<"a";
	else cout<<"A";
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  int q;
  cin>>q;
  int t[q];
  for(int i=0;i<q;i++) cin>>t[i];
  int ans=0;
  for(int i=0;i<q;i++){
    int l=0,r=n;
    while(l+1<r){
      int m=(l+r)/2;
      if(s[m]<=t[i]) l=m;
      else r=m;
    }
    if(s[l]!=t[i]) continue;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4188
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e16;

lint Q, A, B;
int main() {
	cin >> Q;
	while (Q--) {
		cin >> A >> B;
		if (A < B) swap(A, B);
		if (A == B) {
			cout << 2 * A - 2 << endl;
		}
		else if (A == B + 1) {
			cout << 2 * B - 2 << endl;
		}
		else {
			lint lb = -1, ub = 1e9 + 1;
			while (ub - lb > 1) {
				lint mid = (lb + ub) / 2;
				if (mid * mid < A * B) lb = mid;
				else ub = mid;
			}
			lint cnt = lb * 2 - 1;
			if (lb * (lb + 1) >= A * B) cnt--;
			cout << cnt << endl;
		}
	}
}


Measured memory_bytes: 3592
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			int k = n / 4;
			int sum = 0;
			for(int i = 0; i < k; ++i)
			{
				int a = stdIn.nextInt();
				sum += a;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    int A, B, C, D;
    A = N / 1000;
    N -= A * 1000;

    B = N / 100 ;
    N -= B * 100;

    C = N / 10;
    N -= C * 10;

    D = N;

    int op1, op2, op3;

    for (int i = 0; i < 8; i++) {
        op1 = i / 4;
        op2 = (i-op1*4) / 2;
        op3 = i % 2;

        if ( A + B * pow(-1, op1) + C * pow(-1, op2) + D * pow(-1, op3) == 7 ) {
            break;
        }
    }

    string a1 = "+", a2 = "+", a3 = "+";
    if (op1==1) a1 = "-";
    if (op2==1) a2 = "-";
    if (op3==1) a3 = "-";


    cout << A << a1 << B << a2 << C << a3 << D << "=7\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    //データ定義
    double circle_r;

    //半径を取得
    cin >> circle_r;

    //面積を出力
    cout << fixed << setprecision(6) << M_PI * circle_r * circle_r <<endl; 
    //円周の長さを出力
    cout << fixed << setprecision(6) << M_PI * circle_r * 2 << endl;

    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <map>
#define V map<float,int>::value_type
using namespace std;
int main()
{
  map<float,int> m[4];
  map<float,int>::iterator it;
  int i,j,k;
  float f;
  for(k=0;k<3;k++){
    for(i=0;i<8;i++){
      cin >> j >> f;
      m[k].insert( V(f,j) );
    }
  }
  for(k=0;k<3;k++){
    it = m[k].begin();
    for(i=0;i<2;i++){
      printf("%d %.2f\n",(*it).second, (*it).first);
      it++;
    }
    for(i=0;i<2;i++){
      m[3].insert(V((*it).first,(*it).second));
      it++;
    }
  }
  it = m[3].begin();
  for(i=0;i<2;i++){
    printf("%d %.2f\n",(*it).second, (*it).first);
    it++;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.*;

public class Main {

	public static void main(String[] args) {
		double x=0, y=0;
		double angle = 90;
		String[] sepa = new String[2];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			try {
				sepa = in.readLine().split(",");
			} catch (Exception e) {}
			if(sepa[0].equals("0") && sepa[1].equals("0")) break;
			x += Integer.parseInt(sepa[0]) * Math.cos(Math.toRadians(angle));
			y += Integer.parseInt(sepa[0]) * Math.sin(Math.toRadians(angle));
			angle -= Double.parseDouble(sepa[1]);
		}
		System.out.println((int)x);
		System.out.println((int)y);
	}

}

Measured memory_bytes: 16924