akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int main() {
   int N,ma,mb;
    cin>>N>>ma>>mb;
    int dp[N+1][401][401];
    const int INF = 1000000;
    fill_n(&dp[0][0][0],sizeof(dp)/sizeof(dp[0][0][0]),INF);
    dp[0][0][0]=0;
    vector<int> cost;
    for(int i=0;i<N;++i){
        int a,b,c;
        cin>>a>>b>>c;
        for(int j=0;j<400;++j) {
            for (int k = 0; k < 400; ++k) {
               // if(j+a>=400||k+b>=400){continue;}
                if(dp[i][j][k]!=INF){
                    dp[i+1][j+a][k+b] = min(dp[i][j][k] + c, dp[i+1][j+a][k+b]);
                    dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
                    if ((j + a) * mb == (k + b) * ma) {
                        cost.push_back(dp[i + 1][j + a][k + b]);
                    }
                }
            }
        }
    }
    if(cost.size()>0){//*min_element(cost.begin(),cost.end())!=INF){
        cout<<*min_element(cost.begin(),cost.end());
    }else{
        cout<<-1;
    }


    return 0;
}

Measured memory_bytes: 25984
//104
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
    string S;
    string T;
    cin >> S >> T;
    bool flag = false;
    for(int i = 0; i < S.size(); i++)
    {
        /* code */
        
        if(S == T){
            flag = true;
        }
        S = S.back() + S.substr(0,S.size()-1);
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
    int w, h, x, y, r;
    scanf ("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if ((x+r) <= w && (x-r) >= 0 && (y+r) <= h && (y-r) >= 0)
    printf ("Yes\n");
    else
    printf ("No\n");
    return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>> S;
    LL K; cin >> K;
    int len = S.length();
    REP(i,len-1){
        if(S[i] != 'a'){
            int ne = 26 - (S[i] - 'a');
            if(ne <= K) {
                S[i] = 'a';
                K -= ne;
            }
        }
    }

    K %= 26;
    S[len-1] = char((S[len-1] - 'a' + K) % 26 + 'a');

    cout << S << endl;

}

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

int main()
{
	int length[6];
	for(int i=0;i<6;i++){
		length[i] = 0;
	}
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		double l;
		cin >> l;
		if(l < 165.0)
			length[0]++;
		else if(l < 170.0)
			length[1]++;
		else if(l < 175.0)
			length[2]++;
		else if(l < 180.0)
			length[3]++;
		else if(l < 185.0)
			length[4]++;
		else
			length[5]++;
	}
	for(int i=0;i<6;i++){
		cout << i+1 << ":";
		for(int j=0;j<length[i];j++){
			cout << "*";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  // string x, y;
  char x, y;
  cin >> x >> y;
  if (x > y) {
    cout << ">" << endl;
  } else if (x < y) {
    cout << "<" << endl;
  } else {
    cout << "=" << endl;
  }
  return 0;
}


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

using namespace std;

char s[200010], t[200010];
int main()
{
    scanf("%s %s", s, t);

    int c = 0;
    for (int i = 0; s[i] != '\0'; i++)
    {
        if (s[i] != t[i])
            c++;
    }
    printf("%d", c);

    return 0;
}

Measured memory_bytes: 4204
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

AB,BC,CA=get_i
puts AB*BC/2

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vector<vpll> path, path2; vl D1, D2;
//***********//
int main() {
	cin >> N;
	vpll A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i].first;
		A[i].second = i;
	}
	vl Ans(N);
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	ll count = 1;
	ll pos = A[0].second;
	ll prev = A[0].first;
	ll now = 0;
	for (i = 0; i < N-1; i++) {
		if (A[i].first == A[i+1].first) {
			pos = min(pos,A[i+1].second);
			count++;
		}
		else {
			now = A[i + 1].first;
			Ans[pos] += count * (prev-now);
			prev = now;
			pos = min(pos,A[i+1].second);
			count++;
		}
	}
	Ans[pos] += count * prev;
	for (i = 0; i < N; i++) {
		cout << Ans[i] << endl;
	}
}

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


