akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    ll n,m;cin>>n>>m;
    if(n>=m/2){
        cout<<m/2<<endl;
        return 0;
    }
    cout<<(n+(m-2*n)/4)<<endl;
}

Measured memory_bytes: 3588
N = int(input())
S = input()

result = ''

for i in range(len(S)):
    char = S[i]
    ord_char = ord(char)
    ord_char += N
    if ord_char > 90:
        ord_char -= 26
    chr_char = chr(ord_char)
    result = result + chr_char

print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);
static const int MAXN = 1e5+5;

int N, M, S, T;
int d[MAXN];
int d2[MAXN];
int d3[MAXN];
vector< vector<int> > G(MAXN);
vector<int> nex;

void search(int v, int cnt) {
  if (cnt == 1) d2[v] = 0;
  else d3[v] = 0;

  queue<int> q;
  q.push(v);
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int nv = G[u][i];
      if (cnt == 1) {
        if (d3[nv] != INF) continue;
        search(nv, 2);
      } else {
        nex.push_back(nv);
      }
    }
  }
}


void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i <= N+1; i++) {
    d[i] = INF;
    d2[i] = INF;
    d3[i] = INF;
  }
  d[s] = 0;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (d2[v] != INF) continue;
      nex.clear();
      search(v, 1);
      
      for (int j = 0; j < nex.size(); j++) {
        int nv = nex[j];
        if (d[nv] != INF) continue;
        d[nv] = d[u] + 1;
        q.push(nv);
      }
    }
  }

}

int main() {
  cin >> N >> M;
  rep(i, M) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
  }
  cin >> S >> T;

  bfs(S);

  if (d[T] != INF) {
    cout << d[T] << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 6912
# AtCoder Beginner Contest 044 - B
# -*- encoding: UTF-8 -*-

alpha = "abcdefghijklmnopqrstuvwxyz"
cd = {}
for c in alpha:
  cd[c] = 0

w = input()
for c in w:
  cd[c] = cd[c] + 1

result = "Yes"

for v in cd.values():
  if v % 2 == 1:
    result = "No"
    break

print(result)



Measured memory_bytes: 2940
x = []
while(1):
    inp = int(input())
    if inp !=0:
        x.append(inp)
    else:
        x.append(inp)
        break

j=0
while(1):
    if(x[j]!=0):
        print("Case {}: {}".format(j+1,x[j]))
        j+=1
    else:
        break


Measured memory_bytes: 5908
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int a[n];
    int b[n];
    fill(b, b + n, 0);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        b[a[i]-1]++;
        // printf("%d ", a[i]);
    }
    // puts("");

    sort(b, b + n);
    int k_all = 0;
    for(int i = 0; i < n; i++){
        // printf("%d\n", k_all);
        if (b[i] != 0) k_all++;
        // printf("%d ", b[i]);
    }
    // puts("");
    // printf("%d\n", k_all);
    int ans = 0;
    int i = 0;
    while (k_all > k){
        // printf("%d\n", ans);
        if (b[i] != 0){
            ans += b[i];
            k_all--;
            b[i] = 0;
        }
        i++;
    }
    printf("%d\n", ans);
    
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] o = sc.next().toCharArray();
		char[] e = sc.next().toCharArray();

		for (int i = 0; i < o.length + e.length; i++) {
			if (i % 2 == 0) {
				pr.print(o[i / 2]);
			} else {
				pr.print(e[i / 2]);
			}
		}
		pr.println();
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
x = int(input())
ans = 0
if x == 1 or x == 2 or x == 3:
  print(1)
  exit()
  
for i in range(2,33):
  for k in range(2,10):
    if k == 2 and i**k > x:
      print(ans)
      exit()
    elif i**k <= x:
      ans = max(i**k,ans)

Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
 
using namespace std;
 
typedef long long ll;
 
 
const int N = 1e5 + 7;
 
int par[N];
int ans[N];
vector <int> g[N];
 
vector <vector <int> > guys;
vector <multiset <int> > mems;
vector <multiset <int> > anti_guys;
 
int dfs(int v)
{
    vector <int> childs;
    for (int to : g[v])
    {
        childs.push_back(dfs(to));
    }
    if (childs.size() % 2 == 0)
    {
        guys.push_back(childs);
        return v;
    }
    else
    {
        int ans = childs.back();
        childs.pop_back();
        guys.push_back(childs);
        return ans;
    }
}
 
int it = -1;
 
void euler(int v, bool chelik)
{
    if (chelik)
    {
        while (!anti_guys[v].empty())
        {
            int go = *anti_guys[v].begin();
            mems[go].erase(mems[go].find(v));
            anti_guys[v].erase(anti_guys[v].find(go));
            euler(go, 0);
        }
        ans[v] = it;
        it = -it;
    }
    else
    {
        while (!mems[v].empty())
        {
            int go = *mems[v].begin();
            anti_guys[go].erase(anti_guys[go].find(v));
            mems[v].erase(mems[v].find(go));
            euler(go, 1);
        }
    }
}
 
mt19937 rnd(228);
 
