akhauriyash/Code-Regression huggingface dataset:
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
 */
//入力終了→Ctrl+D
import java.time.Year;
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[][] dice=new int[n][6];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 6; j++) {
                dice[i][j]=sc.nextInt();
            }
        }
        String s = "";
        for (int i = 0; i < 4; i++) {
            s += "N";
        }
        for (int i = 0; i < 4; i++) {
            s += "E";
        }
        for (int b=0;b<n;b++) {
            for (int a = 0; a < n; a++) {
                if(a==b)break;
                for (int k = 0; k < s.length(); k++) {
                    for (int j = 0; j < 4; j++) {
                        if (Arrays.equals(dice[a], dice[b])) {
                            out.println("No");
                            exit(0);
                        }
                        roll(dice[b], 'L');
                    }
                    roll(dice[b], s.charAt(k));
                }
            }
        }
        out.println("Yes");
    }

    static void roll(int[] men,char c) {
        int t = men[0];
        switch (c) {
            case 'S':
                men[0] = men[4];
                men[4] = men[5];
                men[5] = men[1];
                men[1] = t;
                break;
            case 'E':
                men[0] = men[3];
                men[3] = men[5];
                men[5] = men[2];
                men[2] = t;
                break;
            case 'W':
                men[0] = men[2];
                men[2] = men[5];
                men[5] = men[3];
                men[3] = t;
                break;
            case 'N':
                men[0] = men[1];
                men[1] = men[5];
                men[5] = men[4];
                men[4] = t;
                break;
            case 'L':
                t=men[1];
                men[1]=men[3];
                men[3]=men[4];
                men[4]=men[2];
                men[2]=t;
                break;
            default:
                break;
        }
    }
}


Measured memory_bytes: 29440
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int n, m; cin >> n >> m;
    rep(i,m) {
        int a; cin >> a;
        n -= a;
    }
    if (n < 0) {
        cout << -1 << endl;
    } else {
        cout << n << endl;
    }
    return 0;
}


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

