akhauriyash/Code-Regression huggingface dataset:
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll>m;
    vector<pair<ll,ll>>v;
    vector<ll>ans;
    f(i,n)
    {
        cin>>a[i];
        m[a[i]]++;
        v.pb(mp(a[i],i+1));
    }
    sortall(v);
    unordered_set<ll>s;
    f(i,n)
    {
        if(m[v[i].F]>1)
        {
            s.insert(v[i].F);
            continue;
        }
        else
        {
            vector<ll>check;
            for(ll j=1;j*j<=v[i].F;j++)
            {
                if((v[i].F)%j==0)
                {
                    check.pb(j);
                    check.pb((v[i].F)/j);
                }
            }
            ll f=0;
            f(j,(ll)check.size())
            {
                if(s.find(check[j])!=s.end())
                {
                    f=1;
                    break;
                }
            }
            if(f==0)
                ans.pb(v[i].S);
            check.clear();
        }
         s.insert(v[i].F);
    }
    cout<<ans.size();
    return 0;
}


Measured memory_bytes: 30072
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;

int N, K;

int main(){
	cin>>N>>K;
	if(K==1) cout<<0<<endl;
	else cout<<N-K<<endl;
	return 0;
}


Measured memory_bytes: 256
// C - Dubious Document 2
#include <bits/stdc++.h>
using namespace std;
string S, T;

string solve(){
	int sn = S.size(), tn = T.size();
	for(int i=sn-tn; i>=0; --i){
		bool exist = true;
		for(int j=0; j<tn; ++j) if(S[i+j] != '?' && S[i+j] != T[j]){ exist  = false; break; }
		if(exist){
			S.replace(i, tn, T);
			replace(S.begin(), S.end(), '?', 'a');
			return S;
		}
	}
	return "UNRESTORABLE";
}