int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> kekos;
    anti_guys.resize(n);
    for (int it = 0; it < 2; it++)
    {
        for (int i = 0; i < n; i++)
        {
            g[i].clear();
        }
        int root = -1;
        for (int i = 0; i < n; i++)
        {
            cin >> par[i];
            par[i]--;
            if (par[i] < 0)
            {
                root = i;
            }
            else
            {
                g[par[i]].push_back(i);
            }
        }
        kekos.push_back(dfs(root));
    }
    for (int i = 0; i < (int) guys.size(); i++)
    {
        multiset <int> q;
        for (int v : guys[i])
        {
            q.insert(v);
            anti_guys[v].insert(i);
        }
        mems.push_back(q);
    }
    for (int i = 0; i < n; i++)
    {
        if (anti_guys[i].size() + (i == kekos[0]) + (i == kekos[1]))
        {
            if (anti_guys[i].size() + (i == kekos[0]) + (i == kekos[1]) != 2)
            {
                cout << "IMPOSSIBLE\n";
                return 0;
            }
        }
    }
    if (kekos[0] != kekos[1])
    {
        euler(kekos[0], 1);
    }
    else
    {
        ans[kekos[0]] = 1;
    }
    for (int i = 0; i < (int) mems.size(); i++)
    {
        if (!mems[i].empty())
        {
            euler(i, 0);
        }
    }
    cout << "POSSIBLE\n";
    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}


Measured memory_bytes: 58692
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;scanf("%d%d", &h, &w);
  getchar();
  //string s[100];
  bool ans=true;
  char s[1000][1000];
  /*for(int i = 0; i < h; i++)cin >>s[i];
  //edge
  if(s[0][0]=='#'&&s[0][1]=='.'&&s[1][0]=='.') ans=false;
  if(s[h-1][0]=='#'&&s[h-1][1]=='.'&&s[h-2][0]=='.') ans=false;
  if(s[0][w-1]=='#'&&s[0][w-2]=='.'&&s[1][w-1]=='.') ans=false;
  if(s[h-1][w-1]=='#'&&s[h-1][w-2]=='.'&&s[h-2][w-1]=='.') ans=false;
  for(int i=0;i<w;i++){
    if(s[0][i]=='#' && s[1][i]=='.') ans=false;
    if(s[h-1][i]=='#' && s[h-2][i]=='.')ans=false;
  }
  for(int i=0;i<h;i++){
    if(s[i][0]=='#' && s[i][1]=='.') ans=false;
    if(s[i][w-1]=='#' && s[i][w-2]=='.')ans=false;
  }*/
  for(int i = 0; i<=w+1;i++) s[0][i] = s[h+1][i]='.';
  for(int i = 0; i<=h+1;i++) s[i][0] = s[i][w+1] ='.';
  for(int i = 1; i<=h;i++){
    for(int j=1; j<=w;j++){
      s[i][j]=getchar();
    }
    getchar();
  }
  //for(int i = 0; i<=h+1;i++) printf("%s\n", s[i]);
  for(int i = 1; i <= h; i++){
    for(int j=1;j<=w;j++){
      //if(s[i][j]=='#')
      //printf("%c\n",s[i][j-1]);
      if(s[i][j]=='#' && s[i-1][j]=='.' && s[i][j-1]=='.'&&s[i+1][j]=='.'&&s[i][j+1]=='.'){
        
        ans=false;
      }
    }
  }
  //printf("%d  ", ans);
  if(ans)puts("Yes");
  else puts("No");
}

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

using ll=long long;

int main(){

int N,K;
cin>>N>>K;

vector<int> h(N);

for(int i=0;i<N;++i) cin>>h[i];

int j=0;

for(int i=0;i<N;++i){
if(h[i]>=K){
++j;
}
}

cout<<j<<endl;

}

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

int main(void){

	int h, w;
	cin >> h >> w;

	char map[100][100];
	for (int i = 0; i < h; i++)
			cin >> map[i];

	int out[100][100];
	memset(out, -1, sizeof(out));
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (map[i][j] == 'c') out[i][j] = 0;
			else{
				for (int k = j, count = 0; k >= 0; k--, count++){
					if (map[i][k] == 'c'){
						out[i][j] = count;
						break;
					}
				}
			}
			if (j < w - 1) cout << out[i][j] << ' ';
			else cout << out[i][j] << endl;
		}
	}
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 100003

