akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    int n,q;
    cin>>n>>q;
    string ss;
    cin>>ss;
    vector<int> a(n,0);
    rep(i,n){
        if(ss[i]=='A'&&ss[i+1]=='C')a[i+1]=a[i]+1;
        else a[i+1]=a[i];
    }
    rep(i,q){
        int l,r;cin>>l>>r;
        l--;r--;
        cout<<a[r]-a[l]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mmax=1000009;

int main(void){
    int n,k;
    cin>>n>>k;
    long long ans=k;
    rep(i,n-1) ans*=(k-1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>

int main()
{
  int n, i;

  scanf("%d", &n);

  for(i = 1; i <= n; i++){
    if(i % 3 == 0 || i % 10 == 3 || (i/10) % 10 == 3 || (i/100) % 10 == 3 ||  (i/1000) % 10 == 3 ) printf(" %d", i);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 596
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::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...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 103000;

    void solve() {
      ll n, k, cnt = 0;
      cin >> n >> k;
      if(k%2 == 0){
        cnt = pow(n/k, 3);
        ll val = 0;
        repA(i, 1, n) i%k == k/2 ? val++:0;
        cnt+=val*val*val;
      } else   cnt = pow(n/k, 3);
      cout << cnt << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //te
      solve();
      return 0;
    } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    string s;
    cin>>s;
    int n = s.size()-1;
    ll ans = 0;
    for(int i = 0;i<(1<<n);i++){
        int bef = -1;
        ll tmp = 0;
        int u = i+pow(2, n);
        rep(j, n+1){
            if((u>>j)&1){
                string t = s.substr(bef+1, j-bef);
                bef = j;
                tmp += stoll(t);
            }
        }
        ans += tmp;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		long N = GetInt();
		long K = (long)Math.Ceiling((-1.0 + Math.Sqrt(1.0 + 8.0 * (double)N)) / 2.0);
		long S = (K * (K + 1)) / 2;
		long X = S - N;
		var sb = new StringBuilder();
		for(int i = 1; i <= K; i++)
		{
			if(i != X)
				sb.AppendFormat($"{i}\n");
		}
		Console.Write(sb);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

int main()
{
	int n, p;
	int stoneOfPerson[50];
	int stoneInBowl;
	int winner;
	
	while (1) {
		cin >> n >> p;
		if ((n == 0) && (p == 0)) {
			break;
		}
		for (int i = 0; i < n; i++) {
			stoneOfPerson[i] = 0;
		}
		stoneInBowl = p;
		
		int i = 0;
		while (1) {
			if (stoneInBowl > 0) {
				stoneOfPerson[i]++;
				stoneInBowl--;
				if ((stoneInBowl == 0) && (stoneOfPerson[i] == p)) {
					winner = i;
					break;
				}
			} else {
				stoneInBowl = stoneOfPerson[i];
				stoneOfPerson[i] = 0;
			}
			i++;
			if (i >= n) {
				i = 0;
			}
		}
		cout << winner << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N = gets.chomp.to_i
Weights = (gets.chomp.split(' ').map(&:to_i))[0..N]

balances = (1.upto(N-1).map do |t|
  smallers, biggers = Weights[0...t], Weights[t...N]
  (biggers.reduce(0, &:+) - smallers.reduce(0, &:+)).abs
end)

puts balances.min


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 1e5+5;

int n,a[N],r[N];

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

    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(int i=n;i>=1;i--){
        if(a[i]>=a[i+1])r[i]=r[i+1]+1;
        else r[i]=1;
        ans=max(ans,r[i]);
    }
    cout<<ans-1;
    return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int64 gcd(int64 a, int64 b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 T;
	cin >> T;
	REP(_, T){
		int64 A, B, C, D;
		cin >> A >> B >> C >> D;
		if(D < B || A < B || A%B > C){
			cout << "No" << endl;
			continue;
		}
		if(C >= B){
			cout << "Yes" << endl;
			continue;
		}
		if(B-C-1 >= gcd(B, D-B)){
			cout << "No" << endl;
			continue;
		}
		cout << "Yes" << endl;

	}
}


Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

a.sort! { |a, b| b <=> a }

sum = a.sum

if 4 * m * a[m-1] < sum
  puts 'No'
else
  puts 'Yes'
end


Measured memory_bytes: 14260
N = int(input())
A = list(map(int,input().split()))
Array = [0] * N
Array_C = [0] * N
for i in range(N):
    Array[A[i] -1] += 1
for i in range(N):
    Array_C[i] = (Array[i]) * (Array[i] - 1) // 2
SUM_ARRAY = sum(Array_C)

for i in range(N):
    print(SUM_ARRAY - Array_C[A[i] - 1] + (Array_C[A[i] - 1] * (Array[A[i] - 1]-2) // Array[A[i] - 1]))

Measured memory_bytes: 26140
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    if (n == 25) {
        cout << "Christmas" << endl;
    } else if (n == 24) {
        cout << "Christmas Eve" << endl;
    } else if (n == 23) {
        cout << "Christmas Eve Eve" << endl;
    } else if (n == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
int main(){
    int A, B, m;
    cin >> A >> B >> m;
    vector<ll> a(A), b(B);
    rep(i,A)cin >> a[i];
    rep(i,B)cin >> b[i];
    ll res = 1e12;
    rep(i,m){
        ll x, y, c;
        cin >> x >> y >> c;
        res = min(res, a[x-1] + b[y-1] - c);
    }
    ll ma = *min_element(all(a)), mb = *min_element(all(b));
    res = min(res, ma + mb);
    cout << res << endl;
    return 0;
}

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

int main(){

  int a=0;
  int b=0;

  std::cin>>a>>b;
  
  int ans=0;

  while(std::pow(b,ans)<=a)ans++;
  std::cout<<ans;
  
}


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

double dp[303][303][303];
int n;

void calc(int i, int j, int k)
{
    if (dp[i][j][k] >= 0)
        return;
    if (i)
        calc(i - 1, j, k);
    if (j)
        calc(i + 1, j - 1, k);
    if (k)
        calc(i, j + 1, k - 1);

    dp[i][j][k] = (i ? dp[i - 1][j][k] * i : 0) + (j ? dp[i + 1][j - 1][k] * j : 0) +
                  (k ? dp[i][j + 1][k - 1] * k : 0) + n;
    dp[i][j][k] *= 1.0 / (i + j + k);
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> cnt(5);
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        cnt[a]++;
    }

    memset(dp, -1, sizeof dp);
    dp[0][0][0] = 0.0;
    calc(cnt[1], cnt[2], cnt[3]);
    printf("%.10lf\n", dp[cnt[1]][cnt[2]][cnt[3]]);

    return 0;
}


Measured memory_bytes: 217600
n=int(input())
edge=[[]for _ in range(n)]
point=[0]*n
edges=[]
point_color=[-1]*n
edge_color={}
edge_to_int=lambda x,y:min(x,y)*100007+max(x,y)
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edges.append((a,b))
  edge[a].append(b)
  edge[b].append(a)
  point[a]+=1
  point[b]+=1
ans=max(point)
ind=point.index(ans)
Q=[ind]
visited={ind}
while Q:
  P=[]
  for i in Q:
    color=0
    for j in edge[i]:
      if j in visited:continue
      visited.add(j)
      P.append(j)
      color+=1
      if point_color[i]==color:color+=1
      point_color[j]=color
      edge_color[edge_to_int(i,j)]=color
  Q=P
print(ans)
for a,b in edges:
  print(edge_color[edge_to_int(a,b)])

Measured memory_bytes: 46716
N, X = map(int, input().split())
A = list(map(int, input().split()))

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

D = []
for a in A:
  D.append(abs(X - a))

answer = 0
for d in D:
  answer = gcd(answer, d)

print(answer)

Measured memory_bytes: 63640
import math

# 入力を3つの数値として扱う
a, b, x = map(int, input().split())

# 水を真横から見た面積(c)
c = x / a

# 傾けて溢れるのは、2パターン
ad = 0
bd = 0

# 水筒の半分よりおおい：[高さから移動した点(bd)を引く]*[底辺(a)]+[高さから移動した点(bd)]*[底辺(a)]/2がcのとき
# (b - bd) * a + bd * a / 2 = c
if x > a * a * b / 2:
    bd = (2 * b * a - 2 * c) / a

# 水筒の半分以下：[高さ(b)]*[底辺から移動した点(ad)]/2がcのとき
# (b * ad) / 2 = c
else:
    ad = (2 * c) / b

# 角度を求める
if ad == 0:
    r = math.atan(bd / a)
else:
    r = math.atan(b / ad)

# 弧度法から度数法への変換
ans = math.degrees(r)

# 答えの出力
print(ans)


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		int w = s.nextInt();
		int n = s.nextInt();
		int [] nums = new int[w];
		for (int i=0;i<w;i++) {
			nums[i] = i + 1;
		}
		for (int i=0;i<n;i++) {
			String[] inp = s.next().split(",");
			int a = Integer.valueOf(inp[0]).intValue() - 1;
			int b = Integer.valueOf(inp[1]).intValue() - 1;
			int temp = nums[b];
			nums[b] = nums[a];
			nums[a] = temp;
		}
		for (int i=0;i<w;i++) {
			System.out.println(nums[i]);
		}
	}
}


Measured memory_bytes: 26152
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	ll a,b,c,d;cin>>a>>b>>c>>d;
	if(a>=0){
		if(c>=0) cout<<b*d<<endl;
		else if(c<=0&&d>=0) cout<<b*d<<endl;
		else if(d<=0) cout<<a*d<<endl;
	}
	else if(a<=0&&b>=0){
		if(c>=0) cout<<b*d<<endl;
		else if(c<=0&&d>=0) cout<<max(a*c,b*d)<<endl;
		else if(d<=0) cout<<a*c<<endl;		
	}
	else if(b<=0){
		if(c>=0) cout<<b*c<<endl;
		else if(c<=0&&d>=0) cout<<a*c<<endl;
		else if(d<=0) cout<<a*c<<endl;		
	}
}


Measured memory_bytes: 3636
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int N, K;
int A[20];
bitset<1 << 20> dp;

int main() {

    cin >> N >> K;
    rep(i, N) cin >> A[i];

    int ans = N;
    rep(S, 1 << N) {
        int sum = 0;
        rep(i, N) if((1 << i) & S) sum += A[i];
        if(sum == K || dp[S] == 1) {
            dp[S] = 1;
            rep(i, N) dp[S | (1 << i)] = 1;
        } else {
            chmin(ans, N - __builtin_popcount(S));
        }
    }

    cout << ans << '\n';
    return 0;

}



Measured memory_bytes: 3216
X, K, D = map(int, input().split())

hu = False
if X < 0:
    X = abs(X)

idou_kaisu = X//D # 移動回数
amari = X%D # あまり

if idou_kaisu >= K: # すべて一方方向
    print(X - (K*D))
    exit()
else:
    X = amari
    K = K - idou_kaisu

three_list = []

for i in range(K):
    three_list.append(X)
    
    if len(three_list) >= 4:
        three_list.pop(0)
    if len(three_list) >= 3:
        if three_list[0] == three_list[2]: # 繰り返し
            if (K-i) % 2 == 0: # 偶数
                print(abs(three_list[0]))
            else:
                print(abs(three_list[1]))
            exit()
    if X >= 0:
        X -= D
    else:
        X +=D
print(abs(X))
    

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

map<int , int> nodes;

signed main(){
    int n , a , node[2] = {};
    
    cin >> n;
    for(int i=0 ;i<n ;i++ ){
        cin >> a;
        nodes[a]++;
        if(nodes[a] == 4){
            node[0] = max(node[0] , a);
            node[1] = max(node[1] , a);
        } else if(nodes[a] == 2){
            if(node[0] > node[1]){
                node[1] = max(node[1] , a); 
            } else {
                node[0] = max(node[0] , a);
            }
        }
    }
    
    cout << (long long)node[0] * node[1] << endl;
    return(0);
}

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

public class Main {
    public static void main(String args[])throws Exception{
        Scanner cin= new Scanner(System.in);
		
		while(cin.hasNextDouble()){
			double in[] = new double[8];
			for(int i=0;i<8;i++) in[i]= cin.nextDouble();
			int t1,t2,t3;
			t1= java.awt.geom.Line2D.relativeCCW(in[0],in[1],in[2],in[3],in[6],in[7]);
			t2= java.awt.geom.Line2D.relativeCCW(in[2],in[3],in[4],in[5],in[6],in[7]);
			t3= java.awt.geom.Line2D.relativeCCW(in[4],in[5],in[0],in[1],in[6],in[7]);
			if((t1==1 && t2==1 && t3==1) || (t1==-1 && t2==-1 && t3==-1)) System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  int cnt = 1;
  int flag, flaglag;
  if(N == 1){
    cout << 1 <<endl;
    return 0;
  }
  else if(a[1] - a[0] > 0){
    //add++;
    flag = 1;
  }else if(a[1] - a[0] < 0){
    //sub++;
    flag = -1;
  }else{
    flag = 0;
    flaglag = 0;
  }
  for(int i = 1; i < N-1; i++){
    if(flag == 1){
      if(a[i+1] - a[i] > 0){
        //add++;
        continue;
      }else if(a[i+1] == a[i]){
        flag = 2;
        flaglag = 1;
      }else{
        flag = 0;
        cnt++;
      }
    }else if(flag == -1){
      if(a[i+1] - a[i] < 0){
        //sub++;
        continue;
      }else if(a[i+1] == a[i]){
        flag = 2;
        flaglag = -1;
      }else{
        flag = 0;
        cnt++;
      }
    }else if(flag == 0){
      if(a[i+1] - a[i] > 0){
        flag = 1;
      }else if(a[i+1] - a[i] < 0){
        flag = -1;
      }else{
        flag = 0;
      }
    }else{
      if(a[i+1] - a[i] > 0 && flaglag == 1){
        //diff > 0, before_diff > 0
        flag = 1;
      }else if(a[i+1] - a[i] > 0 && flaglag == -1){
        flag = 0;
        cnt++;
      }else if(a[i+1] - a[i] < 0 && flaglag == -1){
        flag = -1;
      }else if(a[i+1] - a[i] < 0 && flaglag == 1){
        flag = 0;
        cnt++;
      }else{
        continue;
      }
    }
  }
  cout << cnt <<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
		return 0;
	}
	else {
		cout << "win" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

int const INF = 1e9;

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

struct state {
  int score_k;
  int type;
  int last[26];
  int score;
  std::vector<state>::iterator prev;
  bool operator< (state const& rhs) const { return score_k > rhs.score_k; } // reverse order
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  int const B = 820;
  int const K = 3;
  std::vector<int> t(D);
  
  std::vector<std::vector<state>> states(D+1);
  auto beam_step = [&](int d, int k) {
    auto& prev = states[d];
    auto& curr = states[d+1];
    curr.reserve(prev.size()*26);
    int dd = std::min(d+k, D-1);
    for(auto it = prev.begin(); it != prev.end(); ++it) {
      for(int T = 0; T < 26; ++T) {
        curr.push_back(*it);
        state& st = curr.back();
        st.prev = it;
        st.last[T] = d;
        st.type = T;
        st.score_k = st.score + s[d][T];
        for(int cx = 0; cx < 26; ++cx) {
          st.score_k -= c[cx]*(d+dd - 2*st.last[cx])*(dd-d+1)/2;
        }
      }
    }
    std::sort(curr.begin(), curr.end());
    if(curr.size() > B) curr.resize(B);
    for(auto& st: curr) {
      st.score += s[d][st.type];
      for(int cx = 0; cx < 26; ++cx) {
        st.score -= c[cx]*(d - st.last[cx]);
      }
    }
  };
  
  auto beam_search = [&](int k) {
    states.assign(D+1, std::vector<state>());
    states[0].emplace_back();
    states[0][0].score = 0;
    states[0][0].score_k = 0;
    std::fill_n(states[0][0].last, 26, -1);
    for(int d = 0; d < D; ++d) beam_step(d, k);
    auto it = states[D].begin();
    for(int d = D-1; d >= 0; it = it->prev, --d) {
      t[d] = it->type;
    }
  };
  beam_search(K);
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 971608
#include <iostream>

using namespace std;

int main()
{
    int n,m,p;
    cin>>n>>m;
    int l[m],r[m],q;
    for(int i=0;i<m;i++)
    {
        cin>>l[i];
        cin>>r[i];

    }
    p=l[0];
    q=r[0];
    for(int i=1;i<m;i++)
    {
         if(l[i]>p)
            p=l[i];
        if(r[i]<q)
            q=r[i];
    }
    if(q-p+1>0)
        cout<<q-p+1;
    else
        cout<<0;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>
#include <queue>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 100010;

int t[N], a[N], b[N], c[N];

bool cmp(int x, int y) { return a[x] - b[x] > a[y] - b[y];}

priority_queue<int> ql, qr; 

LL ta[N], tb[N];

int main()
{
	int x, y, z;
	LL sum = 0;
	scanf("%d%d%d", &x, &y, &z);
	Rep(i, x + y + z){
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		t[i] = i, a[i] -= c[i], b[i] -= c[i], sum += c[i];
	}
	sort(t + 1, t + 1 + x + y + z, cmp);
	
	//Rep(i, x + y + z) printf("%d %d %d\n", t[i], a[t[i]], b[t[i]]);
	
	Rep(i, x){
		ql.push(-a[t[i]]);
		ta[x] += a[t[i]];
	}
	
	for (int i = x + 1; i <= x + z; i ++) {
		LL tmp = ta[i - 1];
		if (a[t[i]] > -ql.top()) {
			tmp += ql.top() + a[t[i]];
			ql.pop(); ql.push(-a[t[i]]);
		}
		ta[i] = max(tmp, ta[i - 1]);
	}
	
	for (int i = x + y + z; i >= x + z + 1; i --){
		qr.push(-b[t[i]]);
		tb[x + z + 1] += b[t[i]];
	}
	
	for (int i = x + z; i >= x + 1; i --) {
		LL tmp = tb[i + 1];
		if (b[t[i]] > -qr.top()) {
			tmp += qr.top() + b[t[i]];
			qr.pop(); qr.push(-b[t[i]]);
		}
		tb[i] = max(tmp, tb[i + 1]);
	}
	LL ans = 0;
	for (int i = x; i <= x + z; i ++) ans = max(ans, ta[i] + tb[i + 1] + sum);
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)

int main() {

    bool cnt = false;
    int n;
    int a;
    int ans = 0;
    scanf("%d", &n);
    Repe(i,n+1,1){
        scanf("%d", &a);
        if( a == i ){
            if( cnt ) {
                ans++; cnt = false;
            }else{
                cnt = true;
            }
        }else{
            if( cnt ){
                ans++; cnt = false;
            }
        }
    }

    if( cnt ) ans++;

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MOD = 1e9 + 7;

int main(){
    string s, t; cin >> s >> t;

    cout << t + s << endl;

    return 0;
}

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

int main() {
    // ifstream in("data.txt");
    // cin.rdbuf(in.rdbuf());
    // 入力
    int n, m;
    cin >> n >> m;
    vector<int> P(m), Y(m);
    for(int i = 0; i < m; ++i)
        cin >> P[i] >> Y[i], --P[i];

    // vals[v] := P[i] = v であるような i についての Y[i] の値を集めたもの
    vector<vector<int>> vals(n);
    for(int i = 0; i < m; ++i)
        vals[P[i]].push_back(Y[i]);

    // 各 p の値に対して
    for(int v = 0; v < n; ++v) {
        sort(vals[v].begin(), vals[v].end());

        // 今回は不要だが、通常は数のダブりをなくす
        vals[v].erase(unique(vals[v].begin(), vals[v].end()), vals[v].end());
    }

    // 答え
    for(int i = 0; i < m; ++i) {
        int v = P[i];
        printf("%06d", v + 1);

        // 座標圧縮して導いた答え
        int id =
            lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
        printf("%06d\n", id + 1);
    }
}


Measured memory_bytes: 7808
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

route = {}
point = {}

for idx, p in enumerate(P):
    route[idx+1] = p
    point[p] = C[p-1]

all_max = -float('inf')
for origin_start in range(1, N+1):
    visit = set()
    visit.add(origin_start)
    now_point = 0
    max_point = -float('inf')
    start = origin_start
    for k in range(K):
        now_point += point[start]
        max_point = max(max_point, now_point)
        start = route[start]
        if start in visit:
            roup_count = k + 1
            roup_point = now_point
            if now_point > 0:
              if K // roup_count >= 0:
                now_point = (K // roup_count) * roup_point
                start = origin_start
                for _ in range(K % roup_count):
                    now_point += point[start]
                    max_point = max(max_point, now_point)
                    start = route[start]

              if K // roup_count - 1 >= 0:
                now_point = (K // roup_count - 1) * roup_point
                start = origin_start
                for _ in range(roup_count):
                    now_point += point[start]
                    max_point = max(max_point, now_point)
                    start = route[start]
            break
        visit.add(start)

    all_max = max(max_point, all_max)
print(all_max)

Measured memory_bytes: 115748
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    cin >> s;

    int ans = 0;
    REP(i, 1 << (s.size() - 1)) {
        int sum = 0;
        string sub = "";
        REP(j, s.size()) {
            sub += s[j];
            if (i >> j & 1) {
                sum += atol(sub.c_str());
                sub = "";
            }
        }
        if (sub != "") {
            sum += atol(sub.c_str());
        }

        ans += sum;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()

int main()
{
	int n;
	cin >> n;
	while (n--){
		string m, s;
		cin >> m >> s;
		reverse(all(m));
		for (int i = 0; i < m.size(); i++){
			if (m[i] == 'C'){
				string a(s, 0, 1);
				string b(s, 1, s.size() - 1);
				s = b + a;
			}
			else if (m[i] == 'J'){
				string a(s, 0, s.size() - 1);
				string b(s, s.size() - 1, 1);
				
				//cout << s << " " << a << " " << b << endl;
				
				s = b + a;
			}
			else if (m[i] == 'E'){
				string a(s, 0, s.size() / 2);
				string b(s, s.size() / 2, s.size() % 2);
				string c(s, s.size() / 2 + s.size() % 2, s.size() / 2);
				s = c + b + a;
			}
			else if (m[i] == 'A'){
				reverse(all(s));
			}
			else if (m[i] == 'M'){
				for (int j = 0; j < s.size(); j++){
					if (s[j] >= '0' && s[j] <= '8'){
						s[j]++;
					}
					else if (s[j] == '9'){
						s[j] = '0';
					}
				}
			}
			else if (m[i] == 'P'){
				for (int j = 0; j < s.size(); j++){
					if (s[j] >= '1' && s[j] <= '9'){
						s[j]--;
					}
					else if (s[j] == '0'){
						s[j] = '9';
					}
				}
			}
		}
		
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;

string s1,s2,s3;
int a[200005];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);

    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 412;
const ll inf = 1e15;
ll n,a[MN],dp[MN][MN],pf[MN];
int main (void) {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> a[i];
    pf[0] = a[0];
    for (ll i = 0; i < n; i++) pf[i+1] = pf[i]+a[i+1];
    for (ll i = 0; i < n; i++)
        for (ll j = 0; j < n; j++)
            dp[i][j] = inf;
    for (ll l = n-1; l >= 0; l--) {
        for (ll r = l; r < n; r++) {
            if (l == r) dp[l][r] = 0;
            else {
                ll ps = (l == 0) ? pf[r] : pf[r]-pf[l-1];
                for (ll i = l; i < r; i++)
                    dp[l][r] = min(dp[l][r], dp[l][i]+dp[i+1][r]+ps);
            }
        }
    }
    cout << dp[0][n-1] << '\n';
    return 0;
}



Measured memory_bytes: 1536
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[N];
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	vector <pair <int, int> > v;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		v.pb(mp(x, 1));
	}
	for (int j = 0; j < m; j++){
		int x;
		cin >> x;
		v.pb(mp(x, 2));
	}
	sort(all(v));
	int res = 0;
	n++;
	m++;
	for (int i = 0; i < v.size(); i++){
		if (v[i].s == 1){
			res += m * v[i].f;
			n--;
		}
		else{
			res += n * v[i].f;  
			m--;
		}
	}
	cout << res;
	return 0;
}












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

int main() {
	int a,b;
  cin >> a >> b;
  a%=500;
  if (a==0)
    cout << "Yes" <<endl;
  else if (a<=b)
    cout << "Yes" <<endl;
  else
    cout << "No" <<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    while(true){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }

}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>

using namespace std;

int main () {
    int y, m, d;

    scanf("%d/%d/%d", &y, &m, &d);

    if (y < 2019) {
        cout << "Heisei" << endl;
    }
    else if (m <= 4) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }

    return 0;
}

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

using namespace std;

struct LinearCHT
{
    #define m first
    #define c second
    #define queryDir 1 // 1 if queries are increasing, -1 if decreasing
    typedef long long ftype;
    typedef pair<ftype,ftype> line;
    ftype f(line l,ftype x) { return l.m*x+l.c; }
    bool bad(line l1,line l2,line l3)
    {
        return (l3.c-l1.c)*(l1.m-l2.m)<=(l2.c-l1.c)*(l1.m-l3.m);
    }
    deque<line> q;
    int curQ;
    void init()
    {
        q.clear();
        curQ = 0;
    }
    void add_line(ftype a,ftype b)
    {
        line l = line(a,b);
        if (q.size()==0)
        {
            q.push_back(l);
            return;
        }
        bool left = (l.m>=q.at(0).m);
        while(q.size()>=2)
        {
            if (left)
            {
                line l1 = q.at(0) , l2 = q.at(1);
                if (!bad(l,l1,l2))
                    break;
                q.pop_front();
                curQ-=queryDir;
            }
            else
            {
                line l1 = q.at(q.size()-2) , l2 = q.at(q.size()-1);
                if (!bad(l1,l2,l))
                    break;
                q.pop_back();
                curQ-=queryDir;
            }
        }
        if (left)
            q.push_front(l);
        else
            q.push_back(l);
    }
    ftype query(ftype x)
    {
        if (curQ<0)curQ=0;
        if (curQ>=q.size()) curQ = (int)q.size()-1;
        while(curQ+queryDir<q.size() && curQ+queryDir>=0 && f(q.at(curQ+queryDir),x)<f(q.at(curQ),x))
            curQ+=queryDir;
        return f(q.at(curQ),x);
    }
};


const ll N = 200200;

ll a[N];
ll Dp[N];

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

    for(ll i = 0; i < n; i++)   scanf("%I64d", a + i);

    LinearCHT ConvexHull;

    Dp[n - 1] = 0;
    ConvexHull.add_line( 2 * a[n - 1], a[n - 1] * a[n - 1] + Dp[n - 1]);

    for(ll i = n - 2; ~i; --i)
    {
        Dp[i] = a[i] * a[i] + C + ConvexHull.query(-a[i]);

        ConvexHull.add_line( 2 * a[i], a[i] * a[i] + Dp[i]);
    }

    cout << Dp[0];
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;


ve<int> U,Us;


int check(int a){
    if(a == U[a]) return a;
    else return U[a] = check(U[a]);
    
}


void UnionFind(int a, int b){
    int aa = check(a);
    int bb = check(b);
    if(aa == bb) return;
    
    if(Us[aa] > Us[bb]){
        Us[aa] += Us[bb];
        U[bb] = aa;
    }else{
        Us[bb] += Us[aa];
        U[aa] = bb;
    }
    
}



int main()
{
    int N,M;
    cin >> N >> M;
    ve<int> p(N);
    in(N,p);
    rep(i,N) p[i]--;
    
    U.res(N);
    Us.assign(N,1);
    rep(i,N) U[i] = i;
    
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--,y--;
        UnionFind(x,y);
    }
    int ans = 0;
    
    rep(i,N) if(check(i) == check(p[i])) ans++;
    
    out(ans);

    //outve(U);

    return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

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

const int INF = 1 << 29;
const double EPS = 1e-10;

int W, H;
int field[52][52];

void dfs(int x, int y) {
  field[y][x] = 0;

  REP(dx, -1, 2) REP(dy, -1, 2) {
    int tx = x + dx;
    int ty = y + dy;
    if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue;
    if (field[ty][tx]) dfs(tx, ty);
  }
}

int main() {
  for(; cin >> W >> H, (W | H) != 0; ) {

    rep(i, H) rep(j, W) cin >> field[i][j];

    int ans = 0;
    rep(i, H) rep(j, W) if (field[i][j]) {
      dfs(j, i);
      ans++;
    }

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

Measured memory_bytes: 1312
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int n; cin >> n;
    vector<int> a(n); for(auto& x: a) cin >> x;
    map<int, int> mapp;
    for(auto x: a) mapp[x]++;

    int limit = 1000001;
    vector<int> count(limit);
    for (auto&[x, m] : mapp) {
        for (int i = x; i < limit; i += x) {
            count[i] += m;
        }
    }

    int ans = 0;
    FOR(i, 0, n) {
        if (count[a[i]] == 1) ++ans;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 17100
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;

int main()
{
	int h,w;
	char mp[MaxN ][MaxN ];
	scanf("%d%d",&h,&w);
	for(int i = 1 ; i <= h ; i++)
		for(int j = 1 ; j <= w ; j++)
			cin >> mp[i][j];
	for(int i = 1 ; i <= h ; i++)
	{
		for(int cnt = 1 ; cnt <= 2 ; cnt++)
		{
		for(int j = 1 ; j <= w ; j++)
				printf("%c",mp[i][j]);
				printf("\n");
		}
	}
	return 0;
	}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%lld\n", (ll)a % b == 0 ? -1LL : (ll)a * (b - 1));
	
	Please AC;
}


Measured memory_bytes: 256
n = int(input())
heights = list(map(int, input().split()))

def solve(heights, beg, end) -> int:
    if beg >= end: return 0
    try:
        idx = beg + heights[beg:end].index(0)
        return  solve(heights, beg, idx) + solve(heights, idx+1, end)
    except ValueError:
        pass
    
    minh = min(heights[beg:end])
    for i in range(beg, end):
        heights[i] -= minh
    return minh + solve(heights, beg, end)

cnt = solve(heights, 0, len(heights))
print(cnt)

Measured memory_bytes: 9196
#include "bits/stdc++.h"
using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RFOR(i,1,n+1)
#define ALL(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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; }
using ll = long long;
#define int ll

bool Fcomp(const pair<int,int>& firstElof, const pair<int,int>& secondElof)
{return firstElof.F < secondElof.F;}
bool Scomp(const pair<int,int>& firstElof, const pair<int,int>& secondElof)
{return firstElof.S < secondElof.S;}

//**********
//10:57-11:05, 15:05-

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    int a[100010] = {};
    int ans[100010] = {};
    cin >> n;
    REP(i,n){cin >> a[i+1];}
    a[0] = 0;
    a[n+1] = 0;
    
    int total = 0;
    REP(i,n+1){
        total += abs(a[i+1]-a[i]);
    }
    
    REP(i,n){
        if(a[i]<=a[i+1]&&a[i+1]<=a[i+2]){ans[i+1] = total;}
        else if(a[i]>=a[i+1]&&a[i+1]>=a[i+2]){ans[i+1] = total;}
        else{
            ans[i+1] = total - min(abs(a[i+2]-a[i+1]),abs(a[i+1]-a[i]))*2;
        }
    }
    
    REP(i,n){printf("%lld\n",ans[i+1]);}
    //    else printf("No\n");
    
    return 0;
    
}


Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
using namespace std;
 
int main() {
    int a, b; cin>>a>>b;
    int sum = a + b;
    int sub = a - b;
    int mul = a * b;

    int ans = sum;
    ans = max(ans, sub);
    ans = max(ans, mul);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A[10],f,i,j,k,l,a,b;
main(){
    for(auto& c:A)cin>>c;
    for(;j<A[9];j++){
        cin>>b;
        for(k=0;k<9;++k)A[k]*=A[k]!=b;
    }
    string s="012345678036147258048246";
    for(auto c:s){
        a+=A[c-'0'];
        if((++l)%3==0){
            f+=a==0;
            a=0;
        }
    }
    cout<<(f?"Yes":"No");
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

N, M, X = map(int, input().split())
cost_list = []
A_list_list = []
for i in range(N):
    input_list = list(map(int, input().split()))
    cost_list.append(input_list[0])
    A_list_list.append(input_list[1:])
max_cost = sum(cost_list)

def dfs(bool_list, min_cost):
    if len(bool_list) == N:
        cost = 0
        rikaido_list = [0 for k in range(M)]
        for i in range(N):
            if bool_list[i] :
                cost += cost_list[i]
                for j in range(M):
                    rikaido_list[j] += A_list_list[i][j]
        if min(rikaido_list)>=X:
            min_cost = min(min_cost, cost)
        return min_cost
    for b in [True, False]:
        bool_list.append(b)
        min_cost = min(min_cost, dfs(bool_list, min_cost))
        bool_list.pop()
    return min_cost

def main():
    min_cost = max_cost + 1
    min_cost = dfs([], min_cost)
    if min_cost > max_cost:
        min_cost = -1
    print(min_cost)

if __name__ == "__main__":
    main()




Measured memory_bytes: 9268