akhauriyash/Code-Regression huggingface dataset:
//ABC143
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	for(int i=0;i<n;i++){
		cin >> d.at(i);
	}
	int sigma = 0;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			sigma += d.at(i)*d.at(j);
		}
	}
	cout << sigma << endl;
	return 0;
}

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

int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> sum(n+1); // n文字目までに何個"AC"が出てくるか
    vector<int> l(q),r(q);
    for(int i=0;i<q;i++){
        cin >> l[i] >> r[i];
    }
    sum[0] = 0;
    //cout << sum[0] << endl;
    for(int i=1;i<n;i++){ //i番目までの"AC"の数を求める
        if(s.substr(i-1,2)=="AC") sum[i] = sum[i-1] + 1;
        else sum[i] = sum[i-1];
    }

    for(int i=0;i<q;i++){
        cout << sum[r[i]-1] - sum[l[i]-1] << endl; 
    }  
}

Measured memory_bytes: 2176
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N,K = LI()

ans = K*(K-1)**(N-1)
print(ans)

Measured memory_bytes: 27080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll ans,A,B;
    cin >> A>> B;
    if(A<B){
        swap(A,B);
    }

    /* ユークリッドの互除法 */
    ans = A*B;
    int r = A % B;
    while(r!=0){
        A = B;
        B = r;
        r = A % B;
    }
    ans /= B;
    cout << ans << endl;

}

Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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, 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")
    };
}

use std::cmp;

const INF: usize = 1e15 as usize;

fn main() {
    input!(n: usize, p: [usize1; n - 1], x: [usize; n]);
    let mut graph = vec![vec![]; n];
    for child in 1..n {
        let parent = p[child - 1];
        graph[parent].push(child);
    }
    if dfs(0, &graph, &x) != INF {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}

fn dfs(v: usize, graph: &Vec<Vec<usize>>, x: &Vec<usize>) -> usize {
    let mut dp = vec![INF; x[v] + 1];
    dp[0] = 0;

    for &child in graph[v].iter() {
        let mut next = vec![INF; x[v] + 1];
        let black = x[child];
        let white = dfs(child, graph, x);
        for i in 0..(x[v] + 1) {
            if dp[i] == INF {
                continue;
            }
            if i + black <= x[v] {
                next[i + black] = cmp::min(next[i + black], dp[i] + white);
            }
            if i + white <= x[v] {
                next[i + white] = cmp::min(next[i + white], dp[i] + black);
            }
        }
        dp = next;
    }
    *dp.iter().min().unwrap()
}


Measured memory_bytes: 30972
#include<iostream>
using namespace std;
int n,k;
int main()
{
    int mx=0,pre=0,st;
    cin >>k>>n;
    cin >>pre;
    st=pre;
    for(int i=2;i<=n;i++)
        {
            int now;
            cin >>now;
            if(now-pre>mx)
                mx=now-pre;
            pre=now;

        }
    if(st-pre+k>mx)
        mx=k+st-pre;
    cout <<k-mx;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
li = [list(map(int, input().split())) for i in range(3)] #ビンゴの取得
N = int(input())
B_list = [list(map(int, input().split())) for i in range(N)] #複数行の数値の入力を取得

arr = np.array(li)
arr2 = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])

# print(li)
# print(arr)
# print(B_list)
# print(B_list[1])

for i in range(N):
    for j in range(3):
        for k in range(3):
            if arr[j, k] == B_list[i]:
                arr2[j, k] = 0

# print(arr2)

if arr2[0, 0] == 0 and arr2[0, 1] == 0 and arr2[0, 2] == 0:
    print("Yes")
    exit()
elif arr2[1, 0] == 0 and arr2[1, 1] == 0 and arr2[1, 2] == 0:
    print("Yes")
    exit()
elif arr2[2, 0] == 0 and arr2[2, 1] == 0 and arr2[2, 2] == 0:
    print("Yes")
    exit()
elif arr2[0, 0] == 0 and arr2[1, 0] == 0 and arr2[2, 0] == 0:
    print("Yes")
    exit()
elif arr2[0, 1] == 0 and arr2[1, 1] == 0 and arr2[2, 1] == 0:
    print("Yes")
    exit()
