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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else {
    if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }

}

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


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

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}



Measured memory_bytes: 25128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

int dp[3030][3030]; //dp[i][j] = i番目までの料理をj分以内で食べる時の満足度の最大値

int main() {
    int N,T;
    cin >> N >> T;
    vector<P> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i).first >> vec.at(i).second;
    }
    sort(vec.begin(),vec.end());
    for(int i = 0;i < 3030;i++) {
        dp[0][i] = 0;
    }
    for(int i = 0;i < N;i++) {
        for(int j = 0;j <= T - 1;j++) {
            if(vec.at(i).first > j) {
                dp[i + 1][j] = dp[i][j];
            }
            else {
                dp[i + 1][j] = max(dp[i][j],dp[i][j - vec.at(i).first] + vec.at(i).second);
            }
        }
    }
    int ret = 0;
    for(int i = 0;i < N;i++) {
        ret = max(ret,dp[i][T - 1] + vec.at(i).second);
    }
    cout << ret << endl;
}

Measured memory_bytes: 35840
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>



int main() {
	long long int r, d, x; std::cin >> r >> d >> x;
	for (auto i = 0; i < 10; ++i) {
		x = r * x - d;
		std::cout << x << std::endl;
	}
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    ll N, s;
    cin >> N;
    ll num = 1;
    ll ans = 0;
    s = N;
    while (N) {
        if (N % 2 == 0) ans += num;
        num *= 2;
        N >>= 1;
    }
    cout << ans + s << endl;
    return (0);
}


Measured memory_bytes: 256
import Data.Maybe
import Text.Printf
import qualified Data.ByteString.Char8 as C

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

readInts :: IO [Int]
readInts = map parseInt . C.words <$> C.getLine

main :: IO ()
main = do
  [n, k] <- readInts
  as <- readInts
  let calc m = sum $ map (\l -> (l - 1) `div` m) as
      work l r
        | l >= r = l
        | otherwise =
            let m = (l + r) `div` 2
            in if calc m <= k
                 then work l m
                 else work (m + 1) r
  printf "%d\n" $ work 1 1000000000


Measured memory_bytes: 19448
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int K = 0;
    int S = 0;
    cin >> K >> S;
    int count = 0;
    if (S > K * 3)
    {
        cout << 0;
    }
    else
    {
        for (int x = 0; x <= S && x <= K; ++x)
        {
            for (int y = 0; y <= S - x && y <= K; ++y)
            {
                if (S - x - y <= K)
                    count++;
            }
        }
        cout << count;
    }
    return 0;
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    int N, A, B; cin >>N>>A>>B;
    string S; cin >> S;

    int qualified = 0;
    int count_b = 0;
    rep(i, N) {
        if (S[i] == 'a') {
            if (qualified < A+B) {
                cout << "Yes" << endl;
                qualified++;
            } else {
                cout << "No" << endl;
            }
        } else if (S[i] == 'b') {
            count_b++;
            if (qualified < A+B && count_b <= B) {
                cout << "Yes" << endl;
                qualified++;
            } else {
                cout << "No" << endl;
            }
                
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 848
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1LL;
  }
  if (k == 1) {
    return n;
  }

  if (k % 2 == 0) {
    ll tmp = pow_fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = pow_fast(n, (k - 1) / 2);
    tmp *= tmp;
    tmp %= MOD;
    return tmp * n % MOD;
  }
}

template<typename T>
class stack
{
private:
vector<T> _vec;
public:
  stack () {
  };

  void push(T n) {
    _vec.push_back(n);
    return;
  }

  void pop() {
    if (this->empty()) {
      return;
    }
    _vec.erase(_vec.end() - 1);
    _vec.shrink_to_fit();
    return;
  }

  size_t size() {
   return _vec.size(); 
  }

  T top() {
    return _vec[this->size() - 1];
  }
  bool empty() {
    return _vec.empty();
  }
};


int main() {
  string O;
  string E;
  cin >> O >> E;

  for (ll i = 1; i <= O.size() + E.size(); i++)
  {
    if (i % 2 == 0) {
      cout << E[i / 2 - 1];
    } else {
      cout << O[i / 2];
    }
  }
  
}

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

static const int N=101;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int M[N][N],n; 
int d[N],f[N],color[N];
int tm=0;
int nx[N];