void solve(long long A, long long B, long long C, long long D, long long E){
    vector<ll> vec;
    vector<ll> ans;
    vec.push_back(A);
    vec.push_back(B);
    vec.push_back(C);
    vec.push_back(D);
    vec.push_back(E);
    for(ll x: vec){
        ans.push_back(ceil(x *1.0 / 10) * 10);
    };

    ll diff = 0;
    ll d = 0;
    rep(i, 5) {
        d = ans[i] - vec[i];
        if(diff< d) diff = d;
    }
    ll hoge;
    hoge = accumulate(ans.begin(), ans.end(), 0);


    printf("%lld", hoge - diff);
    return;

}

int main(){

    //FILE* fp_in = freopen("/Users/kokinakamura/atcoder-workspace/abc123/B/in_2.txt", "r", stdin);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    long long E;
    scanf("%lld",&E);
    solve(A, B, C, D, E);

    return 0;
}

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

using namespace std;

typedef pair<int,int> pint;

int main(){
    int n,m,h,k,s;
    while(cin>>n>>m>>h>>k,n){
        vector<pint> pl,hl,chg;
        for(int i=1;i<=n;++i){
            cin>>s;
            pl.push_back(make_pair(i,s));
        }
        int t1,t2;
        for(int i=0;i<m;++i){
            cin>>t1>>t2;
            hl.push_back(make_pair(t2,t1));
        }
        sort(hl.begin(),hl.end());
        for(vector<pint>::iterator it=hl.begin();it!=hl.end();++it){
            swap(pl[it->second].first,pl[it->second-1].first);
            t1=pl[it->second].first;
            t2=pl[it->second-1].first;
            if((t1-k-0.5)*(t2-k-0.5)<0) chg.push_back(make_pair(t1,t2));
        }
        int sum=0,score[1001];
        for(vector<pint>::iterator it=pl.begin();it!=pl.end();++it){
            if(it->first<=k) sum += it->second;
            score[it->first-1] = it->second;
        }
        int ans=sum;
        for(vector<pint>::iterator it=chg.begin();it!=chg.end();++it){
            t1=score[it->first-1]-score[it->second-1];
            if(it->first>k) ans = min(ans,sum+t1);
            else ans = min(ans,sum-t1);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3864
s=input()
q=int(input())
p=0
a=""
b=""
for i in range(q):
    l=list(map(str,input().split()))
    if l[0]=="1":
        p=(p+1)%2
    else:
        if p==0:
            if l[1]=="1":
                a+=l[2]
            else:
                b+=l[2]
        else:
            if l[1]=="1":
                b+=l[2]
            else:
                a+=l[2]
if p==1:
    print(b[::-1]+s[::-1]+a)
else:
    print(a[::-1]+s+b)


Measured memory_bytes: 4468
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		while(true){
			try{
				int n = sc.nextInt();
				String num =  Integer.toBinaryString(n);
				char ctr[] = num.toCharArray();
				int cnt = 1;
				int ans = 0;
				for(int i = ctr.length - 1;i >= 0;i--){
					if(ans == 0){
						if(Integer.parseInt(""+ctr[i]) == 1){
							System.out.print(cnt);
							ans++;
						}
					}else{
						if(Integer.parseInt(""+ctr[i]) == 1){
							System.out.print(" "+cnt);
						}
					}
					cnt *= 2;
				}
				System.out.println();
			}catch(Exception g){
				System.exit(0);
			}
		}
	}
    public static void main(String[] args) {
    	new Main().doIt();
    }
}

Measured memory_bytes: 17252
import math
N = int(input())
sqrt = math.floor(math.sqrt(N))
ans = 10
for A in range(1,sqrt+1):
    n = 0
    if N % A != 0:
        continue
    B = N / A
    while not B == 0:
        n += 1
        B //= 10
    ans = min(ans, n)
print(ans)


Measured memory_bytes: 9024
#include <iostream>
#include <map>
#include <queue>
using namespace std;

#define fi first
#define se second

using ll = long long;

map <ll, ll> mp;

void upd(ll a, ll b) {
	if(mp.find(a) == mp.end())
		mp[a] = b;
	else
		mp[a] = min(mp[a], b);
}

int main() {
	int T; cin >> T;
	while(T --) {
		ll n, a, b, c, d;
		cin >> n >> a >> b >> c >> d;
		mp = {{n, 0}};
		
		ll ans = 1e18L;
		while(!mp.empty()) {
			auto p = *(-- mp.end());
			mp.erase(-- mp.end());
			
			// cout << p.fi << ' ' << p.se << '\n';
			
			if(p.fi < 1e18L / d)
				ans = min(ans, p.second + p.fi * d);
			
			auto f = [&](ll div, ll cost) {
				ll down = p.fi / div;
				ll up = (p.fi + div - 1) / div;
				for(ll to : {up, down}) if(to > 0) {
					upd(to, abs(to * div - p.fi) * d + cost + p.se);
				}
			};
			
			f(2, a); f(3, b); f(5, c);
			
			if(p.fi == 1) break;
		}
		
		cout << ans << '\n';
	}
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	int a, b;
	cin >> a >> b;
	if (a*b % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let print (x :: xs) =
    printf "%i" x
    List.iter (printf " %i") xs
    printfn ""

[<EntryPoint>]
let main _ =
    let [k;x] = reads int
    [x - k + 1 .. x + k - 1]
    |> List.filter (fun x -> -1000000 <= x && x <= 1000000)
    |> print
    0

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;
    public static HashMap<String, Integer> map;
    public static int k;
    public static Edge[] e;
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        e = new Edge[n];
        for (int i = 0; i < n; i++) e[i] = new Edge();
        map = new HashMap<>();
        String[] input = new String[n-1];
        for (int i = 0; i < n-1; i++) {
            int a = in.ni()-1, b = in.ni()-1;
            e[a].add(b); e[b].add(a);
            input[i]= trans(a,b);
        }
        k = 0;
        for(Edge edge: e) k = Math.max(k, edge.size());
        bfs(-1, 0, -1);
        out.println(k);
        for(String s: input){
            out.println(map.get(s)+1);
        }
    }
    public static void bfs(int p, int c, int color){
        for(Integer edge: e[c]){
            if(edge != p){
                color = (color+1)%k;
                bfs(c, edge, color);
                map.put(trans(c,edge), color);
            }
        }
        return;
    }
    public static String trans(int a, int b){
        return Math.min(a,b)+" "+Math.max(a,b);
    }
    public static class Edge extends ArrayList<Integer>{}

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 84968
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum Type{
	BIG,
	SMALL,
	SAME,
};

ll sequence[14],num_digit,sum,mult;
char buf[15];
map<ll,ll> MAP[15][127][3]; //MAP[桁][総和][type][tmp_mult] = 場合の数

ll recursive(int digit,ll tmp_sum,ll tmp_mult,Type type){

	if(MAP[digit][tmp_sum][type][tmp_mult] != 0)return MAP[digit][tmp_sum][type][tmp_mult];

	if(digit == num_digit){ //sequenceと同じ桁だけ動いた場合
		if(tmp_sum < sum){
			return 1;
		}else if(tmp_sum == sum && tmp_mult < mult){
			return 1;
		}else if(tmp_sum == sum && tmp_mult == mult && type == SMALL){
			return 1;
		}else{
			return 0;
		}
	}

	ll ret = 0,number = sequence[digit];

	for(ll next_num = 0; next_num <= 9; next_num++){
		if(type == SAME){
			if((tmp_sum+next_num > sum) || (tmp_sum+next_num == sum && tmp_mult*(next_num+1) > mult))break;

			if(next_num < number){
				ret += recursive(digit+1,tmp_sum+next_num,tmp_mult*(next_num+1),SMALL);
			}else if(next_num == number){ //next_num == number
				ret += recursive(digit+1,tmp_sum+next_num,tmp_mult*(next_num+1),SAME);
			}else{ //next_num > number
				ret += recursive(digit+1,tmp_sum+next_num,tmp_mult*(next_num+1),BIG);
			}
		}else if(type == SMALL){
			if((tmp_sum+next_num > sum) || (tmp_sum+next_num == sum && tmp_mult*(next_num+1) > mult))break;
			ret += recursive(digit+1,tmp_sum+next_num,tmp_mult*(next_num+1),SMALL);
		}else{ //type == BIG
			if((tmp_sum+next_num > sum) || (tmp_sum+next_num == sum && tmp_mult*(next_num+1) > mult))break;
			ret += recursive(digit+1,tmp_sum+next_num,tmp_mult*(next_num+1),BIG);
		}
	}

	return MAP[digit][tmp_sum][type][tmp_mult] = ret;
}

int main(){

	scanf("%s",buf);

	num_digit = 0;
	sum = 0;
	mult = 1;

	for(int i = 0; buf[i] != '\0'; i++){
		sequence[i] = (ll)(buf[i]-'0');

		sum += sequence[i];
		mult *= (sequence[i]+1);
		num_digit++;
	}

	printf("%lld\n",recursive(0,0,1,SAME));

	return 0;
}



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

int main(){
  int n;
  int a[100010];
  long long ans = 0;
  cin >> n;
  for(int i = 0;i < n;i++) cin >> a[i];

  long long tmp = 0;
  for(int i = 0;i < n;i++){
    if(a[i] != 0){
      tmp += a[i];
    }else{
      ans += tmp / 2;
      tmp = 0;
    }
  }
  ans += tmp/2;

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
#define rep(i,s,n) for(ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(),a.end()
#define mod 1000000007
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/

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


/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,k;
    cin>>n>>k;
    vector<ll>h(n),dp(n);
    rep(i,0,n){
        cin>>h[i];
    }
    ll a;
    dp[0]=0;
    rep(i,1,n){
        a=LLONG_MAX;
        if(i==1){
            a=dp[i-1]+abs(h[1]-h[0]);
        }
        else{
            for(ll j=1;j<=k;j++){
                if(i-j>=0){
                    a=min(a,dp[i-j]+abs(h[i-j]-h[i]));
                }
            }
        }
        dp[i]=a;
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
    

    
}


Measured memory_bytes: 1792
/*~~~~~~~~~~~~~~~~~~~~~~~~*
 *  Jeevan ek rahasya hai *
 *     slow_processor     *
 * Author-maskman_lucifer *
 *~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>                                        
#define ll long long 
#define mpr make_pair
#define pll pair<ll,ll>
#define pb push_back
#define M 1000000007
#define PI 3.141592653589793
#define lc '\n'
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n;i++)
    {
        ll sum1=((i-1)*(i))/2;
        ll sum2=(n*(n+1))/2;
        sum2=sum2-((n-i)*(n-i+1))/2;
        ans+=sum2-sum1+1;
        ans=ans%M;
    }
    cout<<(ans+1)%M<<lc;
    return 0;
}

Measured memory_bytes: 3640
def d_Insertion(N, S):
    # 解説通り
    d = 0
    x = 0
    for c in S:
        if c == '(':
            d += 1
        else:
            d -= 1
        x = min(x, d)
    ans = '(' * (-x) + S + ')' * (d - x)
    return ans

N = int(input())
S = input().strip()
print(d_Insertion(N, S))

Measured memory_bytes: 3060
#include<stdio.h>
int a[10010]={0},b[10010]={0},c[100][100]={0};
int main()
{
	int i,j,H,W,N,f=1,t=0;
	scanf("%d%d",&H,&W);
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&a[i]);
	}
	int sum=0;
	for(j=0;j<N;j++)
	{
	for(i=0;i<a[j];i++)
	{
		b[sum+i]=j+1; 
	}
	sum+=a[j];
	}
	
   	for(i=0,j=0,t=0;t<H*W;t++)
   	{	
	    c[i][j]=b[t];
	    i+=f;
   		if(i==H)
   		{ 
   			f=-1;
   			j++;
   			i=H-1;
		}
		if(i==-1)
		{
   			f=1;
   			j++;
   			i=0;
		}
	}
	
   	for(i=0;i<H;i++)
   	{
   		for(j=0;j<W;j++)
   	{
		printf("%d ",c[i][j]); 
		if(j==W-1)printf("\n"); 
	}
	}
	return 0;
}	

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

using ll = long long;

// 最大公約数
ll gcd(ll a, ll b)
{
    if (a < 0)
        a = -a;
    if (b < 0)
        b = -b;
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

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

int main()
{
    string a, b;
    int n, m, k;
    cin >> a;
    if (a == "ARC") {
        cout << "ABC" << endl;
    }
    else {
        cout << "ARC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
N,T = map(int,input().split())
A = list(map(int,input().split()))

cnt = max_profit = 0
INF = float('inf')
min_cost = INF
for a in A:
    profit = a - min_cost
    if profit == max_profit:
        cnt += 1
    elif profit > max_profit:
        cnt = 1
        max_profit = profit
    min_cost = min(min_cost, a)

print(cnt)

Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}



void solve(void){
    double t,x;
    cin >> t >> x;
    cout << t/x;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

signed main(){
  int n,mod=1000000007;
  cin>>n;
  vector<int> x(n);
  rep(i,n)cin>>x[i];
  x[0]=1;
  int ans=1;
  int cnt=0;
  int recnt=0;
  rep(i,n){
    if(x[i]<(cnt+1)*2-1){
	 ans*=(cnt+1);
	 ans%=mod;
	 recnt++;
    }else cnt++;
  }
  dmp(recnt);dmp(cnt);
  FOR(i,recnt,n){
    ans*=cnt--;
    ans%=mod;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int a;
    cin >> a;
    cout << a*(1+a+a*a) << endl;
}

Measured memory_bytes: 3632
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str=input.readLine();
	String str_ary[]=str.split(" ");
	for(int i=0;i<str_ary.length;i++)
	    {
		
		System.out.print(str_ary[i].toUpperCase()+((i==str_ary.length-1)?("\n"):(" ")));
	    }
    }
}

Measured memory_bytes: 16884
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define PII pair<int, int>
#define PL pair<long long, long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
//struct EE{int v, w, nx;}E[M * 2 + N * 2]; int hd[N], EN;
//void init_edge(int num){EN = 0; memset(hd, -1, (num + 2) << 2);}
//void add_edge(int u, int v, int w){
//    E[EN].w = w; E[EN].v = v; E[EN].nx = hd[u]; hd[u] = EN++;
//    E[EN].w = w; E[EN].v = u; E[EN].nx = hd[v]; hd[v] = EN++;
//}
//const int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
int n, a[N];
char s1[100], s2[100];
int main(){
    //IN;
    SC(n);
    SS(s1 + 1);
    SS(s2 + 1);

    LL s = 1;
    int i = 1;
    if(s1[1] == s2[1]){
        i = 2;
        s = 3;
    }else {
        i = 3;
        s = 6;
    }
    while(i <= n){
        if(s1[i] == s2[i]){
            if(s1[i - 1] == s2[i - 1]) s = s * 2 % MOD;
        }else {
            if(s1[i - 1] == s2[i - 1]) s = s * 2 % MOD;
            else s = s * 3 % MOD;
            ++i;
        }
        ++i;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
ls=[]
def rec(n):
    if len(str(n))>9: return
    ls.append(n)
    for i in [3,5,7]: rec(10*n+i)
n=int(input())
rec(0)
cnt=0
for l in ls:
    if l<=n and all(str(l).count(i)>0 for i in "357"): cnt+=1
print(cnt)

Measured memory_bytes: 10256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int A = 26;
    const int M = 2e5;
    int D; cin >> D;
    vector<int> c(A);
    REP(i,A) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    vector<int> last(A,-1);
    vector<int> ans(D);
    REP(i,D) {
        int mx = 0,a = -1;
        REP(j,A) {
            int tmp = (i-last[j])*c[j] + s[i][j];
            if (mx < tmp) {
                mx = tmp;
                a = j;
            }
        }
        ans[i]=a;
        last[a] = i;
    }
    auto calc = [&](const vector<int> &a){
        vector<int> l(A,-1);
        int score = 0;
        REP(i,D) {
            score += s[i][a[i]];
            l[a[i]] = i;
            REP(j,A) {
                score -= c[j]* (i-l[j]);
            }
        }
        return score;
    };

    int maxscore = calc(ans);

    random_device seed_gen;
    mt19937 engine(seed_gen());
    REP(_,M) {
        vector<int> a(ans);
        a[engine()%D] = engine() % A;
        int tmp = calc(a);
        if (maxscore < tmp) {
            swap(ans,a);
            maxscore = tmp;
        }
    }

    REP(i,D) OUT(ans[i]+1)

    return 0;
}

Measured memory_bytes: 3720
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read.ToArray();
            var n = S[S.Length - 1];
            switch(n)
            {
                case '2':
                case '4':
                case '5':
                case '7':
                case '9':
                    WriteLine("hon");
                    break;
                case '0':
                case '1':
                case '6':
                case '8':
                    WriteLine("pon");
                    break;
                case '3':
                    WriteLine("bon");
                    break;
            }
        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }


        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

int main(){

string S,T,U;
int A,B;

cin >> S >> T;
cin >> A >> B;
cin >> U;

if(U == S){
 A -= 1;
}else if(U == T){
 B -= 1;
}

cout << A << " " << B << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isPrime(ll x)
{
    ll i,n;
    n=sqrt(x);
    if(x==1) return false;
    if(x==2 || x==3) return true;
    for(i=2;i<=n;i++)
    {
        if(!(x%i)) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
vector<vll> adj(200001);
map<ll,ll> visited;
ll sum=0;
void dfs(ll n)
{
    visited[n]++;
    sum++;
    ll i,j;
    j=adj[n].size();
    for(i=0;i<j;i++)
    {
        //cout<<adj[n][i]<<"s "<<n;
        //endk
        if(!visited[adj[n][i]])
        {
            dfs(adj[n][i]);
        }
    }
}
int solve()
{
    ll n,m,i,ans=0,j,k;
    cin>>n>>m;
    map<pair<ll,ll>,ll> cnt;
    for(i=0;i<m;i++)
    {
        cin>>j>>k;
        if(!cnt[{j,k}])
        {
            cnt[{j,k}]++;
            adj[j].push_back(k);
            adj[k].push_back(j);
        }
    }
    ans=-1;
        for(i=1;i<=n;i++)
        {
            if(!visited[i])
            {
                sum=0;
                dfs(i);
                ans=max(ans,sum);
            }      
        }
    cout<<ans;
    return 0;
}
int main()
{
    fst;
    test1();
    return 0;
}


Measured memory_bytes: 57832
#include <iostream>
#define llint long long

using namespace std;

llint S;
llint a[100005];

int main(void)
{
  cin >> S;
  for(int i = 1; i <= S; i++){
    llint sum = 0;
    for(int j = i; sum <= S; j++){
      sum += j;
      if(sum <= S) a[sum]++;
    }
  }

  llint ans = 0;
  for(int i = 1; i <= S; i++){
    if(S % i) continue;
    ans += a[i] * a[S/i];
  }
  cout << ans << endl;

  return 0;
}



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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main(){ _
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int l = h1*60+m1, r = h2*60+m2 - k;
	int ans = max(0, r-l);
	cout << ans << endl;
	exit(0);
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	Cout(min(N*A, B));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
 
  if (a * b % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include <stdio.h>
#define NUM 10

int main(void){
	int m[NUM], i, j, temp;

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

	for(i = 0; i < NUM - 1; i++){
		for(j = 0; j < NUM - i - 1; j++){
			if(m[j] < m[j + 1]){
				temp = m[j];
				m[j] = m[j + 1];
				m[j + 1] = temp;
			}
		}
	}

	printf("%d\n", m[0]);
	printf("%d\n", m[1]);
	printf("%d\n", m[2]);
	return 0;
}

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

signed main(){
  int N,M;
  cin>>N>>M;
  cout<<N*N-M<<endl;
  return 0;
}

Measured memory_bytes: 3544
#include<iostream>
#include<vector>
using namespace std;
const int N=3e3+2;
int ar[N];
vector<int> adj[N],ans;
bool f[N];
void dfs(int x,int p){
	f[x]=false;
	for(int i=0;i<adj[x].size();i++){
		if(adj[x][i]!=p){
			dfs(adj[x][i],x);
			if(!f[adj[x][i]]&&ar[x]>ar[adj[x][i]]){
				f[x]=true;	
			}
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	for(i=1;i<n;i++){
		cin>>j>>k;
		adj[j].push_back(k);
		adj[k].push_back(j);
	}
	for(i=1;i<=n;i++){
		dfs(i,i);
		if(f[i]){
			ans.push_back(i);
		}
	}
	//cout<<ans.size()<<'\n';
	for(i=0;i<ans.size();i++){
		cout<<ans[i]<<' ';
	}
}

Measured memory_bytes: 768
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = replicateM 6 readLn >>= printRes . solve . reverse
    where
        printRes b
            | b = putStrLn "Yay!"
            | otherwise = putStrLn ":("

solve :: [Int] -> Bool
solve (k : xs) = check ds
    where
        ds = [ abs $ a - b | a <- xs, b <- xs ]
        check = not . any (> k)

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 508
#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;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

int main(void){
  int n; cin >> n;
  int a[n]; rep(i,n) cin >> a[i];
  int ans = 0;
  int count = 1;
  bool k = 0;
  rep(i,n){
    if(a[i] == 1){
      k = 1;
    }
  }
  if(!k){
    cout << -1 << endl;
    return 0;
  }
  for(int i = 0; i < n; i++){
    if(a[i] == count){
      count++;
    }
    else{
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
A, B = map(int, input().split())

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

a = prime_factorize(A)
b = prime_factorize(B)

common = []
only_a = []
for i in a:
  if i in b:
    common.append(i)
    b.remove(i)
  else:
    only_a.append(i)

p = 1
for x in common + only_a + b:
  p *= x
print(p)

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

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  set<char> s;
  for(int i=0; i<S.size(); i++)
    s.insert(S[i]);

  
  if(s.size()==2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;



  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

using namespace std;
typedef long long ll;

int DAYS;
const int TYPES = 26;
mt19937 engine(random_device{}());

vector<int> c;
vector<vector<ll>> s;

ll point;
vector<ll> penalty;

chrono::system_clock::time_point startTime, endTime;
int elapsed = 0;

void simulate(vector<int> &t) {
    vector<int> last(TYPES, -1);
    point = 0, penalty.assign(TYPES, 0);
    for (int i = 0; i < DAYS; i++) {
        point += s[i][t[i]], last[t[i]] = i;
        for (int j = 0; j < TYPES; j++) {
            penalty[j] += c[j] * (i - last[j]);
        }
    }
}

void update(vector<int> &t, int x, int y) {
    int lastx = -1, lasty = -1;
    penalty[x] = 0, penalty[y] = 0;
    for (int i = 0; i < DAYS; i++) {
        if (t[i] == x)lastx = i;
        if (t[i] == y)lasty = i;

        penalty[x] += c[x] * (i - lastx), penalty[y] += c[y] * (i - lasty);
    }
}

ll scoring() {
    ll ret = point;
    for (auto &x:penalty)ret -= x;
    return ret;
}


ll mod_rnd(ll mod) { return engine() % mod; }

int main() {
    startTime = chrono::system_clock::now();

    cin >> DAYS;
    c.resize(TYPES);
    for (int i = 0; i < TYPES; i++)cin >> c[i];
    s.assign(DAYS, vector<ll>(TYPES));
    for (int i = 0; i < DAYS; i++) {
        for (int j = 0; j < TYPES; j++) {
            cin >> s[i][j];
        }
    }

    vector<int> t(DAYS);
    for (int i = 0; i < DAYS; i++) t[i] = i % TYPES;

    simulate(t);
    ll currentScore = scoring();

    while (elapsed < 1975) {
        int ope = mod_rnd(elapsed / 18 + 3);
        int day1 = -1, day2 = -1;
        int type1 = -1, type2 = -1;

        if (ope == 0) {
            do {
                day1 = mod_rnd(DAYS), type2 = mod_rnd(TYPES);
            } while (t[day1] == type2);

            type1 = t[day1];
            t[day1] = type2;
            point -= s[day1][type1], point += s[day1][type2];
        } else {
            do {
                day1 = mod_rnd(DAYS), day2 = mod_rnd(DAYS);
            } while (day1 == day2);

            type1 = t[day1], type2 = t[day2];
            point -= s[day1][type1], point -= s[day2][type2];
            swap(t[day1], t[day2]);
            point += s[day1][type2], point += s[day2][type1];
        }

        update(t, type1, type2);
        ll changedScore = scoring();

        ll add = max(0, (1800 - elapsed) * 2);
        if (currentScore < changedScore + add)currentScore = changedScore;
        else {
            if (ope == 0) {
                t[day1] = type1;
                point += s[day1][type1], point -= s[day1][type2];
            } else {
                point -= s[day1][type2], point -= s[day2][type1];
                swap(t[day1], t[day2]);
                point += s[day1][type1], point += s[day2][type2];
            }
            update(t, type1, type2);
        }

        endTime = chrono::system_clock::now();
        elapsed = chrono::duration_cast<chrono::milliseconds>(endTime - startTime).count();
    }

    for (auto &x:t)cout << x + 1 << endl;
    return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> AB(N), BA(N);
    REP(i, N){
        int A, B;
        cin >> A >> B;
        AB[i] = make_pair(A, B);
        BA[i] = make_pair(B, A);
    }
    sort(AB.begin(), AB.end());
    sort(BA.begin(), BA.end());

    if(N%2){
        int id = N / 2;
        int L = AB[id].first;
        int R = BA[id].first;
        cout << R - L + 1 << endl;
    }else{
        int id0 = N/2-1;
        int id1 = id0+1;
        int L0 = AB[id0].first;
        int R0 = BA[id0].first;
        int L1 = AB[id1].first;
        int R1 = BA[id1].first;
        int ans = (R0+R1)-(L0+L1)+1;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll dp[100010][3];

int main()
{
    int n; cin >> n;
    int a[n][3];
    rep(i, n)
        rep(j, 3) cin >> a[i][j];

    rep(i, n)
    {
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    ll res = 0;
    rep(i, 3) chmax(res, dp[n][i]);
    cout << res << endl;
}

Measured memory_bytes: 3712