akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n)                    \
  for (int i = 0; i < (int)(n); i++) \
    ;

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

  char first = n.at(0);
  char last = n.at(3);
  string ans = "No";

  if (n.at(1) == first && n.at(2) == first) {
    ans = "Yes";
  }
  if (n.at(2) == last && n.at(1) == last) {
    ans = "Yes";
  }

  cout << ans << endl;
}


Measured memory_bytes: 3636
// Gaurav Aggarwal

/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0)
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/

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

typedef long long ll;
typedef pair<ll,ll> ipair;
typedef pair<long,long> lpair;
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884 
#define debug1(a) cout<<a<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug_arr(a,n) {for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}}
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define beg_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {a[i] = 0;}

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    int n;
    cin>>n;
    int a[n];
    inp_arr(a,n);

    int dp[n] = {0};
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);

    for(int i=2;i<n;++i) {
    	dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout<<dp[n-1]<<"\n";

    return 0;
}

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

int main(void){
    char c; cin >> c;
    char v[] = {'a', 'e', 'i', 'o', 'u'};
    for(int i = 0; i < 5; i++){
        if(c == v[i]){
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
--import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO
import qualified Data.Set                      as S


getVUIL :: IO (VU.Vector Int)
getVUIL = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readI :: BSC8.ByteString -> Int
readI = fst . fromJust . BSC8.readInt
readIL :: BSC8.ByteString -> [Int]
readIL = map readI . BSC8.words
getI :: IO Int
getI = readI <$> BSC8.getLine
getIL :: IO [Int]
getIL = readIL <$> BSC8.getLine

getNIS :: Int -> IO [(Int, BSC8.ByteString)]
getNIS 0 = return []
getNIS n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getNIS (n - 1))
    return ((readI aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

modNum = 10 ^ 9 + 7
newtype Mint = M Int
instance Num Mint where
    (M a) + (M b) = M $ mod (a + b) modNum
    (M a) - (M b) = M (a - b)
    (M a) * (M b) = M $ mod (a * b) modNum
    fromInteger a = M $ mod (fromInteger a) modNum
    abs (M a) = M $ abs a
    signum (M a) = M $ signum a
instance Show Mint where
    show (M a) = show (mod a modNum)

int2MInt :: Int -> Mint
int2MInt a = M (mod a modNum)

main :: IO ()
main = do
    aR <- getI
    let ret = pi * (realToFrac aR * 2)
    print ret


Measured memory_bytes: 4256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		int N = Math.max(A, B);
		int count=0;
		int kekka=0;
		
		for(int i=(Math.min(A, B));i>=1;i--) {
			if(A%i==0 && B%i==0) {
				count++;
				if(count==K) {
					kekka=i;
					break;
				}
			}
		}
		
		System.out.println(kekka);
		
		
		
		sc.close();
	}
}


Measured memory_bytes: 23124
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N: usize,
        A: usize,
        B: usize,
        S: chars,
    }
    let mut a = 0;
    let mut b = 0;

    let mut ans = Vec::with_capacity(N);
    for i in 0..N {
        match S[i] {
            'a' => {
                if a + b < A + B {
                    a += 1;
                    ans.push("Yes");
                } else {
                    ans.push("No");
                }
            }
            'b' => {
                if a + b < A + B && b < B {
                    b += 1;
                    ans.push("Yes");
                } else {
                    ans.push("No");
                }
            }
            'c' => {
                ans.push("No");
            }
            _ => unreachable!(),
        }
    }
    println!("{}", ans.join("\n"));
}


Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N;
  int p = 0, w = 0, g = 0, y = 0;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "P") {
      p = 1;
    }
    else if (S == "W") {
      w = 1;
    }
    else if (S == "G") {
      g = 1;
    }
    else if (S == "Y") {
      y = 1;
    }
  }
  if (p + w + g + y == 4) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" <<endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>


using namespace std;

