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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll a,b,c,k; cin >> a >> b >> c >> k;
  if(k % 2 == 1)cout << b - a << endl;
  else cout << a - b << endl;
  return 0;
}


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

const ll mod = 1e9 + 7;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> dp(h + 1, vector<int>(w, 0));
    dp[0][0] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int bit = 0; bit < (1 << (w - 1)); ++bit) {
                bool connected = true;
                for (int l = 0; l < w - 2; ++l) {
                    if ((bit & 1 << l) && (bit & (1 << (l + 1)))) {
                        connected = false;
                    }
                }
                if (connected) {
                    if (j >= 1 && (bit & (1 << (j - 1)))) {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= mod;
                    } else if (j <= w - 2 && (bit & 1 << j)) {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= mod;
                    } else {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= mod;
                    }
                }
            }
        }
    }
    cout << dp[h][k - 1] << endl;
}

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

int main(){
  ll n,t,a,ans;
  cin >> n >> t >> a;
  vector<ll> H(n);
  vector<ll> A(n);
  rep(i,n) cin >> H[i];
  rep(i,n){
    A[i] = abs((t*1000) - (H[i]*6) - a*1000);
  }
  ans = min_element(A.begin(),A.end()) - A.begin() +1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
 
 
#define fr(i, n) for(int i=0; i<n;i++)
#define fr1(i, n) for(int i=1; i<=n;i++) 
 
#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"
 
void file(){
	readf("in.txt");
    writef("out.txt");
}
 
template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 1e9+5;

int w[105], v[105], dp[100005];


int main()
{
	//file();
 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 	
 	int N, W;

 	cin>>N>>W;

 	int sum = 0;

 	fr1(i,N){
 		cin>>w[i]>>v[i];
 		sum += v[i];
 	}

 

 	int dp[sum + 3];

 	for(int  i = 1; i <= sum; i++)
 		dp[i] = INF;

 	dp[0] = 0;
 	fr1(i,N){

 		for(int j = sum; j >= v[i]; j--){
 			dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
 		}
 	}
 	

 	for(int i = sum; i >= 0; i--)
 		if(dp[i] <= W){
 			cout<<i<<nl;
 			break;
 		}

	


    return 0;
 
}

Measured memory_bytes: 640
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n,k = LI()
h = LI()

h.sort()
print(sum(h[:max(0,n-k)]))

Measured memory_bytes: 27660
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 123;
int n,m;
int a[N];
int b[N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    int cnt = 0;
    sort(b + 1,b + 1 + n);
    for (int i = 1; i <= n; i++) if (a[i] == b[n]) cnt++;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == b[n])
            cout << b[n - 1] << '\n';
        else{ 
            cout << b[n] << '\n';
        }
    }
    return (0);
}




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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