elif arr2[0, 2] == 0 and arr2[1, 2] == 0 and arr2[2, 2] == 0:
    print("Yes")
    exit()
elif arr2[0, 0] == 0 and arr2[1, 1] == 0 and arr2[2, 2] == 0:
    print("Yes")
    exit()
elif arr2[0, 2] == 0 and arr2[1, 1] == 0 and arr2[2, 0] == 0:
    print("Yes")
    exit()
else:
    print("No")


Measured memory_bytes: 21072
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


def main():
    l, r = map(int, input().split())
    ans = float("inf")
    if r - l >= 2500:
        ans = 0
    else:
        for i in range(l, r):
            for j in range(i+1, r+1):
                ans = min((i*j % 2019), ans)
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<int> fact(10);
  fact[0] = 1;
  for (int i = 1; i < 10; i++) {
    fact[i] = fact[i - 1] * i;
  }
  auto Count = [&](int n, vector<int> v) {
    int ans = 0;
    vector<bool> mark(n + 1);
    for (int i = 0; i < n; i++) {
      for (int j = 1; j < v[i]; j++) {
        if (mark[j]) continue;
        ans += fact[n - i - 1];
      }
      mark[v[i]] = true;
    }
    return ans;
  };
  cout << abs(Count(n, a) - Count(n, b)) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second

