akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans = (ans * i) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <array>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

constexpr ll INF       = 1000000000;/* 1e+9a */

void solve(istream& cin) {
    int N;
    while(cin >> N){
        int ma, mb;
        cin >> ma >> mb;
        vector<ll> xi, ci;
        for (int i = 0; i < N; ++i) {
            ll a, b, c;
            cin >> a >> b >> c;
            ll x = a*mb - b*ma;
            xi.push_back(x);
            ci.push_back(c);
        }
        vector<ll> dp(6000, INF);
        for (int i = 0; i < xi.size(); ++i) {
            ll x = xi[i];
            ll c = ci[i];
            auto size = min(dp.size()-x, dp.size());
            auto init = max(ll(0), -x);
            if(x < 0){
                for (int j = init; j < size; ++j) {
                    dp[j+x] = min(dp[j+x], dp[j] + c);
                }
            }
            else{
                for (int j = size-1; j >= init; --j) {
                    dp[j + x] = min(dp[j + x], dp[j] + c);
                }
            }
            dp[x+3000] = min(dp[x+3000], c);
        }
        if(dp[3000] == INF){ cout << -1 << endl; }
        else cout << dp[3000] << endl;
    }
}

int main(int argc, char *argv[]) {
    string FileName("D"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {    
	    cerr << sub << endl;
        string inFile = "sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
alice_count = 0
bob_count = 0

sorted_a = a.sort!{|_a, _b| _b <=> _a}
n.times.each.with_index(1) do |_n, i|
  if i.odd?
    alice_count += sorted_a.shift
  else
    bob_count += sorted_a.shift
  end
end
print alice_count - bob_count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
/* デバッグ */
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define debug2(x,y) cout<<"("<<#x<<","<<#y<<") = ("<<(x)<<","<<(y)<<")\n"
int main(){
  ll N;
  cin>>N;
  cout<<( N*(N-1)/2 )<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dalao main
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
using namespace std;

int a[233333],n,temp;
ll ans=0;
priority_queue<int>pq;//大根堆

int dalao()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>temp;
        pq.push(temp);
    }
    ans+=pq.top();
    pq.pop();
    for(int i=1;i<=n/2-1;i++)
    {
        ans+=2*pq.top();
        pq.pop();
    }
    if(n%2!=0)
        ans+=pq.top();
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4312
import java.io._

object Main extends App {

  val out = new PrintWriter(System.out,true)
  val buf = StringBuilder.newBuilder
  var sb = StringBuilder.newBuilder
  var isContinue = true

  while(isContinue) {
    val cards = io.StdIn.readLine()
    if(cards != "-") {

      sb.append(cards)
      val cnt = io.StdIn.readInt()
      for(_ <- 1 to cnt) {
        val h = io.StdIn.readInt()
        buf.append(sb.substring(h)).append(sb.substring(0,h))
        sb.clear()
        sb.append(buf)
        buf.clear()
      }

      out.println(sb)
      sb.clear()
    }
    else isContinue = false
  }
  out.flush()
}



Measured memory_bytes: 43872
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, k) = get!(usize, usize);
    let xy = get!(i64, i64; n);
    let mut x_order = xy.clone();
    let mut y_order = xy.clone();

    x_order.sort_by_key(|xy| xy.0);
    y_order.sort_by_key(|xy| xy.1);

    let mut ans = i64::max_value();

    for i1 in 0..n {
        for i2 in i1 + 1..n {
            let l = x_order[i1].0;
            let r = x_order[i2].0;
            let mut deq = VecDeque::new();
            for &(x, y) in &y_order {
                if l <= x && x <= r {
                    deq.push_back(y);

                    while deq.len() > k {
                        deq.pop_front();
                    }

                    if deq.len() == k {
                        ans = min(ans, (r - l) * (deq.back().unwrap() - deq.front().unwrap()));
                    }
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           int a,b,c,d;
           cin>>a>>b>>c>>d;
           if(a+b>c+d){
               cout<<"Left";
               return 0;
           }
           if(a+b==c+d){
               cout<<"Balanced";
               return 0;

           } cout<<"Right";
           return 0;

         return 0;

        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,length;
  string s;
  cin >> k >> s;
  length = s.size();
  if(length<=k){
    cout << s << endl;
  }else{
    for(int i=0;i<k;i++){
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3612
s = input()
t = input()

found_s = False
for i in range(len(s) - len(t), -1, -1):
    for c1, c2 in zip(s[i:i+len(t)], t):
        if c1 == '?' or c1 == c2:
            continue
        else:
            break
    else:
        found_s = True
        s = s[:i] + t + s[i+len(t):]
        break

if found_s:
    print(s.replace('?', 'a'))
else:
    print("UNRESTORABLE")
    

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

vector<pair<int,int>> ps;
vector<vector<int>> g;
vector<bool> used;

void dfs(int cur, int &cnt, set<int> &xs, set<int> &ys) {
    if (used[cur]) return;
    cnt++;
    used[cur] = true;
    xs.insert(ps[cur].first);
    ys.insert(ps[cur].second);

    for(int to : g[cur]) {
        dfs(to, cnt, xs, ys);
    }
}

int main(void){
    int n;
    cin >> n;
    ps.resize(n);
    g.resize(n);
    used.resize(n);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        ps[i] = {x,y};
    }

    vector<int> ord(n);
    iota(all(ord), 0);

    sort(all(ord), [&](int i, int j){
        return ps[i].first != ps[j].first ? ps[i].first < ps[j].first : ps[i].second < ps[j].second;
    });
    rep(i,n-1){
        if (ps[ord[i]].first == ps[ord[i+1]].first){
            g[ord[i]].push_back(ord[i+1]);
            g[ord[i+1]].push_back(ord[i]);
        }
    }

    sort(all(ord), [&](int i, int j){
        return ps[i].second != ps[j].second ? ps[i].second < ps[j].second : ps[i].first < ps[j].first;
    });
    rep(i,n-1){
        if (ps[ord[i]].second == ps[ord[i+1]].second){
            g[ord[i]].push_back(ord[i+1]);
            g[ord[i+1]].push_back(ord[i]);
        }
    }

    ll res = 0;
    rep(i,n){
        int cnt = 0;
        set<int> xs, ys;
        dfs(i, cnt, xs, ys);
        res += (ll)xs.size() * (ll)ys.size() - cnt;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
const int L=61;
const ll inf=1e18;
const ll lim=2e17;
int go[N][L];
ll sum[N][L];
int a[N],last[N];
bool in[N];
bool was[N];
int main()
{
	//printf("%lld %lld %lld",(ll)1<<L,lim,((ll)1<<L)-lim);
	ll n,k;
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&a[i]);
		if(!last[a[i]]) last[a[i]]=i;
	}
	auto nxt=[&](int x)
	{
		return x==n?1:x+1;
	};
	for(int i=n;i>=1;i--)
	{
		go[i][0]=nxt(last[a[i]]);
		if(!was[a[i]] || go[i][0]==1) sum[i][0]=1;
		if(!was[a[i]] && go[i][0]==1) sum[i][0]=2;
		last[a[i]]=i;
		was[a[i]]=1;
	}
	for(int j=1;j<L;j++) for(int i=1;i<=n;i++)
	{
		go[i][j]=go[go[i][j-1]][j-1];
		sum[i][j]=sum[i][j-1]+sum[go[i][j-1]][j-1];
		sum[i][j]=min(sum[i][j],inf);
	}
	int u=1;
	for(int j=L-1;~j;j--)
	{
        if(sum[u][j]<k)
		{
			k-=sum[u][j];
			u=go[u][j];
		}
	}
	vector<int> ans;
	for(int i=u;i<=n;i++)
	{
		if(in[a[i]])
		{
			in[a[i]]=0;
			while(ans.back()!=a[i]) in[ans.back()]=0,ans.pop_back();
			ans.pop_back();
		}
		else ans.push_back(a[i]),in[a[i]]=1;
	}
	for(int i:ans) printf("%i ",i);
	return 0;
}

Measured memory_bytes: 147316
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

ll AN(ll A, ll N, ll mod){
  if (N == 0){
    return 1;
  }else{
    if (N % 2 == 0){
      return AN(A * A % mod, N / 2, mod);
    }else{
      return A * AN(A * A % mod, N / 2, mod) % mod;
    }
  }
}

int main(){
  int N; cin >> N;
  
  ll ans = 1;
  vector <ll> D(N);
  for (int i = 0; i < N; i++){
    cin >> D[i];
  }
  if (D[0] != 0) ans = 0;

  sort(D.begin(), D.end());
  vector <ll> cnt(D[N - 1] + 1);
  for (int i = 0; i < N; i++){
    cnt[D[i]]++;
  }

  if (cnt[0] != 1) ans = 0;
  
  for (int i = 1; i < D[N - 1] + 1; i++){
    ans *= AN(cnt[i - 1], cnt[i], 998244353);
    ans %= 998244353;
  }
  cout << ans << endl;
  
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  ll h,a;
  cin>>h>>a;
  cout << (h+a-1)/a << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	var n int
	n = nextInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = 2 * nextInt()
		b[i] = 2 * nextInt()
	}
	sort.Ints(a)
	sort.Ints(b)

	var ans int
	if n%2 == 1 {
		ans = b[n/2]/2 - a[n/2]/2 + 1
	} else {
		ans = (b[n/2]+b[n/2-1])/2 - (a[n/2]+a[n/2-1])/2 + 1
	}

	fmt.Println(ans)
}


Measured memory_bytes: 8348
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

typedef pair<long long, long long> P;
//typedef pair<string, long long> Q;
//typedef tuple<string, string, long long> P;
int main(){
    string s;
    string k;
    cin>>s;
    cin>>k;
    rep(i,s.size()){
        if (to_string(i+1)==k){
            cout<<s[i]<<endl;
            return 0;
        }
        if(s[i]!='1'){
            cout<<s[i]<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 256
tin = [int(i) for i in input().split(' ') ]
A,B,C = tin[0],tin[1],tin[2]
if (A+B+C - max(A,B,C)) % 2 == 0:
  print(int((3*max(A,B,C) - A - B - C)/2))
else:
  print( int( (3*max(A,B,C) - A - B - C - 1)/2 + 2 ) )

Measured memory_bytes: 3064
#include <functional>
#include <list>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <deque>
#include <stack>
#include <cassert>
using namespace std;
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define ALL(x) (x).begin(),(x).end()
#define CASET2 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0)
#define CASET1 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0)
#define CASET int ___T; scanf("%d ", &___T); while (___T-- > 0)
#define SZ(X) ((int)(X).size())
#define LEN(X) strlen(X)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
#define REPL(i,x) for(int i=0;x[i];i++)
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
#define RI1(x) scanf("%d",&x)
#define RI2(x,y) RI1(x), RI1(y)
#define RI3(x,y...) RI1(x), RI2(y)
#define RI4(x,y...) RI1(x), RI3(y)
#define RI5(x,y...) RI1(x), RI4(y)
#define RI6(x,y...) RI1(x), RI5(y)
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv)
#define DRI(argv...) int argv;RI(argv)
#define WRI(argv...) while (RI(argv) != EOF)
#define DWRI(x...) int x; WRI(x)
#define RS(x) scanf("%s",x)
#define MP make_pair
#define PB push_back
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define X first
#define Y second
#define V(x) vector<x >

typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int INF = 1000000000;

void print(int i) { printf("%d", i); }
void print(LL i);
template<class T> void PI(T i) { print(i); puts(""); }
template<class T> void PIS(T i) { print(i); printf(" "); }

template<class T>
void PV(T const &v, int N) {
    REP(i, N) {
        print(v[i]);
        printf("%c", i == N-1 ? '\n' : ' ');
    }
}

template<class T> void PV(T const &v) { PV(v, SZ(v)); }

template<class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; }
long long shift(int i) { return 1ll << i; }

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
int popcount(int x) { return __builtin_popcount(x); } 
int popcount(long long x) { return __builtin_popcountll(x); } 

#include <unordered_set>
#include <unordered_map>
#define EB emplace_back
#define RL(x) scanf("%lld", &(x))
#define PL(x) printf("%lld\n", x)
#define DRL(x) LL x; RL(x)

int main() {
    DRI(A, B, C);
    DRL(K);
    if (K % 2) {
        PI(B - A);
    } else {
        PI(A - B);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
 
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define ul unsigned long long
 
int main() {
  int N;
  cin >> N;
  ll A[N];
  rep(i,N){
    cin >> A[i];
    if(A[i] == 0){
      cout << "0" << endl;
      return 0;
    }
  }
  ll result =1;
  rep(i,N){
    result *= A[i];
    if( result > (long long)1000000000000000000 || result < 1){
      cout << "-1" << endl;
      return 0;
    }
    //cout << i << ", " << A[i] << ", " << result << endl;
  }
  cout << result << endl;
 
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	FOR(i, 0, n) cout << a[i] << b[i];
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, p = 998244353;
int n, a[N];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", a + i);
    sort(a, a + n);
    int ans = 1;
    for (int i = 0; i < n; ++i) ans = 1ll * ans * __gcd(i, a[i]) % p;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>          
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)	make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long MOD = 1000000007;

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

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,i;
	cin >> n >> i;
	cout << n - i + 1 << '\n';
	return 0;
}


Measured memory_bytes: 256
N, A = map(int,input().split())
x = list(map(int,input().split()))
MOD = 5500
DP = [[0]*(MOD) for i in range(N+1)]
DP[0][0] = 1
for i in range(N):
    for j in range(MOD):
        DP[i+1][j] = DP[i][j] + DP[i][(j-A+x[i])%MOD]
print(DP[-1][0] - 1)


Measured memory_bytes: 5748
N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()
diffX = list(map(lambda x,y:x-y, X[1:], X[:-1]))
diffX.sort(reverse = True)

if N-1 >= len(diffX):
	print(0)
else:
	print(sum(diffX[N-1:]))


Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define boost() ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cout << fixed; cout << setprecision(15); srand(time(NULL))
#define endl '\n'
typedef long long ll;
const int _N = 1e5 + 11;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int a, b;

int main() {
	boost();
//	freopen("in", "r", stdin);
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


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

int n,m;
int dis[110][110];
struct road{
	int from;
	int to;
	int cost;
	road(int _from,int _to,int _cost){
		from=_from;
		to=_to;
		cost=_cost;
	}
};
vector<road> r;
void warshall_floyd() { 
  for (int i = 1; i <=n; i++)      
    for (int j = 1; j <=n; j++)    
      for (int k = 1; k <=n; k++)  
        dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
}
int main(){
	cin>>n>>m;
	REP(i,110)
		REP(j,110)
			dis[i][j]=1e8;
	REP(i,110)dis[i][i]=0;
	REP(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		dis[a][b]=c;
		dis[b][a]=c;
		r.push_back(road(a,b,c));
	}
	warshall_floyd();
	int ans=0;
	REP(i,m){
		int flag=0;
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				if(dis[j][k]==dis[j][r[i].to]+r[i].cost+dis[r[i].from][k])flag=1;
			}
		}
		if(!flag)ans++;
	}
	cout<<ans<<endl;
	return 0;
}
	

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

sitaX = 30 * H +  M / 2
sitaY = 6 * M

cosC = math.cos(math.radians(abs(sitaX - sitaY)))

C_2 = A*A + B*B - 2*A*B*cosC

print (math.sqrt(C_2))

Measured memory_bytes: 9436
#include<unordered_map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cassert>
#include<vector>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=3e3+20;
const int mod=1e9+7;
const int inv2=mod+1>>1;

int n,a[maxn],q;
int f[maxn][maxn],g[maxn][maxn];

inline void init()
{
	n=read();q=read();
	REP(i,1,n)a[i]=read();
}

inline void doing()
{
	int u=0;
	REP(i,1,n)REP(j,1,n)
		if(i<=j)g[i][j]=f[i][j]=a[i]<a[j];
		else g[i][j]=f[i][j]=a[i]<a[j];
	REP(t,1,q)
	{
		int i=read(),j=read();
		REP(k,1,n)if(k!=j)
		{
			g[i][k]=(ll)inv2*(f[i][k]+f[j][k])%mod;
		}else g[i][j]=(ll)inv2*(f[i][j]+f[j][i])%mod;

		REP(k,1,n)if(k!=i)
		{
			g[j][k]=(ll)inv2*(f[j][k]+f[i][k])%mod;
		}else g[j][i]=(ll)inv2*(f[i][j]+f[j][i])%mod;
		
		REP(k,1,n)if(k!=i)
		{
			g[k][j]=(ll)inv2*(f[k][j]+f[k][i])%mod;
		}

		REP(k,1,n)if(k!=j)
		{
			g[k][i]=(ll)inv2*(f[k][i]+f[k][j])%mod;
		}
		REP(k,1,n)f[i][k]=g[i][k],f[j][k]=g[j][k];
		REP(k,1,n)f[k][i]=g[k][i],f[k][j]=g[k][j];
	}
	int ans=0,s=1;REP(i,1,q)s=(ll)s*2%mod;
	REP(i,1,n)REP(j,1,i-1)
	{
		ans=(ans+(ll)f[i][j]*s)%mod;
	}
	printf("%d\n",ans);
	
}

int main()
{
	init();
	doing();
	return 0;
}



Measured memory_bytes: 71424
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define M 800050
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,S,T;
int sum[M];
vector<int>s[100010];//数字i在哪些集合 
int F[M],N[M],a[M],c[M],dis[M],pre[M],num[M],fa[M],cur[M];
void add(int x,int y,int z){
	a[++k]=y;c[k]=z;
	N[k]=F[x];F[x]=k;
}
int q[200010],h,t;bool vis[200010];
bool bfs(){
	memset(dis,0,n*4+8);h=t=0;q[++t]=S;dis[S]=1;
	for(rt i=1;i<=n;i++)cur[i]=F[i];
	while(h<t){
		const int x=q[++h];
		for(rt i=F[x];i;i=N[i])if(!dis[a[i]]&&c[i]){
			dis[a[i]]=dis[x]+1,q[++t]=a[i];
			if(a[i]==T)return 1;
		}
	}
	return dis[T];
}
int dfs(int x,int flow){
	if(x==T)return flow;int used=0;
	for(rt i=cur[x];i;i=cur[x]=N[i])if(c[i]&&dis[a[i]]==dis[x]+1){
		const int v=dfs(a[i],1);
		if(v)used++,c[i]--,c[i^1]++,pre[a[i]]=x; 
		if(flow==used||dis[S]>=n)return used;
	}
	return used;
}

void print(int x,int y){
	write(x),putchar(' ');writeln(y);
}
int main(){
	n=r;k=1;
	for(rt i=1;i<n;i++){
		sum[i]=r;
		for(rt j=1;j<=sum[i];j++){
			x=r;s[x].push_back(i);
			if(x>1)add(i,n-1+x-1,1),add(n-1+x-1,i,0);
		}
	}
	S=n*2-1,T=n*2;
	for(rt i=1;i<n;i++)add(S,i,1),add(i,S,0);
	for(rt i=n;i<=n*2-2;i++)add(i,T,1),add(T,i,0);
	n<<=1;int ans=0;
	while(bfs())ans+=dfs(S,1000000000);
	if(ans+1<n/2)return puts("-1"),0;
	n>>=1;h=t=0;
	for(rt i=n;i<=n*2-2;i++)num[pre[i]]=i-n+2;q[t=1]=1;
	while(h<t){
		x=q[++h];
		for(auto i:s[x])if(!vis[num[i]])vis[num[i]]=1,fa[num[i]]=x,q[++t]=num[i];
	}
	for(rt i=1;i<n;i++)if(!fa[num[i]])return puts("-1"),0;
	for(rt i=1;i<n;i++)print(fa[num[i]],num[i]);
	return 0;
}

Measured memory_bytes: 31744
s=list(input())
k=int(input())
n=len(s)
subset=[]
from bisect import bisect_left

for i in range(n):
    tmp=s[i]
    for j in range(i,min(n,i+5)):
        if j==i: pass
        else: tmp+=s[j]
        if tmp not in subset:
            l=bisect_left(subset, tmp)
            if 0<=l<5:
                subset=subset[:l]+[tmp]+subset[l:5]
                subset=subset[:5]
            else:
                break
print(subset[k-1])

Measured memory_bytes: 40304
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 2005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,m;
char mp[MAXN][MAXN];
int d[MAXN][MAXN];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",mp[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            d[i][j]=INF;
    queue<P> que;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(mp[i][j]=='#')
            {
                d[i][j]=0;
                que.push(P(i,j));
            }
    int ans=0;
    while(que.size())
    {
        P p=que.front(); que.pop();
        int x=p.F,y=p.S;
        for(int i=0;i<4;i++)
        {
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<1||nx>n||ny<1||ny>m||d[nx][ny]!=INF) continue;
            d[nx][ny]=d[x][y]+1; que.push(P(nx,ny));
            ans=max(ans,d[nx][ny]);
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 20752
import sys
import networkx as nx
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W].astype('U1')

INF = 1 << 32

total_o = (S == 'o').sum()
G = nx.DiGraph()
sink = 'sink'
G.add_node(sink, demand=total_o)
for i in range(H):
    for j in range(W):
        if S[i, j] == '#':
            continue
        if S[i, j] == 'o':
            G.add_node((i, j), demand=-1)
            G.add_edge((i, j), sink, capacity=1, weight=0)
        elif S[i, j] == '.':
            G.add_node((i, j), demand=0)
            G.add_edge((i, j), sink, capacity=1, weight=0)
        if i + 1 < H and S[i + 1, j] != '#':
            G.add_edge((i, j), (i + 1, j), capacity=INF, weight=-1)
        if j + 1 < W and S[i, j + 1] != '#':
            G.add_edge((i, j), (i, j + 1), capacity=INF, weight=-1)

mcfc = nx.min_cost_flow_cost(G)
ans = -mcfc
print(ans)

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

#define MAX 2000001

using namespace std;

int H, A[MAX];

void maxHeapify(int i){
    int l, r, largest;
    l = 2*i;
    r = 2*i+1;
    
    if(l<=H && A[l]> A[i]){
        largest = l;
    }else{
        largest = i;
    }
    
    if(r<=H && A[r] > A[largest]){
        largest = r;
    }
    
    if(largest != i){
        
        swap(A[i], A[largest]);
        
        maxHeapify(largest);
    }
}


int main(){
    
    cin >> H;
    
    for(int i=1; i<=H; i++){
        cin >> A[i];
    }
    
    for(int j= H/2; j>=1; j--){
        maxHeapify(j);
    }
    
    for(int k = 1; k<=H; k++){
        cout <<" " << A[k];
    }
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 4964
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

int main(){
	string S;
	
	getline(cin, S);
	int i, benar = 0;
	for (i=1; i<S.length(); i++){
		if (S[i] == 'C' && S[i-1] == 'A'){
			benar = 1;
			break;
		}
	}

	if (benar)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

int x;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>x;
    for(int i=0;i*100<=x;i++){
        if(x%100+i*100<=(x/100-i)*5){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;

    return 0;
}

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

int main() {

    string s; cin >> s;
    int ans;
    for ( int i = 2; i <= s.size() - 2; i += 2) {
        string left = s.substr(0, (s.size() - i) / 2);
        string right = s.substr((s.size() - i) / 2, (s.size() - i) / 2);
        if (left == right) {
            ans = 2 * left.size();
            break;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
#define MOD 1000000007
int main() {
    ll N, M;
    cin >> N >> M;
    
    ll x = 100 * (N - M) + 1900 * M;
    
    cout << pow(2, M) * x << endl;
    return 0;
}

Measured memory_bytes: 4192
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  int n; cin>>n;
  ll an = 0;
  ll c[61][31]; fill(c[0],c[61],0); // 足りるか足りないか +15する
  
  for(int i=0;i<n;i++) {
    string s; cin>>s;
    int m = s.size();
    int p = m-1;
    ll fs = 0;
    for(int j=0;j<m;j++) {
      if (s[j] == '.') {
        p = j;
      } else {
        fs = fs * 10 + (s[j] - '0');
      }
    }
    int a2 = p+1-m, a5 = a2;
    while(fs % 2 == 0) fs/=2, a2++;
    while(fs % 5 == 0) fs/=5, a5++;
    //cout<<a2<<" "<<a5<<endl;
    a2 += 30; a5 += 15;
    for(int j=0;j<61;j++) {
      for(int k=0;k<31;k++) {
        if (a2 + j - 60 >= 0 && a5 + k - 30 >= 0) {
          an += c[j][k];
        }
      }
    }
    c[a2][a5]++;
  }
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n,m;
string s,t;

lin gcd(lin a, lin b)
{
    if(a < b)
        return gcd(b,a);

    if(a % b == 0)
        return b;

    return gcd(b, a % b);
}

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

int main(void)
{
    cin >> n >> m;
    cin >> s >> t;

    lin res = lcm(n,m);
    lin ss = res / s.length();
    lin tt = res / t.length();

    for(int i = 0; i < s.length(); i++)
    {
        lin p = i * ss;
        if(p % tt == 0 && s[i] != t[p/tt])
        {
            res = -1;
            break;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans;
    ll b,c;
    if (k%2 == 1){
        ans = pow(n/k,3);
    }else{
        b=0;
        c=0;
        for(ll i=k/2;i<=n;i+=k/2){
            if (i%k==0){
                b += 1;
            }else{
                c+=1;
            }
            ans = pow(b,3)+pow(c,3);
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
typedef long long LL;
#define rep(i,n) for(LL i=0; i<(LL)(n); i++)

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}


//main関数
int main(){
	int W,H,N;
	scanf("%d %d %d",&W,&H,&N);
	int xx[N],yy[N],aa[N];
	rep( i , N) {
		scanf("%d %d %d",&xx[i],&yy[i],&aa[i]);
	}
	
	int ans[100][100] = {0};
	rep( i,N ){
		if(aa[i] == 1){
			for( int j=0; j < xx[i] ; j++){
				for( int k=0; k < H; k++ ){
					ans[j][k] = 1;
				} 
			}
		}
		else if (aa[i] == 2){
			for( int j=xx[i]; j < W ; j++){
				for( int k=0; k < H; k++ ){
					ans[j][k] = 1;
				} 
			}
		}
		else if (aa[i] == 3){
			for( int j=0; j < yy[i] ; j++){
				for( int k=0; k < W; k++ ){
					ans[k][j] = 1;
				} 
			}
		}
		else if (aa[i] == 4){
			for( int j=yy[i]; j < H ; j++){
				for( int k=0; k < W; k++ ){
					ans[k][j] = 1;
				} 
			}
		}	
	}
	int res = 0;
	rep( i,W ){
		rep( j,H ){
			if( ans[i][j] == 0){
				res++;
			}
		}
	}
	printf("%d",res);
}





Measured memory_bytes: 1768
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

string s, t;
set<int> pos[30];

int main() {
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) pos[s[i] - 'a'].insert(i);
	int a = 0, b = 0;
	for (int i = 0; i < t.size(); i++) {
		if (pos[t[i] - 'a'].empty()) {
			cout << -1 << endl;
			return 0;
		}
		if (pos[t[i] - 'a'].lower_bound(b) == pos[t[i] - 'a'].end()) {
			a++;b=0;
		}
		b = *(pos[t[i] - 'a'].lower_bound(b));
		b++;
	}
	cout<<a*s.size()+b<<endl;
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<climits>

using namespace std;

const int INF=(1LL<<31)-1;
int N,K;
//const int sqrtN=512;
int sqrtN;
vector<int> data;
vector<int> bucketmin;
vector<int> lazyflag;
vector<int> lazyupdate;

void init(){
	K=(N+sqrtN-1)/sqrtN;
	data.assign(K*sqrtN,INF);
	bucketmin.assign(K,INF);
	lazyflag.assign(K,false);
	lazyupdate.assign(K,0);
}

void eval(int k){
	if(lazyflag[k]){
		lazyflag[k]=false;
		for(int i=k*sqrtN;i<(k+1)*sqrtN;i++){
			data[i]=lazyupdate[k];
		}
	}
}

void update(int s,int t, int x){
	for(int k=0;k<K;k++){
		int l=k*sqrtN;
		int r=(k+1)*sqrtN;
		if(r<=s || t<=l) continue;
		if(s<=l && r<=t){
			bucketmin[k]=x;
			lazyflag[k]=true;
			lazyupdate[k]=x;
		}
		else{
			eval(k);
			for(int i=max(s,l);i<min(t,r);i++){
				data[i]=x;
			}
			int &minval=bucketmin[k]=INF;
			for(int i=l;i<r;i++){
				minval=min(minval,data[i]);
			}
		}
	}
}

void find_min(int s,int t){
	int minval=INF;
	for(int k=0;k<K;k++){
		int l=k*sqrtN;
		int r=(k+1)*sqrtN;
		if(r<=s || t<=l) continue;
		if(s<=l && r<=t){
			minval=min(minval,bucketmin[k]);
		}
		else{
			eval(k);
			for(int i=max(s,l);i<min(t,r);i++){
				minval=min(minval,data[i]);
			}
		}
	}
	printf("%d\n",minval);
}

int main(){
	int q,com;
	int s,t,x;
	scanf("%d %d",&N,&q);
	sqrtN = (int)sqrt(N);
	//printf("sqrt(N)=%lld\n",sqrtN);
	init();
	for(int i=0;i<q;i++){
		scanf("%d",&com);
		if(com==0){
			scanf("%d %d %d",&s,&t,&x);
			update(s,t+1,x);//[s,t)
		}
		else{
			scanf("%d %d",&s,&t);
			find_min(s,t+1);
		}
	}
}


Measured memory_bytes: 3356
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>S;
    vector<string> ho = {"SUN","MON","TUE","WED","THU","FRI","SAT" };
    rep(i,7){
        if(ho[i] == S){
            cout<<7 - i<<endl;
        }
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool vis[1000010];

signed main()
{
	ios::sync_with_stdio(false);
	int k;
	cin>>k;
	int now=0,cnt=0;
	while(true){
		cnt++;
		now=(now*10+7)%k;
		if(now==0){
			cout<<cnt<<endl;
			break;
		}
		if(vis[now]){
			cout<<-1<<endl;
			break;
		}
		vis[now]=1;
	}
	return 0;
}

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

int main() {
    long n;
    long V[20], C[20];

    cin >> n;
    for (long i = 0; i < n; i++) {
        cin >> V[i];
    }
    for (long i = 0; i < n; i++) {
        cin >> C[i];
    }

    long ans = 0;
    for (long i = 0; i < n; i++) {
        if (V[i] - C[i] > 0) {
            ans += V[i] - C[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

  public static void main(String[] args)
  {
    try (Scanner scanner = new Scanner(System.in))
    {
      while (scanner.hasNextLine())
      {
        scanner.nextLine();
        String[] data = scanner.nextLine().split(" ");
        solver(data);
      }
    }
  }

  private static void solver(String[] data)
  {
    Long[] numArray = new Long[data.length];
    for (int i = 0; i < data.length; i++)
    {
      numArray[i] = Long.valueOf(data[i]);
    }

    for (int i = 1; i <= minNum(numArray); i++)
    {
      int count = 0;
      for (long num : numArray)
      {
        if (num % i == 0) {
          count++;
        }
      }
      if(count == numArray.length) {
        System.out.println(i);
      }
    }
  }

  private static Long minNum(Long[] numArray)
  {
    long min = Long.MAX_VALUE;
    for (long num : numArray)
    {
      min = Math.min(min, num);
    }
    return min;
  }

}



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

int main() {
  string s;
  int k;
  cin >> k >> s;
  int num = s.size();
  if(num <= k) cout << s << endl;
  else {
    s.erase(k);
    for(int i=0; i<3; i++) {
      s.push_back('.');
    }
    cout << s << endl;
  }
}
  

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W, D;
    cin >> H >> W >> D;
    VVL A(H, VL(W));
    rep(i, 0, H){
        rep(j, 0, W){
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    ll Q;
    cin >> Q;
    VL L(Q), R(Q);
    rep(i, 0, Q){
        cin >> L[i] >> R[i];
        L[i]--; R[i]--;
    }
    VP a(H*W);
    rep(i, 0, H){
        rep(j, 0, W){
            a[A[i][j]] = {i, j};
        }
    }
    VL acc(H*W, 0);
    rep(i, 0, H*W){
        if(i < D) continue;
        acc[i] = acc[i-D] + abs(a[i].first - a[i-D].first) + abs(a[i].second - a[i-D].second);
    }
    rep(i, 0, Q){
        cout << acc[R[i]] - acc[L[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vli vector<li>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pi pair<int,int>
#define FOR(i,s,n) for(auto i=s;i<n;++i)
#define FORN(i,s,n) for(auto i=s;i<=n;++i)
#define FORR(i,s,n) for(auto i=s;i>=n;--i)
#define FORE(i,a) for(auto i : a)
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    map<string,int> mp;
    int n;
    cin >> n;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    FOR(i,0,n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC" << " x " << mp["AC"] << endl;
    cout << "WA" << " x " << mp["WA"] << endl;
    cout << "TLE" << " x " << mp["TLE"] << endl;
    cout << "RE" << " x " << mp["RE"] << endl;
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 3660
import sys
from collections import Counter

sys.setrecursionlimit = 10 ** 6
N = int(input())


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def dfs(i, x):
    global N
    global res
    if i != len(prime_keys):
        p = prime_keys[i]
        for num in range(prime[p] + 1):
            x_ = x * (p ** num)
            y = N // x_
            res = min(res, x_ + y - 2)
            dfs(i + 1, x_)


prime = Counter(prime_factorize(N))
prime_keys = list(prime.keys())
res = N * 2
dfs(0, 1)
print(res)


Measured memory_bytes: 3316
n = int(input())
x = list(map(int, input().split()))

x_sorted = sorted(x)

mL = (n - 1) // 2
mR = mL + 1

anss = []
for i in range(n):
    if x[i] <= x_sorted[mL]:
        anss.append(x_sorted[mR])
    else:
        anss.append(x_sorted[mL])
for ans in anss:
    print(ans)

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

#define pb push_back

using namespace std;

int n, m;
vector<int> p;
vector<bool> vis;
vector<vector<int>> adj;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    vis.assign(n, 0);
    adj.assign(n, vector<int>());
    for(int i = 0; i < m; ++i){
        int u, v; cin >> u >> v;
        u--, v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    p.assign(n, -1);
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int cur = q.front();
        q.pop();
        for(auto i : adj[cur]){
            if(!vis[i]){
                p[i] = cur;
                vis[i] = true;
                q.push(i);
            }
        }
    }
    cout << "Yes\n";
    for(int i = 1; i < n; ++i){
        cout << p[i] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 10032
import numpy as np
N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for _ in range(N)])

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        tmp = np.sum((X[i] - X[j]) ** 2)
        if tmp % np.sqrt(tmp) == 0.0:
            ans += 1
print(ans)

Measured memory_bytes: 12508