int main(){

        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);

        int s, w; cin >> s >> w;
        if (w >= s) {
                cout << "unsafe\n";
        }
        else cout << "safe\n";
        return 0;
}



Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main (void) {
    string c[2];

    cin >> c[0];
    cin >> c[1];

    if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    string t = "CODEFESTIVAL2016";
    ll ans = 0;
    for(ll i = 0; i < s.size(); ++i){
        ans += (s.at(i) != t.at(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<int>>> dp ( 110, vector<vector<int>>( 110, vector<int>(110,1e9)));

int main(void){
    int a,b,c; cin>>a>>b>>c;
    dp[a][b][c]=0;
    for(int i=a;i<100;i++){
        for(int j=b;j<100;j++){
            for(int k=c;k<100;k++){
                dp[i+1][j+1][k]= min(dp[i+1][j+1][k],dp[i][j][k]+1);
                dp[i][j+1][k+1]= min(dp[i+1][j][k+1],dp[i][j][k]+1);
                dp[i+1][j][k+1]= min(dp[i+1][j][k+1],dp[i][j][k]+1);
                dp[i+2][j][k]= min(dp[i+2][j][k],dp[i][j][k]+1);
                dp[i][j][k+2]= min(dp[i][j][k+2],dp[i][j][k]+1);
                dp[i][j+2][k]= min(dp[i][j+2][k],dp[i][j][k]+1);
            }
        }
    }
    int ans=1e9;
    for(int i=0;i<100;i++){
        ans=min(dp[i][i][i],ans);
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, u, v; cin >> n >> u >> v;
    u--; v--;
    int a, b;
    vector<int> g[n];
    for(int i=0;i<n-1;i++){
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int du[n];
    int dv[n];
    for(int i=0;i<n;i++) du[i] = -1;
    for(int i=0;i<n;i++) dv[i] = -1;
    // from v aoki
    queue<int> Q;
    dv[v] = 0;
    Q.push(v);
    while(!Q.empty()){
        int s = Q.front(); Q.pop();
        for(int t: g[s]){
            if(dv[t] == -1){
                dv[t] = dv[s] + 1;
                Q.push(t); 
            }
        }
    }
    // from u takahashi
    int ans = 0;
    du[u] = 0;
    Q.push(u);
    while(!Q.empty()){
        int s = Q.front(); Q.pop();
        if(du[s] >= dv[s]){
            // cout << s << endl;
            // end here
            ans = max(ans, dv[s]);
        }else{
            for(int t: g[s]){
                if(du[t] == -1){
                    du[t] = du[s] + 1;
                    Q.push(t); 
                }
            }
        }
    }

    // for(int i=0;i<n;i++) cout << i << " " << du[i] << endl;

    for(int i=0;i<n;i++){
        if(du[i] == -1) continue;
        if(du[i] < dv[i]){
            ans = max(ans, dv[i] - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6656
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) { cin >> X[i]; }
    ll min_counter = 1e9;


    for (int i = 1; i < 101; i++) {
        int counter = 0;
        for (int j = 0; j < N; j++) {
            counter += (X[j] - i) * (X[j] - i);
        }
        if (min_counter > counter) {
            min_counter = counter;
        }
    }
    cout << min_counter << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/agc038/tasks/agc038_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

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

fn main() {
    input! {
        h: usize, w: usize, a: usize, b: usize
    };
    let mut tbl = dvec!('0'; h, w);
    for i in 0..h-b {
        for j in a..w {
            tbl[i][j] = '1';
        }
    }
    for i in h-b..h {
        for j in 0..a {
            tbl[i][j] = '1';
        }
    }

    for i in 0..h {
        println!("{}", join!(tbl[i].clone(), ""));
    }
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0 || i % 5 == 0){
			continue;
		}
		ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define LL long long
//int mat[209][209];
#define LL long long
int dp[209][209];
int main(){
    int n,m,R;cin>>n>>m>>R;
    vector<int>v;
    for(int i=0;i<R;++i){
        int va;cin>>va;
        v.pb(va);
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=m;++i){
        int a,b,c;cin>>a>>b>>c;
    //    mat[a][b]=c;
      //  mat[b][a]=c;
        dp[a][b]=c;
        dp[b][a]=c;
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            if(i==j)dp[i][j]=0;
            else if(dp[i][j]==0) dp[i][j]=1e8;
        }
    }
    for(int k=1;k<=n;++k){
        for(int i=1;i<=n;++i){
            for(int j=1;j<=n;++j){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    int ans=1e9;
    while(next_permutation(v.begin(),v.end())){
        vector<int>b;
        for(auto it:v)b.pb(it);
        int tmp=0;
        for(int i=1;i<(int)b.size();++i){
         tmp+=dp[b[i]][b[i-1]];   
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define fl float
#define db double
#define ii pair<ll,ll>
#define pii pair<ii,ii>
#define ford(i,a,b) for(int i=a;i<=b;i++)
#define foru(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,a,b) for(int i=a;i<b;i++)
#define oo 10000000000001
#define ooo -1000000000001
#define bost  ios_base::sync_with_stdio(false); cin.tie(0);
string s;
int main()
{
    bost
    cin>>s;
    map<char,int > m;
    map<char,int>::iterator it;
    ford(i,0,s.length()-1)
    {
        m[s[i]]++;
    }
    if(m.size()==1)
    {
        cout<<"No";
        return 0;
    }
    else
    {
        int t=0;
        for(it=m.begin(); it!=m.end(); it++)
        {
            if((*it).second>=2)
                t++;
        }
        if(t>=2)
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n, 0);
    for(int i = 0; i < n; i++) cin >> a[i];
    
    priority_queue<int> Q;
    for(int i = 0; i < n; i++) Q.push(a[i]);

    for(int i = 0; i < m; i++){
        int cur = Q.top();
        Q.pop();
        Q.push(cur/2);
    }

    long long int res = 0;
    while(Q.size()){
        res += Q.top();
        Q.pop();
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1276
package main

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

var r = bufio.NewReader(os.Stdin)

func main(){
    var S int
    fmt.Fscan(r, &S)
    
    s := S%60
    m := (S%3600)/60
    h := S/3600
    
    fmt.Printf("%v:%v:%v\n",h,m,s)
}



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

#define M 1046527
#define L 14

string H[M];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

long long getKey(string s){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < s.size(); i++ ){
    sum += p*(getChar(s[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

bool find(string s) {
  long long h, k;
  k = getKey(s);
  for (int i = 0;; i++) {
    h = (h1(k) + i*h2(k)) % M;
    if (H[h] == s) return true;
    else if (H[h].size() == 0) return false;
  }
  return false;
}

bool insert(string s) {
  long long h, k;
  k = getKey(s);
  for (int i = 0;; i++) {
    h = (h1(k) + i*h2(k)) % M;
    if (H[h] == s) return true;
    else if (H[h].size() == 0) {
      H[h] = s;
      return true;
    }
  }
  return false;
}

int main(){
  int i, n, h;
  string s, op;
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';

  cin >> n;

  for ( i = 0; i < n; i++ ){
    cin >> op >> s;

    if ( op[0] == 'i' ){
      insert(s);
    } else {
      if (find(s)){
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 25872
#include <iostream>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<deque>
#include<iomanip>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<stack>
#include<unordered_set>
#include<cstring>
using namespace std;
//	int x=atoi(s.c_str()); s_to_in;
int dx[] = { -1,0,0,1 };
int dy[] = { 0,1,-1 ,0 };
#define endl '\n'
long long mo = 1e9;
const long double P = 3.141592653589793238L;
void trust_yourself()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
long long gcd(long long x, long long y)
{
	if (x == 0)
		return y;
	return gcd(y%x, x);
}
long long fast_power(long long x, long long y, long long mo)
{
	long long p = 1;
	while (y)
	{
		if (y & 1)
			p = (p*x) % mo;
		y = (y >> 1); //y/=2
		x = (x*x) % mo;
	}

	return p;
}
long long convert_to_num(string x) {
	long long  num = 0;
	for (int i = 0; i < x.size(); i++) {
		num *= 2;
		num += x[i] - '0';
	}
	return num;
}

long long com(long long n, long long r) {
	long long p = 1, p1 = 1;
	for (long long i = r + 1; i <= n; i++) {
		p = p * i;
		p /= p1;
		p1++;
	}
	return p;
}


int main()
{
	trust_yourself();
	//freopen("hussien.in", "r", stdin);
	
	int s, w;
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe";
	else
		cout<<"safe";
	
	return 0;

}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N=200006;
int p[MAX_N];
int N,K;

void solve()
{
	double cur = 0;
	for(int i=0;i<K;++i) cur += (1+p[i])/2.0;
	double ans = cur;
	for(int i=K;i<N;++i){
		cur += (1+p[i])/2.0;
		cur -= (1+p[i-K])/2.0;
		ans = max(ans, cur);
	}
	printf("%.7lf\n", ans);
}

int main()
{
	//ios::sync_with_stdio(false);
	cin >> N >> K;
	for(int i=0;i<N;++i) cin >> p[i];
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<math.h>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define Case int t;scanf("%d", &t);while(t--)
typedef long long ll;
const int Max = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int n;
ll a[405];
ll dp[405][405];
ll ans[405][405];

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		dp[i][i] = a[i];
	}

	
	for(int l = 1; l < n; l++){
		for(int i = 1; i+l <= n; i++){
			int j = i+l;
			if(ans[i][j-1]+dp[i][j-1]+a[j] < ans[i+1][j]+dp[i+1][j]+a[i]){
				ans[i][j] = ans[i][j-1]+dp[i][j-1]+a[j];
				dp[i][j] = dp[i][j-1]+a[j];
			}
			else{
				ans[i][j] = ans[i+1][j]+dp[i+1][j]+a[i];
				dp[i][j] = dp[i+1][j]+a[i];	
			}
			for(int k = i+1; k+1 < j; k++){
				if(ans[i][j] > ans[i][k]+ans[k+1][j]+dp[i][k]+dp[k+1][j]){
					ans[i][j] = ans[i][k]+ans[k+1][j]+dp[i][k]+dp[k+1][j];
					dp[i][j] = dp[i][k]+dp[k+1][j];
				}
			}
		}
	}

	cout << ans[1][n] << endl;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n, k;
    cin >> n >> k;

    vector<long long> p(n), c(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
        p[i] -= 1;
    }
    for (int i = 0; i < n; i++)
        cin >> c[i];
    
    vector<bool> vis(n, false);

    function<void (int, long long&, vector<int>&)> dfs = [&](int u, long long &cnt, vector<int> &g) -> void{
        if (vis[p[u]]){
            return ;
        }

        vis[p[u]] = true;
        g.push_back(p[u]);
        cnt += c[p[u]];
        dfs(p[u], cnt, g);
    };
    
    long long ans = LLONG_MIN;
    for (int i = 0; i < n; i++){
        if (!vis[p[i]]){
            vector<int> cycle;
            long long total = 0;
            dfs(p[i], total, cycle);
            
            long long sz = (int) cycle.size();
            for (int i = 0; i < sz; i++){
                long long cnt = 0;
                for (long long rem = 1; rem <= min(sz, k); rem++){
                    cnt += c[cycle[(i + rem) % sz]];
                    auto val1 = cnt;
                    auto val2 = cnt + (k - rem) / sz * total;
                    
                    ans = max({ans, val1, val2});
                }
            }
        }
    }
    
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 4060
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    string S;
    cin >> S;
    
    regex re("A[a-z]+C[a-z]+");
    if(regex_match(S,re)){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
        
    }
    return 0;
}



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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                for (int k = 1; k <= n; k++) {
                    ans += gcd(i, j, k);
                }
            }
        }
        out.println(ans);
    }

    static long gcd(long... a) {
        if (a.length == 0) return 1;
        long ret = a[0];
        for (int i = 1; i < a.length; i++) {
            ret = gcd(ret, a[i]);
        }
        return ret;
    }

    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 42444
#ABC147 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
s = si()
n = len(s)
# s_rev = s[::-1]
# print(s_rev)
# print(s[n-1:n])
ans = 0
for i in range(n//2):
    if s[i:i+1]!=s[n-1-i:n-i]:
        ans+=1
print(ans)

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

int main() {
    int N;cin >> N;
    ll s[9][9] = {};
    for (int i = 1;i < N + 1;i++){
        string x = to_string(i);
        int a = x[0] - '0';
        int b = x[x.size() -1] - '0';
        if (a == 0 || b == 0) continue;
        s[a - 1][b - 1]++;
    }
    ll res = 0;
    for (int i = 0;i < 9;i++){
        for(int j = 0;j < 9;j++){
            res += s[i][j] * s[j][i];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  char c;
  cin>>c;
  int x=0;
  if (c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    x=1;
  }
  if (x==1){
    cout<<"vowel"<<endl;
  }
  else{
    cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<string> vs;

int main() {FIN

	int h, w, k, c = 0, t, i, j, x, y;
	cin >> h >> w >> k;
	vs tb(h);
	for (i = 0; i < h; i++)
		cin >> tb[i];
		
	for (i = 0; i < (1 << h); i++) {
		for (j = 0; j < (1 << w); j++) {
			t = 0;
			for (x = 0; x < h; x++) {
				for (y = 0; y < w; y++) {
					if (i & (1 << x) and j & (1 << y) and tb[x][y] == '#')
						t++;
				}
			}
			if (t == k)
				c++;
		}
	}
	cout << c << "\n";
	
	return 0;
}


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

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

    vector<int> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }

    vector<int> dp(h+1, 1e9);
    dp[0] = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=h; j++){
            dp[j] = min(dp[j], (j + a[i] - 1) / a[i] * b[i]);
        }
        for(int j=0; j<=h; j++){
            if(j >= a[i]) dp[j] = min(dp[j], dp[j-a[i]] + b[i]);
        }
    }

    /*
    for(int j=0; j<=h; j++){
        cout << dp[j] << " ";
    }
    cout << endl;
    */
    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

    fun main(args: Array<String>) {
        val sc = Scanner(System.`in`)

        val a = sc.nextInt()
        val b = sc.nextInt()
        val c = sc.nextInt()

        if (a == b) println(c)
        else if (a == c) println(b)
        else println(a)
    }


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


ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
//最小公倍数
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b;}

int main(void){
    // Your code here!
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll array[40];
	array[1]=1;
	array[2]=1;
	array[3]=1;
	array[4]=2;
	array[5]=1;
	array[6]=2;
	array[7]=1;
	array[8]=5;
	array[9]=2;
	array[10]=2;
	array[11]=1;
	array[12]=5;
	array[13]=1;
	array[14]=2;
	array[15]=1;
	array[16]=14;
	array[17]=1;
	array[18]=5;
	array[19]=1;
	array[20]=5;
	array[21]=2;
	array[22]=2;
	array[23]=1;
	array[24]=15;
	array[25]=2;
	array[26]=2;
	array[27]=5;
	array[28]=4;
	array[29]=1;
	array[30]=4;
    array[31]=1;
	array[32]=51;
ll k;
cin>>k;
cout<<array[k]<<endl;
	
	return 0;
}

//1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51

Measured memory_bytes: 256
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.*
import kotlin.system.exitProcess

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(true) {
            when(c) {
                '\n', Char.MIN_VALUE -> return@buildString
                else -> {
                    append(c)
                    c = readChar()
                }
            }
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

fun check(a: IntArray, len: Int, k: Int): Boolean {
    if (len == 0) {
        return false
    }
    var required = 0

    for (x in a) {
        required += (x - 1) / len
    }

    return required <= k
}

fun check2(a: IntArray, len: Double, k: Int): Boolean {
    var required = 0

    for (x in a) {
        required += floor((x.toDouble() / len)).toInt()
    }

    return required <= k
}

fun isReq(a : IntArray, len: Int, k: Int): Boolean {
    if (!check(a, len, k)) {
        return true
    }

    for (x in a) {
        if ((x % len) > 0) {
            return false
        }
    }

    return true
}

fun main() {
    val (n, k) = readIntArray(2)
    val a = readIntArray(n)

    var low = 0.0
    var high = a.max()!!.toDouble()

    while (high - low > 0.01) {
        var mid = low + (high - low) / 2
        if (check2(a, mid, k)) {
            high = mid
        } else {
            low = mid
        }
    }

    val low2 = floor(low).toInt()
    if (isReq(a.map { it*2 }.toIntArray(), low2 * 2 - 1, k)) {
        println(low2 + 1)
    } else {
        println(low2)
    }

}

Measured memory_bytes: 55300
#include <bits/stdc++.h>
#define ll long long

using namespace std;

// input


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

    cin >> a >> b;

    cout << "a ";

    if(a > b){
        cout << ">";
    }
    else if(a < b){
        cout << "<";
    }
    else{
        cout << "==";
    }


    cout << " b" << "\n";
}


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

int c[50+1];

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        c[a]++;
        c[b]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << c[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;
using ull = unsigned long long;

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

    ull min = LLONG_MAX;
    for (ull i = 1; i * i <= n; ++i)
    {
        if (n % i != 0) continue;
        const ull sum = i + (n / i);
        if (sum < min) min = sum;
    }
    cout << min - 2 << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
s = [list(input()) for i in range(N)]

for i in range(len(s)):
  s[i].sort()
s.sort()

ans = 0
cnt = 1
for i in range(1, N):
  for j in range(10):
    if s[i][j] != s[i - 1][j]:
      break
  else:
    cnt += 1
    continue
  ans += cnt * (cnt - 1) // 2
  cnt = 1
ans += cnt * (cnt - 1) // 2

print(ans)


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



if abs(x)>k*d:
    print( abs(abs(x)-(k*d)) ) 
        
else:
    
    if k%2==0:
        
        kaisuu_odd_0 = abs(x)//(2*d) *2
        kyori_odd_0 = abs( abs(x)-kaisuu_odd_0*d )
        
        kaisuu_odd_1 = kaisuu_odd_0 + 2
        kyori_odd_1 = abs( abs(x)-kaisuu_odd_1*d )
        
        print(min(kyori_odd_0,kyori_odd_1))
        
    else:
        kaisuu_odd_0 = abs(x)//(2*d) *2 +1
        kyori_odd_0 = abs( abs(x)-kaisuu_odd_0*d )
        
        kaisuu_odd_1 = kaisuu_odd_0 - 2
        kyori_odd_1 = abs( abs(x)-kaisuu_odd_1*d )
        
        print(min(kyori_odd_0,kyori_odd_1))
    

Measured memory_bytes: 61728
#[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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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 main() {
    input! {
        n: usize,
        k: usize,
        h: [usize; n],
    }
    let mut h = h;
    h.sort();
    h.reverse();
    let mut result = 0;
    for i in k..n {
        result += h[i];
    }
    println!("{}", result);
}


Measured memory_bytes: 6396
S = raw_input()
P = len(S)


dp = [[0]*11 for i in range(11)]
def foo(p,a):
    if dp[a][p]:
        return dp[a][p]
    if p == P:
        dp[a][p] = [int(S[a:P])]
        return dp[a][p]
    
    #dp[a][p] = foo(p+1,a) + foo(p+1,p) + [int(S[a:p+1])]
    if a == p:
        dp[a][p] = foo(p+1,a)
    else:
        num = int(S[a:p])
        dp[a][p] = foo(p+1,a) + map(lambda x:x+num,foo(p+1,p))
    return dp[a][p]
print sum(foo(0,0))


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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 1, (int)A.size()) out << A[i] + 1 << " ";
    return out;
}

template <class T1, class T2>
T1 powr(T1 a, T2 b) {
    T1 res = 1;
    fr(i, 1, b + 1) res = res * a;
    return res;
}

int32_t main() {
    IOS int n;
    cin >> n ;  bool flag = false;
    fr(i,-3000,3001)    fr(j,-3000,3001){
        if((powr(i,5) - powr(j,5)) == n){
            cout << i << " " << j << endl;
            flag = true;
            break;
        }
        if(flag)    break;
    }
    return 0;
}


Measured memory_bytes: 3536
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 2500, M = 5000, INF = 0x3f3f3f3f;

int oo[1 + M], oj[1 + M];

int link(int o, int j) {
	static int _ = 1;
	oo[_] = o, oj[_] = j;
	return _++;
}

int af[N], ii[M], jj[M], ww[M], qu[N], cnt, dd[N];
bool used[N];

void dfs(int i) {
	if (used[i])
		return;
	used[i] = true;
	for (int o = af[i]; o; o = oo[o]) {
		int j = oj[o];
		dfs(j);
	}
}

int main() {
	int n, m, p; cin >> n >> m >> p;
	for (int h = 0; h < m; h++) {
		int i, j, w; cin >> i >> j >> w, i--, j--;
		ii[h] = i, jj[h] = j, ww[h] = w - p;
		af[j] = link(af[j], i);
	}
	dfs(n - 1);
	fill(dd, dd + n, -INF);
	dd[0] = 0;
	for (int k = 1; k <= n; k++)
		for (int h = 0; h < m; h++) {
			int i = ii[h], j = jj[h];
			if (dd[i] != -INF && used[j]) {
				int d = dd[i] + ww[h];
				if (d >= INF) {
					cout << "-1\n";
					return 0;
				}
				if (dd[j] < d) {
					dd[j] = d;
					if (k == n) {
						cout << "-1\n";
						return 0;
					}
				}
			}
		}
	cout << max(dd[n - 1], 0) << '\n';
	return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

long long n, ai, minVal = 10000000, maxVal = -10000000, sumVal = 0;

int main()
{
    cin >> n;
    
    for (int i=0; i<n; i++){
        cin >> ai;
        minVal = min(minVal, ai);
        maxVal = max(maxVal, ai);
        sumVal += ai;
    }
    cout << minVal << " " << maxVal << " " << sumVal << endl;
}



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

using namespace std;

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

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

    sort(arr, arr+N);
    reverse(arr, arr+N);

    int aliceScore = 0, bobScore = 0;
    for (int i = 0; i < N; ++i)
    {
        if (i % 2 == 0)
            aliceScore += arr[i];
        else if (i % 2 == 1)
            bobScore += arr[i];
    }

    int diff = aliceScore - bobScore;
    cout<<diff<<"\n";



    return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    X, K, D = list(map(int, input().split()))

    if abs(X) // D >= K:
        print(abs(X) - D * K)
    else:
        t = abs(X) // D
        if X == 0 and K % 2 != 0:
            print(D)
        elif X == 0 and K % 2 == 0:
            print("0")
        else:
            if abs(X) - D*t < abs(abs(X) - D*(t+1)):
                if (K - t) % 2 == 0:
                    print(abs(X) - D*t)
                else:
                    print(abs(abs(X) - D*(t+1)))
            else:
                if (K - (t+1)) % 2 != 0:
                    print(abs(X) - D*t)
                else:
                    print(abs(abs(X) - D*(t+1)))




Measured memory_bytes: 9192
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll lcm(ll a,ll b){
    return a*b/__gcd(a,b);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    int n;
    cin>>n;
    vector <int> p(n),q(n);
    rep(i,n)
    cin>>p[i];
    rep(i,n)
    cin>>q[i];
    int cnt=1;
    vector <int> a(n);
    rep(i,n)
    a[i]=i+1;
    ll c,d;
    while (a!=p)
    {
        cnt++;
        next_permutation(all(a));
    }
    c=cnt;
    rep(i,n)
        a[i]=i+1;
    cnt=1;
    while (a!=q)
    {
        cnt++;
        next_permutation(all(a));
    }
    d=cnt;
        cout<<abs(c-d);






}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <chrono>
#include <numeric>

using namespace std;

double limit[101];
bool used[101];
double t[101];
double v[101];
int main(){
  int n;
  int used_count = 0;
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> t[i];
  }
  for (int i=0;i<n;i++) {
    cin >> v[i];
  }

  limit[0] = 0;
  for (int i=1;i<n;i++) {
    limit[i] = v[i-1] < v[i]?v[i-1]:v[i];
  }
  limit[n] = 0;
  for (int i=0;i<=n;i++) {
    used[i] = false;
  }
  while (used_count <= n) {
    int min_idx;
    double min_limit = 1000;
    for (int i=0;i<=n;i++) {
      if (limit[i] < min_limit && !used[i]) {
	min_limit = limit[i];
	min_idx = i;
      }
    }
    if (min_idx > 0) {
      double new_left = limit[min_idx] + t[min_idx - 1];
      limit[min_idx - 1] = limit[min_idx - 1] < new_left?limit[min_idx - 1]:new_left;
    }
    if (min_idx < n) {
      double new_right = limit[min_idx] + t[min_idx];
      limit[min_idx + 1] = limit[min_idx + 1] < new_right?limit[min_idx + 1]:new_right;
    }
    used[min_idx] = true;
    used_count++;
  }
  double max_dist = 0.0;
  for (int i=0;i<n;i++) {
    double t_ceiling_1, t_ceiling_2, t_cross, v_cross;
    t_ceiling_1 = v[i] - limit[i];
    t_ceiling_2 = v[i] - limit[i+1];
    t_cross = (t[i] + limit[i+1] - limit[i])/2;
    v_cross = t_cross + limit[i];
    if (v_cross <= v[i]) {
      max_dist += (limit[i]+v_cross)*t_cross/2 + (limit[i+1]+v_cross)*(t[i]-t_cross)/2;
    } else {
      max_dist += (limit[i]+v[i]) * t_ceiling_1/2
	+ v[i] * (t[i] - t_ceiling_1 - t_ceiling_2)
	+ (limit[i+1]+v[i]) * t_ceiling_2/2;
    }
  }

  printf("%.10f\n", max_dist);
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if len(S) < 6:
        print(NO)
        return
    print(YES if S[2]==S[3] and S[4] == S[5] else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// OURL: https://atcoder.jp/contests/abc133/tasks/abc133_c
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll l,r;
  cin >> l >> r;
  if (r % 2019 <= l % 2019 || (r-l >= 2019)) {
    cout << 0 << endl;
  } else {
    ll a = l % 2019;
    int m = 2019;
    RREP(i,a,r%2019) {
      RREP(j,i+1,r%2019+1) {
        m = min(( i*j )%2019, m);
      }
    }
    cout << m << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define M 200005
#define oo 0x3fffffff
#define fr(i,n) for(i=0;i<n;i++)

using namespace std;


struct emp{
    int a,b;
    bool operator<(const emp &x)const{
        return a<x.a;
    }
};

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

int n,m;
vector<vector<pii> >net;
emp indrg[N];
int dst[N],cnt;
int chk[N],chk_cnt[N];
int is_in[N];

void dfs(int c, int d){
    int i;
    if(chk_cnt[c]==cnt){
        if(dst[c]!=d) {
            printf("No");
            exit(0);
        }
        return;
    }
    chk_cnt[c]=cnt;
    dst[c]=d;

    fr(i,net[c].size()){
        dfs(net[c][i].first,d+net[c][i].second);
    }

}


int main(void){
    int i,j,x,y,z;
   // freopen("in.txt","r",stdin);
    scanf("%d %d",&n,&m);
    net.resize(n+5);

    fr(i,n)indrg[i].b=i;
    fr(i,m){
        scanf("%d %d %d",&x,&y,&z);
        x--;y--;
        //my[i]={x,y,z};
        net[x].push_back(make_pair(y,z));
        indrg[y].a++;
        indrg[y].b=y;
        is_in[x]=is_in[y]=1;
    }
    sort(indrg,indrg+n);
    for(i=0;i<n;i++){
        x=indrg[i].a;
        y=indrg[i].b;
        if(x>0) break;
        cnt++;
        dfs(y,1);
    }

    for(i=0;i<n;i++){
        if(is_in[i]==1 && dst[i]==0) break;
    }
    if(i>=n)printf("Yes");
    else printf("No");

    return 0;
}


Measured memory_bytes: 10752