akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        long x=fsc.nextLong();
        fsc.close();
        Out:for(long p=x;;p++){
            for(long q=2;q*q<=p;q++){
                if(p%q==0){
                    continue Out;
                }
            }
            System.out.println(p);
            return;
        }
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second

#define HII cerr<<"HI"<<endl
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl

template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}

/************************************************/
#define MN 20005
int n;
char s[MN],t[MN];
int pos[MN];int st[MN];
int res=0x3f3f3f3f;
int G1=0,G2=0;
void ck(int x){
	//cerr<<x<<endl;
	//cerr<<pos[x]<<endl;
	int R=0;
	for(int j=-n;j<=n+n;++j){
		int X=min(G1,max(0,x+j));
		int Y=min(G2,max(0,j));
		//cerr<<X<<' '<<pos[X]<<"@"<<Y<<' '<<st[Y]<<endl;
		R+=abs(pos[X]-st[Y]);
	}
	//cerr<<R<<"@"<<endl;
	res=min(R,res);
}
int main(){
	read(n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	for(int i=2;i<=n;++i)if(s[i]!=s[i-1])pos[++G1]=i-1;pos[++G1]=n;
	for(int i=2;i<=n;++i)if(t[i]!=t[i-1])st[++G2]=i-1;st[++G2]=n;
	int H=max(G1,G2);
	for(int i=-H;i<=H;++i)if(s[1]==t[1]^(i&1))ck(i);
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
	int64_t A, B, C;
	std::cin >> A >> B >> C;

	int64_t max_int = std::max(A, std::max(B, C));

	int64_t diff = max_int * 3 - (A + B + C);
	int64_t ans = diff % 2 == 0 ? diff / 2 : diff / 2 + 2;

	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    float L;
    cin>>L;
    float a=L/3.0;
    cout<<fixed << setprecision(15) <<a*a*a<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <functional>

#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::min;

using std::labs;

static long
fix(long N, long K)
{
  long k2 = K + K;
  if (K < k2 && k2 <= N)
  {
    N = fix(N, k2);
  }
  return N < K ? N : N - K;
}

int
main()
{
  long N, K;
  cin >> N >> K;
  if (K < N)
  {
    N = fix(N, K);
  }
  long a = labs(K - N);
  long b = labs(K - a);
  cout << min(a, b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int K,X;
	scanf("%d %d",&K,&X);

	if(500*K >= X){

		printf("Yes\n");

	}else{

		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b;
    scanf("%d%d", &a, &b);

    int ans = 0;
    for (int i = a; i <= b; i++){
        int num1 = i / 10000;
        int num2 = (i - num1 * 10000) / 1000;
        int num3 = (i - num1 * 10000 - num2 * 1000) / 100;
        int num4 = (i - num1 * 10000 - num2 * 1000 - num3 * 100) / 10;
        int num5 = i - num1 * 10000 - num2 * 1000 - num3 * 100 - num4 * 10;
        if (num1 == num5 && num2 == num4){
            ans += 1;
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define N 200000
#define INFINITY 2000000000

int main(){
  int R[N];
  int n,max,min,i,j;

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

  max=-INFINITY;
  min=R[0];

  for(j=1;j<n;j++){
    if(max>R[j]-min) max=max;//最大値の更新
    else max=R[j]-min;

    if(min<R[j]) min=min;//jまでの最小値を保持する
    else min=R[j];
  }

  printf("%d\n",max);

  return 0;
}


Measured memory_bytes: 2552
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var N = RInt;
            var p = RSInt;
            var ans = 0;
            for (int i = 0; i < N; i++)
            {
                if (p[i] == i + 1)
                {
                    ans++;
                    if (i != N - 1 && p[i + 1] == i + 2)
                    {
                        i++;
                    }
                }
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 36124
N, M = map(int, input().split())
shops = [[int(i) for i in input().split()] for _ in range(N)]
shops.sort(key=lambda x: x[0])

money = 0
need = M
for shop in shops:
    if shop[1] >= need:
        print(money + need * shop[0])
        exit(0)
    need -= shop[1]
    money += shop[0] * shop[1]


Measured memory_bytes: 64572
/* Preprocess */
#include <bits/stdc++.h>

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()


/* Field */
using namespace std;


/* Function */

int main (void) 
{

  int N; // 繰り返す回数
  int K; // 操作B

  int i;
  int board;

  cin >> N;
  cin >> K;

  i = 0;
  board = 1;

  while(i < N)
  {

    if(board < K)
    {
      board = board *2;
      // board *= 2;
    }
    else
    {
      board = board +K;
      // board += K;
    }
    

    i++;

  }

  cout << board << endl;



  return 0;

}



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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int X, Y, Z;
  X = 0;
  Y = 0;
  Z = 0;
  for (int i = 0; i < N; i++) {
    int P;
    cin >> P;
    if (P <= A) X++;
    else if (P <= B) Y++;
    else Z++;
  }
  cout << min(min(X, Y), Z) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=100000 +10, M=(ll)1e9+1 ;
 const int mod =998244353 ,sz=5 ;

void work(){
 ll s;
 cin >> s;
 if(s<=(ll)1e9)
        cout << "0 2 0 1 " << s << " " << 5;
 else if(s==(ll)1e18){
    cout << (ll)1e9 << " " << 0 << " " << 0 << " " << (ll)1e9 << " " << 0 << " " << 0;
 }
 else{
    ll y2=s/(ll)1e9,x1=(ll)1e9;
    ll r=s%(ll)1e9,y1=y2+1;
    cout << x1 << " " << y1 << " 0 " << y2 << " " << r << " 0";
 }


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

}


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

int main() {
    int n;
    cin >> n;
    array<int, 32> v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << v[n-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  int r=0;
  for(int i=a;i<=b;i++){
    int s=i%10,t=i/10000%10;
    int u=i/10%10,v=i/1000%10;
    if(s==t&&u==v)r++;
  }
  printf("%d\n",r);
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_map>
#include <math.h>
#include <cctype>
using namespace std;
#define _USE_MATH_DEFINES

int a[200000];
int main() {
	int N;
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	long long min_val = 1e15;
	long long max_diff = -1e15;
	for (int i = 0; i < N; i++) {

		if (a[i] - min_val > max_diff) {
			max_diff = a[i] - min_val;
		}
		if (a[i] < min_val) {
			min_val = a[i];
		}
	}
	cout << max_diff << endl;
}

Measured memory_bytes: 1936
// 線形探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>

using namespace std;

const int MAX_N = 10000;
//const int MAX_Q = 500;

bool linearSearch(int A[], int n, int key);

int main(void)
{

    int n, q, key, count = 0;
    int ary_N[MAX_N];

    scanf("%d", &n);

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

    scanf("%d", &q);

    for(int i = 0; i < q; i++)
    {
        scanf("%d", &key);

        if( linearSearch(&ary_N[0], n, key) == true )
        {
            count++;
        }
    }

    printf("%d\n", count);

    return 0;
}

// 線形探索
bool linearSearch(int A[], int n, int key)
{
    int i = 0;
    // 終了条件の番兵の代入
    A[n] = key;

    while( A[i] != key )
    {
        i++;
    }

    return i != n;
}



Measured memory_bytes: 3216
#include <iostream>
int main(){
	int a[10],i,j,n;
	for(i=0;i<10;++i){
		std::cin>>a[i];
		}
   		for(i=0;i<9;++i){
      		for(j=i+1;j<10;++j){
      			if(a[i]<a[j]){
      				n=a[i];
       				a[i]=a[j];
      				a[j]=n;
       			} 
       		}
       }
       for(i=0;i<3;++i){
       std::cout<<a[i]<<std::endl;
       			}
		
		return 0;
}

Measured memory_bytes: 1160
//! Oos Karim Rokhsat
#include<bits/stdc++.h>
using namespace std;

typedef double                      ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 1e3 + 10;
const ll MXM = 50 + 10;
const ll MX5 = 2e5 + 10;
const ll MX6 = 1e6 + 10;
const ll LOG = 20;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

ll n, A[MX5];
ll p = 1, ans = 0;
bool check(ll x){

    for(int i = 0; i < n; i ++){
        if(A[i] == p){
            p ++;
        }
        else{
            ans ++;
        }
    }
    if(p >= x) return 1;
    return 0;
}

int main(){
    fast_io
    //file_io
    cin >> n;
    for(int i = 0; i < n; i ++) cin >> A[i];

    check(1000);

    cout << (ans == n ? -1 : ans);


    return 0;
}

//! N.N


Measured memory_bytes: 1792
use std::io::*;
use std::str::*;
#[allow(unused_imports)]
use std::collections::*;

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!{
        a : usize,
        b : usize,
        c : usize,
    }
    let m = std::cmp::max(std::cmp::max(a, b), c);
    if a == m {
        println!("{}", m * 10 + b + c);
    } else if b == m {
        println!("{}", m * 10 + c + a);
    } else {
        println!("{}", m * 10 + a + b);
    }
}


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

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

Measured memory_bytes: 256
n = int(input())
aa = list(map(int,input().split()))
x,y,z = [0]*(n+1),[0]*(n+1),[0]*(n+1)
tmp = [0]*n
for i,a in enumerate(aa):
  tmp[a]+=1
  if tmp[a]==1:
    x[i+1] = x[i]+1
    y[i+1] = y[i]
    z[i+1] = z[i]
  elif tmp[a]==2:
    x[i+1] = x[i]
    y[i+1] = y[i]+1
    z[i+1] = z[i]
  else:
    x[i+1] = x[i]
    y[i+1] = y[i]
    z[i+1] = z[i]+1
ans=1
for a,b,c,d in zip(x[:n],y[:n],z[:n],aa):
  ans = ans*[a,b,c].count(d)
print(ans%(10**9+7))

Measured memory_bytes: 17676
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

map<P,ll> m;
vector<ll> v[111111];
ll M=0;

void dfs(int x,int p) {
  set<ll> s;
  rep(i,v[x].size()) {
    int y=v[x][i];
    if(y==p) s.in(m[P(x,y)]);
  }
  ll k=1;
  rep(i,v[x].size()) {
    int y=v[x][i];
    while(s.count(k)) k++;
    if(y==p) continue;
    m[P(x,y)]=m[P(y,x)]=k;
    dfs(y,x);
    s.in(k);
    M=max(M,k);
  }
}

void Main() {
  ll n;
  R n;
  P a[n-1];
  rep(i,n-1) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
    a[i]=P(x,y);
  }
  dfs(0,-1);
  pr(M);
  rep(i,n-1) pr(m[a[i]]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 27520
#include<stdio.h>
int dp[100005];
int arr[100005];
int absv(int a,int b)
{
  if(a>b)
    return a-b;
  return b-a;
}
int dps(int i,int n)
{
  if(dp[i]!=-1)
    return dp[i];
  if(i==n)
    return 0;
  if(i==n-1)
  {
    dp[i] = absv(arr[i],arr[i+1]);
    return dp[i];
  }
  int temp1 = dps(i+1,n) + absv(arr[i],arr[i+1]);
  int temp2 = dps(i+2,n) + absv(arr[i],arr[i+2]);
  if(temp1>temp2)
    dp[i]=temp2;
  else
    dp[i]=temp1;
  return dp[i];
}
int main()
{
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    dp[i]=-1;
    scanf("%d",&arr[i]);
  }
  printf("%d\n",dps(0,n-1));
  return 0;
}


Measured memory_bytes: 5632
from decimal import *
a, b, x = map(int, input().split())
ax = int(Decimal(a) / Decimal(x))
bx = int(Decimal(b) / Decimal(x))
am = a % x
bm = b % x
if ax == bx and am != 0 and bm != 0:
  print(0)
elif am == 0:
  print(bx - ax + 1)
else:
  print(bx - ax)

Measured memory_bytes: 9988
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void a_ringring(void) {
	int a, b, c;
	cin >> a >> b >> c;

	int sum = a + b + c;
	int max_val = max(a, b);
	max_val = max(max_val, c);
	sum -= max_val;

	cout << sum << endl;
}

int main()
{
    a_ringring();
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-7;
const int N=100000+10,maxn=60000+10,inf=0x3f3f3f3f;

map<ll,ll>m;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        ll a;
        cin>>a;
        m[a]++;
    }
    int k,f=0;
    cin>>k;
    for(int i=0;i<k;i++)
    {
        ll a;
        cin>>a;
        if(m[a]<=0)f=1;
        else m[a]--;
    }
    if(f)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}
/********************

********************/


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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

int main()
{
	int n, total = 0;
	cin >> n;
	vector<int> in(n);
	for(int &i: in) {
		cin >> i;
		total += i;
	}
	int m;
	cin >> m;
	while(m--) {
		int p, x;
		cin >> p >> x;
		cout << total - in[p-1] + x << '\n';
	}
}


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

using namespace std;
#define BUF (1000)
#define ll long long 

int n;

//最大公約数   ユークリッド互除法
long long gcd(long long a, long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}

//最小公倍数
long long lcm(long long a,long long b){
    long long g = gcd(a,b);
    return a/g*b;
}

int main(void){
	long long  ans ;
	cin >> n;
	for (int i=1;i<=n;i++){
		long long  temp ;
		cin >> temp;
		if(i==1){
			ans = temp;
			continue;
		}
		ans = gcd(temp ,ans);
	}
	
	cout << ans << endl;

	return 0;
}


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

int main(int argc, char const* argv[])
{
	int n, m;
	int a[100][100] = {{}}, b[100] = {};
	int answer[100] = {};

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

	for (int i=0; i<m; i++) {
		cin >> b[i];
	}


	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			answer[i] += a[i][j] * b[j];
		}
	}

	for (int i=0; i<n; i++) {
		cout << answer[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 1208
#pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;

ll binpow(ll a, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) {
			(res *= a) %= mod;
		}
		p >>= 1;
		(a *= a) %= mod;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ld a, b;
	cin >> a >> b;
	cout << ll(floor(a * b + 1e-18)) << endl;
	return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e18;

using namespace std;


/*==================================================*/

/*==================================================*/

int A, B, C, D, E, F;
int slt[6010];

double rate;
int ansslt;
int answtr;

void func(int na, int nb){
  for(int wa = na; wa*100 <= F; wa += A){
    for(int wb = nb; wb*100 <= F; wb += B){
      for(int sc = 0; sc <= F; sc += C){
        for(int sd = 0; sd <= F; sd += D){

          if(wa*100+wb*100+sc+sd > F) continue;
          if(sc+sd > (wa+wb)*E) continue;

          //if( ansslt*(wa*100+wb*100) <= answtr*(sc+sd)){
          if( ansslt*(wa*100+wb*100+sc+sd) <= (answtr+ansslt)*(sc+sd)){
            ansslt = sc+sd;
            answtr = wa*100+wb*100;
          }

          // if(rate < (double)(sc+sd)/(double)(sc+sd+wa*100+wb*100)){
          //   rate = (double)(sc+sd)/(double)(sc+sd+wa*100+wb*100);
          //   ansslt = sc+sd;
          //   answtr = wa*100+wb*100;
          // }
        }

      }
    }
  }
}

int main(){

  cin>>A>>B>>C>>D>>E>>F;

  // func(A,0);
  // func(0,B);
  func(0,0);
  cout<<ansslt+answtr<<" "<<ansslt<<endl;


  return 0;
}


Measured memory_bytes: 256
// OBïÄh2011 Day4 C : @­³â©¿áñ

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int main(){
	int N, M, L;
	int K[2000], S[100000];
	long long sum[100001];
	while(cin >> N >> M >> L){
		for(int i=0;i<N;i++) scanf("%d", &K[i]);
		for(int i=0;i<M;i++) scanf("%d", &S[i]);
		sort(K, K+N);
		sum[0] = 0;
		for(int i=1;i<=M;i++) sum[i] = sum[i-1]+S[i-1];
		static long long dp[2000][2000];
		memset(dp, -1, sizeof(dp));
		dp[0][1] = (sum[K[1]]-sum[K[0]-1])/L;
		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N-1;j++){
				// K[i], K[j+1] ÌÀÑðìéê
				if(dp[j][j+1]==-1) dp[j][j+1] = dp[i][j]+(sum[K[j+1]]-sum[K[i]-1])/L;
				else               dp[j][j+1] = min(dp[j][j+1], dp[i][j]+(sum[K[j+1]]-sum[K[i]-1])/L);
				// K[j], K[j+1] ÌÀÑðìéê
				if(dp[i][j+1]==-1) dp[i][j+1] = dp[i][j]+(sum[K[j+1]]-sum[K[j]-1])/L;
				else               dp[i][j+1] = min(dp[i][j+1], dp[i][j]+(sum[K[j+1]]-sum[K[j]-1])/L);
			}
		}
		long long res = 1000000000000000LL;
		for(int i=0;i<N-1;i++){
			res = min(res, dp[i][N-1]+(sum[K[N-1]]-sum[K[i]-1])/L);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 32000
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    if v[0] != 0 {
        println!("0");
        return;
    }
    let d: usize = 998244353;
    let mut ls: Vec<usize> = vec![0; n];
    for &x in &v {
        ls[x] += 1;
    }
    if ls[0] != 1 {
        println!("0");
        return;
    }
    let mut ans = 1;
    for i in 2..n {
        ans = ans * pow_m(ls[i - 1], ls[i], d) % d;
    }
    println!("{}", ans);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}


Measured memory_bytes: 6396
# -*- coding: utf-8 -*-

def check(A,i,j):
    tmp = []
    for k in range(i,j):
        tmp.append(A[k])

    print(tmp)

N = int(input())
A = list(map(int, input().split()))

cnt = i = 0
while True:
    flag = 0
    for j in range(i+1,N):
        if flag == 0:
            if A[i] < A[j]:
                flag = 1
            elif A[i] > A[j]:
                flag = -1
        else:
            if flag == 1:
                if A[j-1] > A[j]:
                    #check(A,i,j)
                    i = j
                    cnt += 1
                    break
            elif flag == -1:
                if A[j-1] < A[j]:
                    #check(A,i,j)
                    i = j
                    cnt += 1
                    break
    else:
        cnt += 1
        break

    if i>=N:
        break

print(cnt)
    

Measured memory_bytes: 20416
X = list(map(int,input().split()))
cou5 = 0
cou7 = 0
for i in X:
    if i ==5:
        cou5 +=1
    if i ==7:
        cou7 +=1

if cou5 == 2 and cou7 ==1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const long double PI = (acos(-1));
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int n;
  cin >> n;
 
  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++){
    cin >> x.at(i) >> y.at(i);
  }
 
  double d = 0.0;
  for (int i = 0; i < n - 1; i++){
    for (int j = i + 1; j < n; j++){
      d += sqrt(pow(x.at(i) - x.at(j), 2) + pow(y.at(i) - y.at(j), 2));
    }
  }
 
  cout << fixed << setprecision(10) << 2.0 * d / n << endl;
 
  return 0;
}

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

int Max, N, d[252];
bool graph[252][252], rgraph[252];


main()
{

  while(cin >> Max, Max) {
    fill_n(d, 252, 0);
    fill_n(*graph, 252 * 252, false);

    cin >> N;
    for(int i = 1; i <= N; i++) {
      cin >> d[i];
    }
    for(int i = 0; i <= N; i++) {
      for(int j = 1; j <= Max; j++) {
        int next = max(0, min(N + 1, i + j + d[min(N + 1, i + j)]));
        graph[i][next] = true;
      }
    }
    for(int i = 0; i <= N + 1; i++) {
      for(int j = 0; j <= N + 1; j++) {
        for(int k = 0; k <= N + 1; k++) {
          graph[j][k] |= graph[j][i] & graph[i][k];
        }
      }
    }
    bool flag = true;
    for(int i = 0; i < N + 1; i++) {
      if(graph[0][i] && !graph[i][N + 1]) flag = false;
    } 
    if(flag) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<string.h>
int main(){
    char w[11],t[1001];
    int count=0;
    scanf("%s",&w);
    do{
        scanf("%s",&t);
        if (strcmp(t,"END_OF_TEXT")){
            for(int i=0;i<strlen(t);i++){
                if (t[i]>='A'&&t[i]<='Z'){
                    t[i]=t[i]+32;
                }
            }
        }
        if (strcmp(w,t)==0){
            count=count+1;
        }
    }while(strcmp(t,"END_OF_TEXT")!=0);
    printf("%d\n",count);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

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

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	string s;
	cin >> s;
	x=0;
	for(i=0;i<sz(s);i++)
	{
		x+=(s[i]-'0');
		x%=9;
	}
	if(x)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
}

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

using namespace std;

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); }

int main(){

   ios::sync_with_stdio(0);
   cin.tie(0);

   // freopen ("input.txt", "r", stdin);

   //vector<int> summer;
   long long int n,k,x;
   long long int total = 0;

   cin >> n >> k;

   for(int i=0; i<k; i++){
       cin >> x;
       total += x;
   }

   if(total>n) cout << "-1" << endl;
   else cout << n-total << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;


int main() {
    int n, u, v; cin >> n >> u >> v;
    vector<vector<int>> g(n+1);
    rep(i, n-1){
        int a, b; cin >> a >> b;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }

    vector<int> distU(n+1, -1);
    vector<int> distV(n+1, -1);
    queue<int> qu, qv;
    qu.push(u);
    qv.push(v);
    
    distU.at(u) = 0;
    distV.at(v) = 0;

    while(!qu.empty()){
        int t = qu.front();
        qu.pop();

        for(auto a:g.at(t)){
            if(distU.at(a)!=-1) continue;
            distU.at(a) = distU.at(t) + 1;
            qu.push(a);
        }
    }

    while(!qv.empty()){
        int t = qv.front();
        qv.pop();

        for(auto a:g.at(t)){
            if(distV.at(a)!=-1) continue;
            distV.at(a) = distV.at(t) + 1;
            qv.push(a);
        }
    }

    int fart = v;
    ll dist = 0;
    for(int i=1; i<=n; i++){
        if(distU.at(i)<distV.at(i)){
            if(dist<distV.at(i)){
                dist = distV.at(i);
                fart = i;
            }
        }
    }

    dump(fart);
    if(fart==v){
        cout << 0 << endl;
    }
    else{
        cout << distV.at(fart) - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 6656
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int K = 1000, K2 = K * 2, K4 = K2 * 2;

int bb[K4][K4], ww[K4][K4];

int main() {
	int n, k; cin >> n >> k;
	int k2 = k * 2;
	int k4 = k2 * 2;
	while (n--) {
		int i, j; cin >> i >> j, i %= k2, j %= k2;
		string s; cin >> s;
		char c = s[0];
		if (c == 'B') {
			bb[i][j]++;
			bb[k2 + i][j]++;
			bb[i][k2 + j]++;
			bb[k2 + i][k2 + j]++;
		} else {
			ww[i][j]++;
			ww[k2 + i][j]++;
			ww[i][k2 + j]++;
			ww[k2 + i][k2 + j]++;
		}
	}
	for (int i = 0; i < k4; i++)
		for (int j = 1; j < k4; j++) {
			bb[i][j] += bb[i][j - 1];
			ww[i][j] += ww[i][j - 1];
		}
	for (int i = 1; i < k4; i++)
		for (int j = 0; j < k4; j++) {
			bb[i][j] += bb[i - 1][j];
			ww[i][j] += ww[i - 1][j];
		}
	int ans = 0;
	for (int i_ = 0; i_ < k2; i_++)
		for (int j_ = 0; j_ < k2; j_++) {
			int i, j, cnt = 0;
			i = i_, j = j_;
			cnt += bb[i + k][j + k] - bb[i][j + k] - bb[i + k][j] + bb[i][j];
			i = i_ + k, j = j_ + k;
			cnt += bb[i + k][j + k] - bb[i][j + k] - bb[i + k][j] + bb[i][j];
			i = i_ + k, j = j_;
			cnt += ww[i + k][j + k] - ww[i][j + k] - ww[i + k][j] + ww[i][j];
			i = i_, j = j_ + k;
			cnt += ww[i + k][j + k] - ww[i][j + k] - ww[i + k][j] + ww[i][j];
			ans = max(ans, cnt);
		}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 128600
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

int dsu[100010],tam[100010];

int getF( int u ){
    if( dsu[u] == u ) return u;
    return dsu[u] = getF( dsu[u] );
}

bool join( int u , int v ){
    int Fu = getF( u ) , Fv = getF( v );
    if( Fu == Fv ) return false;
    dsu[ Fu ] = Fv;
    tam[ Fv ]+=tam[ Fu ];
    return true;
}

int n,m,k,a,b,ans[100010],degree[100010];

int main()
{

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

    cin >> n >> m >> k;
    for(int i=1; i<=n; i++) dsu[i] = i , tam[i] = 1;

    for(int i=0; i<m; i++){
        cin >> a >> b;
        join( a , b );
        degree[a]++;
        degree[b]++;
    }

    for(int i=1; i<=n; i++) ans[i] = tam[ getF( i ) ];

    for(int i=0; i<k; i++){
        cin >> a >> b;
        if( getF( a ) == getF( b ) ) ans[a]-- , ans[b]--;
    }

    for(int i=1; i<=n; i++) cout << ans[i]-degree[i]-1 << " ";

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int mn = 1000000001;
  int ans = 0;
  rep(i , n-1){
    if(mn > abs((a[n - 1] - a[i]) - (a[n-1] / 2))){
      mn = abs((a[n - 1] - a[i]) - (a[n - 1] / 2));
      ans = a[i];
    }
  }
  cout << a[n-1] << " " << ans << endl;
}

Measured memory_bytes: 3752
n = int(input())
pl = [int(x) for x in input().split()]

def is_asc(l, o):
    for o1, o2 in zip(o, o[1:]):
        if l[o1] > l[o2]:
            return False
    return True

if is_asc(pl, range(n)):
    print('YES')
else:
    can_asc = False
    for i in range(n):
        for j in range(i+1, n):
            o = list(range(n))
            o[i] = j
            o[j] = i
            if is_asc(pl, o):
                can_asc = True
                break
    if can_asc:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 3064
// Problem : C - XYZ Triplets
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include<set>
#define lli long long int
using namespace std;
int main()
{
	lli i,j,k,n,a;
	map<lli,lli>m;
	for(i=1;i<100;i++){
		for(j=1;j<100;j++){
			for(k=1;k<100;k++){
				a=i*i+j*j+k*k+i*j+i*k+j*k;
				m[a]++;
			}
		}
	}
	cin>>n;
	for(i=1;i<=n;i++){
		cout<<m[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5924
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,m,l,k,a,h;
int d[100][100];
bool f[100];

int main()
{
	while(scanf("%d%d%d%d%d%d",&n,&m,&l,&k,&a,&h),n){
		int s,t,c,ans;
		rep(i,n)f[i]=0;
		rep(i,n)rep(j,n)d[i][j]=inf;
		rep(i,l)scanf("%d",&s),f[s]=1; f[a]=f[h]=1;
		rep(i,k)scanf("%d%d%d",&s,&t,&c),d[s][t]=d[t][s]=c;
		rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		rep(i,n)rep(j,n)if(!f[i]||!f[j]||d[i][j]>m)d[i][j]=inf;
		rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		ans=d[a][h]; if(ans>m)ans+=ans-m;
		if(ans>inf)puts("Help!"); else printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 920
#include <bits/stdc++.h>
#define repeat(i, n) for(int (i) = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	ll N, A, B;
	cin >> N >> A >> B;

	ll a = N / (A+B);
	ll b = N % (A+B);
	
	ll result = 0;
	result += a*A;

	if ( b <= A) {
		result += b;
	} else {
		result += A;
	}

	if (A == 0) result = 0;

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
ans=[]
while True:
    try:
        year,month,day=map(int,raw_input().split())
    except EOFError:
        break
    except ValueError:
        break
    wareki=''
    if (year < 1868) or (year == 1868 and month < 9) or (year == 1868 and month == 9 and day <= 7):
        ans.append('pre-meiji')
        continue
    elif (year < 1912) or (year == 1912 and month < 7) or (year == 1912 and month == 7 and day <= 29):
        wareki+='meiji '+str(year-1867)
    elif (year < 1926) or (year == 1926 and month < 12) or (year == 1926 and month == 12 and day <= 24):
        wareki+='taisho '+str(year-1911)
    elif (year < 1989) or (year == 1989 and month < 1) or (year == 1989 and month == 1 and day <= 7):
        wareki+='showa '+str(year-1925)
    else:
        wareki+='heisei '+str(year-1988)
    ans.append(wareki+' '+str(month)+' '+str(day))
for i in ans:
    print i

Measured memory_bytes: 4280
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)

int func(int X, int Y)
{
	int temp = X%Y;
	if (temp == 0)return Y;
	else func(Y, temp);
}

int main()
{
	int t1, t2,x,y;
	cin >> t1 >> t2;
	x = max(t1, t2);
	y = min(t1, t2);
	cout << func(x, y) << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <limits.h>
#include <cmath>
#include <cstring>
#include <queue>
#include <stdlib.h>

using namespace std;

#define mod (1000000007)
typedef long long  ll;
typedef vector<int> vi;


ll exp(ll a, ll n) {
  if (n==0) return 1;
  if (n == 1) return a;
  if (n%2) {
    ll s = exp(a,n-1);
    return s * a;
  } else {
    ll s = exp(a,n/2);
    return s*s;
  }
}

long max(long a, long b) {
  if (a < b) return b;
  return a;
}

int min(int a, int b, int c) {
  return min(min(a,b), min(b,c));
}


void solve() {
  int n;
  cin >> n;
  vi arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  
  vi dp(n);
  
  dp[0] = 0;
  if (n > 1) dp[1] = abs(-arr[1]+arr[0]);
  
  for (int i = 2; i < n; i++) {
    dp[i] = min(dp[i-1] + abs(arr[i-1]-arr[i]), dp[i-2] + abs(arr[i-2]-arr[i]));
  }
  cout <<  dp[n-1] << "\n";
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 3956
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int antennas[5];
  int k;
  int i;
  int j;
  for(i=0;i<5;i++){
    scanf("%d",&antennas[i]);
  }
  scanf("%d",&k);
 for(i=0;i<5;i++){
   for(j=0;j<5;j++){
    if(abs(antennas[i]-antennas[j])>k){
      printf(":(");
      return 0;
    }
   }
 }
printf("Yay!");
return 0;
}

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

int q, mas[10][10], dy[] = { 1, 1, 2}, dx[] = { 0, 1, 0};
int draw[][5][5] = {
  /*Small*/
  {{ 0, 0, 1, 0, 0},
   { 0, 1, 1, 1, 0},
   { 0, 0, 1, 0, 0}},
  //*midium*/
  {{ 0, 0, 1, 1, 1},
   { 0, 0, 1, 1, 1},
   { 0, 0, 1, 1, 1}},
  /*large*/
  {{ 0, 0, 1, 0, 0},
   { 0, 1, 1, 1, 0},
   { 1, 1, 1, 1, 1},
   { 0, 1, 1, 1, 0},
   { 0, 0, 1, 0, 0}},
};

bool check( int y, int x, int w){
  for(int i = 0 ; i < 5 ; i++ ){
    for(int j = 0 ; j < 5 ; j++ ){
      if(mas[y + i][x + j - 2] - draw[w][i][j] < 0) return false;
    }
  }
  return true;
}

void paint( int y, int x, int w){
  for(int i = 0 ; i < 5 ; i++ ){
    for(int j = 0 ; j < 5 ; j++ ){
      mas[y + i][x + j - 2] -= draw[w][i][j];
    }
  }
}

void repaint( int y, int x, int w){
  for(int i = 0 ; i < 5 ; i++ ){
    for(int j = 0 ; j < 5 ; j++ ){
      mas[y + i][x + j - 2] += draw[w][i][j];
    }
  }
}

bool rec( int y, int x, int n){
  if( n < 0 ) return false;
  if( y == 10 ) return n == 0;
  if( mas[y][x] == 0 ) return rec( y + (x == 9), (x + 1) % 10, n);
  for(int i = 0 ; i < 3 ; i++ ){
    if(!check( y, x, i)) continue;
    paint( y, x, i);
    if(rec( y, x, n - 1)){
      cout << x + (i == 1) << " " << y + 1 + (i == 2) << " " << i + 1 << endl;
      return true;
    }
    repaint( y, x, i);
  }
  return false;
}

int main(){
  cin >> q;
  for(int i = 0 ; i < 10 ; i++ ){
    for(int j = 0 ; j < 10 ; j++ ){
      cin >> mas[i][j];
    }
  }
  rec( 0, 0, q);
 }

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef vector<VB> VBB;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll x=0,y=0,k,n,m,h,w,sum=0,Max=1,Min=1e9+1;
  string s,t,u;
  bool ok = false;

  cin >> n >> m;
  VI a(m),b(m),ans(n);

  rep(i,m) cin >> a[i] >> b[i];

  if(n >= 2){
    rep(i,n){
      if(i==0)
        s += '1';
      else
        s += '0'; 
    }
  }
  else if(n==1){
    s += '0';
  }

  rep(i,m){
    char c = b[i] + '0';
    if(a[i] > 1 && ans[a[i]-1] == 0){
      s[a[i]-1] = c;
      ans[a[i]-1]++;
    }
    else if(a[i] > 1 && ans[a[i]-1] > 0 && s[a[i]-1] != c){
      cout << -1;
      return 0;
    }
    else if (a[i]==1 && ans[a[i]-1] == 0){
      if(c == '0'){
        if(n==1){
          s[a[i]-1] = c; 
          ans[a[i]-1]++;
        }
        else{
          cout << -1;
          return 0;
        }
      }
      else{
        s[a[i]-1] = c;
        ans[a[i]-1]++;
      }
    }
    else if (a[i]==1 && ans[a[i]-1] > 0 && s[a[i]-1] != c){
      cout << -1;
      return 0;
    }
  }

  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256