int main(){
	string ss;
	cin >> ss;
	int n = sz(ss);
	for(int i = 1; i < n; i++){
		if(ss[i] == ss[i - 1]){
			cout << i << ' ' << i + 1 << endl;
			return 0;
		}
	}
	for(int i = 2; i < n; i++){
		if(ss[i - 2] == ss[i]){
			cout << i - 1 << ' ' << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 512
T1, T2, A1, A2, B1, B2 = map(int, open(0).read().split())

P = (A1 - B1) * T1
Q = (A2 - B2) * T2

if P > 0:
    P, Q = -P, -Q

if P + Q < 0:
    print(0)
elif P + Q == 0:
    print("infinity")
else:
    S, T = divmod(-P, P + Q)
    print(S * 2 + (T != 0))


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int P = int.Parse(input[1]);
            
            Console.WriteLine(((A*3 + P) / 2).ToString());
        }
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
ll comb3(ll x) {
	if(x < 3)
		return 0;
	return (x*(x-1)*(x-2))/6;
}
ll comb2(ll x) {
	if(x < 2)
		return 0;
	return (x*(x-1))/2;
}
ll freq[6001];
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, i, j, ans = 0;
    cin>>n;
    vector<ll> v(n);
    for(i=0; i<n; i++) {
    	cin>>v[i];
    	freq[v[i]]++;
    }
    for(i=1; i<6001; i++) {
    	freq[i] += freq[i-1];
    }
    for(i=1; i<1001; i++) {
    	ans += comb3(freq[i] - freq[i-1]);
    	ans += comb2(freq[i] - freq[i-1])*(freq[2*i-1] - freq[i]);
    	for(j = i + 1; j<1001; j++) {
    		ans += (freq[i] - freq[i-1])*comb2(freq[j] - freq[j-1]);
    		ans += (freq[i] - freq[i-1])*(freq[j] - freq[j-1])*(freq[i + j - 1] - freq[j]);
    	}
    }
    cout<<ans<<"\n";
}

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

int main() {
        int n, x;
        cin >> n >> x;
        vector<int> m(n);

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

        int tmp = 0;
        for(i = 0; i < n; i++) {
                tmp += m[i];
        }

        int min;
        sort(m.begin(), m.end());
        min = m.at(0);

        int cnt;
        cnt = (x - tmp) / min;

        cout << cnt + m.size() << endl;
}


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

bool ok(int last, int a, int b, int len) {
	if(last < 0) return ok(-last, b, a, len);
	assert(last <= len);
	if((LL)b * len + len - last >= a && (LL)(a + 1) * len >= b) return true;
	else return false;
}

string finish(int len, int last, int a, int b, int todo) {
	string s(todo, '?');
	for(int i = 0; i < (int)s.size(); ++i) {
		if(a && last + 1 <= len && ok(last < 0 ? 1 : last + 1, a - 1, b, len))
			s[i] = 'A', --a, last = (last < 0 ? 1 : last + 1);
		else
			s[i] = 'B', --b, last = (last > 0 ? -1 : last - 1);
	}
	return s;
}

int maxA(int a, int b, int sz) {
	int len = a < b ? (a + b) / (a + 1) : (a + b) / (b + 1);
	int L = 0, R = min(sz, a);
	while(L < R) {
		int M = (L + R + 1) >> 1;
		if((LL)(sz - M + 1) * len >= M && (LL)(a - M + 1) * len >= b - (sz - M))
			L = M;
		else
			R = M - 1;
	}
	return L;
}

string get(int a, int b, int lb, int rb) {
	int len;
	if(a < b) len = (a + b) / (a + 1);
	else len = (a + b) / (b + 1);
	
	if(lb <= 2) return finish(len, 0, a, b, rb).substr(lb - 1);
	
	int pa = maxA(a, b, lb - 1);
	int ppa = maxA(a, b, lb - 2);
	if(pa == ppa) { // 'B'
		int L = 0, R = lb - 1;
		while(L < R) {
			int M = (L + R) >> 1;
			if(maxA(a, b, M) == pa) R = M;
			else L = M + 1;
		}
		return finish(len, -(lb - L - 1), a - pa, b - (lb - 1 - pa), rb - lb + 1);
	} else { // 'A'
		int L = 0, R = lb - 1;
		while(L < R) {
			int M = (L + R) >> 1;
			if(M - maxA(a, b, M) == lb - 1 - pa) R = M;
			else L = M + 1;
		}
		return finish(len, lb - L - 1, a - pa, b - (lb - 1 - pa), rb - lb + 1);
	}
}

int main() {
	int q; cin >> q;
	while(q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << get(a, b, c, d) << endl;
	}
	return 0;
}


Measured memory_bytes: 384
<?php
$stack = array();
while (!feof(STDIN)) {
    $inVal = trim(fgets(STDIN));
    if ($inVal == 0) {
        $disp = array_pop($stack);
        if (!is_null($disp)) {
            echo $disp.PHP_EOL;
        }
    } else {
        $stack[] = $inVal;
    }
}


Measured memory_bytes: 9240
import java.util.*; 
import java.io.*;
 
public class Main {
		
	public static void solve(InputReader in) {
		long n = in.readLong();
		ArrayList<Long> list = new ArrayList<>();  
		long temp = n; 
		for(long i = 2; i*i <= temp; i++) {
			if(n%i == 0) {
				long count = 0;
				while(n % i == 0) {
					n/=i; 
					count++; 
				}
				list.add(count); 
			}
		}
		if(n > 1) list.add(1L); 
		long sum = 0;
		for(Long i : list) {
			long beg = 0; long end = i; long ans = 0;  
			while( beg <= end) {
				long med = (beg + end)/2;
				if(med*(med + 1)/2 <= i) {
					ans = med; 
					beg = med + 1; 
				}
				else
					end = med - 1; 
			}
			sum += ans; 
		}
		System.out.println(sum); 
	}

    public static void main(String[] args) {
    	InputReader in = new InputReader(System.in); 
    	int t = 1;
    	while(t-- > 0) {
    		solve(in); 
    	}
    }
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

    public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

    public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

    public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

    public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
    public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

    public String next() {
		return readString();
	}

    public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 32528
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x.at(i);
    int ans=1000000;
    for(int i=0;i<=100;i++){
        int sum=0;
        rep(j,n){
            sum+=(i-x.at(j))*(i-x.at(j));
        }
        ans=min(ans,sum);
    }
    cout << ans << endl;
}


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

int main() {
	int h,w;
   cin>>h>>w;
   vector<string> a(h);
   for(int i=0;i<h;i++){
      cin>>a.at(i);
   }
   vector<bool> y(h,false),x(w,false);
   for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
         if(a.at(i).at(j)=='#'){
            y.at(i)=true;
            x.at(j)=true;
         }
      }
   }
   for(int i=0;i<h;i++){
      if(y.at(i)){
         for(int j=0;j<w;j++){
         if(x.at(j)){
            cout<<a.at(i).at(j);
         }
         }
         cout<<endl;
      }
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,L;
  cin>>N>>L;
  int S=L+N-1;
  int eat;
  if(S<=0){
    eat=S;
  }
  else if(L>=0){
    eat=L;
  }
  else{
    eat=0;
  }
  int ans=(S+L)*(S-L+1)/2-eat;
  cout<<ans<<endl;
}
  