int main() {
	string s;
	cin >> s;
	LL ans = INF;
	REP(i, s.length() - 2) {
		LL n = atoi(s.substr(i, 3).c_str());
		ans = min(ans, abs(n - 753));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import javax.sound.midi.Soundbank;
import java.util.*;
import java.lang.*;

public class Main
{
    public static void main (String[] args)
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        int k = s.nextInt();
        int[] a = new int[t];
        for(int i=0; i<t; i++)
        {
            a[i] = s.nextInt();
            if(i>=k)
            {
                if(a[i]>a[i-k])
                    System.out.println("Yes");
                else
                    System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 60424
n,m = map(int,input().split())
h = list(map(int, input().split()))
ab = [0]* m
box = [1] * n
for i in range(m):
    ab[i] = list(map(int,input().split()))
    if h[ab[i][0]-1] == h[ab[i][1]-1]:
        box[ab[i][0]-1] = 0
        box[ab[i][1] - 1] = 0
    elif h[ab[i][0]-1] > h[ab[i][1]-1]:
        box[ab[i][1] - 1] = 0
    else:
        box[ab[i][0] - 1] = 0
print(sum(box))


Measured memory_bytes: 94368
#include <cstdio>
#include <cstring>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int n,m,a[maxn],f[maxn];
int fnd(int x) {
    return x==f[x]?x:(f[x]=fnd(f[x]));
}
void mrg(int x,int y) {
    f[fnd(x)]=fnd(y);
}
int main(void) {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    for (int i=1;i<=n;i++) f[i]=i;
    for (int i=0;i<m;i++) {
        int u,v; scanf("%d%d",&u,&v);
        mrg(a[u],a[v]);
    }
    int ans=0;
    for (int i=1;i<=n;i++) if (fnd(i)==fnd(a[i])) ans++;
    printf("%d\n",ans);
    return 0;
}


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


int main()
{
  string s;
  cin >> s;
  string m = {s[5], s[6]};
  auto mm = atoi(m.c_str());
  if (mm < 5) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  bool can = true;
  for (int i = 0; i < S.size();){
    bool can2 = false;
    for (int j = 0; j < 4; ++j){
      string d = divide[j];
      if (S.substr(i, d.size()) == d){
        can2 = true;
        i += d.size();
      }
    }
    if (!can2){
      can = false;
      break;
    }
  }

  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;  
}


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

int main()
{
	int i,n;

	cin >> i;

	n = i % 10;
	if (n == 3)
	{
		cout << "bon";
	}
	else if (n == 0 || n == 1 || n == 6 || n == 8)
	{
		cout << "pon";
	}
	else
	{
		cout << "hon";
	}
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int arr[N];
long long  n, h, cnt,ans,a;
pair<long long  , long long  >p[N];
int main() {

	scanf("%d%d", &n,&h);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &p[i].first  ,&p[i].second);
		arr[i]=p[i].second;
	}
	sort(p,p+n);
	sort(arr,arr+n);
	reverse(arr,arr+n);
	reverse(p,p+n);
	for (int i = 0; i < n; i++)
	{
	    if(arr[i]<p[0].first )
            break;
        h-=arr[i];
        a++;
        if(h<=0)
          return  cout<<i+1 ,0;

	}

	/**for (int i = 0; i < n; i++){
		if(p[0].first <p[i].second && h )
        {

		cnt+=p[i].second;
            a++;
        }
	}*/
	/**if(cnt>=h)
    {
      return  cout<<a,0;
    }*/
   /* else
    {*/


        ans=a+( h/p[0].first );
        if(h%p[0].first!=0)
            ans++;
        return  cout<<ans,0;
    }


/*
3 10
1 10
1 20
2 3 */


Measured memory_bytes: 3840
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            List<int> n = new List<int>();

            var input = Console.ReadLine().Split(' ');
            for (int i = 0;i < 3;i++)
            {
                n.Add(int.Parse(input[i]));
            }
            if (n[1] >= n[2]) { Console.WriteLine("delicious"); }
            else if (n[1] + n[0] < n[2]) { Console.WriteLine("dangerous"); }
            else { Console.WriteLine("safe"); }
        }
    }
}


Measured memory_bytes: 13140
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<ll> digit(64, 0);
    for(int i=0; i<n; i++){
        for(int j=0; j<61; j++){
            if(a[i] & (1LL << j)) digit[j]++;
        }
    }

    ll ans = 0;
    for(int i=0; i<64; i++){
        ll base = (1LL << i) % MOD;
        ll num = (digit[i] * (n - digit[i])) % MOD;
        ans += base * num;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>

using namespace std;

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

long long p = 1000000007;

long long res(long long l){
    long long d = l/p;
    return l - d*p;
}

long long fact(long long l){
    if(l == 0) return 1;
    if(l == 1) return 1;

    return res(l%p * fact(l-1));
}

int main(){
    long long n, m;
    cin >> n >> m;

    long long output;
    if(n-m == -1 || n-m == 1){
        output = res(fact(n)*fact(m));
    } else if (n==m){
        output = res(2*(fact(n)*fact(m)));
    } else {
        output = 0;
    }

    cout << output << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
 
using namespace std;
 
typedef long long ll;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '

const int MAXN = 200;
//ll a[MAXN], ST[MAXN * 4], LZ[MAXN*4];

/*bool perfectSquare(ll x){
    ll s = sqrt(x);
    if(s *s == x) return true;
    else return false;
}*/

int main() { 
    vector<int> dishes(5);
    for(int i = 0; i < 5; ++i){
        cin >> dishes[i];
    }
    int sum = 0;
    for(int i = 0; i < 5; ++i){
        sum+=(dishes[i] + 9) /10 * 10;
    }
    int time = INT_MAX;
    for(int i = 0; i < 5; ++i){
        int t = sum - (dishes[i] + 9) /10 *10 +dishes[i];
        time = min(time,t);
    }
    cout << time << endl;

    // 29 20 7 35 120
    // sum = 220
    
  
    return 0; 
} 


Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int d;
  cin>>d;
  vecint c(26);
  for(auto&&e:c)cin>>e;
  vector s(d, vecint(26));
  for(auto&&l:s)for(auto&&e:l)cin>>e;
  vecint last(26);
  int score = 0;
  REP(i,d) {
    int t;
    cin>>t;
    --t;
    score += s[i][t];
    last[t] = i+1;
    REP(j,26) {
      score -= c[j] * (i+1 - last[j]);
    }
    cout<<score<<endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const int MOD = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MAX = 555;

LL W[MAX], V[MAX];
VI items[4];
LL S[4][MAX];

int main()
{
    int n,w;
    cin >> n >> w;
    FOR(i, 0, n)
        cin >> W[i] >> V[i];
    FOR(i, 0, n)items[W[i] - W[0]].push_back(-V[i]);
    FOR(i, 0, 4) {
        sort(ALL(items[i]));
        FOR(j, 0, SZ(items[i]))
            S[i][j+1] = S[i][j] + items[i][j];
    }
    LL ans = 0;
    FOR(a, 0, n)
    FOR(b, 0, n)
    FOR(c, 0, n) {
        if (a > items[3].size() || b > items[2].size() || c > items[1].size())continue;
        LL tw = (W[0] + 3) * a + (W[0] + 2) * b + (W[0] + 1) * c;
        if (tw > w)continue;
        LL tv = S[3][a] + S[2][b] + S[1][c] + S[0][min((w - tw)/W[0], (LL)items[0].size())];
        tv = -tv;
        ans = max(ans, tv);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int input = Integer.parseInt(stdin.next() + stdin.next());
		int rePow = (int)Math.pow((int)Math.sqrt(input), 2);
		System.out.println((input == rePow) ? "Yes" : "No");
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	string s,ANS="Yes";
	vector<char>vec1;
	vector<char>vec2;
	cin >> s;

	for (int i = 0; i < (s.size()-1)/2; i++) {
		vec1.push_back(s[i]);
	}
	for (int i = (s.size()-1) / 2; i < s.size(); i++) {
		vec2.push_back(s[i]);
	}
	if (s.size()%2!=0)vec2.erase(vec2.begin());

	for (int i = 0; i < vec1.size(); i++) {
		if (vec1[i] != vec2[vec1.size() - i-1])ANS = "No";
	}
	for (int i = 0; i < vec1.size(); i++) {
		if(vec1[i]!=vec2[i])ANS="No";
	}

	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "POSSIBLE"; }
  string_type do_falsename() const { return "IMPOSSIBLE"; }
};

void solve(ll N, ll M, vector<ll> a, vector<ll> b) {
  set<pair<int,int>> edges;
  REP(i,M) edges.emplace(a[i], b[i]);
  for (int i = 1; i < N; ++i) {
    if (edges.count(make_pair(1, i)) &&
        edges.count(make_pair(i, N))) {
      cout << true << endl;
      return;
    }
  }
  cout << false << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll M;
	ll N;
	scanf("%lld", &N);
	scanf("%lld", &M);
	vector<ll> a(M-1+1);
	vector<ll> b(M-1+1);
	for (int i = 0 ; i <= M-1 ; i++) {
	  scanf("%lld", &a[i]);
	  scanf("%lld", &b[i]);
	}
	solve(N, M, a, b);
	return 0;
}


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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>(x);
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

#define N 1005

int n, m;
ll x[N], y[N], z[N], memo[N][N];

ll solve(int i, int r, bool a, bool b, bool c) {
    if(!r) return 0;
    ll &ans = memo[i][r];
    if(ans != -1) return ans;
        ans = solve(i+1, r-1, a, b, c);
        ans += (a ? -x[i] : x[i]);
        ans += (b ? -y[i] : y[i]);
        ans += (c ? -z[i] : z[i]);
    if(n-i != r) {
        ll ans1 = solve(i+1, r, a, b, c);
        ans = max(ans, ans1);
    }
    return ans;
}

int main() {
	ios::sync_with_stdio(0);
    cin>>n>>m;
    F(n) cin>>x[i]>>y[i]>>z[i];
    mems(memo, -1);
    ll ans = 0;
    F(2) FF(2) rep(k, 0, 2) {mems(memo, -1); ans = max(ans, solve(0, m, i, j, k));}
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8320
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .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 ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($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, parser) => {
        $next
    };

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        mut s: [chars; n],
    }

    s.sort();
    s.dedup();
    println!("{}", if s.len() == 4 { "Four" } else { "Three" });
}


Measured memory_bytes: 4352
// #include <algorithm>
#include <stdio.h>
#include <vector> 
#include <math.h>
using namespace std;

vector<int> Parent;
vector<int> Rank;
vector<int> DiffW;

int findSet(int x);

int getWeight(int x){
  findSet(x);
  return DiffW[x];
}

int diffWeight(int x, int y){
  return getWeight(y) - getWeight(x);
}

void makeSet(int x){
  Parent.push_back(x);
  Rank.push_back(0);
  DiffW.push_back(0);
}
int findSet(int x){
  if( x != Parent[x] ){
    int r = findSet(Parent[x]);
    DiffW[x] += DiffW[Parent[x]];
    Parent[x] = r;
  }
  return Parent[x];
}
void link(int x, int y, int w){
  if( Rank[x] > Rank[y] ){
    Parent[y] = x;
    DiffW[y] = w;
  }else{
    Parent[x] = y;
    DiffW[x] = -w;
    if( Rank[x] == Rank[y] ){
      Rank[y] = Rank[y] + 1;
    }
  }
}

void unite(int x, int y, int w){
  w += getWeight(x); w-= getWeight(y);  
  link(findSet(x), findSet(y), w);
}

int same(int x, int y){
  if(findSet(x)==findSet(y)){
    return 1;
  }
  return 0;
}

int main(){
  int n, q;
  scanf("%d %d" ,&n ,&q);
  for( int i = 0 ; i < n ; i++ ){
    makeSet(i);
  }
  for( int i = 0 ; i < q ; i++ ){
    int com, x, y, z;
    scanf("%d" ,&com);
    if(com == 0){ // 0(relate) x y z
      scanf("%d %d %d" ,&x ,&y ,&z);
      unite(x, y, z);
    }else{ // 1(diff) x y
      scanf("%d %d" ,&x ,&y);
      if(same(x,y)){
        int di = diffWeight(x, y);
        printf("%d\n" ,di );
      }else{
        printf("?\n");
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x,coins = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0;i <= a;i++){
        for(int j = 0;j <= b;j++){
            for(int k = 0;k <= c;k++){
                if(x == 500 * i + 100 * j + 50 * k){
                    coins++;
                }
            }
        }
    }
    cout << coins << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
death = 0
tmp = 0
for i,x in enumerate(b):
    if i == 0:
        death += min(a[i]+a[i+1],b[i])
        if (a[i]+a[i+1])<=b[i]:
            tmp = 0
        else:
            if a[i]>=b[i]:
                tmp = a[i+1]
            else:
                tmp = a[i]+a[i+1]-b[i]
    else:
        death += min(tmp+a[i+1],b[i])
        if (tmp+a[i+1])<=b[i]:
            tmp = 0
        else:
            if tmp>=b[i]:
                tmp = a[i+1]
            else:
                tmp = tmp+a[i+1]-b[i]
    
print(death)

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

int main(){
  string a,b;
  cin >>a >>b;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  if(a<b)
    cout <<"Yes" <<endl;
  else
    cout <<"No" <<endl;
}


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

struct Point{
  double x, y;
};

void koch(int n, struct Point a, struct Point b){
  if(n == 0) return;
  struct Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main(){
  struct Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll ZERO = 0;

int main() {
	string S;
	cin >> S;
	stack<int> st;
	int ret = 0;
	for (int i = 0; i < S.size(); ++i)
	{
		if(S.at(i) == 'S') {
			st.push(1);
		}
		else {
			if(!st.empty()) {
				st.pop();
				ret++;
			}
		}
	}
	cout << S.size() - 2 * ret << endl;
}

Measured memory_bytes: 900
#include <iostream>
using namespace std;
int countIsland(char** world, int N);
void destroyIsland(char** world, int i, int j, int N);

int main (int argc, char* argv[])
{
    const int N = 12;

    // char world[12][12];
	char** world = new char*[N];
    for (int i = 0; i < N; i++) {
        world[i] = new char[N];
    }

    
    char tmp;
    while(cin >> tmp){
        world[0][0] = tmp;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if(i == 0 & j == 0) continue;
                cin >> world[i][j];
                
            }
        }
        cout << countIsland(world, N) << endl;
    }
    
	return 0;
}

int countIsland(char** world, int N){
    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (world[i][j] == '1') {
                destroyIsland(world, i, j, N);
                count++;
            }
        }
    }
    return count;
}

void destroyIsland(char** world, int i, int j, int N){
    world[i][j] = '0';
    if(i > 0){
        if (world[i - 1][j] == '1') {
            destroyIsland(world, i - 1, j, N);
        }
    }
    
    if(j > 0){
        if (world[i][j - 1] == '1') {
            destroyIsland(world, i, j - 1, N);
        }
    }
    
    if(i < N - 1){
        if (world[i + 1][j] == '1') {
            destroyIsland(world, i + 1, j, N);
        }
    }
    
    if(j < N - 1){
        if (world[i][j + 1] == '1') {
            destroyIsland(world, i, j + 1, N);
        }
    }
    
}

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

int main(void){
    string s;
    cin>>s;
    vector<int> v(26);
    rep(i, s.size()) v[s[i]-'a'] = 1;
    if(s.size()!=26) {
        rep(i, 26) if(v[i]==0) {
            s.push_back(i+'a');
            cout<<s<<endl;
            return 0;
        }
    }
    else{
        reverse(s.begin(), s.end());
        char now=s[0];
        int idx = 0;
        for(int i=1;i<=s.size()-1;i++){
            if(s[i]>now) {
                idx++;
                now=s[i];
            }
            else break;
        }
        if(idx == 25) {
            cout<<-1<<endl;
            return 0;
        }
        char mini = 'z';
        rep(i, idx+1){
            if(s[i]>s[idx+1]) mini=min(mini, s[i]);
        }
        reverse(s.begin(), s.end());
        rep(i, s.size()-idx-2) cout<<s[i];
        cout<<mini<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<50;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N, M, R; cin >> N >> M >> R;
    //R is very tiny
    int r[R];
    rep(i, R) cin >> r[i], --r[i];
    int A[M], B[M], C[M];
    vector<vector<ll>>G(N, vector<ll>(N, LLINF));
    rep(i, M) {
        cin >> A[i] >> B[i] >> C[i];
        G[--A[i]][--B[i]] = C[i];
        G[B[i]][A[i]] = C[i];
    }
    rep(i, N)
        G[i][i] = 0;
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    ll ans = LLINF;
    sort(r, r + R);
    do{
        ll sum = 0;
        int prev = r[0];
        for(int v : r) {
            sum += G[v][prev];
            prev = v;
        }
        ans = min(ans, sum);
    }while(next_permutation(r, r + R));

    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

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

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

void pV(vector<ll> A){
    cout << "[vector]";
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    sort(ALL(A));

    int L = A.size();
    
    p(A[L-1] - A[0]);
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static long F(long N, long M)
    {
        if (N > M)
            return F(M, N);
        if (N == 1 && M == 1)
            return 1;
        if (N == 1)
            return M - 2;
        else if (N == 2)
            return 0;
        else
            return (N - 2) * (M - 2);
    }
    public static void Main()
    {
        var s = Console.ReadLine().Split(' ');
        long N = long.Parse(s[0]);
        long M = long.Parse(s[1]);

        Console.WriteLine(F(N, M));
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
 
struct puntos
{
	int a, b, c;
};

ll solve(vector <puntos> &v, int n)
{
	ll dp[n+4][4];
	dp[0][0]=v[0].a;
	dp[0][1]=v[0].b;
	dp[0][2]=v[0].c;
	forr(i,1,n)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+v[i].a;
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+v[i].b;
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+v[i].c;
	}
	return max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}
 
int main()
{ 
	FIN;
	
	#ifdef input
		freopen("test1.txt", "r", stdin);
	#endif
	
	int n;
	cin >> n;
	vector <puntos> v(n);
	forn(i,n) cin >> v[i].a >> v[i].b >> v[i].c;
	cout << solve(v,n) << endl;
	return 0;
}


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

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

  if (A >= 10 || B >= 10)
    cout << -1 << endl;
  else
    cout << A * B << endl;
  return 0;
}

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

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

  int ans = 1e9;//初期値で大きい数を設定する
  rep(si,s.size()) { //開始地点を全て調査する(全探索)
    if (si+t.size() > s.size()) break;//文字列全体よりも小さいものが対象
    int cnt = 0;
    rep(i,t.size()) {
      if (s[si+i] != t[i]) cnt++;//文字を変更する場合カウントする
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    string s;
    cin>>s;
    int n=s.size();
    int m=n/2;
    int flg=1;
    for(int i=0;i<m;i++){
        if(s[i]!=s[n-i-1]){flg=0;}
    }
    int l=m/2;
    for(int i=0;i<l;i++){
        if(s[i]!=s[m-1-i]){flg=0;}
        if(s[m+1+i]!=s[n-1-i]){flg=0;}
    }
    if(flg==1){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}

    return 0;
}

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

const long long int INF = 1e18;


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

    vector<long long int> s(A + 2), t(B + 2), x(Q);
    s[0] = - INF; s[A + 1] = + INF;
    t[0] = - INF; t[B + 1] = + INF;
    
    for (int i = 1; i <= A; i++) {
        cin >> s[i];
    }
    for (int i = 1; i <= B; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> x[i];
    }

    for (int i = 0; i < Q; i++) {
        decltype(s)::iterator sw  = lower_bound(s.begin(), s.end(), x[i]) - 1;
        decltype(t)::iterator tw  = lower_bound(t.begin(), t.end(), x[i]) - 1;
        long long int min_distance = INF;
        for (auto j = sw; j <= sw + 1; j++){
            for (auto k = tw; k <= tw + 1; k++){
                long long int d1 = abs(x[i] - *j) + abs(*j - *k);
                long long int d2 = abs(x[i] - *k) + abs(*k - *j);
                min_distance = min({min_distance, d1, d2});
            }
        }
        cout << min_distance << endl;
    }    
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll dp[3030][3030][4];
int item[3030][3030];

int main() {
	
	int r, c, k;
	cin >> r >> c >> k;
	rep(i, k) {
		int y, x, v;
		cin >> y >> x >> v;
		y--;x--;
		item[y][x] = v;
	}

	rep(i, r)rep(j, c) {

		rep(l, 4) {
			if (j > 0)dp[i][j][l] = max(dp[i][j][l], dp[i][j - 1][l]);
			if (i > 0)dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][l]);
		}

		rep(l, 3) {
			int ll = 2 - l;
			dp[i][j][ll +1] = max(dp[i][j][ll + 1], dp[i][j][ll] + item[i][j]);
		}
	}

	ll ans = 0;
	rep(i, 4)ans = max(ans, dp[r - 1][c - 1][i]);
	cout << ans << endl;

}

Measured memory_bytes: 323068
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }
    val q = readLine()!!.split(" ").map { it.toInt() }

    val plist = mutableListOf<Int>()
    val qlist = mutableListOf<Int>()
    
    for(i in 1..n) {
        plist.add(i)
        qlist.add(i)
    }
    

    val prank = mutableListOf<Int>()
    val qrank = mutableListOf<Int>()
    
    for (i in 0 until n) {
        val pi = plist.indexOf(p[i])
        val qi = qlist.indexOf(q[i])
        prank.add(pi)
        qrank.add(qi)
        plist.removeAt(pi)
        qlist.removeAt(qi)
    }
    
    var k = 1
    var result = 0
    for (i in 2..n) {
        val index = n - i
        result += (prank[index] - qrank[index])*k
        k *= i
    }
    if (result < 0) {
        result *= -1
    }
    print(result)
}

Measured memory_bytes: 37896
#include <stdio.h>

int main(void)
{
  int a[10],i = 0,k,j = 0;
  for(i = 0;i < 5;i++) {
    scanf("%d",&a[i]);
  }
  scanf("%d",&k);

  i = 0;
  for(i = 0;i < 4;i++) {
    j = 0;
    for(j = i + 1;j <5;j++) {
      if(a[j] - a[i] > k) {
        printf(":(\n");
        return 0;
      }
    }
  }
  printf("Yay!\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, E, T, r;
int a[maxn];
ll Min1, Min2 = 1e18, f[maxn];
int main()
{
	deque<ll> Q; 
	scanf("%d%d%d", &n, &E, &T);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	Q.push_back(0);
	for(int i = 1; i <= n; ++i)
	{
		while((a[i] - a[r + 1]) * 2 >= T)
		{
			Min2 = min(Min2, f[r] - 2 * a[r + 1]);
			while(Q.front() <= r) Q.pop_front();
			++r;
		}
		f[i] = min(Min1 + 1ll * i * T, Min2 + 2 * a[i]);
		if(!Q.empty()) f[i] = min(f[i], f[Q.front()] + T);
		Min1 = min(Min1, f[i] - 1ll * i * T);
		while(!Q.empty() && f[i] <= f[Q.back()]) Q.pop_back();
		Q.push_back(i);
	}
	printf("%lld\n", f[n] + E);
	return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    ll n, x, m;
    cin >> n >> x >> m;
    pair<ll, ll> dp[m + 1][41];
    for (int i = 0; i <= m; i++){
        for (int j = 0; j <= 40; j++){
            dp[i][j] = {0, 0};
        }
    }
    fill(dp[0], dp[m + 1], pair<ll, ll>(0, 0));
    for (ll i = 0; i <= m; i++) {
        dp[i][0].first = (i * i) % m;
        dp[i][0].second = (i * i) % m;
    }
    for (ll i = 0; i < 40; i++) {
        for (ll j = 0; j <= m; j++) {
            dp[j][i + 1].first = dp[dp[j][i].first][i].first;
            dp[j][i + 1].second =
                dp[j][i].second + dp[dp[j][i].first][i].second;
        }
    }
    ll cur = x, ans = x;
    for (ll i = 39; i >= 0; i--) {
        if (n >= (1LL << i)) {
            ans += dp[cur][i].second;
            cur = dp[cur][i].first;
            n -= (1LL << i);
        }
    }
    cout << ans - cur << endl;
    return 0;
}

Measured memory_bytes: 67668
#include <cstdio>
#include<iostream>
 
using namespace std;
 
int main(void){
  
  int X,Y;
  
  scanf("%i%i", &X, &Y);
  
  if((Y-2*X)>=0){
    if(Y%2==0){
      if((X-(Y-2*X)/2)>=0){
      cout <<"Yes" <<endl;
    }else{
      cout <<"No" <<endl;
    }}else{
    cout <<"No" <<endl;
  }}else{
    cout <<"No" <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3180
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct rist
{
  int key;
  struct rist *next,*prev;
}Node;

Node *nil;
Node* listSearch(int key)
{
  Node *cur = nil->next;
  while(cur !=nil && cur->key != key)
  {
    cur = cur->next;
  }
  return cur;
}
void  init()
{
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}
void printList()
{
  Node *cur=nil->next;
  int isf = 0;
  while(1)
  {
    if(cur==nil)break;
    if(isf++!=0)printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}
void deleteNode(Node *t)
{
  if(t==nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
void deleteFirst()
{
  deleteNode(nil->next);
}
void deleteLast()
{
  deleteNode(nil->prev);
}
void deleteKey(int key)
{
  deleteNode(listSearch(key));
}
void insert(int key)
{
  Node *x=(Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}
int main()
{
  int key,n,i;
  int size = 0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++)
  {
    scanf("%s%d",com,&key);
    if(com[0]=='i')
    {
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d')
    {
      if(strlen(com)>6)
      {
        if(com[6]=='F')deleteFirst();
        else if(com[6]=='L')deleteLast();
      }
      else
      {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}



Measured memory_bytes: 32948
/*
 *  Created on: 17 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)

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

const ll mod = 1e15 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ss s; cin >> s;
    if (s.back() == '2' || s.back() == '4' || s.back() == '5' || s.back() == '7' || s.back() == '9')
    {
        cout << "hon";
        return 0;
    }
    if (s.back() == '0' || s.back() == '1' || s.back() == '6' || s.back() == '8')
    {
        cout << "pon";
        return 0;
    }
    cout << "bon";
}

Measured memory_bytes: 3608
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    ll k,n,i;
    cin>>k>>n;
    ll a[n+2];
    for(i=0;i<n;i++) cin>>a[i];
    ll d = k - a[n-1] + a[0];

    for(i=0;i<n-1;i++)
    {
    	d = max(abs(a[i] - a[i+1]),d);
    }
    cout<<k-d;
    
}

Measured memory_bytes: 1792