akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
{
    static void Main()
    {
        while (true)
        {
            string[] raw = Console.ReadLine().Split(' ');
            if(raw[0]=="0")break;
            int h = int.Parse(raw[0]);
            int w = int.Parse(raw[1]);
            for (int x = 0; x < w; x++) Console.Write('#');
            Console.WriteLine();
            for(int y=1;y<h-1;y++){
                Console.Write('#');
                for(int x=1;x<w-1;x++)Console.Write('.');
                Console.WriteLine('#');
            }
            for (int x = 0; x < w; x++) Console.Write('#');
            Console.WriteLine();
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 5304
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//

int main(){
        _upgrade;
        int N;
        cin >> N;
        vector<string> s(N);
        for(int i = 0; i < N; i++) cin >> s[i];

        int ans = 0;
        for(int a = 0; a < N; a++){

                int flag = 1;
                for(int i = 0; i < N; i++){
                        for(int j = 0; j < N; j++){
                                flag &= (s[i][j] == s[j][i]);
                        }
                }
                ans += flag;

                for(int i = 0; i < N; i++){
                        s[i] = s[i].substr(1) + s[i].substr(0,1);
                }
        }

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


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

int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> a(3 * N);
  for (auto& x : a) cin >> x;
  vector<int64_t> sum_red(3 * N);
  {
    priority_queue<int64_t, vector<int64_t>, greater<int64_t>> red;
    int64_t sum = 0;
    for (int i = 0; i < N; ++i) {
      red.push(a[i]);
      sum += a[i];
    }
    for (int64_t k = N; k <= 2 * N; ++k) {
      sum_red[k] = sum;
      red.push(a[k]);
      sum += a[k];
      sum -= red.top();   // Removes min.
      red.pop();          // Removes min.
    }
  }
  vector<int64_t> sum_blue(3 * N);
  {
    priority_queue<int64_t, vector<int64_t>, less<int64_t>> blue;
    int64_t sum = 0;
    for (int i = 3 * N - 1; i >= 2 * N; --i) {
      blue.push(a[i]);
      sum += a[i];
    }
    for (int64_t k = 2 * N; k >= N; --k) {
      sum_blue[k] = sum;
      blue.push(a[k - 1]);
      sum += a[k - 1];
      sum -= blue.top();  // Removes max.
      blue.pop();         // Removes max.
    }
  }
  int64_t best = numeric_limits<int64_t>::min();
  for (int64_t k = N; k <= 2 * N; ++k) {
    // printf("%ld %ld\n", sum_red[k], sum_blue[k]);
    best = max(best, sum_red[k] - sum_blue[k]);
  }
  cout << best << endl;
}


Measured memory_bytes: 9068
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int a, p; cin >> a >> p;

    cout << (a * 3 + p) / 2 << endl;
}


Measured memory_bytes: 256
s = gets.chomp
k = "keyence"

l = s.length - k.length

ans = "NO"

if s == k
  ans = "YES"
else
  8.times do |i|
    if s[0..i] == k[0..i] && s[i + 1 + l..-1] == k[i + 1..-1]
      ans = "YES"
      break
    end
  end
end

puts ans


Measured memory_bytes: 1788
n=int(input())
a=[int(input()) for i in range(n)]
a0=0
ans=0
for ai in a[::-1]:
  
  if ai>a0-1:
    ans+=ai
  elif ai<a0-1:
    print(-1)
    exit()
  a0=ai
  
if a0 !=0:
  print(-1)
else:
  print(ans)
  

Measured memory_bytes: 12584
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=100005;
const int M=35;
const int INF=0x3f3f3f;
const ull sed=31;
const ll mod=1e9+7;
const double eps=1e-8;
typedef pair<int,int>P;
typedef pair<double,double>Pd;

ll dp[N][2];
char s[N];

int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    dp[0][0]=1;
    dp[0][1]=0;
    for(int i=1;i<=len;i++)
    {
        dp[i][1]=(dp[i-1][1]*3)%mod;
        if(s[i]=='1')
        {
            dp[i][0]=(dp[i-1][0]*2)%mod;
            dp[i][1]=(dp[i][1]+dp[i-1][0])%mod;
        }
        else dp[i][0]=dp[i-1][0];
    }
    printf("%lld\n",(dp[len][0]+dp[len][1])%mod);
    return 0;
}



Measured memory_bytes: 1920
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        double[]p=Console.ReadLine().Split().Select(double.Parse).ToArray();
        double[]dp=new double[n+1];
        dp[0]=1;
        for(int i=0;i<n;i++){
            for(int j=i;j>=0;j--){
                dp[j+1]+=dp[j]*p[i];
                dp[j]*=1-p[i];
            }
        }
        double ans=0;
        for(int i=(n+1)/2;i<=n;i++){
            ans+=dp[i];
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 13408
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long x,k,d;
    cin>>x>>k>>d;
    long long ans;
    long long val;
    if(x<0)
        x=-x;
    long long temp=llabs(x)/d;
    val=llabs(x-min(temp,k)*d);
    if(temp>=k)
    {
        ans=val;
    }
    else
    {
        k=k-temp;
        if(k%2!=0)
            ans=llabs(val-d);
        else
            ans=val;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
sx, sy, tx, ty = map(int, input().split())
W = tx-sx
H = ty-sy
print(
  "R" * W +
  "U" * H +
  "R" +
  "D" * (H + 1) +
  "L" * (W + 1) +
  "U" * (H + 1) +
  "R" * W +
  "U" +
  "L" * (W + 1) +
  "D" * (H + 1) +
  "R"
)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var p = int.Parse(_[0]);
            var q = int.Parse(_[1]);
            var r = int.Parse(_[2]);

            var l = new int[3];
            l[0] = p + q;
            l[1] = p + r;
            l[2] = q + r;

            Console.WriteLine(l.Min());
        }
    }
}


