akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int N = (int) 1e5 + 5;

long long n;

int main() {

	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int c = 1; c <= 3500; c++)
		for (int b = 1; b <= 3500; b++) {
			long long u = 4 * b * c - n * c - n * b;
			if (u <= 0) continue;
			long long v = n * b * c;
			if (v % u != 0) continue;
			return cout << b << " " << c << " " << v / u, 0;
		}
	return 0;
}

Measured memory_bytes: 256
n,m =  map(int,input().split())
A = [int(input()) for i in range(m)]
mod = 10**9+7
dp=[1]*(n+1)

if m>=2:
    pre = A[0]
    for i in range(1,m):
        if pre+1 == A[i]:
            print(0)
            exit()
        pre = A[i]
if m==0:
    for i in range(1,n+1):
        if i==1:
            dp[i]=1
        else:
            dp[i] = (dp[i-1]+dp[i-2])%mod
    print(dp[-1])
    exit()


idx = 0
a = A[idx]
for i in range(1,n+1):
    if i==a:
        dp[i]=0
        idx+=1
        if idx <m:
            a =A[idx]
    else:
        if i==1:
            dp[i]=1
        else:
            dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[-1])


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

int main(){
    int n,w;
    cin>>n>>w;
    long long weight[n];
    long long value[n];
    for(int i=0;i<n;i++){
        cin>>weight[i];
        cin>>value[i];
    }
    
    long long dp[n+1][w+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0||j==0){
                dp[i][j]=0;
            }
            else{
                long long inc=0,ex=0;
                if(weight[i-1]<=j){
                    inc=value[i-1]+dp[i-1][j-weight[i-1]];
                }
                ex=dp[i-1][j];
                dp[i][j]=max(inc,ex);
            }
            
        }
    }
    
    cout<<dp[n][w]<<endl;
    
   
}

Measured memory_bytes: 79104
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int a,b,x=1;
    cin >> a>> b;
    for(int i=1;i<=25;i++){
        if( a + (a-1)*(i-1) < b )x++;
    }
  if(b==1)x=0;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int sum=0;
	sort(a,a+n);
	for(int i=0;i<k;i++)
	{
		sum+=a[i];
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);


void init() {
     
}

void solve() {
    int m1, d1, m2, d2;
    scanf(IIII,&m1,&d1,&m2,&d2);
    puts( m1 == m2 ? "0" : "1" );
}


#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}


Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
diff_min = float('inf')
for T in range(N):
  s1 = 0
  s2 = 0
  for i in range(T+1):
    s1 += W[i]
  for i in range(N-1,T,-1):
    s2 += W[i]    
    
  diff = abs(s1-s2)
  if diff_min > diff:
    diff_min = diff
    
print(diff_min)

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

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    int hight[t];
    int cnt=0;
    for(int i=0;i<t;i++){
      cin>>hight[i];
      cnt++;
    }
    int maxU,maxD;
    maxU = maxD = 0;
    for(int j=1;j<cnt;j++){
      if(hight[j-1] < hight[j]){
	maxU = max(maxU,hight[j] - hight[j-1]);
      }else{
	maxD = max(maxD,-(hight[j] - hight[j-1]));
      }
    }
    cout << maxU << " " << maxD << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
use std::io::stdin;
use std::collections::VecDeque;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let n:usize = st.trim().parse().unwrap();
    let mut tree:Vec<Vec<usize>> = Vec::with_capacity(n);
    for _i in 0..n {
        tree.push([].to_vec());
    };

    for _i in 0..(n-1) {
        let mut st = String::new();
        stdin().read_line(&mut st).unwrap();
        let (a, b) = {
            let ab:Vec<usize> = st.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
            (ab[0]-1, ab[1]-1)
        };
        tree[a].push(b);
        tree[b].push(a);
    };

    let mut s_queue:VecDeque<usize> = VecDeque::with_capacity(n);
    let mut f_queue:VecDeque<usize> = VecDeque::with_capacity(n);
    s_queue.push_back(n-1);
    f_queue.push_back(0);

    let mut visit:[i64;100002] = [-1; 100002];
    visit[0] = 0;
    visit[n-1] = 0;
    let mut s:i64 = 0;
    let mut f:i64 = 0;

    while (s_queue.len() != 0) || (f_queue.len() != 0) {
        if f_queue.len() != 0 {
            
            let mut g:Vec<usize> = Vec::new();

            while f_queue.len() != 0 {
                let p:usize = f_queue.pop_front().unwrap();
                for i in &tree[p] {
                    let num = *i as usize;
                    if visit[num] < 0 {
                        visit[num] = 0;
                        f += 1;
                        g.push(num);
                    };
                };
            };
            f_queue = g.into_iter().collect();
        };

        if s_queue.len() != 0 {
            
            let mut g:Vec<usize> = Vec::new();

            while s_queue.len() != 0 {
                let p:usize = s_queue.pop_front().unwrap();
                for i in &tree[p] {
                    let num = *i as usize;
                    if visit[num] < 0 {
                        visit[num] = 0;
                        s += 1;
                        g.push(num);
                    };
                };
            };
            s_queue = g.into_iter().collect();
        };
    };
    if f > s {
        println!("Fennec");
    } else {
        println!("Snuke");
    };
}