int main(){
    int N;
    cin>>N;
    int ans=0;
    for(int i=1;i<=N;i++){
        if(i%2==0)continue;
        int temp=0;
        for(int j=1;j<=i;j++){
            if(i%j==0)temp++;
        }
        // cout<<i<<' '<<temp<<endl;
        if(temp==8)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

    for (int i = 2; i*i < 1000000; i++) {
        if (!a[i]) continue;
        for (int j = i*2; j < 1000000; j += i) a[j] = false;
    }

    int n;
    while (~scanf("%d", &n)) {
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
int n, m, dp[100000]={};//its impossible to optain a length of 0 so no need for a memset
vector<vector<int> >g;
int DFS( int u )
{
    if( dp[u] != 0 )
        return dp[u];
    dp[u] = 0;
    for(int i=0;i<g[u].size();++i)
        dp[u] = max( dp[u] , DFS(g[u][i]) );
    return ++dp[u];
}
int main()
{
    cin >> n >> m;
    g.resize(n);
    while( m -- )
    {
        int f, t; cin >> f >> t;
        g[f-1].push_back(t-1);
    }
    int mx = -1;
    for(int i=0;i<n;++i)
        mx = max( mx , DFS(i) );
    cout << mx - 1;//mx is for the number of nodes
    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())

int main(void) {
	int n;
	cin >> n;
	int ans;
	for(int i = 1; i <= 10; i++) {
		if(n <= i * 1000) {
			ans = i * 1000 - n;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
N = int(input())
S = input()
E = [0]*(N+1)
W = [0]*(N+1)
for i in range(N):
  W[i+1]+=W[i]
  if S[i] == "W":
    W[i+1]+=1
for i in reversed(range(N)):
  E[i]+=E[i+1]
  if S[i] == "E":
    E[i]+=1
W = W[1:]
E = E[:-1]

ans = float('inf')
for i in range(N):
  ans = min(W[i]+E[i]-1, ans)
print(ans)

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

void show(vector<ll>& vc)
{
    for(auto it:vc)cout<<it<<" ";
    cout<<endl;
}
#define M 1000009
bool p[M+2];
vector<ll>prime;
void seive(void)
{
    memset(p,0,sizeof p);
    p[1]=1;
    p[0]=1;
    for(int i=4; i<=M; i+=2)
    {
        p[i]=1;
    }

    for(ll i=3; i*i<=M; i+=2)
    {
        if(!p[i])
        {
            for(ll j=i*i; j<=M; j+=2*i)
            {
                p[j]=1;
            }
        }
    }

    prime.push_back(2);
    for(int i=3; i<=M; i+=2)prime.push_back(i);
}
ll dx[] = {-1,-1,0,-1,1,0,1,1};
ll dy[] = {-1,0,-1,1,-1,1,0,1};

typedef pair<ll, ll> pii;
#define x first
#define y second


pii extendedEuclid(ll a, ll b) { // returns x, y | ax + by = gcd(a,b)
  if(b == 0) return pii(1, 0);
  else {
    pii d = extendedEuclid(b, a % b);
    return pii(d.y, d.x - d.y * (a / b));
  }
}

ll modularInverse(ll a, ll n) {
  pii ret = extendedEuclid(a, n);
  return ((ret.x % n) + n) % n;
}





void solve(ll t)
{

       ll n;
       cin>>n;
       ll ans=0;
       for(int i=0;prime[i]*prime[i]<=n;i++)
       {

           ll c=0;
           while(n%prime[i]==0)
           {
               c++;
               n/=prime[i];
           }
           for(ll j=1;c-j>j;j++)
           {
               ans++;
               c-=j;
           }
           if(c>0)
           ans++;
           //cout<<n<<" "<<c<<endl;
       }
       if(n>1)ans++;

       cout<<ans<<endl;
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    seive();


    ll t=1;
    //cin>>t;
    ll T=t;



    while(t--)
    {


        solve(T-t);

    }
}


Measured memory_bytes: 8376
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>

using namespace std;

long long l;
double s, u;

int main () {
    cin >> l;
    u = l /double(3);
    s = double(u) * double(u) * double(u);
    cout << fixed << setprecision(12) << s << endl;
}


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

int main(){
	int n,ud=0,cur,prv,ans=1;
	cin>>n;
	cin>>prv;
	for(int i=0;i<n-1;i++){
		cin>>cur;
		if(ud==1){
			if(cur<prv){ans++;ud=0;}
		}
		else if(ud==-1){
			if(cur>prv){ans++;ud=0;}
		}
		else{
			if(cur>prv)ud=1;
			if(cur<prv)ud=-1;
		}
		prv=cur;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    }
}



Measured memory_bytes: 85212
s, t = input(), input()
ls, lt = len(s), len(t)
dp = [[0 for i in range(lt + 1)] for j in range(ls + 1)]
for i in range(ls):
    for j in range(lt):
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
ans = []
while ls > 0 or ls > 0:
    if dp[ls][lt] == dp[ls-1][lt]:
        ls -= 1
    elif dp[ls][lt] == dp[ls][lt-1]:
        lt -= 1
    else:
        ls -= 1
        lt -= 1
        ans.append(s[ls])
ans = reversed(ans)
print("".join(ans))

Measured memory_bytes: 153564
var A,B,C:Longint;
begin
read(A,B,C);
writeln(A);
writeln(B);
writeln(3*C-A-B);
writeln(4*C-2*A-B);
writeln(C);
writeln(2*A+B-2*C);
writeln(A+B-C);
writeln(2*C-B);
writeln(2*C-A);
end.

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int main(){
  char s[100];
  scanf("%s",s);
  int n=0;
  while(s[n] != NULL){
    n++;
  }
  F(i,0,n){
    if(s[i] != s[n-1-i]){
      printf("No\n");
      return 0;
    }
  }
  F(i,0,(n-1)/2){
    if(s[i] != s[(n-1)/2-1-i]){
      printf("No\n");
      return 0;
    }
  }
  F(i,(n+3)/2-1,n){
    if(s[i] != s[n-1-i]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  y /= 1000;
  rep(i, n + 1) {
    rep(j, n + 1 - i) {
      int k = n - i - j;
      int res = i * 10 + j * 5 + k;
      if (res == y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;


  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(in);
    long x,k,d;
    x = abs(sc.nextLong());
    k = sc.nextLong();
    d = sc.nextLong();
    
    long devide = x/d;
    
    if(devide >= k){ //pvOverFlow
      out.println(x - k*d);
      
    }else if((k - devide) %2 == 0){
      out.println(x % d);
      
    }else{
      out.println(d - x%d);
    }
    sc.close();
  }
}

Measured memory_bytes: 35836
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(ll i=0;i<n;i++)  cin>>h[i];
    ll dp[n];
    for(ll i=2;i<n;i++) dp[i]=1e9;
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(ll i=1;i<n;i++)
    {
        for(int j=i-1, jump=0; j>=0 && jump<k; j--, jump++)
        {
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
        }
    }cout<<dp[n-1];
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

vector<int> a;
set<int> st;
vector<bool> used;
vector<int> indeg;
vector<int> ans;

bool dfs(int ng);

bool f(int i) {
    used[i] = true;
    indeg[a[i]]--;
    bool z = dfs(a[i]);
    used[i] = false;
    indeg[a[i]]++;
    return z;
}

bool dfs(int ng) {
    if (st.empty()) return true;
    int N = st.size();
    if (ng != -1 && !used[ng] && indeg[ng] == N - 1) return false;
    auto it = st.begin();
    rep(t, N) {
        int i = *it;
        if (i != ng) {
            st.erase(i);
            if (f(i)) {
                ans.pb(i);
                return true;
            }
            st.insert(i);
        }
        it++;
    }
    return false;
}

vector<int> solve(vector<int> _a) {
    st.clear();
    a = _a;
    int N = a.size();
    used = vector<bool>(N);
    indeg = vector<int>(N);
    rep(i, N) indeg[a[i]]++;
    rep(i, N) st.insert(i);
    ans.clear();
    dfs(-1);
    reverse(all(ans));
    return ans;
}

vector<int> naive(vector<int> a) {
    int N = a.size();
    vector<int> p(N);
    rep(i, N) p[i] = i;
    do {
        bool ok = true;
        rep(i, N - 1) if (a[p[i]] == p[i + 1]) ok = false;
        if (ok) return p;
    } while (next_permutation(all(p)));
    return {};
}

struct dice {
	mt19937 mt;
	dice() {
		random_device rd;
		mt = mt19937(rd());
	}
	int operator()(int x) { return this->operator()(0, x - 1); }
	int operator()(int x, int y) {
		uniform_int_distribution<int> dist(x, y);
		return dist(mt);
	}
} dc;

int main() {
    for (int t = 0; false; t++) {
        int N = dc(2, 8);
        vector<int> a(N);
        rep(i, N) {
            for (;;) {
                a[i] = dc(N);
                if (a[i] != i) break;
            }
        }
        if (naive(a) != solve(a)) {
            cout << N << endl;
            rep(i, N) cout << a[i] << ' ';
            cout << endl;
            vector<int> p = naive(a);
            vector<int> q = solve(a);
            rep(i, N) cout << p[i] << ' ';
            cout << endl;
            rep(i, N) cout << q[i] << ' ';
            cout << endl;
            cout << "ERR" << endl;
        }
    }
    
    
    int N; cin >> N;
    a = vector<int>(N);
    rep(i, N) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> ans = solve(a);
    if (ans.empty()) {
        cout << -1 << endl;
        return 0;
    }
    for (int i: ans) cout << i + 1 << ' ';
    cout << endl;
}


Measured memory_bytes: 18560
import java.util.*;

public class Main {
	
	
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long w=sc.nextInt(),h=sc.nextInt();
		int x = sc.nextInt(),y=sc.nextInt();
		
		double ans1 = (h*w)/2.0;
		int ans2=0;
		if(x*2==w&&y*2==h) {
			ans2 = 1;
		}
		
		System.out.println(ans1+" "+ans2);
		
	}
		


}


Measured memory_bytes: 21972
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int bit[10] = {
    63,6,91,79,102,109,125,39,127,111,
};
int n;
void print(int a) {
    string ans = "";
    rep(i,7) {
        if(a&1) ans+="1";
        else ans+="0";
        a>>=1;
    }
    reverse(all(ans));
    cout<<ans<<endl;
}
void solve() {
    int a;
    int b;
    cin>>b;
    print(bit[b]);
    rep(i,n-1) {
        cin>>a;
        print(bit[a]^bit[b]);
        b=a;
    }
}
int main() {
    while(cin>>n) {
        if(n==-1) break;
        solve();
    }
    return 0;
}

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

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    int l = 1;
    //int r = -1;
    int r = 1000000000;
    for(int i=0; i<n; i++){
        cin >> a[i];
        //r = max(a[i],r);
    }

    while(l < r){
        int m = l + (r-l)/2;
        int cnt = 0;
        for(int i=0; i<n; i++){
            cnt += (a[i]-1)/m;
        }
        if(cnt > k) l = m + 1;
        else r = m;
        //cout << l << " " << r << endl;
    }
    cout << r << endl;
}

Measured memory_bytes: 3972
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] num = new int[N];
    
    int max = 0;
    for(int i = 0; i < N; i++){
      num[i] = Integer.parseInt(sc.next());
      max = max < num[i] ? num[i] : max;
    }
    
    int n = max;
    int m = 0;
    for(int i = 0; i < N; i++){
      int a = Math.abs(max/2 - num[i]);
      if(a < n && num[i] != max){
        n = a;
        m = num[i];
      }
    }
    System.out.println(max+" "+m);
  }
}

Measured memory_bytes: 46700
import sys

#import numba as nb

input = sys.stdin.readline


#@nb.njit("i8(i8)")
def solve(n):
    ans = 0
    for i in range(1, n + 1):
        m = n // i
        ans += i * m * (m + 1) // 2
    return ans


def main():
    N = int(input())

    ans = solve(N)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int x, a, b; cin >> x >> a >> b;
  cout << (b <= a ? "delicious" : b <= a + x ? "safe" : "dangerous") << '\n';
}


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

int startd(int x)
{
    while (x >= 10)
        x /= 10;
    return x;
}
int main()
{
    int n;
    cin >> n;
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= n; i++)
    {
        mp[make_pair(startd(i), i % 10)]++;
    }
    long long ans = 0;
    for (int i = 1; i <= 9; i++)
        for (int j = 1; j <= 9; j++)
        {
            ans += (long long)mp[make_pair(i, j)] * mp[make_pair(j, i)];
        }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Iterator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();
		
		String ans = "No";
		for (int i = 0; i < s.length(); i++) {
			s = s.substring(s.length() - 1, s.length()) + s.substring(0, s.length() - 1); 
			
			if (s.equals(t)) {
				ans = "Yes";
				break;
			}
		}
		
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define MAXN 710
int G[MAXN][MAXN], vis[MAXN], n, m;
std::vector<std::pair<int, int>> V;
int c1, c2;
void dfs(int x, int color) {
	(color == 1 ? c1 : c2)++;
	vis[x] = color;
	for (int y = 1; y <= n; y++)
		if (y != x && !G[x][y]) {
			if (!vis[y])
				dfs(y, 3 - color);
			else if (vis[x] == vis[y])
				puts("-1"), exit(0);
		}
}
std::bitset<MAXN> f;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d%d", &u, &v);
		G[u][v] = G[v][u] = 1;
	}
	for (int i = 1; i <= n; i++)
		if (!vis[i]) {
			c1 = c2 = 0;
			dfs(i, 1);
			V.emplace_back(c1, c2);
		}
	f.set(0);
	for (auto x : V) f = (f << x.first) | (f << x.second);
	int ans = ~(0U) >> 1;
	for (int i = 0; i <= n; i++) {
		if (f[i]) {
			int tmp = i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2;
			ans = std::min(ans, tmp);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2176
import numpy as np
N = int(input())
A = list(map(int, input().split()))
se = 1
c = True
for n in range(N):
  se *= A[n]
  if se >  10**18:
    c = False
    break
for n in range(N):
  if A[n] == 0:
    se = 0
    c = True
if c:
  print(se)
else:
  print("-1")

Measured memory_bytes: 40176
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  int si=s.size();
  int count=0;
  rep(i,si){
    if(s[i]!=t[i]){
      count++;
    }
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,gcd,ans;
    cin>>a>>b;
    gcd=__gcd(a,b);
    ans=(a*b)/gcd;
    cout<<ans;
    return 0;
}







Measured memory_bytes: 256
def main():
    _ = int(input())
    a = [int(x) for x in input().split()]

    if 0 in a:
        print(0)
        return

    ans = 1
    for aa in a:
        ans *= aa
        if ans > 10**18:
            print(-1)
            return

    print(ans)


main()

Measured memory_bytes: 21648
from random import randint
import sys
input = sys.stdin.readline


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    """
    contest_last_opened = [0]*26  # コンテストiを前回開催した日
    score = 0
    for d, t in enumerate(T, start=1):
        get_score = S[d-1][t-1]
        score += get_score
        contest_last_opened[t-1] = d
        loss_score = 0
        for i in range(26):
            ld = contest_last_opened[i]
            loss_score += C[i]*(d-ld)
        score -= loss_score
    return


def main(D, C, S):
    T = []
    for d in range(1, D+1):
        # d日目に一番満足度が高いコンテストを開催する 1-indexed
        # S[d-1]で最大のコンテストiを選ぶ
        today_score = S[d-1][0]
        today_contest = 1
        for i in range(1, 26):
            if today_score < S[d-1][i]:
                today_score = S[d-1][i]
                today_contest = i+1
        T.append(today_contest)
    return T


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = main(D, C, S)
    print(*T, sep="\n")


Measured memory_bytes: 78040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<P> p;
int main()
{
    int n, d, a;
    cin >> n >> d >> a;
    p.resize(n);

    rep(i,n)cin >> p[i].first >> p[i].second; 
 
    ll total = 0;
    ll ans = 0;
    queue<pair<ll,ll>> q;
    sort(p.begin(),p.end());

    rep(i,n){
        ll x = p[i].first;
        ll h = p[i].second;
        while(q.size() && q.front().first < x){
            total -= q.front().second;
            q.pop();

        }
        h -= total;
        if(h > 0 ){
            ll num = (h+a-1)/a;
            ans += num;
            ll damage = num * a;
            total += damage;
        
            q.emplace(x+(2*d),damage);
        }

    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, k = map(int, input().split())
    grid = [[0] * W for _ in range(H)]
    for _ in range(k):
        r, c, v = map(int, input().split())
        grid[r - 1][c - 1] = v

    # dp[i][h][w]:h行目のアイテムをi個取得した時の、座標(h,w)における価値の最大値
    dp = [[[0] * W for _ in range(H)] for _ in range(4)]
    dp[1][0][0] = grid[0][0]
    for h in range(H):
        for w in range(W):
            for i in range(4):
                # 下に移動する場合
                if h + 1 < H:
                    # アイテムを取らない
                    dp[0][h + 1][w] = max(dp[0][h + 1][w], dp[i][h][w])
                    # アイテムを取る
                    dp[1][h + 1][w] = max(dp[1][h + 1][w], dp[i][h][w] + grid[h + 1][w])
                # 右に移動する場合
                if w + 1 < W:
                    # アイテムを取らない
                    dp[i][h][w + 1] = max(dp[i][h][w + 1], dp[i][h][w])
                    # アイテムを取る（但し、4個以上所持してはいけない）
                    if i + 1 < 4:
                        dp[i + 1][h][w + 1] = max(dp[i + 1][h][w + 1], dp[i][h][w] + grid[h][w + 1])
    res = 0
    for i in range(4):
        res = max(res, dp[i][-1][-1])
    print(res)


if __name__ == '__main__':
    resolve()


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

namespace {
template <class T>
void Print(const vector<T>& xs) {
  for (auto x : xs) cout << x << ", ";
  cout << endl;
}
}  // namespace

int main() {
  int N;
  vector<int> A, B, C;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    A.push_back(-1);
    cin >> *--A.end();
  }
  for (int i = 1; i <= N; ++i) {
    B.push_back(-1);
    cin >> *--B.end();
  }
  for (int i = 1; i <= N; ++i) {
    C.push_back(-1);
    cin >> *--C.end();
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  int64_t sum = 0;
  for (int i = 0; i < N; ++i) {
    auto it_lower = lower_bound(A.begin(), A.end(), B[i]);
    int n_lower = distance(A.begin(), it_lower);
    auto it_upper = upper_bound(C.begin(), C.end(), B[i]);
    int n_upper = distance(it_upper, C.end());
    sum += (int64_t)n_lower * n_upper;
  }
  cout << sum << endl;
}


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    int M=gi();
	    Edge[] E=new Edge[M];

        for(int i=0; i<M; i++) {
        	int a=gi()-1;
        	int b=gi()-1;
        	int c=-gi();
        	E[i]=new Edge(a, b, c);
        }

        long[] k=new long[N];
        for(int i=1; i<N; i++) {
        	k[i]=Long.MAX_VALUE;
        }

        int cnt=0;
        long tmp=Long.MAX_VALUE;
        while(true) {
        	boolean isk=false;
        	for(int i=0; i<M;i++) {
        		Edge e=E[i];
        		if (k[e.gfrom()]!=Long.MAX_VALUE && k[e.gto()]>k[e.gfrom()]+e.gcost()) {
        		    k[e.gto()]=k[e.gfrom()]+e.gcost();
        		    isk=true;
        		}
        	}

        	if(!isk) {
        		break;
        	}

        	cnt++;
        	if(cnt==N) {
        		tmp=k[N-1];
        	}
        	if(cnt==2*N) {
        		if(tmp>k[N-1]) {
        			System.out.println("inf");
        			return;
        		}else {
        			break;
        		}
        	}
        }

        System.out.println(-k[N-1]);
	}

	public static class Edge {
	    private int from;
	    private int to;
	    private long cost;

	    public Edge(int f, int t, long c) {
	    	this.from=f;
	    	this.to=t;
	    	this.cost=c;
	    }

	    public int gfrom() {
	    	return from;
	    }

	    public int gto() {
	    	return to;
	    }

	    public long gcost() {
	    	return cost;
	    }

	    public void sfrom(int f) {
	    	from=f;
	    }

	    public void sto(int t) {
	    	to=t;
	    }

	    public void scost(int c) {
	    	cost=c;
	    }
	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 40380
#!/usr/bin/perl
#
use strict;
use warnings;

my $N = <>;
my @A = split(" ",<>);

my $n=1;
my @B = sort{ $a<=>$b }map{ $_-$n++ }@A;
my $mid = scalar(@B);
my $B = $B[int($mid/2)];
my $l=0;
for (my $i=1; $i<=$N; $i++){
    my $x = $A[$i-1];
    $l += abs($x-($B+$i));
}
print $l;

Measured memory_bytes: 40352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  char prev = ' ';
  ll nbA = 0, nbBC = 0, ret = 0;
  for(char c : s){
    if(c == 'A'){
      if(prev == 'B') nbBC = 0, nbA = 0;
      prev = 'A', ++nbA;
    }
    else if(c == 'B'){
      if(prev == 'B') nbA = 0, nbBC = 0;
      else if(prev == 'C'){
        if(nbBC == 0) nbA = 0;
      }
      prev = 'B';
    }
    else{
      if(prev == 'A') nbA = 0, nbBC = 0;
      else if(prev == 'B') ++nbBC, ret += nbA;
      else nbA = 0, nbBC = 0;
      prev = 'C';
    }
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
		int i;
		
		for(i=0; true; a++){
			if (b < a) break;
			if (c%a == 0){
				i = i+1;
			}
		}
		System.out.println(i);
	}

}

Measured memory_bytes: 26292
#include<iostream>
#include<cmath>
using namespace std;
typedef long long int ll;

const int MAX_N = 51;

int main(){
  ll N,X;
  cin >> N >> X;

  ll len[MAX_N];
  ll cntp[MAX_N];
  len[0] = 1;
  cntp[0] = 1;
  for(int i = 1 ; i < MAX_N ; i++){
    len[i] = len[i-1]*2 + 3;
    cntp[i] = cntp[i-1]*2 + 1;
  }
  ll sum = 0;
  while(X > 0 && N >= 0){
    //cout << "X = " << X << " N = " << N << " sum = " << sum << endl;
    if(N == 0){
      sum++;
      break;
    }
    ll c = (ll)ceil((double)len[N]/2);
    //cout << "c = " << c << endl;
    if(X >= c){
      sum += (cntp[N-1] + 1); // P
      //cout << "(cntp[N-1] + 1) = " << (cntp[N-1] + 1) << endl;
      N--;
      X -= (len[N] + 2); // P,B
      //cout << "(len[N-1] + 2) = " << (len[N-1] + 2) << endl;
    }
    else{
      N--;
      X--;
    }
    //cout << "===" << endl;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    unsigned long long int q, h, s, d;
    scanf("%lld %lld %lld %lld", &q, &h, &s, &d);
    unsigned long long int n;
    scanf("%lld", &n);
    unsigned long long int ans = 0;
    unsigned long long int min = d;
    if (2 * s < min)min = 2 * s;
    if (4 * h < min)min = 4 * h;
    if (8 * q < min)min = 8 * q;
    ans += min * (n / 2);
    n %= 2;
    min = s;
    if (2 * h < min)min = 2 * h;
    if (4 * q < min)min = 4 * q;
    ans += min * n;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin>>n;
    int a[n];
    rep(i,n){cin>>a[i];}
    int cnt=0;
    rep(i,n){
        if(i+1!=a[i]){
            cnt++;
        }
    }
    if(cnt<=2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
#define MOD (1e9+7)
typedef pair < ll, ll> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}


ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N)//素数列挙
{
	std::vector<bool> is_prime(N + 1);
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	std::vector<int> P;
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

int N;
int A[200005],sz[200005];
int main()
{
	cin >> N;
	rep(i, N-1)cin >> A[i];
	rep(i, N-1)sz[A[i]-1]++;
	rep(i, N)cout << sz[i] << endl;

}


Measured memory_bytes: 5116
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MAX=1000000007;


signed main() {
    int n;
    cin>>n;
    int a[3],t=0,a0,l=0,o=0,u[3]={};
    while(l!=3&&o<n){
        t=0;
        cin>>a0;
        
        o++;
        for(int i=0;i<l;i++){
            if(a[i]==a0){
                t=1;
                u[i]++;
        }
        }
        if(t==0){
            a[l]=a0;
            u[l]++;
            l++;
        }
        
    }
    t=0;
    for(int i=o;i<n;i++){
        cin>>a0;
        if(a[0]!=a0&&a[1]!=a0&&a[2]!=a0)t=1;
        if(a[0]==a0)u[0]++;
        if(a[1]==a0)u[1]++;
        if(a[2]==a0)u[2]++;

    }
    if(l>=3){
    if(t==1)cout<<"No";
    else{
        if((a[0]^a[1])==a[2]){
           if((u[0]==u[1])&&(u[0]==u[2])) cout<<"Yes";
           else cout<<"No";
        }
        else cout<<"No";
    }}else{
        if(l==1){
            if(a[0]==0)cout<<"Yes";
            else cout<<"No";}
        if(l==2){
            if(((u[0]==2*u[1])&&(a[1]==0))||((u[0]*2==u[1])&&(a[0]==0)))cout<<"Yes";
            else cout<<"No";
        }
    }


   


    return 0;


}


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

const int END = -1;
struct StNod
{
  int m_nKey;
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
    m_nKey(END), m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

void fnInput(vector<StNod> &rvoNod)
{
  StNod oNod;
  int nMaxSiz;

  cin >> nMaxSiz;
  rvoNod.resize(nMaxSiz, oNod);

  for (int i = 0; i < nMaxSiz; i++)
  {
    int nKey, nLeft, nRigt;
    cin >> nKey >> nLeft >> nRigt;

    rvoNod[nKey].m_nKey  = nKey;
    rvoNod[nKey].m_nLeft = nLeft;
    rvoNod[nKey].m_nRigt = nRigt;
    if (nLeft != END)  rvoNod[nLeft].m_nParnt = nKey;
    if (nRigt != END)  rvoNod[nRigt].m_nParnt = nKey;
  }
}

void fnPreOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  cout << " " << nx;
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnInOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  cout << " " << nx;
  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnPostOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
  cout << " " << nx;
}

void fnTreeWalk(const vector<StNod> &cnrvoNod)
{
  int nx = 0;
  while (cnrvoNod[nx].m_nParnt != END)
    nx = cnrvoNod[nx].m_nParnt;

  cout << "Preorder" << endl;
  fnPreOrder(cnrvoNod, nx);
  cout << endl;

  cout << "Inorder" << endl;
  fnInOrder(cnrvoNod, nx);
  cout << endl;

  cout << "Postorder" << endl;
  fnPostOrder(cnrvoNod, nx);
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StNod> voNod;

  fnInput(voNod);
  fnTreeWalk(voNod);
  return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
vector<array<int,3>> a(N);
int n,dp[N][3];

int dfs(int i,int v){
   if(i>n) return 0;
   int &ans = dp[i][v];
   if(ans != -1) return ans;
   if(v==0){
      ans = a[i][v]+max(dfs(i+1,1),dfs(i+1,2));
   }else if(v==1){
      ans = a[i][v]+max(dfs(i+1,0),dfs(i+1,2));
   }else{
      ans = a[i][v]+max(dfs(i+1,0),dfs(i+1,1));
   }
   return ans;
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   // #ifndef ONLINE_JUDGE
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   // #endif
   cin >> n;
   f(i,1,n+1){
      cin >> a[i][0] >> a[i][1] >> a[i][2];
   }
   f(i,0,n+1){
      f(j,0,3){
         dp[i][j] = -1;
      }
   }
   int ans = max({dfs(1,0),dfs(1,1),dfs(1,2)});
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=210;
int n;
int a[N];
long long ans=0ll;
int main()
{
    scanf("%d",&n);
    for(int k=1;k<=n*2;k++)
        scanf("%d",&a[k]);
    sort(a+1,a+1+n*2);
    for(int k=1;k<=n*2;k+=2)
        ans+=a[k];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3824
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#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)
const int mod = 1000000007;
const int INF = 1001001001;
const int MAX_H = 101;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  rep(i, n) cin >> x[i] >> y[i] >> h[i];
  int cx, cy, H;
  rep(i, MAX_H) {
    rep(j, MAX_H) {
      cx = i, cy = j;
      auto f = [&](int nx, int ny, int nh){
        return nh + abs(nx - cx) + abs(ny - cy);
      };
      rep(k, n) if(h[k] > 0) H = f(x[k], y[k], h[k]);
      bool ok = true;
      rep(k, n) {
        int t = max(H - abs(x[k] - cx) - abs(y[k] - cy), 0);
        if(h[k] != t) ok = false;
      }
      if(ok) {
        cout << cx <<  " " << cy << " " << H << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( stdin.hasNextLine() ) {

	    final String input = stdin.nextLine();
	    final StringBuilder sb = new StringBuilder();
	    for ( int i = 0; i < input.length(); i++ ) {
		if ( input.charAt( i ) != '@' ) {
		    sb.append( input.charAt( i ) );
		} else {
		    final int no = input.charAt( i + 1 ) - '0';
		    final char ch = input.charAt( i + 2 );
		    for ( int j = 0; j < no; j++ ) {
			sb.append( ch );
		    }
		    i += 2;
		}
	    }
	    System.out.println( sb.toString() );
	}	
    }    
}

Measured memory_bytes: 17132
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

Measured memory_bytes: 256
//#include "pch.h"
#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>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	string s;
	cin >> s;
	int n = s.size();
	stack<char>st;
	rep(i, n) {
		if (i != 0 && !st.empty()) {
			if (st.top() != s[i]) {
				st.pop();
			}
			else {
				st.push(s[i]);
			}
		}
		else {
			st.push(s[i]);
		}
	}
	cout << n-st.size() << endl;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;



int main(){
    int n;
    cin >> n;
    int a[n];
    int col[9];
    rep(i, 9) col[i] = 0;
    rep(i, n)
    {
        int tmp;
        cin >> tmp;
        if (1 <= tmp && tmp < 400){
            col[0] = 1;
        }
        else if (400 <= tmp && tmp < 800){
            col[1] = 1;
        }
        else if (800 <= tmp && tmp < 1200){
            col[2] = 1;
        }else if(1200<= tmp && tmp < 1600){
            col[3] = 1;
        }else if(1600<= tmp && tmp < 2000){
            col[4] = 1;
        }else if(2000<= tmp && tmp < 2400){
            col[5] = 1;
        }else if(2400<= tmp && tmp < 2800){
            col[6] = 1;
        }else if(2800<= tmp && tmp < 3200){
            col[7] = 1;
        }else{
            col[8]++;
        }
    }
    int cnt = 0;
    rep(i, 8)
    {
        if(col[i]==1)
            cnt++;
    }
    if(cnt == 0)
        cout << 1 << " ";
    else cout << cnt << " ";
    cnt += col[8];
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256