Measured memory_bytes: 3592
N,L = map(int,input().split())

apples = [i+L-1 for i in range(1,N+1)]

ans = float("inf")
res = float("inf")

for apple in apples:
  if ans > abs(apple):
    ans = min(ans,abs(apple))
    res = apple
  
print(sum(apples) - res)

Measured memory_bytes: 9088
/*
[keyence2019] D - Double Landscape
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;

int NM[2];
vector<int> AB[2];

ll solve() {
    for (int d = 0; d < 2; d++) {
        AB[d].push_back(NM[0] * NM[1] + 1);
        sort(AB[d].begin(), AB[d].end());
        if (unique(AB[d].begin(), AB[d].end()) != AB[d].end()) {
            return 0;
        }
    }

    ll ans = 1;
    for (int i = NM[0] * NM[1]; i > 0; i--) {
        int idx[2];
        for (int d = 0; d < 2; d++) {
            idx[d] = lower_bound(AB[d].begin(), AB[d].end(), i) - AB[d].begin();
        }

        ll t = 1;
        if (AB[0][idx[0]] != i && AB[1][idx[1]] != i) {
            t = (NM[0] - idx[0]) * (NM[1] - idx[1]) - (NM[0] * NM[1] - i);
        } else if (AB[0][idx[0]] != i) {
            t = (NM[0] - idx[0]);
        } else if (AB[1][idx[1]] != i) {
            t = (NM[1] - idx[1]);
        }

        (ans *= t) %= MOD;
    }

    return ans;
}

int main() {
    cin >> NM[0] >> NM[1];
    for (int d = 0; d < 2; d++) {
        AB[d].resize(NM[d]);
        for (int i = 0; i < NM[d]; i++) {
            cin >> AB[d][i];
        }
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
const int MOD = 1000000007;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
    int n;cin >> n;
    cout << 3*n*n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int a,b,check[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    cin >> a >> b;
    if(check[a] == check[b]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#include <atcoder/all>

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

using namespace std;
using namespace atcoder;

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

    dsu ds(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        ds.merge(a, b);
    }

    set<int> s;
    rep(i, n) s.insert(ds.leader(i));

    cout << s.size() - 1 << endl;
    return 0;
}


Measured memory_bytes: 7480
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}


	public void run() {
		Scanner sc = new Scanner(System.in);
		char s[] = sc.next().toCharArray();
		long k=sc.nextLong();
		char ans  = '1';
		for(int i=0; i<s.length; i++) {
			if(s[i] != '1') {
				if((long)i+1<=k) {
					ans = s[i];
				}
				break;
			}
		}
		System.out.println(ans);
		sc.close();
	}


}


Measured memory_bytes: 23636
#include <iostream>
using namespace std;
int main(){
    char i;
    while((i=cin.get()))
    {
        if(i=='\n') {
            cout << endl;
            break;
        }
        if (i>='a'&&i<='z')
            cout<<char(i-32);
        else if (i>='A'&&i<='Z')
            cout<<char(i+32);
        else
            cout<<i;

    }
    return 0;
}


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

class Solve {
private:
	using pii = std::pair<int, int>;
	using vii = std::vector<pii>;
	using vvii = std::vector<vii>;
	
	vvii dice;

	int dir[4][2]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
	int tl_r[6][6]{
		{-1, 2, 4, 1, 3, -1},
		{3, -1, 0, 5, -1, 2},
		{1, 5, -1, -1, 0, 4},
		{4, 0, -1, -1, 5, 1},
		{2, -1, 5, 0, -1, 3},
		{-1, 3, 1, 4, 2, -1}
	};

	// fの方向をh+,t→fの右ねじ方向をw+とする
	// dir_iはtの方向を軸としてh+→w+の方向にdir_i個隣を指す
	void fall(int h, int w, int t, int f)
	{
		// 落ちる方向の目(4, 5, 6)とその場合のdir_i
		pii next{-1, -1};
		for (int i{}; i < 4; i++)
			next = std::max(next, fallable(h, w, t, f, i));
		if (next.first >= 0)
		{
			int next_f{calcF(t, f, next)};
			fall(h + dir[next.second][0], w + dir[next.second][1], 5 - next.first, next_f);
		}
		else
		{
			dice[h][w].first = t;
			dice[h][w].second++;
		}
	}

	pii fallable(int h, int w, int t, int f, int dir_i)
	{
		if (dice[h + dir[dir_i][0]][w + dir[dir_i][1]].second >= dice[h][w].second) return {-1, -1};
		pii ret{f, dir_i};
		for (int i{}; i < dir_i; i++)
			ret.first = tl_r[t][ret.first];
		if (ret.first < 3) return {-1, -1};
		else return ret;
	}

	int calcF(int t, int f, pii& next)
	{
		if (next.second & 1) return f;
		else if (next.second == 0) return t;
		else return 5 - t;
	}

public:
	bool is_last_query{};
	Solve()
	{
		int N;
		scanf("%d", &N);
		if (N == 0)
		{
			is_last_query = true;
			return;
		}
		dice.resize(40, vii(40, {-1, 0}));
		for (int n_i{}; n_i < N; n_i++)
		{
			int t, f;
			scanf("%d%d", &t, &f);
			t--;
			f--;
			fall(20, 20, t, f);
		}
		int table[6]{};
		for (auto& e: dice)
			for (auto& f: e)
				if (f.first >= 0)
					table[f.first]++;
		for (int i{}; i < 6; i++)
			printf("%d%c", table[i], i == 5?'\n':' ');
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll f[401][401];


ll modpow(ll x, int k){
    if(f[x][k] != -1) return f[x][k];
    if(k == 0){
        return 1;
    }
    ll p = modpow(x, k / 2);
    p *= p;
    p %= mod;
    if(k % 2){
        p *= x;
        p %= mod;
    }

    f[x][k] = p;
    return p;

}


int main()
{
    memset(f, -1, sizeof(f));
    int n, c;
    cin >> n >> c;
    int a[n], b[n];
    fr(i, 0, n){
        cin >> a[i];
    }
    fr(i, 0, n){
        cin >> b[i];
    }
    ll pre[n][c + 1];
    memset(pre, 0, sizeof(pre));
    fr(i, 0, n){
        fr(x, 0, c + 1){
            fr(j, a[i], b[i] + 1){
                pre[i][x] += modpow(j, x);
                pre[i][x] %= mod;
            }
        }
    }


    ll dp[n][c + 1];
    memset(dp, 0, sizeof(dp));


    fr(i, 0, c + 1){
        fr(X, a[0], b[0] + 1){
            dp[0][i] += modpow(X, i);
            dp[0][i] %= mod;
        }
    }
    fr(i, 1, n){
        fr(ctot, 0, c + 1){
            fr(cbef, 0, ctot + 1){
                int C = ctot - cbef;
                dp[i][ctot] += (pre[i][C] * dp[i - 1][cbef]) % mod;
                dp[i][ctot] %= mod;
            }
        }
        /*
        fr(X, a[i], b[i] + 1){
            fr(ctot, 0, c + 1){
                fr(cbef, 0, ctot + 1){
                    dp[i][ctot] += (dp[i - 1][cbef] * modpow(X, ctot - cbef))%mod;
                    dp[i][ctot] %= mod;

                }
            }
        }*/
    }

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





    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    set<int> v;
    int temp;
    for(int i = 0; i < n; ++i)
    {
        cin >> temp;
        v.insert(temp);
    }
    cout << v.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