Measured memory_bytes: 13268
#!/usr/bin/env python3

# input = stdin.readline



def main():
  N = int(input())
  h = list(map(int,input().split()))
  highest = 0
  res = 0
  for i in range(N):
    if h[i] >= highest:
      res += 1
      highest = h[i]
  print(res)
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9108
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n; cin >> n;
  vi a(n), b(n), c(n - 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n - 1) cin >> c[i];

  int ans = 0;
  ans += accumulate(all(b), int());
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] + 1 == a[i + 1]) {
      ans += c[a[i] - 1];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())

ans = "Yes"
i = 0

while i < N:
  t,x,y = [ int(num) for num in input().split() ]
  
  if x+y <= t and (t-x-y)%2 == 0:
    i += 1
  else:
    ans = "No"
    break

print(ans)

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<string>> s(h, vector<string> (w));
    rep(i, h) {
        rep(j, w) {
            cin >> s[i][j];
        }
    }
    rep(i, h) {
        rep(j, w) {
            if(s[i][j] == "snuke") {
                char ans = 'A' + j;
                cout << ans << i + 1 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(void){
  int n;
  cin >> n;
  int x[n];
  rep(i,n){
    cin >> x[i];
  }

  int ans = MAX;
  for(int i=1;i<=100;i++){
    int tmp = 0;
    rep(j,n){
      tmp += (i-x[j])*(i-x[j]);
    }
    if(tmp < ans){
      ans = tmp;
    }
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int N = 1e5+5;
const ll INF = 1000000000000000000;
struct edge{
	int to,cost;
};
int n;
vector<edge>g[N];
ll d[N];
void dij(int s)
{
	priority_queue<P ,vector<P> , greater<P> > que;
	fill (d+1,d+n+1,INF);
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty())
	{
		P p =que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first) continue;
		for(int i=0;i<g[v].size();i++)
		{
			edge e = g[v][i];
			if(d[e.to]>d[v]+e.cost)
			{
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	} 
}
int main()
{
	int a,b,c;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		edge x;
		x.to = b;x.cost=c;
		g[a].push_back(x);
		x.to = a;
		g[b].push_back(x); 
	}
	int q,k;
	scanf("%d%d",&q,&k);
	dij(k);
	for(int i=0;i<q;i++)
	{
		scanf("%d%d",&a,&b);
		//cout<<d[a]<<"  "<<d[b]<<endl;
		cout<<d[a]+d[b]<<endl;
	}
	
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define vvii vector<vii>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

ll n, u, v;
vi val;
vvi ed;
vi sum, res, last;

void solve(ll v, ll p) {
    ll t = 0, cr = last[val[v]];
    REP(i, 0, ed[v].size()) {
        ll c = ed[v][i];
        if (c == p)
            continue;
        last[val[v]] = 0;
        solve(c, v);
        sum[v] += sum[c];
        t = sum[c] - last[val[v]];
        res[val[v]] -= (t*(t+1))/2;
    }
    last[val[v]] = cr + sum[v];
}

int main() {
    fast;
    cin >> n;
    val.resize(n+1);
    ed.resize(n+1);
    sum.resize(n+1, 1);
    res.resize(n+1, (n*(n+1))/2);
    last.resize(n+1, 0);
    REP(i, 1, n+1)
        cin >> val[i];
    REP(i, 0, n-1) {
        cin >> u >> v;
        ed[u].pb(v);
        ed[v].pb(u);
    }
    solve(1, 0);
    ll x;
    REP(i, 1, n+1) {
        x = sum[1] - last[i];
        res[i] -= (x*(x+1))/2;
    }
    REP(i, 1, n+1)
        cout << res[i] << endl;
}


Measured memory_bytes: 35908
n = gets.to_i
pre_sieve = Array.new(n) { |i| i }
sieve = Array.new(n)
ans = 0

s = Math.sqrt(n - 1).to_i
2.upto(s) do |i|
  ((n - 1) / i).times do |j|
    pre_sieve[i * (j + 1)] = i if i < pre_sieve[i * (j + 1)]
  end
end

2.upto(n - 1) do |i|
  h = Hash.new(0)
  x = i
  while x != 1
    h[pre_sieve[x]] += 1
    x /= pre_sieve[x]
  end
  sieve[i] = h
end

2.upto(n - 1) do |i|
  x = 1
  sieve[i].each_value do |j|
    x *= (j + 1)
  end

  ans += x
end

puts ans + 1


Measured memory_bytes: 214844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define pb push_back

signed main()
{
  int N;
  string S;
  cin >> N >> S;
  
  int l = 0, r = N / 3 + 1;
  while (l + 1 < r) {
    bool flag[1000005] = {0}, f = true;
    int m = (l + r) / 2, i, cnt;
    vector<int> I_idx, O_idx;
    for (i = N - 1, cnt = 0; i >= 0 && cnt < m; i--) {
      if (S[i] == 'I') {
	flag[i] = true, cnt++;
	I_idx.pb(i);
      }
    }
    if (cnt < m) f = false;
    if (f) {
      for (i = N - 1, cnt = 0; i >= 0 && cnt < m; i--) {
	if (S[i] == 'O' && I_idx[cnt] > i) {
	  flag[i] = true, cnt++;
	  O_idx.pb(i);
	}
      }
      if (cnt < m) f = false;
    }
    if (f) {
      for (i = N - 1, cnt = 0; i >= 0 && cnt < m; i--) {
	if (!flag[i] && (S[i] == 'J' || S[i] == 'I') && O_idx[cnt] > i)cnt++;
      }
      if (cnt < m) f = false;
    }
    if (f) l = m;
    else r = m;
  }
  cout << l << endl;
  return 0;
}

Measured memory_bytes: 14092
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main() 
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a-b==b-c)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nab = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            if ((nab[2] - nab[1]) % 2 == 0)
            {
                Console.WriteLine((nab[2] - nab[1]) / 2);
                return;
            }
            else
            {
                var left = nab[2] - 1;
                var right = nab[0] - nab[1];
                if (nab[1] == 1 || left <= right && nab[2] != nab[0])
                {
                    var tmp = nab[1];
                    Console.WriteLine(tmp + ((nab[2] - tmp) / 2));
                    return;
                }
                else
                {
                    var tmp = nab[0] - nab[2] + 1;
                    Console.WriteLine(tmp + ((nab[0] - (nab[1] + tmp)) / 2));
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 13396
//21:49
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int D[N];
vector<int>V[N];
int stk[N],cnt=0;
bool vis[N];
void dfs(int No)
{
	vis[No]=true;stk[cnt++]=No;
	for(auto j:V[No]){
		if(!vis[j])dfs(j);
	}
}
map<int,int>Q;
int main()
{
	//freopen("/home/zz7/CFInput","r",stdin);
	int n,m;scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%d",&D[i+1]);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		V[a].push_back(b),V[b].push_back(a);
	}int ans=0;
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			cnt=0;
			dfs(i);Q.clear();
			for(int i=0;i<cnt;i++)Q[stk[i]]=1;
			for(int i=0;i<cnt;i++)if(Q[D[stk[i]]]==1)ans++;
		}
	cout<<ans<<'\n';
}


Measured memory_bytes: 13312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


class Main
{	
	
	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
		
		int n = fs.nextInt();
		long balance = 1000,stocks=0;
		int arr[] = fs.arrayIn(n);

		for(int i=1; i<n; i++)
		{
				while (i<n && arr[i-1]>=arr[i]) i++;
				
				if(i < n)
				{
					stocks = balance/arr[i-1];
					balance = balance%arr[i-1];
				}
				i++;
				while(i<n && arr[i-1]<= arr[i]) i++;
				if(i < n)
				{
					balance += stocks*arr[i-1];
					stocks = 0;
				}
				
		}
		if(balance < 1000)
		{
			balance += stocks*arr[n-1];
			stocks = 0;
		}
		System.out.println(balance);
		
			
	}


	
}
class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int[] arrayIn(int n) throws IOException
	{
		int arr[] = new int[n];
		for(int i=0; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
}



	

Measured memory_bytes: 32736
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

ll gcd(ll a, ll b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}
//b is not 0
ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

int main(){
    int n; cin >> n;
    ll ans = 1;
    for(int i = 0; i < n; i++){
        ll t; cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 10;
const ll INF = 1e18;

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

int main(){
    //cout << INF << endl;
    int x,y;
    scanf("%d%d",&x,&y);
    if(x < y) return 0 * printf("%d\n",x);
    if(x % y == 0) return 0 * printf("-1\n");
    ll ans = 1ll * x * x / (ll)gcd(x,y);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
int n, m;
int a[maxn], b[maxn], num[maxn];
int read() {
	int x; scanf("%d", &x); return x;
}
int main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	n = read();
	for (int i = 1; i <= n; ++i) a[i] = read(), num[a[i]]++;
	long long ans = 0;
	for (int i = 1; i <= n; ++i) ans += a[i];
	m = read();
	while (m--) {
		int x = read(), y = read();
		num[y] += num[x]; 
		ans += (y - x) * num[x];
		num[x] = 0;
		cout << ans << endl;
	}
}	

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
int main(){
int w,a,b;
cin>>w>>a>>b;
  if((a<=b&&b-w<=a)||(a-w<=b&&b<=a)){
    cout<<"0"<<endl;
    return 0;
  }

    if(b+w<a){
        cout<<a-b-w<<endl;
        return 0;
    }
    else{
        cout<<b-a-w<<endl;
        return 0;
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())

S = 'AGCT'  # AGCT = 0123
num = [[[1]*4 for _ in range(4)] for _ in range(4)]

count = 0
if N == 3:
    print(61)
    exit()
for i in range(4, N+1):
    num_now = [[[0] * 4 for _ in range(4)] for _ in range(4)]
    for pre3 in range(4):
        for pre2 in range(4):
            for pre1 in range(4):
                for now in range(4):
                    now_S = S[pre2] + S[pre1] + S[now]
                    now_S2 = S[pre3] + S[pre2] + S[pre1]
                    if now_S2 != 'AGC' and now_S2 != 'GAC' and now_S2 != 'ACG' and now_S != 'AGC' and now_S != 'GAC' and now_S != 'ACG' and S[pre3] + S[pre1] + S[now] != 'AGC' and S[pre3] + S[pre2] + S[now] != 'AGC':
                        num_now[now][pre1][pre2] += num[pre1][pre2][pre3]
                        if i == N:
                            count += num[pre1][pre2][pre3]

    num = num_now.copy()


print(count%((10**9) + 7))


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

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

    vector<ll> dp(n);

    rep(i,n){
        if(i == 0) {
            dp[i] = 1000;
            continue;
        }

        ll temp = dp[i-1];
        rep(j,i){
            temp = max(temp,dp[j]%v[j]+(dp[j]/v[j])*v[i]);
        }
        dp[i]  = temp;
    }

    cout << dp[n-1] << endl;

    
}

Measured memory_bytes: 3584
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static final int MOD = 998244353;

	static int add(int a, int b) {
		int res = a + b;
		return res >= MOD ? res - MOD : res;
	}

	static int sub(int a, int b) {
		int res = a - b;
		return res < 0 ? res + MOD : res;
	}

	static int mul(int a, int b) {
		int res = (int) ((long) a * b % MOD);
		return res < 0 ? res + MOD : res;
	}

	static int pow(int a, int e) {
		if (e == 0) {
			return 1;
		}
		int r = a;
		for (int i = 30 - Integer.numberOfLeadingZeros(e); i >= 0; i--) {
			r = mul(r, r);
			if ((e & (1 << i)) != 0) {
				r = mul(r, a);
			}
		}
		return r;
	}

	static int inv(int a) {
		return pow(a, MOD - 2);
	}

	static void solve() throws Exception {
		int n = scanInt();
		long a = scanLong();
		long b = scanLong();
		long k = scanLong();
		int facts[] = new int[n + 1];
		facts[0] = 1;
		for (int i = 1; i <= n; i++) {
			facts[i] = mul(facts[i - 1], i);
		}
		int factsI[] = new int[n + 1];
		factsI[n] = inv(facts[n]);
		for (int i = n; i > 0; i--) {
			factsI[i - 1] = mul(factsI[i], i);
		}
		int ans = 0;
		for (int i = 0; i <= n; i++) {
			long r = k - a * i;
			if (r < 0 || r > n * b || r % b != 0) {
				continue;
			}
			int j = (int) (r / b);
			ans = add(ans, mul(mul(facts[n], mul(factsI[i], factsI[n - i])), mul(facts[n], mul(factsI[j], factsI[n - j]))));
		}
		out.print(ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

 
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}


int main(){
    dcl(n,m);
    vector<vector<pii>> el(n+1);
    set<pii> used; 
    rep(i,m){
        dcl(a,b,c);
        el[a].eb(b,c);
        el[b].eb(a,c);
    }
    vvi distMat(n+1,vi(n+1,0));
    for(int st=1;st<=n;st++){
        vi ans(n+1,-1);
        ans[0]=0;
        using edge=pair<int,pii>;
        auto cmp=[](edge a, edge b){return a.fs>b.fs;};
        priority_queue<edge, vector<edge>, decltype(cmp)> que(cmp);
        que.emplace(0,mp(st,st));
        while(!que.empty()){
            auto t=que.top();
            que.pop();
            int cost=t.fs;
            int prev=t.sc.fs;
            int curr=t.sc.sc;
            
            if(ans[curr]==-1){
                ans[curr]=cost;
                if(prev!=curr){
                    if(prev>curr){
                        used.emplace(curr,prev);
                    }else{
                        used.emplace(prev,curr);
                    }
                }
                for(auto l:el[curr]){
                    que.emplace(cost+l.sc,mp(curr,l.fs));
                }
            }
        }
        distMat[st]=ans;
    }
    
    //putii(distMat);
    cout<<m-used.size()<<endl;
}


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

#define Ff(i,a,b) for(i=a;i<b;i++)
#define Fb(i,a,b) for(i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define mp make_pair
#define PI 2*asin(1)
#define all(x) x.begin(),x.end()
#define trav(x) for(auto& i:x)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define spc ' '

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<long long> vll;
typedef map<int, int> mi;
typedef map<long long, long long> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<long long, long long> umll;
typedef set<int> si;
typedef set<long long> sll;
typedef unordered_set<int> usi;
typedef unordered_set<long long> usll;

// #define int long long

void sub() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
}


void solve() {
	int d, t, s;
	cin >> d >> t >> s;
	if (t * s >= d)cout << "Yes";
	else cout << "No";
	cout << endl;
}



int32_t main() {
	FIO
	sub();
	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}




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

int main(){
    int N;
    cin>>N;

    vector<long long> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    long long money=1000;
    long long kabu=0;
    for(int i=0;i<N-1;i++){
        if(A[i]<A[i+1]){
            kabu+=money/A[i];
            money%=A[i];
        }else if(A[i]>A[i+1]){
            money+=kabu*A[i];
            kabu=0;
        }
    }
    money+=kabu*A[N-1];
    cout<<money<<endl;

    return 0;
}

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

int main() {
  ll l,r; 
  cin >> l >> r;
  
  int m = 2018;
  
  r = min(r, l+2019);
  for (ll i=l; i<r; i++){
    for (ll j=i+1;j<=r;j++){
      int x = i*j%2019;
      m = min(m, x);
    }
  }
  cout << m << endl;
}


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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    string s;
    cin >> s;
    multiset<char>m(s.begin(), s.end());
    if(m.count('7') >= 1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3612
#!/usr/bin/env pyton3

num=input().split()

N = int(num[0])
M = int(num[1])

AB = []

for a in range(1,N+1):
    date = []
    date2 = input().split()

    date.append(int(date2[0]))
    date.append(int(date2[1]))

    AB.append(date)

AB.sort(key = lambda x:x[0])

total_num = 0
price = 0


for i in range(1,N+1):
    if total_num < M:
        total_num += AB[i-1][1]
        price += AB[i-1][0] * AB[i-1][1]
        j = i

defference = total_num - M

price -= AB[j-1][0] * defference

print(price)
    

    

            
        
    



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

using namespace std;
#define ull unsigned long long
#define ll long long

/*-----------------------------------------------------MATH------------------------------------------------*/
inline ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

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

inline int pwm(ll xx, ll pow, int MD) {
    if (pow < 0) { pow = pow % (MD - 1) + MD - 1; }
    ll mlt = 1;
    while (pow) {
        if (pow & 1) {
            mlt *= xx;
            mlt %= MD;
        }
        xx *= xx;
        pow >>= 1;
        xx %= MD;
    }
    return (int) mlt;
}

inline ll gcdex(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll xx, yy;
    ll gc = gcdex(b, a % b, yy, xx);
    x = xx;
    y = yy - (a / b) * xx;
    return gc;
}

inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }

/*-----------------------------------------------------MATH------------------------------------------------*/

const int inf = 1e6;
const int MAXN = 2e5 + 10;
ll mod = 998244353;
vector<vector<int>> vert(1e5+10, vector<int>(0));
vector<int> depth(1e5+10, 0);
vector<int> parent(1e5+10, -1);
vector<bool> was(1e5+10, false);
int fix;
int delta=0;
int nowvert=-1;

void dfs(int v, int u, int lvl){
    was[v]=true;
    if(v==u){
        fix=(lvl-1)/2;
        if(lvl%2==0) delta=1;
    }
    for(int son:vert[v]){
        if(was[son]) continue;
        parent[son]=v;
        dfs(son, u, lvl+1);
        depth[v]=max(depth[v], depth[son]+1);
    }
}
void solve() {
    int n;
    cin>>n;
    int u,v;
    cin>>u>>v;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        vert[a].push_back(b);
        vert[b].push_back(a);
    }
    dfs(v, u, 0);
    for(int i=1;i<n+1;i++) was[i]=false;
    int ans=fix;
    while(fix){
        u=parent[u];
        fix--;
    }
    ans+=depth[u]+delta;
    cout<<ans;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n = 1;
    for (int i = 0; i < n; i++) solve();
    return 0;
}

Measured memory_bytes: 12928
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC113_2 solver = new ABC113_2();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC113_2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int T = in.nextInt();
            int A = in.nextInt();
            int ANS = 0;
            int diff_from_a = 2147483647;

            int evaluated[] = new int[N];


            for (int i = 0; i < N; i++) {
                int H = in.nextInt();
                int WK = (int) ((T * 1000) - H * 6);
                int cc = Math.abs(WK - (A * 1000));
                if (diff_from_a > cc) {
                    diff_from_a = cc;
                    ANS = i + 1;
                }
//            evaluated[i]= WK;
            }
        /*
        for (int i = 0; i < evaluated.length; i++) {
            if (evaluated[i] < A) {
                if (Math.abs(diff_from_a) >  Math.abs((A*1000) - evaluated[i])) {
                    diff_from_a = (int) Math.abs((A*1000) - evaluated[i]);
                    ANS = i + 1;
                }
            } else {
                // evaluated[i] >= A
                if (Math.abs(diff_from_a) >  Math.abs(evaluated[i]-(A*1000))) {
                    diff_from_a = (int) Math.abs(evaluated[i]-(A*1000));
                    ANS = i + 1;
                }
            }
        }
        */
/*
            if (A > 0)  {
                if (Math.abs(diff_from_a) > (int) Math.abs(A-WK)) {
                    diff_from_a = (int) Math.abs(A-WK);
                    ANS = i + 1;
                }
            } else {
                if (Math.abs(diff_from_a) > (int) Math.abs(A + WK)) {
                    diff_from_a = (int) Math.abs(A + WK);
                    ANS = i + 1;
                }
            }
*/
            /*
            if (diff_from_a < 0) {
                if (diff_from_a > WK) {
                    diff_from_a = (int) (A - (T - H * 0.006));
                    ANS = i + 1;
                }
            } else {
                if (diff_from_a > (int) (A-(T - H * 0.006))) {
                    diff_from_a = (int) (A - (T - H * 0.006));
                    ANS = i + 1;
                }
            }
            */
            //}
            out.println(ANS);
        }

    }
}



Measured memory_bytes: 23508
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n, k;
    double ans = 0;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
    vector<double> exp(n);
    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 1; j <= p.at(i); j++) {
            sum += j;
        }
        exp.at(i) = (double)sum / p.at(i);
    }
    vector<double> s(n + 1, 0);
    for (int i = 0; i < n; i++) {
        s.at(i + 1) += s.at(i) + exp.at(i);
    }
    for (int i = 0; i < n - k + 1; i++) {
        ans = max(ans, s.at(i + k) - s.at(i));
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) {return log(b) / log(a);}

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i, n) {
		cin >> h[i];
	}
	vector<int> a(n);
	a[0] = 0;
	FOR(i, 1, n) {
		int mi = INF;
		rep(j, k) {
			if (i - j - 1 < 0) {
				continue;
			}
			mi = min(mi, a[i - j - 1] + abs(h[i] - h[i - j - 1]));
		}
		a[i] = mi;
	}
	cout << a[n - 1] << endl;
}


Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-20;
const long double INF = 1e18;

