akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define v(T) vector<T>
#define vb vector<bool>
#define pi pair<int,int>
#define ppi pair<pair,int,int>, int>
#define vpi vector<pair<int,int>>
#define w(t) int t; cin>>t; while(t--)
#define FIO  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
void init() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int fact[10];
int32_t main() {
	FIO;
	init();
	int cnt[4];
	memset(cnt, 0, sizeof(cnt));
	w(t) {
		string s; cin >> s;
		if (s == "AC") cnt[0]++;
		else if (s == "WA")cnt[1]++;
		else if (s == "TLE") cnt[2]++;
		else cnt[3]++;
	}
	cout << "AC x " << cnt[0] << endl;
	cout << "WA x " << cnt[1] << endl;
	cout << "TLE x " << cnt[2] << endl;
	cout << "RE x " << cnt[3] << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<cstring>
#include<list>
using namespace std;

int main() {
	int n, key;
	char op[20];
	list<int> List;
	scanf("%d", &n);
	getchar();

	for (int i = 0; i < n; i++) {
		scanf("%s %d", op, &key);
		if (op[0] == 'i') {
			List.push_front(key);
		}
		else {
			if (strlen(op) > 6) {
				if (op[6] == 'F') {//????????´??????
					List.pop_front();
				}
				else {//???????°???????
					List.pop_back();
				}
			}
			else { //????????????
				for (list<int>::iterator it = List.begin(); it != List.end(); it++) {
					if (*it == key) {
						List.erase(it);
						break;
					}
				}
			}
		}
	}
	int flag = 0;
	for (list<int>::iterator it = List.begin(); it != List.end(); it++) {
		if (flag != 0)
			printf(" ");
		flag++;
		printf("%d", (*it));
	}
	printf("\n");
	return 0;
}

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

int N, h[100];

bool is_end(){
  bool end = true;
  for(int i = 0; i < N; i++){
    if(h[i] > 0){
      end = false;
    }
  }
  return end;
}

int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }

  int ans = 0;

  while(!is_end()){
    int l = 0;
    for(int i = 0; i < N; i++){
      if(h[i] > 0){
        l = i;
        break;
      }
    }
    int r = N - 1;
    for(int i = l; i < N; i++){
      if(h[i] == 0){
        r = i - 1;
        break;
      }
    }
    for(int i = l; i <= r; i++){
      h[i] -= 1;
    }
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
typedef long double ld;
typedef long long ll;
typedef long long i64;

const int M = 100100;

ll n, a[M];
ll d[M];

void read() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
}

void no() {
    cout << "NO\n";
    exit(0);
}

void yes() {
    cout << "YES\n";
    exit(0);
}

void kill() {
    if (n == 1)
        yes();

    for (int i = 0; i < n; ++i) {
        d[i] = a[(i + 1) % n] - a[i];
    }

    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += a[i];
    }

    ll tot = n * (n + 1) / 2;
    if (sum % tot != 0) {
        no();
    }

    ll k = sum / tot;
    for (int i = 0; i < n; ++i) {
        d[i] -= k;
    }

    ll c = 0;

    for (int i = 0; i < n; ++i) {
        ll x = -d[i];
        //cerr << x << endl;
        if (x < 0)
            no();
        if (x % n != 0)
            no();
        c += x / n;
    }

    if (c != k)
        no();

    yes();
}

int main() {
#ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
#endif
    ios_base::sync_with_stdio(false);

    read();
    kill();
}



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