Measured memory_bytes: 15356
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, M, K;
  cin >> N >> M >> K;
  vector<int64_t> A(N);
  rep(i, N) cin >> A[i];
  vector<int64_t> B(M);
  rep(i, M) cin >> B[i];

  int64_t sumK = 0;
  int64_t answer = 0;
  int64_t a;
  for (a = 0; a < N; ++a) {
    if (K < sumK + A[a]) break;
    sumK += A[a];
    ++answer;
  }

  int64_t tmp_ans = answer;
  rep(i, M) {
    if (K <= sumK) {
      if (a > 0) {
        sumK -= A[--a];
        --tmp_ans;
      } else {
        break;
      }
    }
    sumK += B[i];
    ++tmp_ans;
    if (sumK <= K) {
      answer = max(answer, tmp_ans);
    }
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int h, w;
char field[1010][1010];
int dx[]={0, 0, 1, -1}, dy[]={1, -1, 0, 0};
int main(){
  cin>>h>>w;
  queue<P> que;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>field[i][j];
      if(field[i][j]=='#')que.push(P(i, j));
    }
  }
  int ans=0;
  while(true){
    bool update=false;
    queue<P> tmp;
    while(que.size()){
      P p=que.front();que.pop();
      for(int k=0;k<4;k++){
        int x=p.first+dx[k], y=p.second+dy[k];
        if(0<=x&&x<h&&0<=y&&y<w&&field[x][y]=='.'){
          tmp.push(P(x, y));
          field[x][y]='#';
          update=true;
        }
      }
    }
    que = tmp;
    if(!update)break;
    ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 9600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int main(void) {
    int n;
    cin >> n;
    vector<pair<int, int>> s;
    rep1(i,n) {
        int a;
        cin >> a;
        s.push_back(make_pair(a, i));
    }
    sort(s.begin(), s.end());
    for (auto it : s) {
        cout << it.second << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int64_t>vec(N);
    for (int i=0; i < N; i++) {
        cin >> vec.at(i);
    }

    for (int i=N-1; i > 0; i--) {
        if (vec[i-1] > vec[i]) {
            vec[i-1] = vec[i-1] - 1;
        }
    }

    bool higensyou = true;
    for (int i=0; i < N-1; i++) {
        if (vec[i] > vec[i+1]) {
            higensyou = false;
            break;
        }
    }

    if (higensyou) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B,us=0;
  int C[VMAX+1];
  int n,i,j;

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */

  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }

  for(j=0;j<n;j++){
    scanf("%u",&A[j+1]);
    C[A[j+1]]++;
  }

  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    printf("%u",B[i]);

    if(i<n){
      printf(" ");
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 9576
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    if(a > b) {
        cout << 0 << endl;
        return 0;
    }
    if(n == 1) {
        if(a == b) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else {
        ll ans = b*(n-2)-a*(n-2)+1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,k;
  cin>>n>>k;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll dp[100][2];
  rep(i,100) rep(j,2) dp[i][j]=-1;
  dp[0][0]=0;
  rep(i,50){
    ll mask=1LL<<(50-1-i);
    ll num=0;
    rep(j,n) if(v[j]&mask) num++;
    ll cost0=mask*num;
    ll cost1=mask*(n-num);
    if(dp[i][1]!=-1) chmax(dp[i+1][1],dp[i][1]+max(cost0,cost1));
    
    
    if(dp[i][0]!=-1) if(mask&k) chmax(dp[i+1][1],dp[i][0]+cost0);
    
      
    if(dp[i][0]!=-1){
      if(mask&k) chmax(dp[i+1][0],dp[i][0]+cost1);
      else chmax(dp[i+1][0],dp[i][0]+cost0);
    }
    
  }
  cout<<max(dp[50][0],dp[50][1])<<endl;
}

Measured memory_bytes: 1024
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

data Mode = Inc | Dec deriving Eq

set :: VU.Vector Int -> Int -> Int
set vec acc
  | VU.length vec == 1 = acc + 1
  | otherwise = 
    case compare a b of
      LT -> trav vec Inc acc
      EQ -> set ts acc
      GT -> trav vec Dec acc
  where
    a = VU.head two
    b = VU.last two
    two = VU.take 2 vec
    ts = VU.tail vec

trav :: VU.Vector Int -> Mode -> Int -> Int 
trav vec mode acc 
  | VU.length vec == 1 = acc + 1
  | (mode == Inc) && (a <= b) = trav ts mode acc
  | (mode == Dec) && (a >= b) = trav ts mode acc
  | otherwise = set ts (acc+1)
  where
    a = VU.head two
    b = VU.last two
    two = VU.take 2 vec
    ts = VU.tail vec

main = do
  n <- readLn :: IO Int
  vec <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
  print $ set vec 0



Measured memory_bytes: 3836
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();

      int[] p = new int[n];
      for (int i = 0; i < p.length; i++) {
         p[i] = sc.nextInt();
      }

      int[] q = new int[n];
      for (int i = 0; i < q.length; i++) {
         q[i] = sc.nextInt();
      }

      int a = 0;
      int b = 0;

      int c = 0;


      if(n>2){
      int e = 1;
      for(int i = 1; i <= p.length-1; i++){
         e = e * i;
      }
      a = (p[0] - 1) * e;

      for(int j = 1; j < p.length-2; j++){
         c = 0;
         for (int i = j+1; i < p.length; i++) {
            if(p[j] > p[i]){
               c = c + 1;
            }
         }
         e = 1;
         for(int i = 1; i <= p.length-j-1; i++){
            e = e * i;
         }
         a = a + c * e; 
      }

      if(p[p.length-2] < p[p.length-1]){
         a = a + 1;
      }
      else{
         a = a + 2;
      }


      e = 1;
      for(int i = 1; i <= q.length-1; i++){
         e = e * i;
      }
      b = (q[0] - 1) * e;

      for(int j = 1; j < q.length-2; j++){
         c = 0;
         for (int i = j+1; i < q.length; i++) {
            if(q[j] > q[i]){
               c = c + 1;
            }
         }
         e = 1;
         for(int i = 1; i <= q.length-j-1; i++){
            e = e * i;
         }
         b = b + c * e; 
      }
      if(q[q.length-2]<q[q.length-1]){
         b = b + 1;
      }
      else{
         b = b + 2;
      }
      System.out.println(Math.abs(a-b));
      }

      else{
         System.out.println(1);
      }
   }
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a.at(i);
    }
    sort(a.rbegin(), a.rend());
    const vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    vector<int> max_digit(n + 1, -1);
    max_digit.at(0) = 0;
    for (int i = 0; i < n; i++) {
        if (max_digit.at(i) == -1) continue;
        
        for (int j = 0; j < m; j++) {
            int c = cost.at(a.at(j));
            if (i + c <= n) max_digit.at(i + c) = max(max_digit.at(i + c), max_digit.at(i) + 1);
        }
    }

    int num = n;
    int d = max_digit.at(n);
    
    while (num > 0) {
        for (int i = 0; i < m; i++) {
            int c = cost.at(a.at(i));
            if (num - c < 0) continue;
            
            if (d - 1 == max_digit.at(num - c)) {
                printf("%d", a.at(i));
                num -= c;
                d--;
                break;
            }
        }
    }
    cout << endl;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e16
ll n0;
ll dp[100005]={0};
ll fun(ll arr[],ll i)
{
    if(dp[i]!=-1) return dp[i];
    if(i==n0) return 0;
    if(i>n0) return INF;
    ll a=fun(arr,i+1)+abs(arr[i+1]-arr[i]);
    ll b=fun(arr,i+2)+abs(arr[i+2]-arr[i]);
    dp[i]=min(a,b);
    return dp[i];
    
    
}
void solv()
{
    ll a,b,c,d,e,f,n,m,k,t,q;
    cin>>n;
    ll arr[n+1];
    n0=n;
    for(int i=0;i<n;i++) 
    {
        cin>>arr[i+1];
        dp[i+1]=-1;
    }
    
    a=fun(arr,1);
    
    cout<<a<<"\n";
    
}
int main()
{
    ll a,b,c,d,e,f,n,m,k,t,q;
    t=1;
    //cin>>t;
    string s1,sf,phrase;
    while(t--)
    {
        solv();
    }
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#define mod 998244353
#define PI acos(-1.0)
typedef long long ll;
typedef unsigned long long ull;
//const int INF=0x3f3f3f3f;
const ll INF=1000000000000000000;
//priority_queue<int, vector<int>, greater<int> >p;
int main()
{
    ll n,x,y;
    ll sum=0,ans=INF;
    scanf("%lld",&n);
    while(n--)
    {
        scanf("%lld%lld",&x,&y);
        sum+=y;
        if(x>y)ans=min(ans,y);
    }
    if(ans==INF)printf("0\n");
    else printf("%lld\n",sum-ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
const int MAX = 505050;
const int MID = 777;
int vis[MAX];
vector<pair<int,pair<int,int> > > que[MID];
int ans[MAX];
int arr[MAX];
bool tmr(pair<int,pi> a,pair<int,pi> b){
	return a.y.x < b.y.x;
}
int main(void){
	int n,q;
	scanf("%d%d",&n,&q);
	for(int e=0;e<n;e++) scanf("%d",&arr[e]);
	for(int e=0;e<q;e++){
		int l,r;
		scanf("%d%d",&l,&r);
		l--;
		r--;
		que[l/MID].push_back(mk(l,mk(r,e)));
	}
	for(int e=0;e<MID;e++){
		if(sz(que[e])==0) continue;
		memset(vis,0,sizeof(vis));
		sort(all(que[e]),tmr);
		int tot = 0;
		for(int p=que[e][0].x;p<=que[e][0].y.x;p++){
			if(vis[arr[p]]==0) tot++;
			vis[arr[p]]++;
		}
		ans[que[e][0].y.y] = tot;
		int ll = que[e][0].x,rr = que[e][0].y.x;
		for(int p=1;p<sz(que[e]);p++){
			int l2 = que[e][p].x,r2 = que[e][p].y.x,wh = que[e][p].y.y;
			if(ll>l2){
				for(int q=ll-1;q>=l2;q--){
					if(vis[arr[q]]==0) tot++;
					vis[arr[q]]++;
				}
			}else{
				for(int q=ll;q<l2;q++){
					vis[arr[q]]--;
					if(vis[arr[q]]==0) tot--;
				}
			}
			for(int q=rr+1;q<=r2;q++){
				if(vis[arr[q]]==0) tot++;
				vis[arr[q]]++;
			}
			ans[wh] = tot;
			ll = l2;
			rr = r2;
		}
	}
	for(int e=0;e<q;e++) printf("%d\n",ans[e]);
	return 0;
}


Measured memory_bytes: 18652
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    string s;
    cin >> s;

    ll L = s.size();

    if(s[0]==s.back()){
        // ababa
        if(L%2==0){
            p("First");
        }else{
            p("Second");
        }
    }
    else{
        // ababab
        if(L%2==1){
            p("First");
        }else{
            p("Second");
        }
    }

    return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


class BIT {//binary indexed tree, Fenwick treeとも
	int lg;
	std::vector<int> bit;
public:
	BIT(int size) :bit(size + 1, 0) {
		lg = size;
		while (lg&lg - 1)lg &= lg - 1;
	}
	void add(int i, int x) {//i番目にx加える
		i++;//BIT添え字は1～ｎだから
		while (i<(int)bit.size()) {
			bit[i] += x;
			i += i&-i;
		}
	}
	int sum(int a)const {//[0,a]の和
		a++;
		int res = 0;
		while (0<a) {
			res += bit[a];
			a -= a&-a;
		}
		return res;
	}
	int sum(int a, int b)const {//[a,b]の合計
		return sum(b) - sum(a - 1);
	}
};


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

	int n, m, q;
	cin >> n >> m >> q;
	vector<pair<int, int>> v;
	rep(i,m) {
		int l, r;
		cin >> l >> r;
		v.emplace_back(l, r);
	}
	sort(all(v));


	vector<tuple<int, int, int>> query;
	rep(i,q) {
		int p, q;
		cin >> p >> q;
		query.emplace_back(p, q, i);
	}
	sort(all(query));

	vector<int> ans(q);
	BIT bit(n + 1);
	int idx = m - 1;
	for (int i = q - 1; i >= 0;i--) {
		int p = get<0>(query[i]);
		int q = get<1>(query[i]);

		while (0 <= idx && p <= v[idx].first) {
			bit.add(v[idx].second, 1);
			idx--;
		}
		ans[get<2>(query[i])] = bit.sum(q);
	}
	rep(i, q) {
		cout << ans[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 5232
class UnionFind():
    def __init__(self, n):
        self.parents = [-1 for _ in range(n)]  # 各要素の親 自分が根の場合は -1 * (木の要素数)

    def root(self, x):  # xが属する木の根を返す
        if self.parents[x] < 0:  # 自分が根の場合
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def merge(self, x, y):  # xが属する木とyが属する木を合体する
        x_root = self.root(x)  # xの根
        y_root = self.root(y)  # yの根

        if x_root == y_root:  # 同じ木に属する
            return

        if abs(self.parents[x_root]) >= abs(self.parents[y_root]):  # 要素数の比較
            self.parents[x_root] += self.parents[y_root]
            self.parents[y_root] = x_root
        else:
            self.parents[y_root] += self.parents[x_root]
            self.parents[x_root] = y_root

    def size(self, x):  # xが属する木の要素数
        return -self.parents[self.root(x)]

    def same(self, x, y):  # xとyが同じ木に属するか判定
        return self.root(x) == self.root(y)

    def roots(self):  # すべての根を求める
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):  # 木が何個あるか
        return len(self.roots())


def main():
    n, m = map(int, input().split())
    ab_list = [list(map(int, input().split())) for _ in range(m)]
    ans_list = [0 for _ in range(m)]
    ans_list[m - 1] = n * (n - 1) // 2
    uf = UnionFind(n)

    for i in range(m - 1, 0, -1):
        a = ab_list[i][0] - 1
        b = ab_list[i][1] - 1
        if uf.same(a, b):
            ans_list[i - 1] = ans_list[i]
        else:
            ans_list[i - 1] = ans_list[i] - \
                uf.size(uf.root(a)) * uf.size(uf.root(b))
        uf.merge(a, b)

    for ans in ans_list:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 101232
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N + 1];
            for (int i = 0; i < N; i++) {
                a[i + 1] = in.nextInt();
            }
            int[] boxBalls = new int[N + 1];
            for (int i = N; i >= 1; i--) {
                int sumBalls = 0;
                for (int j = i; j < boxBalls.length; j += i) {
                    sumBalls += boxBalls[j];
                }
                boxBalls[i] = sumBalls % 2 == a[i] ? 0 : 1;
            }

            int M = 0;
            StringBuilder sb = new StringBuilder();
            for (int i = N; i >= 1; i--) {
                if (boxBalls[i] > 0) {
                    if (sb.length() > 0) {
                        sb.append(" ");
                    }
                    sb.append(i);
                    M++;
                }
            }
            System.out.println(M);
            System.out.println(sb.toString());
        }
    }
}


Measured memory_bytes: 78652
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  rep(i,h) cin >> v[i];

  vector<vector<int>> a(h);
  vector<vector<int>> b(w);

  rep(i,h) {
    int count = 0;
    rep(j,w) {
      if (v[i][j] == '.') count++;
      else {
        rep(k,count) a[i].push_back(count);
        a[i].push_back(0);
        count = 0;
      }
    }
    rep(k,count) a[i].push_back(count);
  }
  rep(i,w) {
    int count = 0;
    rep(j,h) {
      if (v[j][i] == '.') count++;
      else {
        rep(k,count) b[i].push_back(count);
        b[i].push_back(0);
        count = 0;
      }
    }
    rep(k,count) b[i].push_back(count);
  }

  int ans = 0;
  rep(i,h) {
    rep(j,w) {
      ans = max(ans, a[i][j] + b[j][i] - 1);
    }
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 43112
#pragma warning (disable :4996)
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-12;
#define For(i,n,m) for(int i=n;i<=m;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,l,r) for(int i=l;i>=r;--i)
#define clr(a,b) memset(a,b,sizeof(a))

ll n, A, B, C;
string s[100500];
char ans[100500];
void dfs(int cur ,int a, int b, int c) {
	if(cur>n){
		cout << "Yes\n";
		rep(i, 1, n) cout << ans[i] << "\n";
		exit(0);
	}
	if (s[cur] == "AB") {
		if (a >= 1) { ans[cur] = 'B'; dfs(cur + 1, a - 1, b + 1, c); }
		if (b >= 1) { ans[cur] = 'A'; dfs(cur + 1, a + 1, b - 1, c); }
	}
	else if (s[cur] == "AC") {
		if (a >= 1) { ans[cur] = 'C'; dfs(cur + 1, a - 1, b, c + 1); }
		if (c >= 1) { ans[cur] = 'A'; dfs(cur + 1, a + 1, b, c - 1); }
	}
	else {
		if (b >= 1) { ans[cur] = 'C'; dfs(cur + 1, a, b - 1, c + 1); }
		if (c >= 1) { ans[cur] = 'B'; dfs(cur + 1, a, b + 1, c - 1); }
	}
}
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> n >> A >> B >> C;
	rep(i, 1, n) cin >> s[i];
	dfs(1, A, B, C);
	cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 14708
#include<iostream>
#include<string>
using namespace std;
 int main(){
	 string A ;
	 char R;
	 cin>>A;
	 

	 for(int i =0; i<A.length()/2; i++){
		 R = A[i];
		
		 A[i]=A[A.length()-i -1] ;
		 A[A.length()-i-1]= R;
	 }

	 cout<<A<<endl;

	 return 0;


}

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

template<typename type>
struct union_find{
	vector<type>par; vector<size_t>rank,len;
	explicit union_find(size_t n)
		:par(n,-1),rank(n),len(n,1){}
	type find(type val){
		if(par.at(val)<0)return val;
		return par.at(val)=find(par.at(val));
	}
	bool same(type a,type b){
		return find(a)==find(b);
	}
	void unite(type a,type b){
		a=find(a),b=find(b);
		if(a==b)return;
		if(rank.at(a)<rank.at(b)){
			par.at(a)=b;
			len.at(b)+=len.at(a);
		}
		else{
			if(rank.at(a)==rank.at(b))++rank.at(a);
			par.at(b)=a;
			len.at(a)+=len.at(b);
		}
	}
	size_t size(type i){return len.at(find(i));}
};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	union_find<int>uf(n+1);
	for(int i=0;i<m;++i){
		int x,y,z; cin>>x>>y>>z;
		uf.unite(x,y);
	}
	vector<bool>v(n+1,false);
	for(int i=1;i<=n;++i)v.at(uf.find(i))=true;
	cout<<count(v.begin(),v.end(),true)<<"\n"s;
}


Measured memory_bytes: 5312
import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    K = int(rl())
    ans = 0
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            for k in range(1, K + 1):
                tmp = gcd(i, j)
                tmp = gcd(tmp, k)
                ans += tmp
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9196
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
std::vector<pii> v;
ll n;
ll ans[2005][2005];
ll val = 0;
ll sol = 0;

ll dp(ll l, ll r)
{
	ll k=(r-l+1);
	//base case
	if (l == r)
	{
		return v[k].fir * abs(r - v[k].sec);
	}
	else
	{
		if(ans[l][r]==-1)
		{
			ll len;
		    len= max(v[k].fir * abs(l - v[k].sec) + dp(l + 1, r), v[k].fir * abs(r - v[k].sec) + dp(l, r - 1));
		    ans[l][r]=len;
		    return len;
		}
		else
			return ans[l][r];
	}

}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(ans, -1, sizeof(ans));
	ll y;
	cin >> n;
	v.pb(make_pair(INT_MIN, 0));
	for (int i = 1; i <= n; i++)
	{
		cin >> y;
		v.pb(make_pair(y, i));
	}
	sort(v.begin(), v.end());
	cout << dp(1, n);


}

Measured memory_bytes: 35200
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int mod = 2019;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res=res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>>vec(h, vector<char>(w));
	set<int>vec2;
	set<int>vec3;
	rep(i, h) {
		rep(j, w) {
			cin >> vec[i][j];
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (vec[i][j] == '#') {
				goto skip;
			}
		}
		vec2.insert(i);
		skip:;
	}
	rep(i, w) {
		rep(j, h) {
			if (vec[j][i] == '#') {
				goto skip2;
			}
		}
		vec3.insert(i);
	skip2:;
	}
	rep(i, h) {
		if (vec2.count(i)) {
			continue;
		}
		rep(j, w) {
			if (vec3.count(j)) continue;
			cout<< vec[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k; cin >> n >> k;
  set<int>s;
  for(int i = 0; i < n; i++){
    int d; cin>> d;
    for(int j = 0; j < d; j++){
      int a; cin >> a;
      s.insert(a);
    }
  }
  cout << n - s.size();
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main()
{
  int a,b;
  cin>>a>>b;
  int i=1,x=-1;
  
  for(i=1;i<10001;i++)
  {
    int A=i*0.08,B=i*0.1;
    if((A==a)&&(B==b))
    {
      x=i;
      break;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  solve
  def solve: Unit = {
    val a = readLine.trim
    if (a == ".") return
    val b = readLine.trim
    println(parse(a.toList, b.toList) match {
      case Identical ⇒ "IDENTICAL"
      case Close ⇒ "CLOSE"
      case Different ⇒ "DIFFERENT"
    })
    solve
  }
  sealed trait Similarity
  case object Identical extends Similarity
  case object Close extends Similarity
  case object Different extends Similarity
  sealed trait State
  case class ConstString(string: List[Char]) extends State
  case class NonString(state: List[Char]) extends State
  def parse(stateA: List[Char], stateB: List[Char]): Similarity = {
    @tailrec
    def sub(state: List[Char], result: List[Char]): (List[Char], List[Char]) = {
      state match {
        case Nil ⇒ (result, Nil)
        case '"'::t ⇒ (result, t)
        case h::t ⇒ sub(t, h::result)
      }
    }
    @tailrec
    def subParse(state: List[Char], result: List[State] = Nil): List[State] = {
      state match {
        case Nil ⇒ result
        case '"'::t ⇒ sub(t, Nil) match {
          case (str, rest) ⇒ subParse(rest, ConstString(str)::result)
        }
        case t ⇒ sub(t, Nil) match {
          case (str, Nil) ⇒ NonString(str)::result
          case (str, t) ⇒ subParse('"'::t, NonString(str)::result)
        }
      }
    }
    @tailrec
    def compare(a: List[Char], b: List[Char]): Boolean = {
      (a, b) match {
        case (ha::ta, hb::tb) if ha == hb ⇒ compare(ta, tb)
        case (Nil, Nil) ⇒ true
        case _ ⇒ false
      }
    }
    @tailrec
    def compareState(a: List[State], b: List[State], result: Similarity = Identical): Similarity = {
      (a, b) match {
        case (ConstString(sa)::ta, ConstString(sb)::tb) ⇒ if (compare(sa, sb)) compareState(ta, tb, result)
        else result match {
          case Close ⇒ Different
          case _ ⇒ compareState(ta, tb, Close)
        }
        case (NonString(sa)::ta, NonString(sb)::tb) if compare(sa, sb) ⇒ compareState(ta, tb, result)
        case (Nil, Nil) ⇒ result
        case _ ⇒ Different
      }
    }
    val parsedA = subParse(stateA)
    val parsedB: List[State] = subParse(stateB)
    compareState(parsedA, parsedB)
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 47760
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.q = l
        heapq.heapify(self.q)
        return

    def push(self, n):
        heapq.heappush(self.q, n)
        return

    def pop(self):
        return heapq.heappop(self.q)


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    X, Y, A, B, C = Scanner.map_int()
    P = Scanner.map_int()
    Q = Scanner.map_int()
    R = Scanner.map_int()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    P = P[:X]
    Q = Q[:Y]
    A = P + Q + R
    A.sort(reverse=True)
    print(sum(A[:X + Y]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 120092
N,Y = map(int,input().split())
answer = -1,-1,-1
for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        if 0 <= z <= 2000 and 10000*x+5000*y+1000*z == Y:
            answer = x,y,z
            break
    else:
        continue
print(*answer)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    string a,b,c;

    cin >> a >> b >> c;
    string ans = "";
    string turn ="a";

    for (ll i=0;i<1000000;i++){
        if(turn=="a"){
            if(a.size()==0){
                pri("A");
                return 0;
            }
            turn = a[0];
            a.erase(0, 1);
        }else if(turn=="b"){
            if(b.size()==0){
                pri("B");
                return 0;
            }
            turn = b[0];
            b.erase(0, 1);
        }else{
            if(c.size()==0){
                pri("C");
                return 0;
            }
            turn = c[0];
            c.erase(0, 1);
        }
    }

    return 0;
}



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

// (nCm)
ll combination(ll n,ll m){
	ll nume=1; //分子
	for(int i=0;i<m;i++){
		nume*=(n-i);
	}
	ll deno=1; //分母
	for(int i=1;i<=m;i++){
		deno*=i;
	}
	ll res=nume/deno;
	return res;
}

int main(){
    ios::sync_with_stdio(false);
	ll N,M,ans=0;
	cin>>N>>M;
	ll table[N+1];
	table[0]=0;
	for(int i=1;i<N+1;i++){
		cin>>table[i];
		table[i]+=table[i-1];
		table[i]%=M;
	}
	sort(table,table+N+1);
	ll tmp=table[0],c=1;
	for(int i=1;i<N+1;i++){
		if(table[i]==tmp){
			c++;
		}else{
			ans+=combination(c,2);
			c=1;
			tmp=table[i];
		}
	}
	ans+=combination(c,2);
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> s(N);
  
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  
  sort(s.begin(), s.end());
  
  string ans;
  
  for (int j = 0; j < N; j++) {
    ans += s.at(j);
  }
  
  cout << ans << endl;
  
}

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

import collections
A_count = collections.Counter(A)

import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2

for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Measured memory_bytes: 25716
use std::io;
use std::io::prelude::*;

fn main() {
    let stdin = io::stdin();
    let lock = stdin.lock();
    let lines = lock.lines();

    let mut t = 0;
    let mut rt = 0;
    let mut at = 0;
    let mut ot = 0;

    for l in lines {
        let l = l.unwrap();
        let mut words = l.split_whitespace();
        let a: i64 = words.next().unwrap().parse().unwrap();
        let b: i64 = words.next().unwrap().parse().unwrap();
        let c: i64 = words.next().unwrap().parse().unwrap();

        let abc = a + b - c;
        let bca = b + c - a;
        let cab = c + a - b;

        if abc * bca * cab <= 0 {
            break;
        }

        let cosa = b * b + c * c - a * a;
        let cosb = c * c + a * a - b * b;
        let cosc = a * a + b * b - c * c;

        let det = cosa * cosb * cosc;
        if det < 0 {
            ot += 1;
        } else if det == 0 {
            rt += 1;
        } else {
            at += 1;
        }
        t += 1;
    }
    println!("{} {} {} {}", t, rt, at, ot);
}



Measured memory_bytes: 5036
#include <stdio.h>

int main(void){
    int n, count = 0;
    scanf("%d", &n);
    int p[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &p[i]);
    }
    for(int i = 1; i < n-1; i++) {
        if(p[i] > p[i-1] && p[i] < p[i+1]) {
            count++;
        }
        if(p[i] < p[i-1] && p[i] > p[i+1]) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

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

using namespace std;

int N;
int d[305][305];
bool notUsed[305][305];

int main() {
  cin >> N;

  for (int i=1; i<=N; i++) {
    int a;
    for (int j=1; j<=N; j++) {
      cin >> a;
      d[i][j] = a;
    }
  }

  for (int k=1; k<=N; k++) {
    for (int i=1; i<=N; i++) {
      for (int j=1; j<=N; j++) {
        if (d[i][j] > d[i][k] + d[k][j]) {
          cout << -1 << endl;
          return 0;
        }
        if (k==i || k==j) {
          continue;
        }
        notUsed[i][j] = notUsed[i][j] || (d[i][j] == d[i][k] + d[k][j]);
        if (notUsed[i][j]) {
          if (i!=j) {
            // cout << "k: " << k << " i: " << i << " j: " << j << endl;
          }
        }
      }
    }
  }

  long ans = 0;
  for (int i=1; i<=N; i++) {
    for (int j=i+1; j<=N; j++) {
      if (!notUsed[i][j]) {
        ans += (long)d[i][j];
      }
    }
  }
  cout << ans << endl;
}


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


using namespace std;

int main(){
    long A, B;
    cin >> A >> B;

    
    if(A > B){
        long tmp = A;
        A = B;
        B = tmp;
    }
    if(B%2 == 1 && A%2 == 0){
        cout << (B-A+1)/2%2;
    }
    else if(B%2 ==1){
        cout << (A ^ ((B-A)/2%2));
    }
    else if(A%2 == 0){
        cout << (B ^ ((B-A)/2%2));
    }
    else {
        cout << ((A ^ B) ^ ((B-A-1)/2%2));
    }

}

Measured memory_bytes: 256
x, k, d = map(int, input().split())

x = abs(x)
if x ==0:
    ans = d * (k % 2)
elif x - d * k  >= 0:
    ans = x - d * k
else:
    if abs(x - x // d * d) <= abs(x - (x // d + 1) * d):
        div = x // d
    else:
        div = x // d + 1
    if (k - div) % 2 == 0:
        ans = abs(x - d * div)
    else:
        ans = min(abs(x - d * div + d),abs(x - d * div - d))
print(ans)

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,a[10010];
 cin>>n;
 for(int i=1;i<=n;i++){
 	cin>>a[i];
 	if(a[i]%2==0){
 		if(a[i]%3!=0&&a[i]%5!=0){
 			cout<<"DENIED";
 			return 0;
		}
	}
 }
 cout<<"APPROVED";
return 0;
}


Measured memory_bytes: 256