int next(int u){
  for(int v=nx[u];v<n;v++){
    nx[u]=v+1;
    if(M[u][v]) return v;
  }
  return -1;
}

void dfs(int u){
  stack<int> S;
  for(int i=0;i<n;i++) nx[i]=0;

  S.push(u);
  color[u]=GRAY;
  d[u]=++tm;
  
  while(!S.empty()){
    int r=S.top();
    int v=next(r);
    if(v!=-1){
      if(color[v]==WHITE){
	color[v]=GRAY;
	d[v]=++tm;
	S.push(v);
      }
    }else{
      S.pop();
      color[r]=BLACK;
      f[r]=++tm;
    }
  }
}

void solve(){
  for(int i=0;i<n;i++){
    color[i]=WHITE;
    nx[i]=0;
  }
  tm=0;

  for(int i=0;i<n;i++){
    if(color[i]==WHITE) dfs(i);
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
}

int main(){
  int u,k,v;

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

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

  solve();
  
  return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Boolean result = false;
    int t = 0;
    int x = 0;
    int y = 0;

    for (int i = 0; i < n; i++) {
      t = sc.nextInt() - t;
      x = Math.abs(sc.nextInt() - x);
      y = Math.abs(sc.nextInt() - y);

      if (x + y > t || t % 2 != (x + y) % 2) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}


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

using namespace std;

#define MAX 500000
#define SENTINEL 2000000000


int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;

    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

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

int main()
{


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

    mergeSort(A, n, 0, n);

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

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



Measured memory_bytes: 7112
#include <cstdio>
#include <cstring>

int main()
{
    int n;
    scanf("%d", &n);

    char taro[100], hanako[100];
    int score_taro = 0, score_hanako = 0;

    for(int i = 0; i < n; i++){
        scanf("%s", taro);
        scanf("%s", hanako);
        if(strcmp(taro, hanako) > 0) score_taro += 3;
        else if(strcmp(taro, hanako) < 0) score_hanako += 3;
        else {
            score_taro += 1;
            score_hanako += 1;
        }
    }

    printf("%d %d\n", score_taro, score_hanako);
    return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main (){
    long long r,d,x;
    cin>>r>>d>>x;
    vector<long long>k;
    for(long long i=1;i<=d;i++){
        if(r%i==0&&d%i==0){
            k.push_back(i);
        }
        else{
            continue;
        }
    }
    reverse(k.begin(),k.end());
    cout<<k[x-1];
      return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = Reader.NextUInt;
        int last = 0;
        int cur = 0;
        int max = 0;
        for (int i = 0; i < n; i++)
        {
            var h = Reader.NextUInt;
            if (last >= h) max = Max(max, ++cur);
            else cur = 0;
            last = h;
        }
        Console.WriteLine(max);
    }
}

static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] buffer = new byte[BUF_SIZE];
    static int ptr = 0;

    private static void Read() { Stream.Read(buffer, 0, BUF_SIZE); }

    private static byte Next { get { if (ptr >= buffer.Length) { Read(); ptr = 0; } return buffer[ptr++]; } }

    public static int NextUInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; byte next; do { next = Next; } while (next < 48);
            do { res = res * 10 + (next ^ 48); next = Next; } while (48 <= next);
            return res;
        }
    }

    public static long NextULong
    {
        get
        {
            long res = 0; byte next; do { next = Next; } while (next < 48);
            do { res = res * 10 + next - 48; next = Next; } while (48 <= next);
            return res;
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int sum = 0;
    rep(i, n) sum += a[i];

    int ans = -1;
    int diff = INF;
    rep(i, n) {
        if (chmin(diff, abs(n * a[i] - sum))) ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;

int n,lr[100005],put[100005];
char c[100005];
//0-->S 1-->W
void print(){
	for(int i=1;i<=n;i++)
	if(put[i]==0)printf("S");
	else printf("W");
}

void work(int num1,int num2){
	memset(put,0,sizeof(put));
	put[1]=num1;
	put[2]=num2;
	for(int i=2;i<=n;i++){
		if((c[i]=='x'&&put[i]==1)||(c[i]=='o'&&put[i]==0))
		put[i+1]=put[i-1];
		if((c[i]=='o'&&put[i]==1)||(c[i]=='x'&&put[i]==0))
		put[i+1]=1-put[i-1];
	}
	if(((c[1]=='x'&&put[1]==1)||(c[1]=='o'&&put[1]==0))&&put[2]==put[n]&&put[n+1]==put[1]){
		print();
		exit(0);
	}
	if(((c[1]=='o'&&put[1]==1)||(c[1]=='x'&&put[1]==0))&&put[2]+put[n]==1&&put[n+1]==put[1]){
		print();
		exit(0);
	}
}

int main(void){
	scanf("%d",&n);
	scanf("%s",c+1);
	for(int i=0;i<=1;i++){
		for(int j=0;j<=1;j++){
			work(i,j);
		}
	} 
	printf("-1");
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;

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

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

int n;
ll p[101], q[101], r[101], b[101];

ll dfs(int pos){
    ll ret;
    if(r[pos] == 0){
        if(b[pos] == 0){
            ret = p[pos] + q[pos];
        }else{
            ll y = dfs(b[pos]);
            ll l = lcm(p[pos], q[pos]*y);
            ret = l/p[pos] + l/q[pos];
        }
    }else if(b[pos] == 0){
        ll x = dfs(r[pos]);
        ll l = lcm(p[pos]*x, q[pos]);
        ret = l/p[pos] + l/q[pos];
    }else{
        ll x = dfs(r[pos]), y = dfs(b[pos]);
        ll l = lcm(p[pos]*x, q[pos]*y);
        ret = l/p[pos] + l/q[pos];
    }
    return ret;
}

int main(){
    while(cin >> n, n){
        memset(p, 0, sizeof(p));
        memset(q, 0, sizeof(q));
        memset(r, 0, sizeof(r));
        memset(b, 0, sizeof(b));
        int indeg[101] = {};
        for(int i = 1; i <= n; i++){
            cin >> p[i] >> q[i] >> r[i] >> b[i];
            indeg[r[i]]++, indeg[b[i]]++;
            ll g = gcd(p[i], q[i]);
            p[i] /= g, q[i] /= g;
        }
        int root;
        for(root = 1; root <= n; root++)    if(indeg[root] == 0)    break;
        cout << dfs(root) << endl;
    }
}


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

using ll = long long;
#define f(i,a,b) for (int i = a; i < b; i++)

const ll mod = 1e9+7;

ll modpow(ll a, ll b) {
	return b?modpow(a*a%mod,b/2)*(b&1?a:1)%mod:1;
}

void add(ll &a, ll b) {
	if (b>=mod) b%=mod;
	a += b; if (a >= mod) a-=mod;
}

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

	int n;
	cin>>n;
	int a[n];
	f(i,0,n) cin >> a[i];
	ll pre[n];
	f(i,0,n) pre[i] = ((i?pre[i-1]:0)+modpow(i+1,mod-2))%mod;
	ll ans = 0;
	f(i,0,n) {
		add(ans,a[i]*pre[i]);			
		add(ans,a[i]*pre[n-1-i]);
		add(ans,mod-a[i]);
	}
	f(i,0,n) ans = (ans*(i+1))%mod;
	cout << ans << endl;
	return 0;
}
	


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

LL sum(LL x,LL y){
	return x*(y*(y+1)/2);
}

int main(){
	cin>>N;
	LL ans=0;
	REP(i,N+1){
		if(i==0)continue;
		LL x=N/i;
		ans+=sum(i,x);
		/*if(x!=0){
			cout<<i<<" "<<x<<" "<<sum(i,x)<<endl;
			cout<<ans<<endl;
		}*/
	}
	/*if(10000<N){
		ans+=(1,N);
		ans-=(1,10000);
	}*/
	cout<<ans<<endl;
}

Measured memory_bytes: 3644
n=int(input())
alis=list(map(int,input().split()))
counter=1
for i in range(n):
	if alis[i]%2==0:
		if alis[i]%3==0 or alis[i]%5==0:
			counter*=1
		else:
			counter*=0
print("APPROVED" if counter==1 else "DENIED")

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 3000 + 5;

int n;
ll arr[N];

ll memo[N][N][2];

ll solve(int i, int j, bool turn)
{
	if (i > j)
		return 0;

	ll &ret = memo[i][j][turn];

	if (~ret)
		return ret;

	if (!turn)
	{
		ret = -1e16;
		ret = max(ret, arr[i] + solve(i + 1, j, !turn));
		ret = max(ret, arr[j] + solve(i, j - 1, !turn));
	}
	else
	{
		ret = 1e16;
		ret = min(ret, -arr[i] + solve(i + 1, j, !turn));
		ret = min(ret, -arr[j] + solve(i, j - 1, !turn));
	}
	return ret;
}

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

	cin >> n;
	rep(i, 0, n)
		cin >> arr[i];

	reset(memo, -1);
	cout << solve(0, n - 1, 0) << endl;

	return 0;
}


Measured memory_bytes: 141568
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;


int main() {
	int n; string s;
	cin >> n >> s;
	if (n < 3200) { cout << "red"; }
	else { cout << s; }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);
#define OUTP(x) cout << x.first << ' ' << x.second << endl;
using namespace std;
const int N = 2005;
int mod = 1e9 + 7;

int main()
{
    ll n, a, b; cin >> n >> a >> b;
    if(a > b)swap(a, b);
    if((b - a) % 2 == 0)cout << ((b - a) / 2);
    else
    {
        ll need1 = ((b - a - 1) / 2) + a, need2 = ((n - (a + n - b + 1)) / 2) + n - b + 1;
        cout << min(min(b - 1, need1), min(need2, n - a));
    }
    return 0;
}
/*
1000 1000
1
5 5
4 7 3 2 5
3 7 4 5 2
*/


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,K;

int main(){
	cin >> N >> K;
	int x = 1;
	repp(i,0,N) x += min(x,K);
	cout << x;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
  
#define N 100005
#define U [N]={}
map<L,L> path[N];
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,a,b,c,p;
char s[5];
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
    
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
    
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
L S(L i, L x){
    x=edgecost(x)-sum(i+1)+sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
  
main(){
    for(cin>>n>>k;p<n-1;p++)
        cin>>a>>b>>c,
        path[a][b]=path[b][a]=c;
    dfs(0);
    
    for(c=p=0;p<n;p++)
        if(!p|hev[par[p]]-p)
        for(a=p;!c|a;a=hev[a])
            pos[a]=c++,
            hl_par[a]=p,
            S(pos[a],hev[a]);
    
    for(cin>>a;cin>>s>>a>>b;)
        if(*s&2){
            for(c=0;p=hl_par[a],n=hl_par[b],p-n;a=par[p])
                dep[p]<dep[n]?swap(p,n),swap(a,b),0:0,
                c+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<c+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }else
            add[a]+=b,
            S(pos[a],hev[a]),
            a?S(pos[a]-1,a):0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    string S;
    cin >> S;

    REP(i, S.length()) {
        cout << 'x';
    }
    cout << endl;
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k,r,s,p,sc=0;
    cin>>n>>k>>r>>s>>p;
    string st;
    char a[n];
    cin>>st;
    int i;
    k--;
    for(i=0;i<st.size();i++)
    {
        if(i<=k)
        {
            if(st[i]=='r') {
                    sc+=p;
                    a[i]='p';
                   // cout<<p<<endl;
            }
            if(st[i]=='s') {
                    sc+=r;
                    a[i]='r';
                  //  cout<<r<<endl;
            }
            if(st[i]=='p') {
                    sc+=s;
                    a[i]='s';
                  //  cout<<s<<endl;

            }
         }
         else{
            if(st[i]=='r')
            {
                if(a[i-k-1]!='p') {
                        sc+=p;
                        a[i]='p';
                       // cout<<p<<endl;
                }
                else {
                       // sc+=r;
                        a[i]='1';
                      //  cout<<r<<endl;
                }
            }
            if(st[i]=='s')
            {
                if(a[i-k-1]!='r') {
                        sc+=r;
                        a[i]='r';

//cout<<r<<endl;
                }
                else {
                       // sc+=s;
                        a[i]='1';
                      //  cout<<s<<endl;
                }
            }
            if(st[i]=='p')
            {
                if(a[i-k-1]!='s') {
                        sc+=s;
                        a[i]='s';
                      //  cout<<s<<endl;
                }
                else {
                       // sc+=p;
                        a[i]='1';
                       // cout<<p<<endl;
                }
            }
         }
    }
 //   for(i=0;i<n;i++) cout<<a[i];
  //  cout<<endl;
    cout<<sc<<endl;

    return 0;
}


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

int main(void)
{
	int  i;
	int  len;
	char a[25];

	scanf("%s", a);

	len = strlen(a);

	for (i = len-1; i >= 0; i--)
		putchar(a[i]);

	putchar('\n');

	return 0;
}

Measured memory_bytes: 524
#include <cstdio>

static const int N = 1000;

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

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

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

  trace(A, n);

  for (i = 1; i < n; ++i)
  {
    int k = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > k){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = k;
    trace(A, n);
  }

  return 0;
}

Measured memory_bytes: 1032
#include <cstddef>
#include <deque>
#include <iostream>

void print(const std::deque<int> &a) {
  std::cout << ">";
  for (std::size_t i = 0; i < a.size(); ++i) {
    std::cout << a.at(i);
  }
  std::cout << std::endl;
}

int main() {
  int q;
  std::cin >> q;
  std::deque<int> a;

  for (int i = 0; i < q; ++i) {
    int c;
    std::cin >> c;
    int x, d, p;
    switch (c) {
    case 0:
      std::cin >> d >> x;
      if (d == 0)
        a.push_front(x);
      else
        a.push_back(x);
      break;
    case 1:
      std::cin >> p;
      std::cout << a.at(p) << std::endl;
      break;
    case 2:
      std::cin >> d;
      if (d == 0)
        a.pop_front();
      else
        a.pop_back();
      break;
    }
  }
}



Measured memory_bytes: 4592
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        string S = NextString();
        Console.WriteLine(Math.Min(S.Count(v => v == '0'), S.Count(v => v == '1')) * 2);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 13396
#include <iostream>

using namespace std;



int main(void){
    long N;
    long A;
    long B;
    long C;
    long anskouho=0;
    long ans=100000;
    cin>>N;
    
    
    
    for(A=1;A<=N-1;A++)
    {
        B=N-A;
        C=A;
        anskouho=0;
        while (C > 0)
        {
            anskouho+=C%10;
            C=C/10;
        }
        while (B >0)
        {
            anskouho+=B%10;
            B=B/10;
        }
        if(anskouho<ans)
        {
            ans=anskouho;
            
        }
        else
        {
            
        }
        
        
    }
   
    
    
    
    cout<<ans<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <string>
#include <string.h>
using namespace std;
int main(){
    string a, b;
    cin >> a >> b;
    a = a + a ;
    if(a.find(b) != std::string::npos){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>

using namespace std;

int main() {
	int size = 4;
	int ina[size];
	int inb[size];
	while(true){
		int hit=0, blow=0;
		cin>>ina[0]>>ina[1]>>ina[2]>>ina[3];
		cin>>inb[0]>>inb[1]>>inb[2]>>inb[3];
		if(cin.eof()) break;
		for(int i=0; i<size; i++) {
			if(ina[i] == inb[i]) hit++;
			for(int j=0; j<size; j++){
				if(i==j) continue;
				if(ina[i] == inb[j]) blow++;
			}
		}
		cout<<hit<<" "<<blow<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

s=[[1,3,5,7,8,10,12],[4,6,9,11],[2]]
uf=UnionFind(13)
for i in range(len(s)):
    for j in range(len(s[i])):
        uf.union(s[i][0],s[i][j])

x,y=map(int,input().split())
if uf.same(x,y):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
from itertools import combinations

N = int(input())
l = [tuple(map(int, input().split())) for _ in range(N)]
t = {i for i in l}

if N==1 or N==2:
    print(1)
else:
    ans = N
    for i in range(N):
        for j, k in combinations([l[j] for j in range(N) if j!=i], 2):
            x1, y1 = j
            x2, y2 = k
            x, y = x1-x2, y1-y2

            b = 1
            for m in range(N):
                if i==m:continue
                x3, y3 = l[m]
                if not (x3-x, y3-y) in t:
                    b += 1
            ans = min(ans, b)
    print(ans)


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

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

//#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
string itob(int x) {
  string ret;
  while (x) {
    if (x & 1)
      ret += "1";
    else
      ret += "0";
    x >>= 1;
  }
  while (ret.size() < 26)
    ret += "0";
  reverse(all(ret));
  return ret;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  vector<int> dp(1 << 26, INF);
  int bits = 0;
  rep(i, 0, s.size()) {
    int a = s[i] - 'a';
    bits ^= 1 << a;
    dump(itob(bits));
    if(not (bits&(bits-1)))dp[bits]=1;

    rep(j, 0, 26) { chmin(dp[bits], dp[(1 << j) xor bits] + 1); }
    dump(dp[bits]);
  }
  cout << dp[bits] << endl;

  return 0;
}


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

int main(){
    int n;cin >>n;
    vector<int> v(n);
    for(auto&& w:v)cin>>w;
    int sum,mn;
    sum=accumulate(v.begin(),v.end(),0);
    mn=sum;
    for(auto&& w:v){
        if(w%10!=0)mn=min(mn,w);
    }
    cout<<((sum%10==0)?(sum-mn):sum)<<endl;
}

Measured memory_bytes: 256
# 2019-11-18 00:38:19(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n = int(sys.stdin.readline().rstrip())
    print(n ** 3)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

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

  vll lst(n);

  for (ll i = 0; i < n; i++) {
    cin >> lst[i];
  }

  ll lp = 0;
  ll rp = 0;
  ll s = lst[0];
  ll x = lst[0];
  ll streak = 1;
  ll ans = 0;
  while (lp <= n - 1) {
    if (s == x) {
      ans += streak;
      rp++;
      if (rp >= n) break;
      streak++;
      s += lst[rp];
      x ^= lst[rp];
    } else {
      s -= lst[lp];
      x ^= lst[lp];
      lp++;
      streak--;
    }
    assert(lp <= rp);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  ll N,M;
  cin >> N >> M;
  if(M%2==0){
    rep(i,M/2){
      cout << i+1 << " " << M-i+1 << endl;
      cout << M+i+2 << " " << 2*M-i+1 << endl;
    }
  }else{
    rep(i,M/2){
      cout << i+1 << " " << M-i+1 << endl;
      cout << M+i+2 << " " << 2*M-i+1 << endl;
    }
    cout << M/2+1 << " " << M/2+2 << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()
typedef long long ll;

const ll  INF  = 1LL << 50;;
const int MAXC = 21;
const int MAXN = 110;
const int MAXD = 20100;

ll dist[MAXC][MAXN][MAXN];
ll cost[MAXC][MAXN][MAXN];
ll best_cost[MAXN][MAXN];

int main(){
  ios::sync_with_stdio(false);

  int n, m, c, s, g;

  while (cin >> n >> m >> c >> s >> g && n){

    s--, g--;
    REP(i, MAXC) REP(j, MAXN) REP(k, MAXN){
      dist[i][j][k] = INF;
      cost[i][j][k] = INF;
    }

    REP(ci, c) REP(i, n){
      dist[ci][i][i] = 0;
      cost[ci][i][i] = 0;
    }
    
    REP(i, m){
      int x, y, c, d;
      cin >> x >> y >> d >> c;
      x--, y--, c--;
      dist[c][x][y] = dist[c][y][x] = min(dist[c][x][y], (ll)d);
    }
    
    REP(ci, c) REP(k, n) REP(i, n) REP(j, n){
      dist[ci][i][j] = min(dist[ci][i][j], dist[ci][i][k] + dist[ci][k][j]);
    }

    vector<int> ps(c);
    REP(ci, c) cin >> ps[ci];

    REP(ci, c){
      vector<ll> qs(ps[ci], INF);
      vector<ll> rs(ps[ci], INF);
      vector<ll> ct(MAXD, 0);
      
      REP(i, ps[ci] - 1){
        cin >> qs[i];
      }

      REP(i, ps[ci]){
        cin >> rs[i];
      }

      int pos   = 0;
      int money = 0;
      REP(i, MAXD){
        ct[i] = money;
        if (i == qs[pos]) pos++;
        money += rs[pos];
      }
      
      REP(i, n) REP(j, n) if (dist[ci][i][j] < INF){
        cost[ci][i][j] = ct[dist[ci][i][j]];
      }
    }
    
    REP(i, n) REP(j, n){
      best_cost[i][j] = INF;
      REP(k, c){
        best_cost[i][j] = min(best_cost[i][j], cost[k][i][j]);
      }
    }

    REP(k, n) REP(i, n) REP(j, n){
      best_cost[i][j] = min(best_cost[i][j], best_cost[i][k] + best_cost[k][j]);
    }

    cout << (best_cost[s][g] < INF ? best_cost[s][g] : -1) << endl;
  }
  return 0;
}

Measured memory_bytes: 5432
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[500][500];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;cin>>n;
vector<ll> s(n),sum(n+1,0);
for(int i=0;i<n;i++)cin>>s[i];
for(int i=0;i<n;i++)sum[i+1]=sum[i]+s[i];
for(int i=2;i<=n;i++){
    for(int l=0;l<=n-i;l++){
        int r=i+l;
        ll tmp=inf;
        for(int k=l+1;k<r;k++){
            tmp=min(tmp,dp[l][k]+dp[k][r]);
        }
        dp[l][r]=tmp+(sum[r]-sum[l]);
    }
}
cout<<dp[0][n]<<endl;
}


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

using ll=long long;

int main() {
  int A,B,C; cin >>A >>B >>C;
  int ans=0;
  if (A+B>=C) {
    ans=B+C;
  } else {
    ans=B+B+A+1;
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3616
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int [10];
        for (int i = 0; i < 2; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        //var input = int.Parse(Console.ReadLine());

        if (spliti[0] < spliti[1])
        {
            Console.WriteLine("a < b");
        }
        if (spliti[0] > spliti[1])
        {
            Console.WriteLine("a > b");
        }
        if (spliti[0] == spliti[1])
        {
            Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 8848
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int len1 = h1 * 60 + m1;
  int len2 = h2 * 60 + m2;
  len2 -= len1;
  len2 -= k;
  cout << len2 << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


typedef unsigned long long ll;

vector<vector<ll> > lines;
int n;
int field[9][9];

vector<ll> tmp;

const int dy[]={0,0,-1,1};
const int dx[]={1,-1,0,0};

bool ok=false;

ll fin;


void dfs(ll s,int idx){
	if(ok){
		return;
	}
	if(idx==lines.size()){
		if(fin==s)
			ok=true;
		return;
	}
	for(int i = 0; i < lines[idx].size(); i++){
		if((s&lines[idx][i])==0){
			dfs(s|lines[idx][i],idx+1);
		}
	}
}

void lineSearch(ll s,int curSum,int ret,int x,int y){
	if(curSum==ret){
		tmp.push_back(s);
	}
	for(int i= 0; i < 4; i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx>=0&&ny>=0&&nx<n&&ny<n&&field[ny][nx]>=1&&(curSum+field[ny][nx]<=ret)){
			if(!((s>>(ny*n+nx))&(1ull))){
				ll ns=s|(((1ull)<<(ny*n+nx)));
				lineSearch(ns,curSum+field[ny][nx],ret,nx,ny);
			}
		}
	}
}

int main(){


	while(cin>>n&&n!=0){
		fin=0;
		for(int i = 0; i < n*n; i++){
			fin|=(1ull<<i);
		}

		ok=false;
		lines.clear();
		vector<pair<int,pair<int,int> > > vpii;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin>>field[i][j];
				if(field[i][j]<0){
					vpii.push_back(make_pair(field[i][j],make_pair(i,j)));
				}
			}
		}
		for(int i = 0; i < vpii.size(); i++){
			tmp.clear();
			lineSearch(((1ull)<<(vpii[i].second.first*n+vpii[i].second.second)),0,-vpii[i].first,vpii[i].second.second,vpii[i].second.first);
			lines.push_back(tmp);
		}
		dfs(0ull,0);
		if(ok)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int cnt[200010] = {};
    for (int i = 0; i < N - 1; i++) {
        int A;
        cin >> A;
        cnt[A]++;
    }
    for (int i = 1; i <= N; i++) {
        cout << cnt[i] << endl;
    }
}

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

#define F first
#define S second

using namespace std;
typedef long double ld;
typedef long long ll;

const int max_n = 200011, inf = 1000111222;
const ll inff = 1000111222333444;

int n;
vector<int> v[max_n];

void p(int x, int y) {
    printf("%d %d\n", x, y);
    v[x].push_back(y);
    v[y].push_back(x);
}

void init1() {
    p(1, 2);
    p(2, 3);
    p(3, n + 1);
    p(n + 1, n + 2);
    p(n + 2, n + 3);
}

void init2() {
    p(1, 2);
    p(2, 3);
    p(3, n + 1);
    p(n + 1, n + 2);
    p(n + 1, 4);
    p(n + 1, 5);
    p(5, n + 4);
    p(5, 6);
    p(6, n + 3);
    p(n + 3, n + 5);
    p(n + 5, n + 6);
}

set<pair<int, int> > s;
void add(int x, int y) {
    assert((x ^ y) == 1);
    s.insert({x, x + n});
    s.insert({y, y});
    p(x, y);
    p(y, n + 1);
    p(n + 1, x + n);
    p(x + n, y + n);
}

bool dfs(int x, int p, int st, int xr) {
    cout << "(" << x << ", " << xr << "); ";
    if (x == st + n && xr != st) {
        return false;
    }
    if (x == st + n) return true;
    if (x != st) xr ^= (x > n) ? (x - n) : x;
    for (int to : v[x]) {
        if (to == p) continue;
        if (dfs(to, x, st, xr)) {
            return true;
        }
    }
    return false;
}

bool check() {
    for (int i = 1; i <= n; ++i) {
        cout << i << ": ";
        if (!dfs(i, -1, i, 0)) {
            return false;
        }
        cout << endl;
    }
}

int upd(int x) {
    return (x > n) ? (x - n) : x;
}

map<int, vector<pair<int, int> > > mp;
void dfs1(int x, int p, int st, int xr) {
    xr ^= upd(x);
    mp[xr].push_back({st, x});
    for (int to : v[x]) {
        if (to == p) continue;
        dfs1(to, x, st, xr);
    }
}

void get_all() {
    for (int i = 1; i <= n * 2; ++i) {
        dfs1(i, -1, i, 0);
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    int nn = n;
    while (nn % 2 == 0) nn /= 2;
    if (nn == 1) {
        cout << "No\n";
        return 0;
    }
    printf("Yes\n");
    int st;
    init1();
    st = 4;
    s.insert({3, 3});
    s.insert({2, n + 2});
    for (int i = st; i + 1 <= n; i += 2) {
        add(i, i + 1);
    }
    if (n % 2 == 0) {
        for (auto a : s) {
            int val = n ^ a.F ^ 1;
            if (s.count({val, val})) {
                p(n, a.S);
                p(val, n + n);
                break;
            }
            if (s.count({val, val + n})) {
                p(n, a.S);
                p(val + n, n + n);
                break;
            }
        }
    }
    // assert(check());
    return 0;
}


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

int main(void) {
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	string ans = "Yes";
	char c;
	for (int i = 0; i < 3; i++) {
		if (S[i] == c) {
			ans = "No";
			break;
		}
		c = S[i];
	}
	cout << ans << "\n";

	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int n;
    cin >> n;

    string s,t;
    cin >> s >> t;

    for (int i = 0; i < n; i++) {
        if (s.substr(i, n-i) == t.substr(0, n-i)) {
            cout << n+i << endl;
            return;
        }
    }
    cout << 2*n << endl;


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
n = int(input())
if n < 10:
  print(n)
elif 10 <= n and n < 100:
  print(9)
elif 100 <= n and n < 1000:
  print(9+(n-99))
elif 1000 <= n and n < 10000:
  print(909)
elif 10000 <= n and n < 100000:
  print(909+(n-9999))
else:
  print(90909)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define mpp make_pair
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 100000007
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
const int MAXN = 3e5+5;
#define MAXI 2e18+3
#define all(v) v.begin(), v.end()
#define endl "\n"
# define PI 3.14159265358979323846

const int mod=998244353;
int fac[200004];
int modInverse(int a, int m) 
{ 
    int m0 = m; 
    int y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        int q = a / m; 
        int t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
  
 
int ncr(int n,int r)
{
  if(n<r)
    return 0;
  int z=fac[n];
  z=(z*modInverse(fac[r],mod))%mod;
  z=(z*modInverse(fac[n-r],mod))%mod;
  return z;
}
 
int power[200005];

signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    power[0]=1;
	int n,m,k;
	cin>>n>>m>>k;
	fac[0]=1;
	for(int i=1;i<=200000;i++)
	{
	  power[i]=(power[i-1]*(m-1))%mod;
	  fac[i]=(fac[i-1]*i)%mod;
	}
	int ans=0;
	for(int i=0;i<=k;i++)
	{
	  ans+=(ncr(n-1,i)*((m*(power[n-1-i]))%mod))%mod;
	  ans%=mod;
	}
	cout<<ans;
}

Measured memory_bytes: 6776
#include<iostream>
using namespace std;
int main() {
	string s;
	int a,b;
	cin>>a>>b>>s;
	for (int i=0,len=s.size();i<len;++i) {
		if (i!=a&&(s[i]>'9'||s[i]<'0')) return cout<<"No"<<endl,0;
		if (i==a&&s[i]!='-') return cout<<"No"<<endl,0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256