int main(){
	cin>>S>>T;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long A, B, C;
int main(){
	cin >> A >> B >> C;
	if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0 ){
		cout << 0 << endl;
		return 0;
	}

	cout << (min(A*B, min(B*C, C*A))) << endl;


}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn chmin(a:f64, b:f64) -> f64 {
    if a<=b{
        return a;
    }
    b
}
fn main() {
    input!{
        n: usize,
        mut t: [usize;n],
        mut v: [f64;n],
    }
    // t.reverse();
    // t.push(0.0);
    // t.reverse();
    // t.push(0.0);
    // v.reverse();
    // v.push(0.0);
    // v.reverse();
    // v.push(0.0);
    // println!("{:?}\n{:?}", t, v);
    let mut T:usize = 0;
    for i in 0..n {
        T += t[i];
    }
    let mut maxV:Vec<f64> = vec![100.0;2*T+1];
    let mut nowT:usize = 0;
    for i in 0..n {
        for ti in 0..t[i] {
            let t1 = nowT + ti*2;
            let t2 = nowT + ti*2 + 1;
            maxV[t1] = chmin(maxV[t1], v[i]);
            maxV[t2] = chmin(maxV[t2], v[i]);
        }
        nowT += t[i] * 2;
        maxV[nowT] = chmin(maxV[nowT], v[i]);
    }
    maxV[0] = 0.0;
    maxV[T*2] = 0.0;
    // println!("{:?}", maxV);
    for i in 0..2*T {
        maxV[i+1] = chmin(maxV[i+1], maxV[i]+0.5);
    }
    for i in (0..2*T).rev() {
        maxV[i] = chmin(maxV[i], maxV[i+1]+0.5);
    }
    let mut ans:f64 = 0.0;
    for i in 0..2*T {
        ans += (maxV[i] + maxV[i+1])/4.0;
    }
    // println!("{:?}", maxV);
    println!("{:.10}", ans);
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll M;
    cin >> M;
    vector<ll> d(M), c(M);
    REP(i, M) cin >> d[i] >> c[i];

    ll res = 0;
    ll keta = 0;
    REP(i, M) keta += c[i];
    res += (keta-1);
    ll S = 0;
    REP(i, M) S += d[i]*c[i];
    res += (S-1)/9;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;
static const int MAX=100;
static const long long INFTY=(1LL<<32);

int n;
long long d[MAX][MAX];

void floyd()
{
    for(int k=0; k<n; k++)
    {
        for(int i=0; i<n; i++)
        {
            if(d[i][k]==INFTY)continue;
            for(int j=0; j<n; j++)
            {
                if(d[k][j]==INFTY)continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}
int main()
{
    int e,u,v,c;
    cin>>n>>e;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            d[i][j]=((i==j)?0:INFTY);
        }
    }
    for(int i=0; i<e; i++)
    {
            cin>>u>>v>>c;
            d[u][v]=c;
    }
    floyd();
    bool negative=false;
    for(int i=0; i<n; i++)if(d[i][i]<0)negative=true;
    if(negative)
    {
        cout<<"NEGATIVE CYCLE"<<endl;
    }
    else
    {
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
            {
                if(j)cout<<" ";
                if(d[i][j]==INFTY)cout<<"INF";
                else cout<<d[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3180
// O(n) solution

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int N;
long long C;

// f(a) = v[0] + v[1] + ... + v[a-1] - x[a-1]
long long Soa[100000] = {0};
long long Sob[100000] = {0};
// g(a) = max(f(0), f(1), ..., f(a))
long long Moa[100000] = {0};
long long Mob[100000] = {0};

// OA + 2OB
long long solve_oa_2ob(const vector<long long>& x) {
  long long ans = Moa[N - 1];
  for (int i = N - 1; i > 0; --i) {
    const auto w_2ob = Sob[i] - (C - x[i]);
    const auto w_oa = Moa[i - 1];
    ans = max(ans, w_oa + w_2ob);
  }
  return ans;
}

// 2OA + OB
long long solve_2oa_ob(const vector<long long>& x) {
  long long ans = Mob[0];
  for (int i = 0; i < N - 1; ++i) {
    const auto w_2oa = Soa[i] - x[i];
    const auto w_ob = Mob[i + 1];
    ans = max(ans, w_2oa + w_ob);
  }
  return ans;
}

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

  vector<long long> x(N);
  vector<long long> v(N);

  long long sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> v[i];

    sum += v[i];
    Soa[i] = sum - x[i];
  }

  sum = 0;
  for (int i = N - 1; i >= 0; --i) {
    sum += v[i];
    Sob[i] = sum - (C - x[i]);
  }

  Moa[0] = Soa[0];
  for (int i = 1; i < N; ++i) {
    Moa[i] = max(Moa[i - 1], Soa[i]);
  }

  Mob[N - 1] = Sob[N - 1];
  for (int i = N - 2; i >= 0; --i) {
    Mob[i] = max(Mob[i + 1], Sob[i]);
  }

  const long long ans = max({0LL, solve_oa_2ob(x), solve_2oa_ob(x)});
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
 
int mins(char *, char *);
 
int main(void){
 
    char a[1000], s[1000];
    int la;
    int ls;
    int i;
    int max = 0;
 
    scanf("%s%s",a,s);
 
    la = strlen(a);
    ls = strlen(s);
 
    for(i=0;i<=la-ls;i++){
        if(max < mins(a+i,s)){
            max = mins(a+i,s);
        }
    }
 
    printf("%d",ls-max);
 
    return 0;
}
 
int mins(char *a, char *s){
    int i = 0;
    while(*s != '\0'){
        if(*a == *s){
            i++;
        }
        a++;
        s++;
    }
    return i;
}

Measured memory_bytes: 1736
n,m,x=map(int,input().split())
c=[]
a=[]
mn=float("inf")
for i in range(n):
  aa=list(map(int,input().split()))
  c.append(aa.pop(0))
  a.append(aa)

for i in range(2**n):
  buy=[]
  kai=[0]*m
  cost=0
  for j in range(n):
    if((i>>j)&1):
      buy.append(j)
  for j in buy:
    cost+=c[j]
    for k in range(m):
      kai[k]+=a[j][k]
  fl=True
  for j in range(m):
    if kai[j]<x:
      fl=False
      break
  if fl:
    mn=min(mn,cost)
if mn==float("inf"):
  print(-1)
else:
  print(mn)

Measured memory_bytes: 9248
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i, b, n) for(int i=b;i<(int)n;i++)
#define rep(i, n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it, o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;

//ハマったらチェックリスト見ろ!!

int main() {
    ll N;
    cin >> N;
    vector<ll> V(N);
    vector<ll> imos(N+1);
    rep(i, N)cin>>V[i];
    imos[0] = 0;
    rep(i, N){
        imos[i+1] = imos[i] + V[i];
    }

    ll ans = imos[N] * 10;

    rep(bc, N){
        //A: [0, ab)
        //B: [ab, bc)
        //C: [bc, cd)
        //D: [cd, N)

        ll lab = 0, rab = bc;
        if (lab >= rab)continue;
        while (lab  +1 < rab) {
            ll mid = (lab + rab)/2;
            if(imos[mid] < imos[bc]/2){
                lab = mid;
            }
            else {
                rab = mid;
            }
        }

        ll lcd = bc+1, rcd = N;
        if (lcd >= rcd)continue;
        while (lcd +1< rcd) {
            ll mid = (lcd + rcd)/2;
            ll base = imos[bc];
            if(imos[mid] - base < (imos[N] - base)/2){
                lcd = mid;
            }
            else {
                rcd = mid;
            }
        }

        for(ll ab = lab-1; ab < rab+1;ab++){
            for(ll cd = lcd-1; cd < rcd+1; cd++){
               if(ab - 0 < 1)continue;
                if(bc - ab < 1)continue;
                if(cd - bc < 1)continue;
                if(N - cd < 1)continue;
                ll A = imos[ab];
                ll B = imos[bc] - imos[ab];
                ll C = imos[cd] - imos[bc];
                ll D = imos[N] - imos[cd];
                ll mini = min(min(A,B), min(C, D));
                ll maxi = max(max(A, B), max(C, D));
                ans = min(ans, abs(maxi-mini));
            }
        }
    }

    cout << ans <<endl;

    return 0;
}

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

double two(double x){
  return x*x;
}

int main(void){
  int N, D;
  scanf("%d %d",&N, &D);

  double p[N][D];
  int i, j, k;
  for(i=0 ; i<N ; i++)
    for(j=0 ; j<D ; j++)
      scanf("%lf", &p[i][j]);

  double d, sum = 0;
  int count = 0;
  for(i=0 ; i<N ; i++)
    for(j=i+1 ; j<N ; j++){
      sum = 0;
      for(k=0 ; k<D ; k++)
	sum += two(p[i][k]-p[j][k]);

      d = sqrt(sum);
      if(ceil(d) == floor(d))
	count++;
    }

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

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MD=1e9+7;
int n,m,a[2001][2001],row[2001][2001],col[2001][2001],ans;
int main() {
    string str;
    cin>>n>>m;
    for (int i=0; i<n; i++) {
        cin>>str;
        for (int j=0; j<m; j++) a[i][j]=(str[j]=='#');
    }
    for (int i=0; i<n; i++) {
        int pre=-1,cur=0;
        while (cur<m) {
            while (cur<m and !a[i][cur]) cur++;
            for (int j=pre+1; j<cur; j++) row[i][j]=cur-pre-1;
            pre=cur; cur++;
        }
    }
    for (int j=0; j<m; j++) {
        int pre=-1,cur=0;
        while (cur<n) {
            while (cur<n and !a[cur][j]) cur++;
            for (int i=pre+1; i<cur; i++) col[i][j]=cur-pre-1;
            pre=cur; cur++;
        }
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            ans=max(ans,row[i][j]+col[i][j]-1);
        }
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 50536
// 12/07/2020  @ 19:54:17
// *****************************************************************
// *****************************************************************
#include <bits/stdc++.h>
// *****************************************************************
// *****************************************************************
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#define fr(i,n) for(llu i=0;i<n;i++)
#define fl(j,a,b) for(llu j=a;j<=b;j++)
#define Pi 3.1415926535897932384626
#define mod 1e9+7
#define MID(a,b) ((a + b) >> 1)
#define MAX(a,b) ((a) > (b) ? (a): (b))
#define MIN(a,b) ((a) < (b) ? (a) :(b))
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define printer(a, n) fr(i,n) cout << a[i] << " ";
// *****************************************************************
// *****************************************************************
typedef long long unsigned int llu;
typedef long long int ll;
// *****************************************************************
// *****************************************************************
using namespace std;
// *****************************************************************
// *****************************************************************

                   // Dream it. Wish it. Do it.

                         // tannatsri //

              // Without tact you can learn nothing.

// *****************************************************************
// *****************************************************************
bool rev(ll a, ll b) {
    return a > b;
}
// *****************************************************************
void solution() {
	ll a, b;
	cin >> a >> b;
	cout << a * b;

}
// *****************************************************************
int main() {
    IOS;
    // #ifndef ONLINE_JUDGE
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/input.txt", "r", stdin);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/output.txt", "w", stdout);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/error.txt", "w", stderr);
    // #endif
    // *****************************************************************
    // *****************************************************************
    int t = 1;
    // cin >> t;
    while(t--) {

       solution();
       cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#define N 2000000
#define A 10000

int main(){
  int *a, *b, c[A], n, i;

  scanf("%d", &n);

  a = (int *)malloc(sizeof(int) * n);
  b = (int *)malloc(sizeof(int) * n);
  for(i = 0; i < A; i++)
    c[i] = 0;

  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
    c[a[i]]++;
  }

  for(i = 1; i < A; i++)
    c[i] += c[i - 1];

  for(i = n - 1; i >= 0; i--){
    b[c[a[i]] - 1] = a[i];
    c[a[i]]--;
  }
  
  for(i = 0; i < n - 1; i++){
    printf("%d ", b[i]);
  }
  printf("%d\n", b[i]);

  free(a);
  free(b);

  return 0;
}

Measured memory_bytes: 16124
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);

const int N = 1e5 + 5;
int t;

int main()
{
	double l;
	while (cin >> l)
	{
		l /= 3;
		printf("%.12lf", l*l*l);
	}
	return 0;
}

Measured memory_bytes: 256
import static java.util.Arrays.deepToString;
import static java.util.Arrays.fill;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			char[][] t = new char[8][8];
			for (int i = 0; i < 8; i++) t[i] = sc.next().toCharArray();
			
			t = rot(t);
			System.out.println(90);
			print(t);
			t = rot(t);
			System.out.println(180);
			print(t);
			t = rot(t);
			System.out.println(270);
			print(t);
			
		}
	}
	void print(char[][] t) {
		for (int i = 0; i < t.length; i++) System.out.println(new String(t[i]));
	}
	char[][] rot(char[][] t) {
		char[][] res = new char[t[0].length][t.length];
		for (int i = 0; i < t.length; i++) {
			for (int j = 0; j < t[0].length; j++) {
				res[j][t.length - 1 - i] = t[i][j];
			}
		}
		return res;
	}
}

Measured memory_bytes: 17124
/// 10
var (n,k) = cin.pair
/// [2, 3, 4, 5, 6, 4]
/// [1, 2, 3, 4, 5, 3]
let A = cin.array.map { $0-1 }
/// []
var seen = [Int]()
var seenb = (0..<n).map { _ in false }
/// 0
var current = 0

while true {
    seen.append(current)
    seenb[current] = true
    current = A[current]
    k -= 1

    if k == 0 {
        print(current+1)
        exit(0)
    }

    if seenb[current] {
        break
    }
    // if seen.contains(current) {
    //     break
    // }
}

/// seen: [0, 1, 2, 3, 4, 5]
/// current: 5
/// loop: [4, 5, 3]
/// k: 10 - 5 = 5

let loop = Array(seen[seen.firstIndex(of: current)!..<seen.count])

/// res = 5%3 = 2
/// loop[2] = 3
/// ans: 5 (index: 4)

let ans = loop[k%loop.count]
print(ans+1)

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


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

using namespace std;

int k;
string s;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> k;
    cin >> s;
    if (int(s.size()) <= k) cout << s <<'\n';
    else {
        for (int i = 0; i < k; ++i) cout << s[i];
        cout << "..." << '\n';
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});

int main() {
	int n;
	cin >> n;
	if (n < 1000)puts("ABC");
	else puts("ABD");
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    double x1,y1,x2,y2,a,i;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    a=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    i=sqrt(a);
    printf("%lf\n", i);
    return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n),B(n),C(n);
  for(auto &a:A)cin>>a;
  for(auto &a:B)cin>>a;
  for(auto &a:C)cin>>a;
  sort(ALL(A));
  sort(ALL(C));
  ll ans = 0;
  A.pb(llINF);C.pb(llINF);
  for(int i=0;i<n;i++){
    auto lb = lower_bound(ALL(A),B[i]);
    auto ub = upper_bound(ALL(C),B[i]);
    ll num = (lb-A.begin());
    ll num2 = n-(ub-C.begin());
    ans += num*num2;
    // cout<<num<<" "<<num2<<endl;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3456
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

vector<int> a, b, c;

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, 3){
    REP(j, n){
      int tmp;
      cin>>tmp;
      switch(i){
      case 0:
	a.push_back(tmp);
	break;
      case 1:
	b.push_back(tmp);
	break;
      case 2:
	c.push_back(tmp);
	break;
      }
    }
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll ans = 0LL;
  REP(i, n){
    auto ab = lower_bound(a.begin(), a.end(), b[i]);
    auto bc = upper_bound(c.begin(), c.end(), b[i]);
    ll d1 = distance(a.begin(), ab);
    ll d2 = distance(bc, c.end());
    //cout << ab << " " << bc << endl;
    ans += d1*d2;
  }
  
  cout << ans << endl;
  
  return 0;
}


  /*
  //O(n^2logn)になりTLE
  REP(i, n){
    vector<int>::iterator it1 = upper_bound(b.begin(), b.end(), a[i]);
    if(n <= distance(b.begin(), it1)) continue;
    int cnt = distance(it1, b.end()), ii = 0;
    //cout << "cnt: " << cnt << endl;
    while(ii<cnt){
      vector<int>::iterator it2 = upper_bound(c.begin(), c.end(), b[n-cnt+ii]);
      if(n <= distance(c.begin(), it2)) continue;
      //cout << " a: " << a[i] << " b: " << *it1 << " c: "<< *it2 << endl;    
      ans += distance(it2, c.end());
      ii++;
    }
    //cout << distance(b.begin(), it1) << endl;
  }
  */


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

int main() {

    int h, w;
    char ch;

    vector<vector<char> > c;
    
    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        vector<char> v;
        for (int j = 0; j < w; j++) {
            cin >> ch;
            v.push_back(ch);
        }
        c.push_back(v);
    }
    for (int i = 0; i < w+2; i++) {
        cout << "#";
    }
    cout << endl;

    for (int i = 0; i < h; i++) {
        cout << "#";
        for (int j = 0; j < w; j++) {
            cout << c[i][j];
        }
        cout << "#" << endl;
    }
    for (int i = 0; i < w+2; i++) {
        cout << "#";
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
map<ll, int> mp;

int main () {
  cin >> N;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    mp[tmp]++;
  }

  ll f = 0;
  ll s = 0;

  for (auto p: mp) {
    if (p.second >= 4) {
      f = p.first;
      s = p.first;
    } else if (p.second >= 2) {
      s = f;
      f = p.first;
    }
  }

  cout << f * s << "\n";
}

Measured memory_bytes: 6528
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int w = scanner.nextInt();
        int[] wt = new int[n];
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            wt[i] = scanner.nextInt();
            p[i] = scanner.nextInt();
        }
        int sum=0;
        for(int i : p)
            sum +=i;
        long[] dp = new long[sum+1];
        Arrays.fill(dp,Integer.MAX_VALUE);
        dp[0]=0;
        for (int i = 0; i < n; i++) {
            for (int j =sum-p[i]; j >=0 ; j--) {
                dp[j+p[i]] = Math.min(dp[j+p[i]],dp[j]+wt[i]);
            }
        }
        long ans = 0;
        for (int i = sum; i >=0 ; i--) {
            if(dp[i]<=w){
                ans = Math.max(ans, i);

            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 36936
#python3

def main():
    n, m = map(int, input().split())
    lamp = []
    for _ in range(m):
       lamp.append([int(i)-1 for i in input().split()][1:]) 
    p = [int(i) for i in input().split()]
    cnt = 0
    for i in range(1<<n):
        partition = [0 for _ in range(n)]
        for j in range(n):
            if i>>j & 1:
                partition[j] = 1
            
        #j番目のlampをみる
        flag = True
        for j in range(m):
            s = 0
            #j番目のlampのk番目のswitchの番号を取り出す
            for k in range(len(lamp[j])):
                v = lamp[j][k]
                if partition[v]:
                    s += 1
            if s%2 != p[j]:
                flag = False
        if flag:
            cnt += 1
    print(cnt)
main() 

                    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

#define SEG_LEN (1<<20)
vector<ll> seg(2*SEG_LEN);
vector<ll> a;

void change(int ind,ll x){
  ind+=SEG_LEN;
  seg.at(ind)=x;
  while(1){
    ind/=2;
    if(ind==0)  break;
    seg.at(ind)=max(seg.at(2*ind),seg.at(2*ind+1));
  }
}
ll max_search(int l,int r){
  l+=SEG_LEN;
  r+=SEG_LEN;
  ll ans=0;
  while(l<r){
    if(l%2==1){
      ans=max(ans,seg.at(l));
      l++;
    }
    l/=2;
    if(r%2==1){
      ans=max(ans,seg.at(r-1));
      r--;
    }
    r/=2;
  }
  return ans;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i=0;i<N;i++)  cin >> h.at(i);
  a.resize(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);

  for(int i=0;i<N;i++){
    ll ma=max_search(0,h.at(i));
    change(h.at(i),ma+a.at(i));
  }
  cout << seg.at(1) << endl;

  return 0;
}

Measured memory_bytes: 18944
#include <vector>
#include <iostream>

#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
using namespace std;

int main () {
  int n,k;
  scanf("%d",&n);
  int a[n][n];
  std::vector<int> v(n,0);
  // bool flag[n];
  // cout << "debug" << endl;
  rep(i,n) {
    // flag[i] = false;
    rep(j,n-1) {
      cin >> k;
      a[i][j] = k-1;
    }
    a[i][n-1] = -1;
  }
  // cout << "debug" << endl;
  bool today[n];
  int count = 0, days = 0;
  while(count < n*(n-1)/2) {
    days++;
    // cout << days << endl;
    for(int i = 0; i < n; i++) {
      today[i] = false;
    }
    rep(i,n) {
      // if(days == 4 && flag[i] == true)  cout << i << " :: " << flag[i] << endl;
      if(today[i] == true) continue;
      if (a[a[i][v[i]]][v[a[i][v[i]]]] == i && a[i][v[i]] > i && today[a[i][v[i]]] == false/* && flag[i] == false && flag[a[i][v[i]]] == false*/) {
        today[i] = true; today[a[i][v[i]]] = true;
        count++;
        // cout << i << " VS " << a[i][v[i]] << ", count = " << count << ", days = " << days << endl;
        // if(v[a[i][v[i]]] < n-1)
        v[a[i][v[i]]]++;
        // else {flag[a[i][v[i]]] = true;
        // if(v[i] < n-1)
        v[i]++;
        // else flag[i] = true;
      }
    }
    rep(i,n) {
      if(today[i]) break;
      if(i == n-1) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  cout << days << endl;
}


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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }






  int main(){
    int N;
    cin >> N;
    map<int, int> mp;
    REP(i, N){
      int d; cin >> d; mp[d]++;
    }
    int K; cin >> K;
    REP(i, K){
      int t; cin >> t; mp[t]--;
      if(mp[t] < 0){
          cout << "NO" << endl; return 0;
      }
    }
    cout << "YES" << endl;
  }




Measured memory_bytes: 9600
L,R=map(int,input().split())
M=[]
A=[]
if (R-L)>=2019:
    print(0)
else:
    for i in range(L,R+1):
        M.append(i%2019)
    for j in range(0,len(M)-1):
        for k in range(j+1,len(M)):
            b=M[j]*M[k]
            A.append(b%2019)
    print(min(A))

Measured memory_bytes: 75440
from bisect import bisect_left
n,k = map(int,input().split( ))
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    a[i] -= 1
sm= 0
a_sm = [0]
for i in range(n):
    sm += a[i]
    sm%=k
    a_sm.append(sm)

dic = {}
for i in range(n+1):
    if a_sm[i] in dic:
        dic[a_sm[i]].append(i)
    else:
        dic[a_sm[i]]=[i]

for t in dic:
    for j in range(len(dic[t])-1):
        dm = bisect_left(dic[t],dic[t][j]+k)
        ans += dm - j - 1

       
print(ans)

Measured memory_bytes: 122368
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N;
    int a[301][301] = {}, b[301][301] = {};
    int c=1;
    long long ans = 0;

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

    for(int i = 1; i < N+1; i++){
        for(int j = 1; j<N+1; j++){
            for(int k=0; k < N+1; k++){
                if(a[j][k] > a[j][i] + a[i][k]){
                    cout << "-1\n";
                    return 0;
                }
            }
        }
    }

    for(int i = 1; i < N+1; i++){
        for(int j = 1; j<N+1; j++){
            for(int k=1; k < N+1; k++){
                if(k == j || k == i){}
                else if(a[i][j] == a[i][k] + a[k][j]){
                    b[i][j] = b[j][i] = 0;
                }
            }
        }
    }

    for(int i = 1; i < N+1; i++){
        for(int j = 1; j < N+1; j++){
            ans += b[i][j];
        }
    }

    cout << ans/2 << '\n';
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, a[200005];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] >= i){
			printf("-1\n");
			return 0;
		}
		if(i > 1 && a[i] >= a[i - 1] + 2){
			printf("-1\n");
			return 0;
		}
	}
	
	long long ans = 0;
	
	for(int i = n; i > 0; i--){
		ans += a[i];
		while(i > 1 && a[i - 1] == a[i] - 1){
			i--;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+3;
long long dp[N][N][2];
int a[N];
int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		dp[i][i][0] = dp[i][i][1] = a[i];
	}
	for(int len = 1; len < n; ++len)
		for(int st = 0; (st+len) < n; ++st){
			int ed = st + len;
			dp[st][ed][0] = max(a[st] - dp[st+1][ed][1], a[ed] - dp[st][ed-1][1]);
			dp[st][ed][1] = max(a[st] - dp[st+1][ed][0], a[ed] - dp[st][ed-1][0]);
		}
	cout << dp[0][n-1][0];
	return 0;
}