void solve(long long N, long long A, long long B)
{
    cout << (N / (A + B)) * A + min(A, N % (A + B)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=(a[1]//a[2])-(a[0]-1)//a[2]
C=(a[1]//a[3])-(a[0]-1)//a[3]
d=(a[2]*a[3])//(fractions.gcd(a[2],a[3]))
D=(a[1]//d)-((a[0]-1)//d)
print(int(A-B-C+D))

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

using namespace std;
using ll = long long;

int main()
{
    ll n, a;
    string s;
    cin >> n;
    while (n >= 1)
    {
        a = n % 26;
        if (a == 0)
        {
            a = 26;
        }
        n -= a;
        s += (char)97 + a - 1;
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 1e5+100;
const ll inf = 1e15;
const ll mod = 1e9+7;



int main(){
	fastio;
	ll a,b,n,x = inf;
	cin >>n;
	for(ll i = 1;i*i<=n;i++){
		if(n%i ==0){
			x = min(x,i+n/i -2);
		}
	}
	cout << x << endl;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  ll S;
  cin >> S;
  ll K = 1e9;
  ll p, q;
  q = S % K;
  p = 1 + (S - q) / K;
  if (q == 0) {
    q = K;
    p--;
  }
  cout << 0 << " " << 1 << " " << K << " " << 0 << " " << q << " " << p << endl;

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i] >> B[i];
    }
    
    ll cnt = 0;
    
    for(int i = N - 1; i >= 0; --i){
        ll temp;
        A[i] += cnt;
        if(A[i] % B[i] == 0)        continue;
        temp = B[i] - A[i] % B[i];
        cnt += temp;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dp[103][100007];
ll V[100007],W[100007];

int main(){
  ll N,w;
  cin >> N >> w;
  rep(i,N){
    cin >> W[i+1] >> V[i+1];
  }
  Rep(i,1,N+1){
    rep(j,w+1){
      if(j>=W[i]){
        dp[i][j]=max(dp[i-1][j-W[i]]+V[i],dp[i-1][j]);
      }
      else{
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  cout << dp[N][w] << endl;
}

Measured memory_bytes: 80256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
char ch[505][505];
int vis[505][505];
int love[8][8]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};
int h[8][8]={{0,1},{1,0},{-1,0},{0,-1}};
int n,m;
int arr[123];
int main()
{
	ll k,d,x;
	scanf("%lld%lld%lld",&x,&k,&d);
	if(x<0)
	x=abs(x);
	ll a=x/d;
	ll b=x%d;
	if(k<a)
	{
		ll c=x-k*d;
		printf("%lld",c);
	}
	if(k==a)
	{
		printf("%lld",b);
	}
	if(k>a)
	{
		ll c=k-a;
		if(c%2==0)
		printf("%lld",b);
		else
		{
			ll e=min(abs(b-d),b+d);
			printf("%lld",e);
		}
	}
} 
       

Measured memory_bytes: 3824
/*
	Author: Ritik Patel
*/
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
// #define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
// #pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#include <bits/stdc++.h>
using namespace std;
 
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
//find_by_order()->returns an iterator to the k-th largest element(0-based indexing)
//order_of_key()->Number of items that are strictly smaller than our item
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define int long long int
// #define ll long long int
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
// #define ld long double
// const ld PI  = 3.141592;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&

const int MAXN = 1e4 + 5;
int cnt[MAXN];

int calc(int x, int y, int z){
    int temp = (x*x + y*y + z*z + x*y + y*z + z*x);
    if(temp >= MAXN)
        temp = 0;
    return temp;
}

void solve(){
    int N; cin >> N;
    for(int i = 1; i <= 200; ++i){
        for(int j = 1; j <= 200; ++j){
            for(int k = 1; k <= 200; ++k){
                cnt[calc(i, j, k)]++;
            }
        }
    }
    for(int i = 1; i <= N; ++i){
        cout << cnt[i] << '\n';
    }
}
 
 
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    // cin >> T;
    for(int i = 1; i <= T; ++i){
        // brute();
        solve();
    }
    return 0;
}
 
/*
Sample inp
*/

Measured memory_bytes: 3660
N = int(input())
S = input()
count = 0
if N == 3:
  if S == 'ABC':
    count = 1
elif N > 3:
	for i in range(N-2):
		if S[i] == 'A':
			if S[i+1] == 'B':
				if S[i+2] == 'C':
					count += 1
print(count)


Measured memory_bytes: 9176
#include <cmath>
#include <deque>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int main()
{
    int L = 0, R = 0, d = 0;
    int ans = 0;

    cin >> L;
    cin >> R;
    cin >> d;

    for (int i = L; i <= R; i++)
        if (i % d == 0)
            ans++;

    cout << ans << endl;

    return 0;
}

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

int main()
{
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    int k;
    cin >> k;

    if (e - a <= k)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();

		int rgb = 100*r + 10*g + b;

		if (rgb % 4 == 0){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21972
use std::io::*;
use std::vec::*;
use std::collections::BinaryHeap;

fn dijkstra(graph: &Vec<Vec<(usize, i64)>>, start: usize) -> Vec<i64> {
    let mut dist = vec![-(1 << 62); graph.len()];
    let mut heap = BinaryHeap::new();
    dist[start] = 0;
    heap.push((0, start));
    while let Some((acc, pos)) = heap.pop() {
        if dist[pos] > acc { continue; }
        for &(dst, cost) in &graph[pos] {
            if acc + cost > dist[dst] {
                dist[dst] = acc + cost;
                heap.push((acc + cost, dst));
            }
        }
    }
    return dist;
}

fn main(){
    let mut input = String::new();
    let _ = stdin().read_line(&mut input);

    let nums: Vec<i32> = input.split_whitespace().map(|e| e.parse().unwrap()).collect();
    let v = nums[0] as usize;
    let e = nums[1];
    let r = nums[2];

    let mut graph = vec![vec![]; v];

    for _ in 0..e {
        let mut input = String::new();
        let _ = stdin().read_line(&mut input);
        let edge: Vec<i64> = input.split_whitespace().map(|e| e.parse().unwrap()).collect();
        let s = edge[0] as usize;
        let t = edge[1] as usize;
        let d = edge[2];
        graph[s].push((t, -d));
    }

    for d in dijkstra(&graph, r as usize) {
        if d <= -(1 << 62) {
            println!("INF");
        } else {
            println!("{}", -d);
        }
    }
}



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

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

  rep(x,50000) {
    if ((int)(x * 1.08) == n) {
      cout << x << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 3540
import numpy as np
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

a = np.array(A)
b = np.array(B)
c = np.zeros(N)

# cはaとbの要素をすべて足したもの
c = a + b
# 降順にソート
csorted = np.sort(c)[::-1]
# bの総和
bsum = np.sum(b)
# csortedの奇数番目を足していって最後にbsumの値を引けば求まる。
csum = 0
for i in range(N):
    if i % 2 == 0:
        csum += int(csorted[i])

ans = csum - bsum

print(ans)

Measured memory_bytes: 22984
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <functional>
//#include <cmath>

int main(){
    int32_t N, L;
    std::cin >> N >> L;
    
    // sumN
    // sumN-1 = sumN - Ti
    // choose Ti where smallest |Ti|

    int32_t sum = 0;
    if(L < 0){
        if(L + N - 1 >= 0){
            //pick 0
            for(int32_t i = 1; i <= N; i++){
                sum += L + i - 1;
            }
        }
        else{
            //pick biggest
            for(int32_t i = 1; i <= N - 1; i++){
                sum += L + i - 1;
            }
        }
    }
    else{
        //pick smallest
        for(int32_t i = 2; i <= N; i++){
            sum += L + i - 1;
        }
    }
    std::cout << sum;

    return 0;
}


Measured memory_bytes: 256
import sys, heapq
from collections import defaultdict
from itertools import product, permutations, combinations

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

N, u, v = map(int, input().split())



def dijkstra_heap(s,edge):
#始点sから各頂点への最短距離
    d = [10**20] * N
    used = [True] * N #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

AB = [list(map(int, input().split())) for _ in range(N-1)]

adjl = [[] for _ in range(N)]
for ab in AB:
    a, b = ab[0]-1, ab[1]-1
    adjl[a].append([1, b])
    adjl[b].append([1, a])

du = dijkstra_heap(u-1, adjl)
dv = dijkstra_heap(v-1, adjl)
dOK = [j for i, j in zip(du, dv) if i < j]

print(int(max(dOK)-1))


Measured memory_bytes: 107996
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    h, w = input_int_list()
    ans = []
    grid = []
    for _ in range(h):
        grid.append(input_int_list())
    # 行ごとに左から偶数を作っていく
    # 右端での調整は1行したに渡す
    # 計算量: O(hw)

    for i in range(h):
        for j in range(w):
            if grid[i][j] % 2 == 1:
                if i == h - 1 and j == w - 1:
                    break
                grid[i][j] -= 1
                if j < w - 1:
                    grid[i][j + 1] += 1
                    ans.append((i + 1, j + 1, i + 1, j + 2))  # 1-indexed
                elif i < h - 1:
                    grid[i + 1][j] += 1
                    ans.append((i + 1, j + 1, i + 2, j + 1))  # 1-indexed

    print(len(ans))
    for query in ans:
        print(*query)

    return


if __name__ == "__main__":
    main()


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

int main(){
	int N,W;
  cin>>N>>W;
  ll w[N],v[N];
  
  rep(i,N){
  	cin>>w[i]>>v[i];
  }
  
  ll dp[N+10][W+10];
  
  rep(i,W)dp[0][i]=0;
  
  for(int i=0;i<N;i++){
  	for(int sub=0;sub<W+1;sub++){
    	if(sub-w[i]>=0)dp[i+1][sub]=max(dp[i][sub],dp[i][sub-w[i]]+v[i]);
      else dp[i+1][sub]=dp[i][sub];
    }
  
  }
  cout<<dp[N][W];
  
  
}

Measured memory_bytes: 79872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG


signed main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i] -= i+1;
  }
  
  sort(all(A));
  
  int b = A[N/2];
  
  int ans = 0;
  rep(i, N) ans += abs(A[i]-b);
  cout << ans << endl;
    
  
}

Measured memory_bytes: 4788
N = int(input())
A = list(map(int, input().split()))
Cnt = [0] * (N+1)
for a in A:
    Cnt[a] += 1
ans0 = 0
for c in Cnt:
    ans0 += c * (c-1) // 2
Ans = [ans0 - Cnt[a] + 1 for a in A]
print("\n".join(map(str, Ans)))


Measured memory_bytes: 46804
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

int Sum10(int n);

int main()
{
    // 入力
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i=0;i<h;i++){
        cin >> a[i];
    }

    vector<bool> row(h,false);
    vector<bool> col(w,false);
    for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
            if (a[i][j]=='#'){
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i=0;i<h;i++){
        if(row[i]){
            for (int j=0;j<w;j++){
                if (col[j]){
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }

    return 0;
}

int Sum10(int n){
    int sum = 0;
    while (n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}


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

int		main(void)
{
	int		n, sum;
	cin >> n >> sum;
	int		x, y, z;

	sum /= 1000;
	x = 0;
	while (x <= n){
		y = 0;
		while (x + y <= n){
			z = n - x - y;
			if (10 * x + 5 * y + z == sum){
				cout << x << " " << y << " " << z;
				return (0);
			}
			y++;
		}
		x++;
	}
	cout << "-1 -1 -1";
}


Measured memory_bytes: 256
X,Y,Z,K = map(int,input().split())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
C = [i for i in map(int,input().split())]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for i in range(X):
    for j in range(Y):
        if (i+1) * (j+1) > K:
            break
        for k in range(Z):
            if (i+1) * (j+1) * (k+1) > K:
                break
            ABC.append(A[i] +  B[j] + C[k])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

Measured memory_bytes: 8708
def resolve():
    n = int(input())
    l = [list(map(int,input().split())) for i in range(2)]

    count = 0
    for i in range(n):
        tmp = 0
        c = -1
        for j in range(0, i+1):
            tmp += l[0][j]
            c += 1
        tmp += l[1][c]
        c += 1
        for k in range(c, n):
            tmp += l[1][k]
        count = max(tmp, count)

    print(count)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

bool check_XX(string& s, pair<int, int>& result) {
	result = make_pair(-1, -1);
	bool found = false;
	for (int i=0; i<s.size()-1; i++) {
		if (s[i] == s[i+1]) {
			result = make_pair(i+1, i+2);
			found = true;
			break;
		}
	}

	return found;
}

bool check_XYX(string& s, pair<int, int>& result) {
	result = make_pair(-1, -1);
	bool found = false;
	for (int i=0; i<s.size()-2; i++) {
		if (s[i] != s[i+1] && s[i] == s[i+2]) {
			result = make_pair(i+1, i+3);
			found = true;
			break;
		}
	}

	return found;
}

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

	pair<int, int> result;

	if (!check_XX(s, result)) {
		check_XYX(s, result);
	}

	cout << result.first << " " << result.second << endl;

	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li x[55];
li y[55];
li n;

inline li calc(li dx, li dy) {
    li cnt = 0;
    rin{
        repp(j, i + 1, n) {
            if ((x[i] - x[j] == dx &&
            y[i] - y[j] == dy) ||
            (x[i] - x[j] == -dx &&
            y[i] - y[j] == -dy)) {
                cnt++;
            }
        }
    }
    return cnt;
}


int main() {
    cin >> n;
    rin{
        cin >> x[i] >> y[i];
    }

    li res = n;

    rin{
        repp(j, i + 1, n) {
            li dx = x[i] - x[j];
            li dy = y[i] - y[j];
            res = min(res, n - calc(dx, dy));
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i=0; i<n; i++){
            double x1 = sc.nextDouble();
            double y1 = sc.nextDouble();
            double x2 = sc.nextDouble();
            double y2 = sc.nextDouble();
            double x3 = sc.nextDouble();
            double y3 = sc.nextDouble();
            double px = ((y1-y3)*(Math.pow(y1,2) -Math.pow(y2,2) +Math.pow(x1,2) -Math.pow(x2,2)) -(y1-y2)*(Math.pow(y1,2) -Math.pow(y3,2) +Math.pow(x1,2) -Math.pow(x3,2))) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
            double py = ((x1-x3)*(Math.pow(x1,2) -Math.pow(x2,2) +Math.pow(y1,2) -Math.pow(y2,2)) -(x1-x2)*(Math.pow(x1,2) -Math.pow(x3,2) +Math.pow(y1,2) -Math.pow(y3,2))) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
            double r = Math.pow(Math.pow(x1-px,2) + Math.pow(y1-py,2), 0.5);
            System.out.format("%.3f %.3f %.3f\n", px, py, r);
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  
  int a = n/10; //上3桁
  int b = n%1000; //下3桁
  int c = n/1000; //1000の位
  int d = n%10; //1の位

  if ( a == (c*100+c*10+c) || b == (d*100+d*10+d) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;


public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String read = null;
		ArrayList<String> output = new ArrayList<String>();

		int loop = Integer.parseInt(reader.readLine());

		while (loop > 0) {
			read = reader.readLine();
			String[] parts = read.split(" ");
			int[] nums = new int[3];
			int c = 0;
			for (String part:parts) {
				nums[c] = Integer.parseInt(part);
				c++;
			}

			Arrays.sort(nums);

			if (Math.pow(nums[0], 2) + Math.pow(nums[1], 2) == Math.pow(nums[2], 2)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}


			loop--;
		}

		for (String str:output) {
			System.out.println(str);
		}

	}

}

Measured memory_bytes: 20240
#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define L(a,d) ((a)<<((d)*3))
#define R(a,d) (((a)>>((d)*3))&7)
int h,w,c,f[16][16],ofs[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
void P(int d){int m=~L(7,d+1);rep(i,h)rep(j,w){f[i][j]&=m;f[i][j]|=L(R(f[i][j],d),d+1);}}
int F(int x,int y, int d, int C){int n=1;int a=R(f[y][x],d);int m=~L(7,d+1);f[y][x]&=m;f[y][x]|=L(C,d+1);for(auto l:ofs){int s=x+l[0];int t=y+l[1];if(0<=s&&s<w&&0<=t&&t<h&&R(f[t][s],d)==a&&R(f[t][s],d+1)!=C)n+=F(s,t,d,C);}return n;}
int D(int d){if(d&4){P(d);F(0,0,d,c);P(d+1);return F(0,0,d+1,7);}int x=0;for(int r=1;r<=6;++r){P(d);F(0,0,d,r);int v=D(d+1);x=x>v?x:v;}return x;}
int main(){while(cin>>h>>w>>c,h){rep(i,h)rep(j,w)cin>>f[i][j];cout<<D(0)<<endl;}return 0;}

Measured memory_bytes: 1164
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;


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

	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;

		vector<int> ai(k);
		for (int j = 0; j < k; j++) {
			cin >> ai[j];
		}
		a.push_back(ai);
	}
	vector<int> p;
	for (int i = 0; i < m; i++) {
		int pi;
		cin >> pi;
		p.push_back(pi);
	}
	int ans = 0;
	for (int i = 0; i < pow(2, n); i++) {
		bool flag = true;
		int fl = i;
		vector<int> s(n);
		int num = pow(2, n-1);
		for (int j = n - 1; j >= 0; j--) {
			if (fl >= num) {
				s[j] = 1;
				fl = fl - num;
				num = num / 2;
			}
			else {
				s[j] = 0;
				num = num / 2;
			}
	
		}

		
		for (int j = 0; j < m; j++) {
			int sum = 0;
			for (int k = 0; k < a[j].size(); k++) {
				if (s[a[j][k] - 1] == 1) { 
					sum++;
					
				}
			}
			if (sum % 2 != p[j]) {
				flag = false;
			}
			
			
		}
		if (flag)ans++;

	}


	cout << ans << endl;
	return 0;

}


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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    if (N == M) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];



signed main(){
	IOS();
	ll n, sum, x;
	while(1){
		cin >> n;
		sum = 0;
		ll MAX = 0;
		ll MIN = 114514;
		if(n == 0)break;
		for (int i = 0;i < n;++i) {
			cin >> x;
			MAX = max(x, MAX);
			MIN = min(x, MIN);
			sum += x;
		}
		ll ans = floor((sum - MAX - MIN) / (double)(n - 2));
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int tmp;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'E') {
      tmp++;
    }
  }
  int minv = tmp;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'W') {
      tmp++;
    }
    if (s[i] == 'E') {
      tmp--;
    }
    minv = min(minv, tmp);
  }
  cout << minv << '\n';
  return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int x[5],y[5];
    rep(i,3) if(i) cin >> x[i] >> y[i];
    int dx = x[2] - x[1], dy = y[2] - y[1];
    x[3] = x[2] - dy;
    y[3] = y[2] + dx;
    x[4] = x[1] - dy;
    y[4] = y[1] + dx;
    cout << x[3] << " " << y[3] << " " << x[4] << " " << y[4] << endl;
    return 0;
}


Measured memory_bytes: 256
import collections as cl

n = int(input())
s = [""]*n
for i in range(0, n):
    s[i] = input()
    s[i] = ''.join(sorted(s[i]))

cs = cl.Counter(s)
num = list(cs.values())
count = 0

for j in range(0, len(num)):
    if num[j] != 1:
        count = count + (num[j] * (num[j] - 1)) / 2

print(int(count))

Measured memory_bytes: 19720
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int H, W, N; std::cin >> H >> W >> N;
  int A = std::max(H,W);
  int B = std::min(H,W);
  std::cout << std::ceil( (double)N/A ) << std::endl;

  return 0;
}




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

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++){
    int x = i;
    if(x % 3 == 0){
      cout << " " << i;
      continue;
    }
    while(x > 0){
      if(x % 10 == 3){
        cout << " " << i;
        break;
      }
      x /= 10;
    }
    
  }
  cout << endl;
}


Measured memory_bytes: 3104
#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() {
  string S;
  cin >> S;

  deque<char> q;
  for (char c : S) q.push_back(c);
  bool flip = false;

  int Q;
  cin >> Q;
  rep(i, Q) {
    int T;
    cin >> T;
    if (T == 1) {
      flip = !flip;
    } else {
      int F; char C;
      cin >> F >> C;
      if (flip) F = 3 - F;
      if (F == 1) {
        q.push_front(C);
      } else {
        q.push_back(C);
      }
    }
  }

  if (flip) reverse(q.begin(), q.end());
  string ans;
  for (char c : q) ans += c;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
     
    using namespace std;
    typedef long long ll;
    ll mod = 1e9+7;
     
    int main(void)
    {
      ll A,B,C,X,Y;cin>>A>>B>>C>>X>>Y;
      ll res;
      if(C*2>A+B){
        res=X*A+B*Y;
      }
      else{
        ll pat1=min(X,Y)*C*2;
        if(X>Y){
          pat1+=(X-Y)*A;
        }
        else if(Y>X){
          pat1+=(Y-X)*B;
        }
        
        ll pat2=max(X,Y)*C*2;
        
        res = min(pat1,pat2);
      }
      cout<<res<<endl;
    }

Measured memory_bytes: 256
#include <stdio.h>


int main(){

	char s[100];

	scanf("%s",s);

	int i=0,cnt=0;
	for(i=0;i<100;i++){
		if(s[i]=='C')
			cnt=1;

		if(s[i]=='F'&cnt==1)
			cnt=2;
	}
	if(cnt==2)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

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

using namespace std;

typedef long long LL;
int N,A,B,X[100010];

int main()
{
	scanf("%d%d%d",&N,&A,&B);
	for (int i=1;i<=N;i++)scanf("%d",&X[i]);
	LL ans=0;
	for (int i=2;i<=N;i++)
	ans+=min(LL(A)*LL(X[i]-X[i-1]),LL(B));
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

//typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int N, K;

bool check(long long int A){
	long long int hoge = A;
	for(int i = 0; i < N - 1; i++){
		hoge -= hoge / K + (hoge % K > 0);
	}
	return (hoge > 0);
}

long long int bin_search(long long int lef, long long int rig){
	long long int middle = (lef + rig) / 2;
	//cout << middle << " ";
	if(rig - lef <= 1){
		if(check(lef)){
			return lef;
		}else{
			return rig;
		}
	}
	if(check(middle)){
		rig = middle;
	}else{
		lef = middle;
	}
	return bin_search(lef, rig);
}

int main(){
	
	cin >> N >> K;
	
	cout << bin_search(0, 1e18 + 1) - 1 << endl;
	
	return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
#include<string.h>
 
int main(void){
 
	char a,b,c;
	int d,e,f;
	scanf("%c %c %c",&a,&b,&c);
 
	d = a - '0';
	e = b - '0';
	f = c - '0';
 
 
	if((a*100+b*10+c)%4==0){printf("YES\n");}
	else{printf("NO\n");}
 
	return 0;
}

Measured memory_bytes: 128
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD = 1000000007;
lli gcd(lli a, lli b)
{
    return a < b ? gcd(b, a) : (b == 0 ? a : gcd(b, a % b));
}
lli p1, p2;
int main()
{
    lli n, A = 1, B = 1, a, t;
    cin >> n;
    rep(i, n)
    {
        cin >> a >> t;
        if (A % a != 0)
            A += a;
        if (B % t != 0)
            B += t;
        lli ans = max(A / a, B / t);

        if (ans == 0)
            ans = 1;
        A = ans * a, B = ans * t;
    }
    cout << A + B << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long long a, b;
  cin >> a >> b;

  long long c, d;
  c = min(a, b);
  d = max(a, b);

  while (c) {
    d = d % c;
    swap(c, d);
  }

  cout << a * b / d << endl;
}

Measured memory_bytes: 256
import sys
from itertools import combinations 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
X = []
Y = []
XY = []
for _ in range(N):
    x,y = map(int,readline().split())
    X.append(x)
    Y.append(y)
    XY.append((x,y))
INF = 10**31
ans = INF
for x1,x2 in combinations(X,2):
    for y1,y2 in combinations(Y,2):
        if x1 > x2:
            x1,x2 = x2,x1
        if y1 > y2:
            y1,y2 = y2,y1
        cnt = 0 
        for x,y in XY:
            if x1 <= x <= x2 and y1 <= y <= y2:
                cnt += 1 
        if cnt >= K:
            tmp = (x2-x1)*(y2-y1)
            ans = min(ans,tmp)

print(ans)

Measured memory_bytes: 74420
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

ll dp[200005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,in;
	cin>>n;
	vi v(n);
	rep(i,n)cin>>v[i],v[i]--;
	vi prev(200001,-1);
	dp[0]=1;
	rep(i,n){
		dp[i+1]=dp[i];
		if(prev[v[i]]!=-1&&prev[v[i]]!=i-1){
			dp[i+1]+=dp[prev[v[i]]+1];
			dp[i+1]%=MOD;
		}
		prev[v[i]]=i;
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 3456
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long K, long long N, std::vector<long long> A) {
  ll start = 0;
  ll distance = 0;
  ll max = 0;
  rep(i, N) {
    ll diff;
    if (i == 0) {
      diff = (K - A[N - 1]) + A[i];
    } else {
      distance += A[i];
      diff = A[i] - A[i - 1];
    }
    if (diff > max) {
      max = diff;
      // start = i;
    }
  }
  ANS(K - max);
}

// clang-format off
int main() {
  long long K;
  scanf("%lld",&K);
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(K, N, std::move(A));
  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
char s[Max];
int main()
{
	int len;
	int a,b,c;
	a=0,b=0,c=0;
	scanf("%s",s);
	len=strlen(s);
	for(int i=0;s[i];i++)
		if(s[i]=='a')
			a++;
		else if(s[i]=='b')
			b++;
		else if(s[i]=='c')
			c++;
	int ans=min(a,min(b,c));
	a-=ans;
	b-=ans;
	c-=ans;
	if(a>=2 || b>=2 || c>=2)
		printf("NO\n");
	else
		printf("YES\n");
    return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

void solve()
{
    int N; cin >> N;
    vi a(N); REP(i, N) cin >> a[i];
    sort(ALL(a), greater<>());
    int alice = 0, bob = 0;
    REP(i, N)
    {
        if(i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll X, A, B;
  cin >> X >> A >> B;
  if (B <= A) {
    cout << "delicious" << endl;
  } else if (B - A <= X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
def points(i):
    if i=="r":
        point=p
    elif i=="s":
        point=r
    else:
        point=s
    return point
    
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

ans=0
L=[]
for j in range(n):
    if j<k:
        ans+=points(t[j])
        L.append(t[j])
    else:
        if t[j]==L[j-k]:
            L.append("b")
            continue
        else:
            ans+=points(t[j])
            L.append(t[j])
print(ans)

Measured memory_bytes: 4212
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long M = sc.nextLong(),N = sc.nextLong();
		long total = 0;
		for(int i = 0;i<N;i++) {
			total += sc.nextInt();
		}
		if(M-total<0) {
			System.out.println(-1);
		}else {
			System.out.println(M-total);
		}
	}

}


Measured memory_bytes: 46580