#define MAX_N 20001
int par[MAX_N];
int rank[MAX_N];

void init(int n){
	REP(i,n){
		par[i]=i;
		rank[i]=0;
	}
}

int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(rank[x]<rank[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rank[x]==rank[y]) rank[x]++;
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

int main(){
	int N,M;
	while(cin>>N>>M&&N){
		vector<pair<long,PII> >pi;
		REP(i,M){
			long t;
			int s,d;
			cin>>t>>s>>d;
			pi.PB(MP(t,MP(s,d)));
		}
		SORT(pi);
		int res=1;
		init(N+1);unite(0,1);
		REP(i,SZ(pi)){
			if(same(pi[i].second.first,0)&&!same(pi[i].second.second,0)){
				res++;
				unite(pi[i].second.second,0);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 2000
// problem: "https://atcoder.jp/contests/abc158/tasks/abc158_b"

#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll n,a,b;
    cin>>n>>a>>b;

    cout<<a * (n/(a+b)) + min(a,n%(a+b));

    return 0;
}


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

int main(){
    ll n,k,ans=0,ret=0;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a[i];
    }
    for(int i = 40;i >= 0;i --){
        ll mask=1ll<<i;
        ll cnt = 0;
        for(int j = 0;j < n;j ++){
            if(a[j]&mask) cnt ++;
        }
        if(cnt>=n-cnt){
            ans += mask*cnt;
        }else{
            if(mask+ret<=k){
                ans += mask*(n-cnt);
                ret += mask;
            }else{
                ans += mask*cnt;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main ()
{
    int a,b;
    
    scanf("%d %d",&a,&b);
     if (a < b){
         printf("a < b\n");
     }
     else if(a > b){
         printf("a > b\n");
     }
     else{
         printf("a == b\n");
     }
     return 0;
     
}


Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

#define MAX 51

int main() {
    int n, m;
    int a, b;
    int road[MAX];
    
    cin >> n >> m;
    for ( int i = 1; i <= n; i++ ) {
        road[i] = 0;
    }
    
    for ( int i = 0; i < m; i++ ) {
        cin >> a >> b;
        road[a]++;
        road[b]++;
    }
    
    for ( int i = 1; i <= n; i++ ) {
        cout << road[i] << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
int main()
{
    int k;
    std::string s;
    std::cin >> k >> s;

    if (s.size()<=k){
        std::cout << s << std::endl;
    }
    else{
        for (int i = 0; i < k; i++)
            std::cout << s[i];
            std::cout << "..." << std::endl;
    }
    
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

bool ok(int64 n) {
    vector<bool> di(10, false);
    while(n!=0) di[n%10]=true,n/=10;
    return di[3] && di[5] && di[7];
}

void dfs(const int64 i, const int& n, int64& ans) {
    if (i > n) return;
    if (ok(i)) ans++;
    dfs(i*10+7, n, ans);
    dfs(i*10+5, n, ans);
    dfs(i*10+3, n, ans);
}

int main() {
    int n;
    cin >> n;
    int64 ans = 0;

    dfs(0,n,ans);

    cout << ans << endl;
}

Measured memory_bytes: 3192
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};

using namespace std;

struct edge{
  int from,to,cost;
};
typedef vector<vector<edge> > AdjList;
typedef long long int ll;
AdjList graph;
typedef pair<int , int> P;
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
int E,V;
edge es[100001];
int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}


long long int MOD = 1000000007;
long long int ruiseki[200001];
int ncrset(){
  ruiseki[0] = 1;
  for(int i=1;i<200001;i++){
    ruiseki[i] = (ruiseki[i-1] * i) % MOD;
  }
}

long long int powld(long long int x,long long int n){
  long long int ans = 1;
  while(n > 0){
    if((n&1) == 1){
      ans = (ans*x)  % MOD;
    }
    x = (x*x) % MOD;
    n >>= 1;
  }
  return ans % MOD;
}

int ncrgyaku(int n,int r){
  long long int gyakuk,gyakur;
  long long int res = 1,x,y,z;
  y = powld(ruiseki[r],MOD-2);
  z = powld(ruiseki[n-r],MOD-2);
  return (((ruiseki[n]*y) % MOD)*z) % MOD;

}


int main()
{
  ll N,K,H,W,A,B,res=0,MOD=10E8+7;
  ncrset();
  cin >> H >> W >> A >> B;
  vector<ll> sg(0);
  REP(i,H-A){
    sg.push_back(ncrgyaku(B-1+i,B-1));
  }
  REP(i,H-A){
    res = (res+(sg[i]*(ncrgyaku(W-B-1+H-i-1,H-i-1)))) % MOD;
  }
  cout << res << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll s, c;
    cin >> s >> c;
    ll k = min(s, c / 2);
    s -= k;
    c -= 2 * k;
    cout << k + c / 4;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
p = list(map(int, input().split()))

parent = [i for i in range(n + 1)]
rank = [0] * (n + 1)

def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

def union(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        parent[x] = y
    else:
        parent[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

def same_check(x, y):
    return find(x) == find(y)

for i in range(m):
    x, y = map(int, input().split())
    union(p[x - 1], p[y - 1])
ans = 0
for i in range(n):
    if same_check(i + 1, p[i]):
        ans += 1
print(ans)

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

using namespace std;

#define ll long long

int gcd(int a, int b) {
  if(a < b) swap(a, b);
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
    int x,y;cin>>x>>y;
    for(int i=0;i<=x/2;i++)
    {
        int l = x-i;
        if((l*2+i*4)==y)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        else if((i*2+l*4)==y)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3624