int main() {
  int x;

  cin >> x;

  if (400 <= x && x <= 599) {
    cout << 8 << endl;
  } else if (600 <= x && x <= 799) {
    cout << 7 << endl;
  } else if (800 <= x && x <= 999) {
    cout << 6 << endl;
  } else if (1000 <= x && x <= 1199) {
    cout << 5 << endl;
  } else if (1200 <= x && x <= 1399) {
    cout << 4 << endl;
  } else if (1400 <= x && x <= 1599) {
    cout << 3 << endl;
  } else if (1600 <= x && x <= 1799) {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3156
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int x, a, b; cin >> x >> a >> b;
    cout << (abs(a-x) < abs(b-x) ? "A" : "B") << endl;
    return 0;
}


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


// 2011/10/23

// 0141 ®é®éÍl
public class Main {

	// C return falseÅ¨µÜ¢
	boolean main() throws IOException {

		int size = readIntArray()[0];
		
		int[][] map = new int[size][size];
		int x = 0;
		int y = 0;
		int v = 0; // muki
		boolean lastm = false; //OñÈªÁ½©?
				
		
		loop:
		for(int step = 0; step < 10000; step++) {
			map[x][y] = 1;
			int xx = 0;
			int yy = 0;
			boolean m = false;
			for(int s = 0;;s++) {
				if (s > 2)
					break loop;
				if (v == 0) { // º
					xx = 0;
					yy = 1;
				}
				else if (v == 1) {
					xx = 1;
					yy = 0;
				}
				else if (v == 2) {
					xx = 0;
					yy = -1;
				}
				else if (v == 3) {
					xx = -1;
					yy = 0;
				}
				if (x + xx < 0 || x + xx >= size || y + yy < 0 || y + yy >= size ||
						(x + xx*2 >= 0 && x + xx*2 < size && y + yy*2 >= 0 && y + yy*2 < size && map[x+xx*2][y+yy*2] != 0)) {
					if (lastm)
						break loop;
					v = (v + 1) % 4;
					m = true;
					continue;
				}
				break;
			}
			lastm = m;
			x += xx;
			y += yy;
		}
		
		for(y = 0; y < size; y++) {
			for(x = 0; x < size; x++) {
				System.out.printf("%s", map[x][size - 1 - y] != 0 ? "#" : " ");
			}
			System.out.printf("\n");
		}
		
		
		return true; // ³íI¹ Ö
	}
	

//	private final static boolean DEBUG = true;  // debug
	private final static boolean DEBUG = false; // release

	public static void main(String[] args) throws IOException {

		if (DEBUG) {
			log = System.out;
			
			String inputStr = "1:15:";

			inputStr = inputStr.replace(":", "\n");

			reader = new BufferedReader(new StringReader(inputStr)); 

		}
		else {
			log = new PrintStream(new OutputStream() { public void write(int b) {} } ); // «ÌÄ
			reader = new BufferedReader(new InputStreamReader(System.in)); // R\[©ç
		}
		
		int N = readIntArray()[0];

		for(int i = 0; i < N; i++) {
			if (i != 0)
				System.out.printf("\n");
			boolean b = new Main().main();
			if (!b)
				break;
		}		
		
		reader.close();
	}

	
	static PrintStream log;
	static BufferedReader reader;
	

	// WüÍæè1sªÌæØè¶æØèÅÌ®lðÇÞ
	// EOFÌêÍnullðÔ·
	private static int[] readIntArray() throws IOException {

		String s = null;
		for(;;) {
			s = reader.readLine();
//			log.printf("%s\n", s);
			if (s == null)
				return null;
			s = s.trim();
			if (s.length() != 0) // ¦¦¦@Ç¤àËRósðÇÞ±Æª éBÇÝòÎ·Æ¤Ü­¢­çµ¢BBBB
				break;
		}
		
		String[] sp = s.split("[ ,]"); // æØè¶ÍXy[X©J}
		int[] a = new int[sp.length];
		for(int i = 0; i < sp.length; i++) {
			a[i] = Integer.parseInt(sp[i]);
		}
		return a;
	}
		
}

Measured memory_bytes: 13000
X = int(input())
nums = set([1])
for i in range(2, int(1000 ** .5) +1):
    b = 2
    while True:
        temp = i ** b
        if temp > 1000:
            break
        nums.add(temp)
        b += 1
sorted_nums = sorted(list(nums), reverse=True)
# print(f"nums:{sorted_nums}", file=sys.stderr)
if X >= sorted_nums[0]:
    print(sorted_nums[0])
else:
    for i in range(len(sorted_nums) - 1):
        if sorted_nums[i] > X >= sorted_nums[i + 1]:
            print(sorted_nums[i + 1])


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

int main(){
  int n;
  cin >> n;
  int x[n+1];
  for (int i = 1; i <= n; i++){
  	x[i] = 0;
  }
  x[1] += 1;
  for (int i = 2; i <= n; i++){
    int u = i*i;
  	while(u <= n) {
      x[u]++;
      u *= i;
    }
  }
  for (int i = n; i > 0; i--){
  	if (x[i] != 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rr return 0
#define fi first
#define se second
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define sz(s) s.size()
using namespace std;
//Debug template by livw
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

//ll pm(ll x,ll y){ll res = 1;while(y>0){if(y&1) res = (res*x)%mod;x= (x*x)%mod;y/=2;}return res;}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
 fastio;
 int i,n,j,k,count=0;
 cin>>n;
 int arr[n];
 for(i=0;i<n;i++)cin>>arr[i];
  sort(arr,arr+n);
 for(i=0;i<=n-3;i++)
 {
  for(j=i+1;j<n-1;j++)
  {
    if(arr[i]!=arr[j])
    {
    for(k=j+1;k<n;k++)
    {
      if(arr[i]!=arr[k]&&arr[j]!=arr[k]&&arr[i]+arr[j]>arr[k])
      {
        count++;
      }
    }
   }
  }
 }
 cout<<count;
rr;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	int x;
	cin >> x;
	ll i = 1;
	while (true) {
		if (360 * i % x == 0) {
			cout << 360 * i / x << endl;
			return 0;
		}
		i++;
	}
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
signed main(){
    bool f = false;
    int n;
    cin>>n;
    while(n>0){
        if(n%10 == 7){
            f = true;
        }
        n/=10;
    }
    if(f){
        cout<<"Yes\n";
    } else {
        cout<<"No\n";
    }
    return(0);
}

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

a = list(map(int,input().split()))

for i in range(N):
   for j in reversed(range(i+1,N)):
        #print(i,j)
        if a[j] > a[j-1]:
            temp = a[j]
            a[j] = a[j-1]
            a[j-1] = temp

Alice = 0
Bob = 0

k = 0
count =1
while k < N:
    if count % 2 == 0:
        Bob += a[k]
    else:
        Alice += a[k]
    k += 1
    count += 1

print(Alice-Bob)

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

bool comparator(const string& a, const string& b) {
  if (a.size() == b.size()) return a < b;
  else                      return a.size() < b.size();
}

int solve(int n) {
  map<string, int, decltype(comparator)*> orders(comparator);
  //map<string, int, bool(*)(const string&, const string&)> orders(comparator);

  for (auto i = 0; i < n; ++i) {
    string name;
    int num;
    cin >> name >> num;
    orders[name] += num;
  }

  for (auto order : orders) {
    cout << order.first << " " << order.second << endl;
  }

}

int main() {
  int n;
  cin >> n;
  solve(n);
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define maxn 500005
#define ll long long
#define mod 1000000007
using namespace std;

typedef pair<int, char> P;

int n;
vector<int> a, b;
vector<int> zero;

bool cmp(int x, int y)
{
    return x > y;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int now;
        scanf("%d", &now);
        if (now == 0)
            zero.push_back(0);
        else if (now > 0)
            a.push_back(now);
        else
            b.push_back(now);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), cmp);
    if (!zero.empty())
    {
        int now = 0;
        for (int i = 0; i + 1 < a.size(); i++)
            now -= a[i];
        if (!a.empty())
            now = a.back() - now;
        for (int i = 0; i < b.size(); i++)
            now -= b[i];

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

        now = 0;
        for (int i = 0; i + 1 < zero.size(); i++)
            printf("0 0\n");
        for (int i = 0; i + 1 < a.size(); i++)
        {
            printf("%d %d\n", now, a[i]);
            now -= a[i];
        }
        if (!a.empty())
        {
            printf("%d %d\n", a.back(), now);
            now = a.back() - now;
        }
        for (int i = 0; i < b.size(); i++)
        {
            printf("%d %d\n", now, b[i]);
            now -= b[i];
        }
    }
    else if (!b.empty() && !a.empty())
    {
        int now = b[0];
        for (int i = 0; i + 1 < a.size(); i++)
            now -= a[i];
        if (!a.empty())
            now = a.back() - now;
        for (int i = 1; i < b.size(); i++)
            now -= b[i];

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

        now = b[0];
        for (int i = 0; i + 1 < a.size(); i++)
        {
            printf("%d %d\n", now, a[i]);
            now -= a[i];
        }
        if (!a.empty())
        {
            printf("%d %d\n", a.back(), now);
            now = a.back() - now;
        }
        for (int i = 1; i < b.size(); i++)
        {
            printf("%d %d\n", now, b[i]);
            now -= b[i];
        }
    }
    else if (b.empty())
    {
        int now = a[0];

        for (int i = 1; i + 1 < a.size(); i++)
            now -= a[i];
        now = a.back() - now;
        printf("%d\n", now);

        now = a[0];
        for (int i = 1; i + 1 < a.size(); i++)
        {
            printf("%d %d\n", now, a[i]);
            now -= a[i];
        }
        printf("%d %d\n", a.back(), now);
    }
    else
    {
        int now = b[0];
        for (int i = 1; i < b.size(); i++)
            now -= b[i];
        printf("%d\n", now);

        now = b[0];
        for (int i = 1; i < b.size(); i++)
        {
            printf("%d %d\n", now, b[i]);
            now -= b[i];
        }
    }

    return 0;
}

Measured memory_bytes: 2424
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
int arr[1000];
int main() {
    int x,n;
    cin >> x >> n;
    int min = -1;
    int max = 102;
    int p;
    FOR(i, 0, n) {
        cin >> p;
        arr[p] = 1;
    }
    if (n == 0) {
        cout << x << endl;
        return 0;
    }
    
    int off = 0;
    int i = x;
    if (i <= min)
        i = min + 1;
    if (i >= max)
        i = max - 1;

    while (off <= 105) {
        if (i - off > min && i - off < max && arr[i - off] == 0) {
            cout << i - off << endl;
            return 0;
        }
        else if (i + off > min && i + off < max && arr[i + off] == 0) {
            cout << i + off << endl;
            return 0;
        }
        off++;
    }
    return 0;
}

Measured memory_bytes: 3600
n = int(input())
a = [int(input()) for i in range(5)]
cnt = 0

mn = min(a)
for i in range(5):
    if a[i] == mn:
        cnt += 1

if n % mn == 0:
    ans = 4 + n // mn
else:
    ans = 4 + n // mn + 1

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<limits>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(ll i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(ll i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
using namespace std;

ll gcd(ll ma, ll mi) {
	if (ma % mi != 0)
		return gcd(mi, ma%mi);
	else
		return mi;
}

int main() {
	ll a, b, c, d, ans, g;
	cin >> a >> b >> c >> d;
	ll mi = min(c, d);
	ll ma = (mi == c) ? d : c;
	g = (c*d)/gcd(ma, mi);
	a -= 1;
	ans = (b - (b / c) - (b / d) + (b / g)) - (a - (a / c) - (a / d) + (a / g));
	cout << ans << endl;
	return 0;
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  
  int max;
  int min1;
  int maxnedan;
  int minnedan;
  
  if (x>y){
    max = x;
    min1 = y;
    maxnedan = a;
  }
  else if (x < y){
    max = y;
    min1 = x;
    maxnedan = b;
  }
  
  int total;
  if (a+b > c*2){
    total = 2*c*min1 + min(c*2,a)*(x - min1) + min(c*2,b)*(y - min1);
  }
  else{
    total = a*x + b*y;
  }
  
  cout << total << endl;
}

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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    string N;

    cin >> N;

    cout << (N[0] == N[2] ? "Yes" : "No") << endl;

    return 0;
}

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


Measured memory_bytes: 3612
#include "bits/stdc++.h"

using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (1)
	{
		c -= b;
		if (c <= 0)
		{
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if (a <= 0)
		{
			cout << "No" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3468
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

template<class T> class segtree {
	int n;
	vector<T> data;
	T id = 0;
	T operation(T a, T b) { return a + b; };
public:
	segtree(int _n) {
		n = 1;
		while (n < _n + 2) n <<= 1;
		data = vector<T>(2 * n, id);
	}
	void change(int a, int b, int x) {
		a += n; b += n;
		while (a < b) {
			if (a & 1) data[a++] = data[a] + x;
			if (b & 1) data[b] = data[--b] + x;
			a >>= 1; b >>= 1;
		}
	}
	T get(int i) {
		T ret = id;
		i += n;
		while (i > 0) {
			ret = operation(ret, data[i]);
			i >>= 1;
		}
		return ret;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	while (k--) {
		segtree<int> seg(n + 1);
		rep(i, n) seg.change(max(0ll, i - a[i]), min(n, i + a[i] + 1), 1);
		bool flag = true;
		rep(i, n) {
			a[i] = seg.get(i);
			if (a[i] != n) flag = false;
		}
		if (flag) break;
	}
	rep(i, n) cout << a[i] << ' ';
	cout << '\n';
}

Measured memory_bytes: 6900
#include<bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979323846
#define pb push_back
#define po pop_back()
#define mp make_pair
#define fi first
#define se second
#define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007 
using namespace std;
bool isPowerofTwo(ll n){
	return n&(n-1)==0;
}
void solution(){
	ll n,k,ans=0;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(ll i=0;i<k;i++)
	ans+=a[i];
	cout<<ans;
}
int main()
{
	hello;
	/*int t;
	cin>>t;
	while(t--){
		solution();
		cout<<"\n";
	}*/
	solution();
	return 0;
}


Measured memory_bytes: 3652
// B - KEYENCE String
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string s,t="keyence";
	cin>>s;
	int sn = s.size(), tn = t.size();
	rp(L, 0, tn){
		string r;
		int R = sn - (tn-L) - 1;
		rp(m, 0, sn) if(m < L || R < m) r += s[m];//delete [L,R]
		if(r == t){ puts("YES"); return 0; }
	}
	puts("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> l{0};
    for(int i = 1; i <= n; ++i) {
        int y;
        cin >> y;
        y += l.back();
        l.push_back(y);
    }
    cout << upper_bound(l.begin(), l.end(), x) - l.begin() << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(int argc, char** argv)
{
	double a, b, C, radian;

	scanf("%lf %lf %lf", &a, &b, &C);

	//86 77 120
	double radianC = C * M_PI / 180.0;
	double h = b * sin(radianC);
	double S = a * h / 2;
	double L = 0;

	if (C <= 90) {
		double hc = a - sqrt((b * b) - (h * h));
		L = a + b + sqrt((hc * hc) + (h * h));
	}
	else {
		double d = a + sqrt((b * b) - (h * h));
		L = a + b + sqrt((d * d) + (h * h));
	}

	printf("%lf\n%lf\n%lf\n", S, L, h);
	return 0;
}

Measured memory_bytes: 672
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
 
int main() {
 
  int long long t=0,i=0,j=0,T,N,X;
  double sum=0;
  string S;
  int long long ans=0,now=0;

  cin >> N >> X >> T;
  
  ans=(N/X)*T;
  if(N%X!=0){
    ans+=T;
  }
  
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	dp := make([]int, len(s)+1)
	cnt := map[int]int{}
	cnt[0]++
	ans := 0
	b := 1
	for i := 0; i < len(s); i++ {
		num, _ := strconv.Atoi(string(s[len(s)-1-i]))
		dp[i+1] = (num*b%2019 + dp[i]) % 2019
		b *= 10
		b %= 2019
		ans += cnt[dp[i+1]]
		cnt[dp[i+1]]++
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 4324