Measured memory_bytes: 139648
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using P = pair<ll, ll>;
const int INF = 1001001001;

int main(void){
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<P> apple;
  REP(i, a){
    ll p;
    cin >> p;
    apple.push(P(p, 0));
  }
  REP(i, b){
    ll q;
    cin >> q;
    apple.push(P(q, 1));
  }
  REP(i, c){
    ll r;
    cin >> r;
    apple.push(P(r, 2));
  }
  ll p = 0, q = 0, r = 0;
  ll ans = 0;
  while(p+q+r != x+y){
    P ap = apple.top();
    apple.pop();
    if(ap.second == 0){
      if(p < x){
        p++;
        ans += ap.first;
      }
    }
    if(ap.second == 1){
      if(q < y){
        q++;
        ans += ap.first;
      }
    }
    if(ap.second == 2){
      r++;
      ans += ap.first;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 10476
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Vector.Unboxed as VU
import Data.Char
import Data.List

toTuple :: B.ByteString -> (Int, Int)
toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

make :: MP.Map Int [Int] -> (Int, Int) -> MP.Map Int [Int]
make m (a,b) =
    case MP.lookup a m of
        Just _ -> MP.adjust (b:) a m
        Nothing -> MP.insert a [b] m

rebuild :: MP.Map Int [Int] -> MP.Map Int (VU.Vector Int) -> MP.Map Int (VU.Vector Int)
rebuild m n
    | MP.null m = n
    | otherwise = rebuild m' (MP.insert i xs' n)
        where
            ((i,xs),m') = MP.deleteFindMin m
            xs' = VU.fromList $ sort xs

lowerBound :: VU.Vector Int -> (Int, Int) -> Int -> Int
lowerBound vec (from, to) target
    | from == to = from
    | mValue >= target = lowerBound vec (from, mid) target
    | mValue < target = lowerBound vec (mid + 1, to) target
        where
            mid = (from + to) `quot` 2
            mValue = vec VU.! mid

comp :: Int -> String
comp n = zero ++ n'
    where
        n' = show n
        zero = replicate (6 - (length n')) '0'

main = do
    [n,m] <- map read . words <$> getLine
    xs <- VU.replicateM m (toTuple <$> B.getLine)
    let m = VU.foldl' make MP.empty xs
    let m' = rebuild m MP.empty
    VU.forM_ xs $ \(p,y) -> do
        let Just ys = MP.lookup p m'
        let lb = lowerBound ys (0, VU.length ys) y
        putStrLn $ comp p ++ comp (lb+1)

Measured memory_bytes: 38908
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000000;

ll A[MAXN];

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

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

int f(int x) {
  int res = 0;
  while (x%2 == 0) {
    x /= 2;
    res++;
  }
  return res;
}

int main(){
    int N, M;
    cin >> N >> M;
    ll a = 1;
    int t;
    rep(i,N){
        cin >> A[i];
        A[i] /= 2;
        if(i){
            if( t != f(A[i]) ){
                cout << 0 << endl;
                return 0;                
            }
        }
        else{
            t = f(A[i]);
        } 
        a = lcm(a,A[i]);
        if(a > MAX){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = (a+M)/(2*a);

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

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//



int main()
{
	fastio;
    // int T;
    // cin >> T;
    // while(T--)
    // {

    // }
    int N;
    cin >> N;
    vector<ll>f(N+1, 2);
    f[1]=1;
    for(ll i = 2; i <= N; i++)
    {
        for(ll j = i+i; j <= N; j+=i)
        {
            f[j]++;
        }
    }
    ll ans = 0;
    for(ll i=1;i<=N;i++)
    {
        ans += i*f[i];
    }
    cout<<ans<<'\n';

}

Measured memory_bytes: 81336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    double n;cin>>n;
    cout<<ceil((sqrt(1+8*n)-1)/2.0)<<endl;
}

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char** argv){
    int A, B;
    cin >> A >> B;
    int ans = 0;
    int cur = 1;
    while (cur < B){
        cur += A-1;
        ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxm=2e5+5;
int a[maxm];
int b[maxm];
int n;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int x,y;cin>>x>>y;
        a[i]=x-y;
        b[i]=x+y;
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    int ans=max(a[n]-a[1],b[n]-b[1]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6744
@d=$t=1;
$/=\1;
for(;$t+=($j=ord<>)>10?($c+=$j%3,1):-1;$d[$c<$t?$t:$c-$t]=0){
	for($j=$c;$j;){
		($d[$j]+=$d[--$j])%=998244353
	}
}
print$d[$c]+0

Measured memory_bytes: 768
// After contest.
// Greedy.

#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>

using namespace std;

const int maxn = 200002;

int n, ans, d[maxn];
unordered_map<int, int> freq;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	sort(d, d+n);
	
	for (int i = n-1; i >= 0; --i)
		if (freq[d[i]]) {
			--freq[d[i]];

			int sum = 1;
			while (sum <= d[i])
				sum <<= 1;
			
			if (freq[sum-d[i]] > 0) {
				++ans;
				--freq[sum-d[i]];
			}
		}

	cout << ans << endl;

	return 0;
}

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

int main(){
    ll n;
    cin >> n;
    ve<ll> A(100010);
    ll ans= 0;
    rep(i,n){
        int a;
        cin >> a;
        A[a]++;
        ans += a;
    }
    ll q;
    cin >> q;
    rep(Q,q){
        int b,c;
        cin >> b >> c;
        ans += (c-b)*A[b];
        cout << ans << endl;
        A[c] += A[b];
        A[b] = 0;

    }
    return 0;
}

Measured memory_bytes: 4036
#include<stdio.h>
int main(void){
 int i,j,m,yama[11]={0};
    for(i=1;i<11;i++){
        scanf("%d",&yama[i]);
    }
        for(i=0;i<3;i++){
            for(j=i+1;j<11;j++){
                if(yama[i]<yama[j]){
                    m=yama[i];
                    yama[i]=yama[j];
                    yama[j]=m;
                }
            }
        }
        for(i=0;i<3;i++){
            printf("%d\n",yama[i]);
        }
        return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll h[110000];
ll dp[110000];
int main(){
    ll n,k;
    cin>>n>>k;
    rep(i,0,n){cin>>h[i];dp[i]=1e9;}
    dp[0]=0;
    rep(i,0,n){
        rep(j,1,min(k,i)+1){
            dp[i]=min(dp[i],dp[i-j]+labs(h[i]-h[i-j]));
        }
        
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1792