int main() {
	int a, b;
	cin >> a >> b;
	int ans = -1;
	for (int x = 1; x < 10101; ++x) {
		if (x * 2 / 25 == a && x / 10 == b) {
			ans = x;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/**
 *  Hi, I'm Arpan.
 *  Hardwork beats talent if talents doesn't work hard, friend me if you want to. ✌.|•͡˘‿•͡˘|.✌
 *
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
#define inv(v)         \
    for (auto &it : v) \
        cin >> it;
#define MOD 1000000007
#define pb push_back

ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

void solve()
{
    int n,k;
    cin >> n >> k;
    vl a(n);
    inv(a);
    sort(a.begin(),a.end());
    ll ans = 0;
    for(int i=0;i<k;i++) ans+=a[i];
    cout << ans;
}

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


Measured memory_bytes: 3660
#include<bits/stdc++.h>
typedef long long ll; 
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vi vector <ll>
using namespace std ; 
	ll fact[500005];
  ll invfact[500005];
ll power(ll x,ll y,ll m)
{            //power(x,y)=x^y  %m;
	ll res=1%m;
	while(y)
	{
	    if(y&1)
	    res=(res*x)%m;
	    x=(x*x)%m;
	    y=(y>>1)%m;
	}
	return res;
}
ll mod_inverse(ll x,ll m)
{
	return power(x,m-2,m)%m;
}
ll countways(ll x,ll y)
{
    //cout<<x<<" "<<"y="<<y;
    if(x<y)
    {
       // cout<<"dd";
    return 0;
    }
    if(x==y)
    return 1;
    return ((fact[x]%mod*invfact[y]%mod)%mod*invfact[x-y]%mod)%mod;
}
//ll least_prime[10000005]; 

  
int main ()
{
    ios_base :: sync_with_stdio ( false );
    cin.tie( NULL );
    cout.tie( NULL );
ll t = 1 ;
//cin>>t;
while ( t--)  
{
    ll n,m;
    cin>>n>>m;
    if(m<n)
    {
        cout<<0<<"\n";
        continue;
    }
   fact[0]=1;
  for (int i = 1; i < 500005; i++){
        fact[i] = (fact[i-1]%mod*i%mod)%mod;
       
    }
    invfact[0]=1;
    invfact[500004]=mod_inverse(fact[500004],mod);
    for(ll i=500003;i>=1;i--)
    {
        invfact[i]=(invfact[i+1]%mod*(i+1)%mod)%mod;
    }
    ll ans1=1;
    ll ans;
    ans1=(ans1%mod*countways(m,n)%mod);
    ans1%=mod;
    ans1=(ans1%mod*fact[n]%mod)%mod;
   ans=ans1%mod;
   for(ll i=1;i<=n;i++)
   {
       if(i%2==1)
       {
           ans=(ans-(countways(n,i)%mod*countways(m-i,n-i)%mod*fact[n-i]%mod)%mod)%mod;
         ans=(ans+mod)%mod;
           ans%=mod;
       }
       else
       {
           ans=(ans+(countways(n,i)%mod*countways(m-i,n-i)%mod*fact[n-i]%mod)%mod)%mod;
           ans%=mod;
       }
   }
   cout<<(ans1%mod*ans%mod)%mod<<"\n";
    
}

 return 0;
}


Measured memory_bytes: 11468
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 3e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;

inline int add(int A, int B){
	if(A + B >= MOD) return A + B - MOD;
	return A + B;
}

inline int mul(int A, int B){
	return (ll)A * B % MOD;
}

vector < int > v[3];
int n, A[N], poc[N], krj[N];

int main(){
	scanf("%d", &n);
	for(int i = 0;i < 3 * n;i++){
		char c; scanf(" %c", &c);
		if(c == 'R') v[0].PB(i), A[i] = 0;
		if(c == 'G') v[1].PB(i), A[i] = 1;
		if(c == 'B') v[2].PB(i), A[i] = 2;
	}
	for(int i = 0;i < n;i++){
		int x = v[0][i], y = v[1][i], z = v[2][i];
		poc[min(x, min(y, z))] = 1;
		krj[max(x, max(y, z))] = 1;
	}
	int sol = 1, cur = 0;
	for(int i = 0;i < 3 * n;i++){
		if(poc[i])
			cur++;
		else if(!krj[i]){
			sol = mul(sol, cur); cur--;
		}
	}
	cur = 0;
	for(int i = 3 * n - 1;i >= 0;i--){
		if(krj[i])
			cur++;
		else if(!poc[i]){
			sol = mul(sol, cur); cur--;
		}
	}
	for(int i = n;i >= 1;i--) 
		sol = mul(sol, i);
	printf("%d\n", sol);
	return 0;
	
}

Measured memory_bytes: 5104
#include<iostream>
using namespace std;
int main(){
    int n,x;
    long long sum=0;
    int max=-1000000;
    int min=1000000;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        sum=sum+x;
        if(max<x){
            max=x;
        }
        if(min>x){
            min=x;
        }
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1e9+7;
pair<int,int> p[200010];

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

  ll ans = 1;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first;
    p[i].second = 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i + n].first;
  }
  sort(p,p+2*n);
  ll ct1 = 0, ct0 = 0;
  for (int i = 0; i < 2 * n; i++) {
    if (p[i].second == 0) {
      if (ct1 == 0) {
        ct0++;
      } else {
        ans *= ct1--;
        ans %= MOD;
      }
    } else {
      if (ct0 == 0) {
        ct1++;
      } else {
        ans *= ct0--;
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	deque<char> ans;
	stack<char> st;
	cin >> n >> s;
	for(int i = 0; i < n; ++i){
		if(s[i] == '('){ 
			st.push(s[i]);
			ans.push_back(s[i]);
		}
		else{
			ans.push_back(s[i]);
			if(st.size() == 0) ans.push_front('(');
			else st.pop();
		}
	}
	while(ans.size() > 0){
		cout << ans.front();
		ans.pop_front();
	}
	while(st.size() > 0){
		cout << ')';
		st.pop();
	}
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($i = 0; $i < $H; $i++){
  $str = trim(fgets(STDIN));
  for($j = 0; $j < $W; $j++){
    $map[$i][$j] = $str[$j];
    $p[$i][$j] = 0;
  }
  $map[$i][$W] = "#";
}
for($j = 0; $j < $W; $j++){
  $map[$H][$j] = "#";
}
for($i = 0; $i < $H; $i++){
  $h = 0;
  for($j = 0; $j < $W+1; $j++){
    if($map[$i][$j] == "#"){
      for($k = 0; $k < $h; $k++){
        $p[$i][$j - 1 - $k] = $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
for($i = 0; $i < $W; $i++){
  $h = 0;
  for($j = 0; $j < $H+1; $j++){
    if($map[$j][$i] == "#"){
      for($k = 0; $k < $h; $k++){
        $p[$j - 1 - $k][$i] += $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
$max = 0;
for($i = 0; $i < $H; $i++){
  $max = max($max, max($p[$i]));
}
echo $max - 1;

Measured memory_bytes: 401912
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
   if((a==1 && b==2) || (a==2 && b==1)){
    cout<<"3"<<endl;
   }
   else if((a==3 && b==2) || (a==2 && b==3)){

     cout<<"1"<<endl;
   }

     else if((a==1 && b==3) || (a==3 && b==1)){
     cout<<"2"<<endl;
   }

  return 0;
}


Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTakAndCards solver = new CTakAndCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTakAndCards {
        static int n;
        static int k;
        static int[] arr;
        static Long[][][] memo;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            n = sc.nextInt();
            k = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            memo = new Long[n][n + 1][n * 50];
            pw.print(dp(0, 0, 0));
        }

        private long dp(int idx, int sum, int taken) {
            if (idx == n) {
                if (taken == 0)
                    return 0;
                if ((1d * sum) / (1d * taken) == k)
                    return 1;
                return 0;
            }
            if (memo[idx][taken][sum] != null)
                return memo[idx][taken][sum];
            long take = dp(idx + 1, sum + arr[idx], taken + 1);
            long leave = dp(idx + 1, sum, taken);
            return memo[idx][taken][sum] = take + leave;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

    }
}



Measured memory_bytes: 55292
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i)
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
    ~debug() { cerr << endl; }
eni(!=) { cerr << boolalpha << i; ris; }
eni(==) { ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << &", " [ 2 * (it == d.b)] << *it;
  ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
};
#define imie(...) "" << #__VA_ARGS__ " = " << (__VA_ARGS__) << ""
#define arr array
const int INF = 1e9 + 5;
const int N = 1e5 + 5;

//dp[curr_index][value_till_curr_idx] => min weight

int main() {
	int n,W;
	cin >> n >> W;
	vector<int> w(n),v(n);
	for(int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	
	vector<vector<long long>> dp(105, vector<long long>(N,INF));
	
	for(int index = 0; index < n; index++) {
		for(int value = 0; value <= 100000; value++) {
			if(index == 0) {
				if(value == 0) {
					dp[index][value] = 0;
				}else {
					dp[index][v[index]] = w[index];
				}
			}else {
				//discard the current item
				dp[index][value] = dp[index-1][value];
				//pick the current item
				if(v[index] <= value) {
					dp[index][value] = min(dp[index][value],w[index] + dp[index-1][value - v[index]]);
				}
			}
		}
	}
	
	long long ans = 0;
	for(int value = 100000; value >= 0; value--) {
		if(dp[n-1][value] <= W) {
			ans = value;
			break;
		}
	}
	
	cout << ans << "\n";


    return 0;
}




Measured memory_bytes: 86396
#include <bits/stdc++.h>
using namespace std;
// ==================================================
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)
#define din(t, ...) t __VA_ARGS__;_din(__VA_ARGS__)
#define v(t,n) vector<t> n
void _din() {}
void dout() { cout << endl; }
template <typename T, typename ... Args> inline void _din(T& head, Args& ... rest) { cin >> head; _din(rest...); }
template <typename T, typename ... Args> inline void dout(T head, Args ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
template <typename T>inline void qsortv(vector<T>& v) { qsort(v.data(), v.size(), sizeof(T), [](const void*a, const void*b)->int {if ((*(T*)a) < (*(T*)b))return -1; if ((*(T*)a) == (*(T*)b))return 0; return 1; }); }
template <typename T, typename F>inline void qsortv(vector<T>& v, F func) { qsort(v.data(), v.size(), sizeof(T), func); }
template <typename T>inline void sortv(vector<T>& v) { sort(v.begin(), v.end()); }
// ==================================================

int main()
{
	din(int, k);
	int odd = k / 2;
	dout((k / 2) * ((k + 1) / 2));
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key)
    {
      if(k < u->key) u = u->left;
      else u = u->right;
    }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right); // case 1
  Node y = x->parent;
  while(y != NIL && x == y->right)
    {
      x = y;
      y = y->parent;
    }
  return y; // case 2
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;//子が0 or 1の時
  else y = treeSuccessor(z);//子が2の時、消えるのは次節点

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;//yが根の時
  else if(y == y->parent->left) y->parent->left = x;//yが左子の時
  else y->parent->right = x;//yが右子の時

  if(y != z) z->key = y->key;//子が2の時、yをコピー
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y = x;
      if(z->key < x->key)x = x->left;
      else x = x->right;
    }
  z->parent = y;
  if(y == NIL)root = z;
  else if(z->key < y->key)y->left = z;
  else y->right = z;
}

void inorder(Node u){
  int i=0;
  if(u != NIL)
    {
      inorder(u->left);
      printf(" %d", u->key);
      inorder(u->right);
    }
}

void preorder(Node u){
  int i=0;
  if(u != NIL)
    {
      printf(" %d", u->key);
      preorder(u->left);
      preorder(u->right);
    }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20456
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

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

  vector<int> vec;
  for(int i = 1; i <= sqrt(sum); i++){
    if(sum % i == 0){
      vec.push_back(i);
      vec.push_back(sum / i);
    }
  }

  int ans = 0;
  for(int p : vec){
    auto v = a;
    for(int i = 0; i < n; i++){
      v[i] = a[i] % p;
    }
    sort(v.begin(),v.end());
    vector<int> left(n+1, v[0]), right(n+1, 0);
    for(int i = 1; i < n; i++){
      left[i] = left[i-1] + v[i];
    }
    for(int i = n-1; i >= 0; i--){
      right[i] = right[i+1] + p - v[i];
    }
    for(int i = 1; i <= n; i++){
      if(left[i-1] == right[i] && max(left[i-1], right[i]) <= k){
        ans = max(ans, p);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())

initial = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(n):
    s = input()
    if s[0] in initial:
        initial[s[0]] += 1

values = [v for k, v in initial.items()]
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += values[i] * values[j] * values[k]

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    char a[n][n], b[m][m];
    rep(i, 0, n){
        char s[n+1];
        scanf("%s", s);
        rep(j, 0, n){
            a[i][j] = s[j];
        }
    }
    rep(i, 0, m){
        char s[m+1];
        scanf("%s", s);
        rep(j, 0, m){
            b[i][j] = s[j];
        }
    }
    int q = n-m+1;
    int ans = 0;
    rep(i, 0, q){
        rep(j, 0, q){
            int f = 1;
            rep(k, i, i+m){
                rep(l, j, j+m){
                    if(a[k][l] != b[k-i][l-j]){
                        f = 0;
                    }
                }
            }
            if(f){
                ans = 1;
            }
        }
    }
    printf(ans?"Yes":"No");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    string s;
    cin >> s;
    int n = s.length();
    vstr ls = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 4) reverse(all(ls[i]));
    string tmp = "";
    int l = 0;
    rrep(i, n) {
        tmp += s[i];
        l++;
        if (l > 7) {
            puts("NO");
            return 0;
        }
        rep(j, 4) {
            if (tmp == ls[j]) {
                tmp = "";
                l = 0;
            }
        }
    }
    yn(l==0);
    return 0;
}

Measured memory_bytes: 512
n = gets.chomp!.to_i
w_n = gets.chomp!.split(" ").map!(&:to_i)

diff_min = 99999999999
1.upto(n-1) do |t|
  s1 = w_n[0, t].inject(&:+)
  s2 = w_n[t, n-t].inject(&:+)

  if diff_min > (s1 - s2).abs
    diff_min = (s1 - s2).abs
  end
end

puts diff_min



Measured memory_bytes: 1788
# https://atcoder.jp/contests/dp/tasks/dp_g
import sys
sys.setrecursionlimit(10**7)


class DAG:
    def __init__(self, n):
        # n: num of vertices
        self.n = n
        self.adj = [[] for _ in range(n)]

    def addEdge(self, parent, child):
        self.adj[parent].append(child)

    def dfs(self, node):
        ans = 0
        for child in self.adj[node]:
            ans = max(ans, 1 + self.dfs(child))
        return ans

    def dfsWithMemo(self, node, memo, visited):
        if(visited[node]):
            return memo[node]
        visited[node] = True
        for child in self.adj[node]:
            memo[node] = max(
                memo[node], 1 + self.dfsWithMemo(child, memo, visited))
        return memo[node]

    def dfsWithDp(self, node, dp, visited):
        if(visited[node]):
            return dp[node]
        visited[node] = True
        for child in self.adj[node]:
            if not visited[child]:
                self.dfsWithDp(child, dp, visited)
            dp[node] = max(dp[node], 1 + self.dfsWithDp(child, dp, visited))
        return dp[node]

    # o(n^2) solution
    def findLongestPathNaive(self):
        ans = 0
        for i in range(self.n):
            ans = max(ans, self.dfs(i))
        return ans

    # o(n) solution
    def findLongestPathWithMemo(self):
        visited = [False] * self.n
        memo = [0] * self.n
        ans = 0
        for i in range(self.n):
            ans = max(ans, self.dfsWithMemo(i, memo, visited))
        return ans

    # O(n) solution
    def findLongestPathWithDp(self):
        visited = [False] * self.n
        dp = [0] * self.n  # dp[i] := longest path starting from vertex i
        ans = 0
        for i in range(self.n):
            ans = max(ans, self.dfsWithDp(i, dp, visited))
        return ans


def main():
    N, M = map(int, input().split())
    dag = DAG(N)
    for _ in range(M):
        parent, child = map(lambda i: int(i) - 1, input().split())
        dag.addEdge(parent, child)
    # print(dag.findLongestPathNaive())
    #  print(dag.findLongestPathWithMemo())
    print(dag.findLongestPathWithDp())


main()


Measured memory_bytes: 64668
n, k = map(int, input().split())
x_list = list(map(int, input().split()))
ans = float("inf")
for i in range(n - k + 1):
    start = i
    end = i + k - 1
    left = abs(x_list[start]) + abs(x_list[end] - x_list[start])
    right = abs(x_list[end]) + abs(x_list[end] - x_list[start])
    ans = min(ans, left, right)
print(ans)


Measured memory_bytes: 62576
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>
#define int ll

int a[] = {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};

void solve() {
	int k;
	cin >> k;
	cout << a[k - 1] << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    L, R = map(int, readline().split())

    if R - L > 3000:
        print(0)
    else:
        A = [i % 2019 for i in range(L, R + 1)]
        ans = INF
        for i in range(R - L):
            for j in range(i + 1, R - L + 1):
                ans = min(ans, A[i] * A[j] % 2019)
        print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);++(i))
using namespace std;
const int mod=998244353,maxn=16384;
int n,m,i,j,rev[maxn+5],a[maxn+5],b[maxn+5],dp[505][maxn+5],w[maxn+5],fac[maxn+5],inv[maxn+5],fi[maxn+5];
int c(int x,int y){
	if(x<y||x<0||y<0) return 0;
	return 1ll*fac[x]*fi[y]%mod*fi[x-y]%mod;
}
int pw(int x,int y){
	int z=1;
	while(y){
		if(y&1){
			z=1ll*z*x%mod;
		}
		x=1ll*x*x%mod;
		y/=2;
	}
	return z;
}
void init(){
	int i;
	inv[1]=w[0]=1;w[1]=pw(3,(mod-1)/maxn);fac[0]=fac[1]=fi[0]=fi[1]=1;
	for(i=2;i<=maxn;i++){
		w[i]=1ll*w[i-1]*w[1]%mod;
		fac[i]=1ll*fac[i-1]*i%mod;
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fi[i]=1ll*fi[i-1]*inv[i]%mod;
	}
}
int getrev(int x){
	int l=1;
	while(l<=x) l=l+l;
	for(i=0;i<l;i++){
		rev[i]=rev[i/2]/2+((i&1)*(l/2));
	}
	return l;
}
void ntt(int *a,int len,int op){
	int i,j,k;
	for(i=0;i<len;i++)if(rev[i]<i) swap(a[i],a[rev[i]]);
	for(i=1;i<len;i<<=1){
		int ys=maxn/i/2;
		for(j=0;j<len;j+=i+i){
			int t=(op==1?0:maxn);
			for(k=0;k<i;k++){
				int x=a[j+k],y=1ll*w[t]*a[j+k+i]%mod;
				a[j+k]=(x+y)%mod;
				a[j+k+i]=(x-y+mod)%mod;
				t+=op*ys;
			}
		}
	}
	if(op==-1){
		for(i=0;i<len;i++){
			a[i]=1ll*a[i]*inv[len]%mod;
		}
	}
}
int main(){
	init();
	scanf("%d%d",&n,&m);
	dp[0][0]=1;
	int len=getrev(n+n+2);
	rep(i,m){
		for(j=0;j<len;j++){
			a[j]=b[j]=0;
		}
		for(j=0;j<=n;j++){
			a[j]=1ll*dp[i-1][j]*fi[j]%mod;
			if(j==0) b[j]=0; else b[j]=fi[j+2];
		}
		ntt(a,len,1);ntt(b,len,1);
		for(j=0;j<len;j++){
			a[j]=1ll*a[j]*b[j]%mod;
		}
		ntt(a,len,-1);
		for(j=0;j<=n;j++){
			dp[i][j]=(1ll*a[j]*fac[j+2]%mod+1ll*dp[i-1][j]*(1+c(j+1,2))%mod)%mod;
		}
	}
	int ans=0;
	for(i=0;i<=n;i++){
		ans=(ans+1ll*dp[m][i]*c(n,i))%mod; 
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

bool hitachi(string s)
{
    if (s=="")
    {
        return true;
    }
    else if (s.size() <2)
    {
        return false;
    }
    else if (s.substr(0,2)=="hi")
    {
        return hitachi(s.substr(2));
    }
    else
    {
        return false;
    }
}

int main()
{
    string s;
    cin >> s;
    if (hitachi(s))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
ans=1
mod=10**9+7
from collections import defaultdict
d=defaultdict(int)
n=int(input())
for i in range(2,n+1):
    lst=factorization(i)
    for a,b in lst:
        d[a]+=b
for v in d.values():
    ans*=(v+1)
    ans%=mod
print(ans)

Measured memory_bytes: 74924
void 
solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

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

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, a[30], b[30], c[30];
	cin>>n;
	REP(i, n){
		cin>>a[i];
		--a[i];
	}
	REP(i, n){
		cin>>b[i];
	}
	REP(i, n-1){
		cin>>c[i];
	}
	int ans=0;
	REP(i, n){
		ans+=b[a[i]];
		if(i<n-1 && a[i]+1==a[i+1]){
			ans+=c[a[i]];
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;


namespace util {

// 文字列のSplit
std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

// 累乗
template < class S, class T >
S pow(S x, T n)
{
  ll ret = 1LL;
  while (n > 0) ret *= x, n--;
  return ret;
}

// 桁和
ll digitSum(ll x)
{
  std::string s = std::to_string(x); ll ret = 0LL;
  for (auto c : s) {ret += c - '0';}
  return ret;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

// DIGNUM
std::vector<ll> dignum(ll x) {
  if (x == 0) return {0};
  std::vector<ll> res;
  while (x) {
    res.push_back(x % 10);
    x /= 10;
  }
  std::reverse(res.begin(), res.end());
  return res;
}

// FAIL
void fail(){ print(-1); std::exit(0); }
//void fail(){ print("No"); std::exit(0); }

int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N;
  std::cin >> N;

  ll sum = 0LL;
  ll cnt = 0LL;
  for (ll i = 1; i <= N; i++) {
    sum += i;
    if (sum >= N) {
      cnt = i;
      break;
    }
  }

  for (ll i = 1; i <= cnt; i++) {
    if (i == sum - N) continue;
    print(i);
  }

  return 0;
}


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

int main(void) {
  int N, K, ans = 0;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ans += 2 * min(abs(x), abs(K - x));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;



void main() {
	int n = to!int(readln().strip());
	while(n != 0) {
		int t[];
		foreach(i; 0..n) {
			t ~= to!int(readln().strip());
		}
		t.sort();
		long sum;
		foreach(i; 0..n) {
			sum += t[i]*(n-1-i);
		}
		writeln(sum);

		n = to!int(readln().strip());
	}
}

Measured memory_bytes: 1520
#include <bits/stdc++.h>
using namespace std;
char stra[1000], strb[1000];
int lena, lenb;

int main()
{
//	freopen("a.in", "r", stdin);
//	freopen("out.txt", "w", stdout);
	while(true)
	{
		memset(stra, 0, sizeof(stra));
		memset(strb, 0, sizeof(strb));
		scanf("%s", stra);
		lena = strlen(stra);
		if(stra[0] == '.')
			break;
		scanf("%s", strb);
		lenb = strlen(strb);
		int posa = 0, posb = 0;
		int cnt = 0;
		bool ff = false;
		bool fa = false;
		int qa = 0, qb = 0;
		for(int i = 0; i < lena; i++)
			if(stra[i] == '\"')
				qa++;
		for(int i = 0; i < lenb; i++)
			if(strb[i] == '\"')
				qb++;
		if(qa != qb)
		{
			printf("DIFFERENT\n");
			ff = true;
			continue;
		}
		while(true)
		{
			if(posa >= lena && posb >= lenb)
			{
				break;
			}
			if(stra[posa] != strb[posb])
			{
				printf("DIFFERENT\n");
				ff = true;
				break;
			}
			if(stra[posa] == '\"')
			{
				bool fg = false;
				posa ++, posb ++;
				while(true)
				{
					if(stra[posa] == strb[posb] && strb[posb] == '\"')
					{
//						posa ++, posb ++;
						break;
					}
					if(stra[posa] == strb[posb])
					{
						posa ++, posb ++;
						continue;
					}
					else
					{
						cnt++;
						for(posa; posa < lena && stra[posa] != '\"'; posa++);
						for(posb; posb < lenb && strb[posb] != '\"'; posb++);
						fg = true;
						break;
					}
				}
				if(fg && cnt == 2)
				{
					printf("DIFFERENT\n");
					ff = true;
					break;
				}
			}
			posa ++, posb ++;
		}
		if(cnt == 1 && !ff)
			printf("CLOSE\n");
		else if(cnt == 0 && !ff && lena != lenb)
			printf("DIFFERENT\n");
		else if(!ff && cnt ==0 && lena == lenb)
			printf("IDENTICAL\n");
		else if(!ff)
			assert(false);
	}
	return 0;
}



Measured memory_bytes: 3160
def divisors(n):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i**2 != n:
                div.append(n//i)
    return div

n = int(input())

ans = 0

for i in range(n):
    if len(divisors(i+1))==8 and i%2==0:
        ans+=1
print(ans)

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

#define ll long long int

int main(){
  string s;
  cin >> s;
  int l = s.size();
  int fl=0;
  for(int i=0;i<l;i++){
    if((i+1)%2==0){
      if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
        continue;
      }
      else{
        fl=1;
        break;
      }
    }
    else if((i+1)%2==1){
      if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
        continue;
      }
      else{
        fl=1;
        break;
      }
    }
  }
  if(fl==1){
      std::cout << "No" << '\n';
  }
  else{
    std::cout << "Yes" << '\n';
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[100009];
int main()
{
    ll n,ans,rmd,l=0;
    scanf("%lld",&n);
    ll n1=n;
    if(n1==0)
    {
        printf("0\n");
    }
    else
    {
        while(n1!=0)
        {
            if(n1/-2>=0&&n1<0)
            {
                if(n1%(-2)!=0)
                {
                    ans=abs((-n1/-2)-1);
                }
                else
                {
                    ans=n1/-2;
                }
                rmd=n1-(-2*ans);
                a[l]=rmd;
                l++;
                n1=ans;
            }
            else
            {
                ans=(n1/-2);
                rmd=n1-(ans*-2);
                a[l]=abs(rmd);
                l++;
                n1=ans;
            }
        }
        for(int i=l-1; i>=0; i--)
        {
            printf("%lld",a[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}



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

  int n,m;
  cin >> n >> m;
  WeightedGraph< int > g(3*n);
  int u,v;
  rep(i,m){
    cin >> u >> v;
    u--;v--;
    g[u].emplace_back(n+v, 1);
    g[n+u].emplace_back(2*n+v, 1);
    g[2*n+u].emplace_back(v, 1);
    //    g[v].emplace_back(n+u, 1);
    //    g[n+v].emplace_back(2*n+u, 1);
    //    g[2*n+v].emplace_back(u, 1);
  }
  int s,t;
  cin >> s >> t;
  s--;t--;
  vector<int> vec=dijkstra(g,s);
  //  rep(i,3*n) cout << i << " " << vec[i] << endl;
  if(vec[t]==INT_MAX) cout << -1 << endl;
  else cout << vec[t]/3 << endl;
  

  
  return 0;
    

}


Measured memory_bytes: 18428
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl;
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#else
#define dbg(...)
#define dbgmap(...)
#define dbgset(...)
#define dbgarr(...)
#define dbgdp(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    ll n;
    cin>>n;
    Vec a(n);
    cin>>a;

    ll g = a[0];
    REP(i,1,n){
        g = gcd(a[i],g);
    }

    out(g);
    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
//    ll T;
//    cin>>T;
//    while(T--)
    solve();
}


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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

const int MOD = 998244353;

struct bit {
    vi a;
    int n;

    bit(int n) : a(n + 1), n(n) { }

    int query_util(int i) {
        int sum = 0;
        while (i > 0) {
            sum += a[i];
            i -= i & -i;
        }
        return sum;
    }

    pii query(int i) {
        pii res;
        res.first = query_util(i);
        res.second = query_util(n) - res.first;
        return res;
    }

    void update(int i, int x) {
        while (i <= n) {
            a[i] += x;
            i += (i & -i);
        }
    }
};

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

    int n;
    cin >> n;
    vector<pii> p(n);
    vi y(n), pow(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
        y[i] = p[i].second;
    }
    sort(p.begin(), p.end());
    sort(y.begin(), y.end());

    pow[0] = 1;
    for (int i = 1; i <= n; ++i) {
        pow[i] = 2 * pow[i - 1] % MOD;
    }

    bit l(n), r(n);
    for (int i = 1; i <= n; ++i) {
        r.update(i, 1);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int yind = lower_bound(y.begin(), y.end(), p[i].second) - y.begin() + 1;
        r.update(yind, -1);
        auto lp = l.query(yind), rp = r.query(yind);
        vi cnt = {lp.second, lp.first, rp.first, rp.second};
        ans += pow[n] - 1;
        for (int i = 0; i < 4; ++i) {
            ans -= pow[cnt[i]] - 1;
            ans -= (ll) (pow[cnt[i]] - 1) * (pow[cnt[(i + 1) % 4]] - 1) % MOD;
        }
        ans %= MOD;
        if (ans < 0) {
            ans += MOD;
        }
        l.update(yind, 1);
    }
    cout << ans << '\n';

    return 0;
}

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

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

	const int p = 100010;
	vector<int> num(p, 0);
	
	for (int i = 0; i < n; i++) {
		int a, l, u;
		
		cin >> a;
		l = a - 1;
		u = a + 1;	
	
		num[a + 1]++;
		num[l + 1]++;
		num[u + 1]++;
	}
	
	int ans = 0;
	for (int j = 0; j < p; j++) {
		ans = max(ans, num[j]);
	}

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

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>

#define MAX_H 30
#define MAX_W 30

using namespace std;

int h, w;
char maze[MAX_H][MAX_W];

int bfs(int sx, int sy) {
  int dx[] = {-1, 0, 0, 1};
  int dy[] = {0, -1, 1, 0};

  int dist[MAX_H][MAX_W];
  for (int i = 0; i < MAX_H; i++) {
    for (int j = 0; j < MAX_W; j++) {
      dist[i][j] = -1;
    }
  }

  queue<pair<int, int> > q;
  q.push( make_pair(sx, sy) );
  dist[sy][sx] = 0;

  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= w || ny < 0 || ny >= h) { continue; }
      if ( maze[ny][nx] == '#' ) { continue; }
      if ( dist[ny][nx] != -1  ) { continue; }
      dist[ny][nx] = dist[y][x] + 1;
      q.push( make_pair(nx, ny) );
    }
  }
  int ret = -1;
  for (int x = 0; x < w; x++) {
    for (int y = 0; y < h; y++) {
      ret = max(ret, dist[y][x]);
    }
  }
  return ret;
}

int main () {
  cin >> h >> w;
  for (int i = 0; i < h; i++) { cin >> maze[i]; }

  int ans = 0;

  for (int sx = 0; sx < w; sx++) {
    for (int sy = 0; sy < h; sy++) {
      if (maze[sy][sx] == '#') { continue; }
      ans = max(ans, bfs(sx, sy));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define ld long double
int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  ll n;cin>>n;
  ld ans = n;
  ans = ceil(ans/2);
  ans/=n;
  cout<<ans<<'\n';
  return 0 ; 
}

Measured memory_bytes: 256