akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}


#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...)
#endif


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, M, Q;
    cin >> N >> M >> Q;

    int m[N][N];
    REP(i, N) REP(j, N) m[i][j] = 0;
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        --l; --r;
        m[l][r] += 1;
    }

    REP(i, N) REP(j, N-1) {
        m[i][j+1] += m[i][j];
    }

    REP(i, N) REP(j, N) {
        m[N-i-2][j] += m[N-i-1][j];
    }

    REP(i, Q) {
        int p, q;
        cin >> p >> q;
        --p; --q;
        cout << m[p][q] << endl;
    }

}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
void solve()
{
    string s;
    cin>>s;
    set<char> ch;
    for(int i=0;i<26;i++)
    {
        ch.insert((char)(i+97));
    }
    for(int i=0;i<s.size();i++)
    {
        ch.erase(s[i]);
    }
    if(ch.size()==0)
    {
        int i=s.size()-2;
        while(i>-1&&s[i]>s[i+1])
        i--;
        if(i==-1)
        cout<<-1<<endl;
        else
        {
            int j=i+1;char ch1=s[j];
            while(j<s.size())
            {
                if(s[j]>s[i]&&s[j]<ch1)
                ch1=s[j];
                j++;
            }
            cout<<s.substr(0,i)<<ch1<<endl;
        }
    }
    else
    {
        cout<<s<<*(ch.begin())<<endl;
    }
}
int main()
{
    solve();
}

Measured memory_bytes: 256
package main
 
import (
        "errors"
        "fmt"    
)
 
func weatherPrediction(today string) string {
        switch {    
        case today == "Sunny":
                return "Cloudy"
        case today == "Cloudy":
                return "Rainy"
        case today == "Rainy":
                return "Sunny"
        default:
                panic(errors.New("No solution"))
        }
}
 
func main() {
        var weather string
        fmt.Scan(&weather)
        fmt.Println(weatherPrediction(weather))
}

Measured memory_bytes: 512
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a[100010], cnt[100010] = {}, ans = 0, ma = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > 100000)ans++;
		else {
			cnt[a[i]]++;
		}
	}
	for (int i = 1; i <= 100000; i++) {
		if (cnt[i] >= i)ans += cnt[i] - i;
		else ans += cnt[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace div2019a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int R = int.Parse(s[0]);
            int G = int.Parse(s[1]);
            int B = int.Parse(s[2]);
            int N = int.Parse(s[3]);

            int i, j, k;
            int aa, bb, cc;

            if(R >= G && G >= B)
            {
                aa = R; bb = G; cc = B;

            }else if(G >= R && R >= B)
            {
                aa = G;bb = R;cc = B;
            }else if (B >= R && R >= G)
            {
                aa = B;bb = R;cc = G;
            }else if (R >= B && B >= G)
            {
                aa = R;bb = B;cc = G;
            }else if (G >= B && B >= R)
            {
                aa = G;bb = B;cc = R;
            }else if (B >= G && G >= R)
            {
                aa = B;bb = G;cc = R;
            }
            else
            {

                aa = R; bb = G; cc = B;

            }

            int count = 0;

            for (i = 0; i < (N / aa )+1; i++)
            {
                for (j = 0; j < (N / bb)+1; j++)
                {
                    if ((i * aa + j * bb) > N)
                    {
                        break;
                    }
                    if ((N - (i * aa + j * bb)) % cc == 0)
                    {
                        count++;
                    }


                }
            }

            Console.WriteLine(count);
            Console.ReadLine();

        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#define LL long long
#define mod 1000000007
LL sum,mn,mx;
int main()
{
    LL n,k,i;
    scanf("%lld%lld",&n,&k);
    for(i=k; i<=n+1; i++)
    {
        mn=i*(i-1)/2;
        mx=(n+n-i+1)*i/2;//右边界
        sum=(sum+mx-mn+1)%mod;
    }
    printf("%lld\n",sum);
    return 0;
}


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

using namespace std;
int graph[125][125];
int d[125];
void bfs(int s, int n){
	queue<int> Q;
	int color[125];	
	for(int i=1;i<=n;i++){
		color[i] =0;
		d[i] = 2e9;
	}
	color[s] = 1;
	d[s] = 0;
	Q.push(s);
	while(Q.size()!=0){
		int u = Q.front();
		Q.pop();
		for(int v=1;v<=n;v++){
			if(graph[u][v] == 0) continue;
			if(color[v] == 0){
				color[v] = 1;
				d[v] = d[u] +1;
				Q.push(v);
			}
		}
		color[u] = 2;
	}
}

int main(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			graph[i][j] = 0;
		}
	}
	for(int i=1;i<=n;i++){
		int num;
		int k;
		int tmp;
		cin >> num >> k;
		if(k !=0){
			for(int j=0;j<k;j++){
				cin >> tmp;
				graph[num][tmp] = 1;
			}
		}
	}
	bfs(1, n);
	for(int i=1;i<=n;i++){
		cout << i << " "<<((d[i] == 2e9)? (-1) :d[i]) << endl;
	}
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 998244353;

ll dp[3005];

int main(){
  int N, S;
  cin >> N >> S;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;
  rep(i,N){
    dp[0] += 1;
    vector<ll> dp2(3005, 0);
    rep(j,S+1){
      dp2[j] += dp[j];
      dp2[j] %= MOD;
      if(j+v[i] <= S){
        dp2[j+v[i]] += dp[j];
        dp2[j+v[i]] %= MOD;
      }
    }
    rep(j,3005) dp[j] = dp2[j];

    ret += dp[S];
    ret %= MOD;
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.math.BigInteger;

 
public class Main implements Runnable {
  static Scanner in;
  // static FastReader in;
  static PrintWriter out;
  static int[][] dirs8 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
  static int[][] dirs = {{0, -1}, {1, 0}, {0, +1}, {-1, 0}};
 
  static int[][] E;
  // static List<int[]>[] adj;
  static List<Integer>[] adj;
  static int[] vis;
 
  static long INFL = (long) 1e15 + 7;
  static int INF = (int) 1e7 + 9;
 
  static int T, n, m, k, count;
  static boolean flag;
  static int[] a, b;
  static int[][] map;

  static int mod = 998244353;
 
  static void solve() throws Exception {
    int n = in.nextInt();
    int cur = 0;
    for (int i = 0; i < n; i++) {
      if (in.nextInt() == cur + 1) {cur++;}
    }
    if (cur > 0) {out.println(n - cur);}
    else {out.println(-1);}
  }


  public static void main(String[] args) throws Exception {
 
    in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    // in = new FastReader();
    out = new PrintWriter(System.out);
 
    // int T = in.nextInt();
    // for (int tt = 1; tt <= T; tt++) {
    //   // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    //   // t.start();
    //   // t.join();
    //   solve();
    // }
 
    // // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    // // t.start();
    // // t.join();
    solve();
 
    out.flush();
    out.close();
  }
 
  @Override
  public void run() {
    try {
      solve();
    } catch (Exception e) {
      e.printStackTrace(); 
    }
  }
 
  static class FastReader {
    public BufferedReader br; 
    StringTokenizer st; 
    public FastReader() {br = new BufferedReader(new InputStreamReader(System.in));} 
    String next() { 
      while (st == null || !st.hasMoreElements()) { 
          try {st = new StringTokenizer(br.readLine());} 
          catch (IOException e) {e.printStackTrace();} 
      } 
      return st.nextToken(); 
    } 
    int nextInt() {return Integer.parseInt(next());} 
    long nextLong() {return Long.parseLong(next());} 
    double nextDouble() {return Double.parseDouble(next());} 
    String nextLine() {
      String str = ""; 
        try {str = br.readLine();} 
        catch (IOException e) {e.printStackTrace();} 
        return str; 
    }
  }

  static void as(boolean result) throws Exception {
    if (!result) {
      throw new Exception();
    }
  }

  static int modInverse(int a, int m) { 
    int m0 = m; 
    int y = 0, x = 1; 
    if (m == 1) {return 0;} 
    while (a > 1) { 
      // q is quotient 
      int q = a / m; 
      int t = m; 
      // m is remainder now, process 
      // same as Euclid's algo 
      m = a % m; 
      a = t; 
      t = y; 
      // Update x and y 
      y = x - q * y; 
      x = t; 
    } 
    // Make x positive 
    if (x < 0) 
      x += m0; 
    return x; 
  } 
} 

Measured memory_bytes: 66960
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int K = Integer.parseInt(scan.next());
		List<Long> numList = new ArrayList<Long>();
		long sum = 0;
		for(int i = 0; i < N; i++) {
			numList.add(Long.parseLong(scan.next()));
		}
		Collections.sort(numList, Collections.reverseOrder());
		if(N <= K) {
			System.out.println(sum);
			return;
		}
		for(int i = K; i < N; i++) {
			sum += numList.get(i);
		}
		System.out.println(sum);
	}
}

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

int main() {
  int num;
  int cnt = 0;
  string str;
  
  cin >> num >> str;
  
  for(int i = 0; i < num-2; i++){
    if(str.substr(i,3) == "ABC") cnt++;
  }
  
  cout << cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n; cin >> n;
    if(n%2==0) cout <<0.5000000000<<endl;
    else cout<<(double)((n/2)+1)/n<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int a[5], n=5;

void solve()
{
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) {
        if (a[i]==0) {
            nout(i+1);return;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

// 見当つかなかったので解説見たりググったりした

func main() {
	N := nextInt()
	An := make([]int, N)
	Bn := make([]int, N)
	var sumA, sumB, sumBAdiff, ans int
	keys := make([]int, 0)
	ABdiff := make([]int, 0)
	for i := range An {
		An[i] = nextInt()
		sumA += An[i]
	}
	for i := range Bn {
		Bn[i] = nextInt()
		sumB += Bn[i]
	}
	if sumA < sumB {
		fmt.Println(-1)
		return
	}
	for i := 0; i < N; i++ {
		if An[i] >= Bn[i] {
			ABdiff = append(ABdiff, An[i]-Bn[i])
		} else {
			sumBAdiff += Bn[i] - An[i]
			keys = append(keys, i)
			ans++
		}
	}
	if ans == 0 {
		fmt.Println(0)
		return
	}
	sort.Sort(sort.Reverse(sort.IntSlice(ABdiff)))
	minus := ans
	for i, d := range ABdiff {
		sumBAdiff -= d
		if sumBAdiff <= 0 {
			ans += i + 1
			break
		}
	}
	// この部分がないと本当はダメだと思うが、これがなくても通ってしまう
	// Bi > Ai となっている項について、
	// Bi > Aiとなっている項同士で入れ替えてマイナスになっているところを消せる数をカウント
	// 消しきれない項の数がプラスになっている項の数よりも多い場合はNGとしている。
	Amin := make([]int, len(keys))
	Bmin := make([]int, len(keys))
	for i, k := range keys {
		Amin[i] = An[k]
		Bmin[i] = Bn[k]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(Amin)))
	sort.Sort(sort.Reverse(sort.IntSlice(Bmin)))
	var Amindex int
	for i := 0; i < len(Bmin); i++ {
		if Bmin[i] <= Amin[Amindex] {
			minus--
			Amindex++
		}
	}
	if sumBAdiff > 0 || minus > len(ABdiff) {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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


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

typedef long long ll;
#define pii pair<int ,int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;
string s;

int main()
{
    _FastIO;
    cin >> s;
    if(s[3] == s[2] && s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

#define REP(i, n) for(ll i = 0; i < n; ++i)
#define REP3(i, B, E) for(ll i = B; i <= E; ++i)

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

template<class T> T& chmin(T &obj, T val){ return obj = min(obj, val); }
template<class T> T& chmax(T &obj, T val){ return obj = max(obj, val); }

// 二分探索 : [low, high) の範囲で述語 pred がtrue を返す最大の値を返す
template<class Pred>
ll bsearch(ll low, ll high, Pred pred){
    while(low + 1 < high){
        const ll mid = low + (high - low) / 2;
        if(pred(mid)){ low = mid; }
        else{ high = mid; }
    }
    return low;
}


//! 最大公約数
ll gcd(ll a, ll b)
{
    // ユークリッドの互除法
    return b ? gcd(b, a % b) : a;
}

//! 最小公倍数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int main() {
    ll N, M;
    cin >> N >> M;
    auto a = read<ll>(N);
    
    auto lcm_v = a[0];
    for(auto v: a){ lcm_v = lcm(lcm_v, v); }
    bool is_all_odd = true;
    for(auto v : a){ if( (lcm_v / v) % 2 == 0 ){
        is_all_odd = false;
        break;
    }}
    if(!is_all_odd){ cout << 0 << endl; return 0; }
    
    cout << (2 * M / lcm_v + 1) / 2 << endl; 
    
}



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

#define ll long long

int main(){

	int N,M,C;
	cin >> N >> M >> C;
    int B[M];
  	for(int j = 0; j < M;j++){
        	cin >> B[j];
    }
  	int sum;
  	int cont = 0;
  	for(int i = 0; i < N;i++){
    	int A;
      	sum = 0;
    	for(int j = 0; j < M;j++){
        	cin >> A;
          	sum =sum+A*B[j];
        }
	
    	if(sum+C>0){
        	cont++;
        }
    
    }
  	cout << cont << endl;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		init(n);
		for (int i=0;i<n-1;i++) {
			int s = in.nextInt();
			int t = in.nextInt();
			int w = in.nextInt();
			// bidirectional
			adList[s].add(new P(t, w));
			adList[t].add(new P(s, w));
		}
		
		System.out.println(getFurthest().dist);
	}

	static List<P>[] adList;
	static long[] dist;
	static P getFurthest() { // return P have index and furthest distance
		dijkstra(0);
		long furthest = -1;
		int furthestIdx = -1;
		for (int i=0;i<dist.length;i++) {
			if (furthest < dist[i]) {
				furthest = dist[i];
				furthestIdx = i;
			}
		}
		Arrays.fill(dist, Long.MAX_VALUE);
		dijkstra(furthestIdx);
		furthest = -1;
		furthestIdx = -1;
		for (int i=0;i<dist.length;i++) {
			if (furthest < dist[i]) {
				furthest = dist[i];
				furthestIdx = i;
			}
		}
		return new P(furthestIdx, furthest);
	}
	static void dijkstra(int s) { // s is start
		dist[s] = 0L;
		PriorityQueue<P> q = new PriorityQueue<P>();
		q.add(new P(s, 0L));
		
		while (!q.isEmpty()) {
			P cur = q.poll();
			if (dist[cur.index] < cur.dist)
				continue;
			for (P next : adList[cur.index]) {
				if (dist[next.index] > dist[cur.index] + next.dist) {
					dist[next.index] = dist[cur.index] + next.dist;
					q.add(new P(next.index, dist[next.index]));
				}
			}
		}
	}
	@SuppressWarnings("unchecked")
	static void init(int n) {
		adList = new List[n];
		for (int i=0;i<n;i++) {
			adList[i] = new ArrayList<P>();
		}
		dist = new long[n];
		Arrays.fill(dist, Long.MAX_VALUE);
	}
	static class P implements Comparable<P> {
		int index; long dist;
		public P(int index, long dist) {this.index = index; this.dist = dist;}
		public int compareTo(P p) {return this.dist < p.dist ? -1 : this.dist == p.dist ? 0 : 1;}
		public String toString() {return index+","+dist;}
	}
	// in adList, P.dist is distance from adjacent point
	// in q, P.dist is shortest path distance from start point
}

Measured memory_bytes: 122840
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.List
import Data.Array.IO
import Control.Monad

type Memo = IOUArray Int Int

modN :: Int
modN = 10^9+7

main = do
  n <- readLn :: IO Int
  a <- getIntListBC
  check <- newArray (1, n) 0 :: IO Memo
  l <- numbering check a 1
  table <- newArray (0, n+1) 0 :: IO Memo
  makeTable table (n+1) (n+1)
  let k = [1..n+1]
      dup = n - l - 1
      cn = fact (n+1)
      cnl = fact dup
  ans <- mapM (solve table cn cnl n l) k
  putStr $ unlines . map show $ ans

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.words <$> BC.getLine

numbering :: Memo -> [Int] -> Int -> IO Int
numbering memo [] n = return 0
numbering memo (i:is) n = do
  c <- readArray memo i
  case c of
    0 -> do
      writeArray memo i n
      return =<< numbering memo is $ n + 1
    _ -> do
      return $ n - c - 1

--x^n (mod modN)
(|^) :: Int -> Int -> Int
(|^) x n
  | n == 0    = 1
  | even n    = (mod (x * x) modN) |^ (n `div` 2)
  | otherwise = (flip mod modN) . (*x) $ x |^ (n - 1)

--x! (mod modN)
fact :: Int -> Int
fact n
  | n == 0    = 1
  | otherwise = (flip mod modN) . (*n) $ fact (n-1)

makeTable :: Memo -> Int -> Int -> IO Memo
makeTable table n (-1) = return table
makeTable table n i
  | n == i = do
    writeArray table i $ (fact n) |^ (10^9+5)
    makeTable table i $ i-1
  | otherwise = do
    ie <- readArray table (i+1)
    writeArray table i $ flip mod modN $ ie * (i+1)
    makeTable table i $ i-1

comb :: Memo -> Int -> Int -> Int -> IO Int
comb memo cn n k
  |n >= k = do
    ik <- readArray memo k
    ink <- readArray memo $ n - k
    let tmp = flip mod modN $ cn * ik
        ans = flip mod modN $ tmp * ink
    return ans
  | otherwise = return 0

solve :: Memo -> Int -> Int -> Int -> Int -> Int -> IO Int
solve table cn cnl n l k = do
  x <- comb table cn (n+1) k
  y <- comb table cnl (n-l-1) (k-1)
  return $ flip mod modN $ modN + x - y


Measured memory_bytes: 42236
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

bool a[10];

bool check(int x)
{
    for(; x; x /= 10)
        if(a[x % 10])
            return false;

    return true;
}

int main(void)
{
    int n, k;
    int i;
    int d;

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

    for(i = n; ; i ++)
        if(check(i))
        {
            printf("%d\n", i);
            break;
        }

    return 0;
}

Measured memory_bytes: 256
ans = 0
def dfs(v, visiteNode, graph):
  visiteNode[v] = 1
  if all(visiteNode):
    global ans
    ans += 1
    return
  for node in graph[v]:
    if visiteNode[node]:
      continue
    else:
      dfs(node, visiteNode[:], graph)

N,M = map(int, input().split())
v = 0
visiteNode = [0] * N

graph = [[] for _ in range(N)]
for _ in range(M):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)
  
dfs(v, visiteNode, graph)
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
char s[50];
int n,cnt;
int main()
{
	scanf("%d\n",&n);
	n-=2;
	gets(s);
	for(int i=0;i<n;i++)
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			cnt++,i+=2;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] nm = reader.readLine().split(" ");
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);
        int maxl = 0;
        int minr = n;
        for (int i = 0; i < m; i++) {
            String[] lr = reader.readLine().split(" ");
            int l = Integer.parseInt(lr[0]);
            int r = Integer.parseInt(lr[1]);
            if (maxl < l) {
                maxl = l;
            }
            if (r < minr) {
                minr = r;
            }
            if (minr < maxl) {
                break;
            }
        }
        System.out.println(Integer.max(0, minr - maxl + 1));
    }
}


Measured memory_bytes: 43548
<?php

$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$q = (int)$input[1];

$cnt = [];
$visited = [];
for ($i=0; $i < $n; $i++) { 
	$cnt[$i+1] = 0;
	$visited[$i+1] = false;
}

$tree = [];
for ($i=0; $i < $n-1; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$a = (int)$input[0];
	$b = (int)$input[1];
	if (isset($tree[$a])) {
		$tree[$a][] = $b;
	}else{
		$tree[$a] = [$b];
	}
	if (isset($tree[$b])) {
		$tree[$b][] = $a;
	}else{
		$tree[$b] = [$a];
	}
}

for ($i=0; $i < $q; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$p = (int)$input[0];
	$x = (int)$input[1];
	$cnt[$p] += $x;
}

$visited[1] = true;
dfs(1);

echo implode(' ', $cnt);


function dfs($p){
	global $tree;
	global $cnt;
	global $visited;
	foreach ($tree[$p] as $child) {
		if (!$visited[$child]) {
			$cnt[$child] += $cnt[$p];
			$visited[$child] = true;
			dfs($child);
		}
	}
}

Measured memory_bytes: 170476
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  rep(i, N)
  {
    cin >> T[i];
  }

  rep(i, N)
  {
    cin >> A[i];
  }

  bool is_ok = true;
  vector<int> mountain_hight(N, -1);
  mountain_hight[0] = T[0];
  rep(i, N - 1)
  {
    if(T[i] < T[i + 1])
      mountain_hight[i + 1] = T[i + 1];
  }
  REVERSE(A);
  REVERSE(mountain_hight);
  
  rep(i, N)
  {
    if(mountain_hight[i] != -1 && mountain_hight[i] > A[i])
      is_ok = false;
  }

  if(mountain_hight[0] == -1)
    mountain_hight[0] = A[0];
  else if(mountain_hight[0] != A[0])
    is_ok = false;

  rep(i, N - 1)
  {
    if(A[i] < A[i + 1])
    {
      if(mountain_hight[i + 1] == -1)
        mountain_hight[i + 1] = A[i + 1];
      else if(mountain_hight[i + 1] != A[i +1]) 
        is_ok = false;
    }
  }

  if(!is_ok)
  {
    cout << 0 << endl;
    return 0;
  }

  REVERSE(A);
  REVERSE(mountain_hight);

  int mod = 1e9 + 7;
  long long ans = 1;
  rep(i, N)
  {
    if(mountain_hight[i] == -1)
    {
      ans *= min(T[i], A[i]);
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
mod=10**9+7
n=10**6
inv_t=[0]+[1]
for i in range(2,n):
  inv_t+=[inv_t[mod%i]*(mod-int(mod/i))%mod]

kai=[1,1]
rev_kai=[1,inv_t[1]]
for i in range(2,n):
  kai.append(kai[-1]*i%mod)
  rev_kai.append(rev_kai[-1]*inv_t[i]%mod)

def cmb(n,r):
  return kai[n]*rev_kai[r]*rev_kai[n-r]%mod

def prm(n,r):
  return kai[n]*rev_kai[n-r]%mod

N,M=map(int, input().split())
def f(x):
  e=cmb(N,x)*prm(M,x)*prm(M-x,N-x)*prm(M-x,N-x)
  e%=mod
  return e

ans=0
for i in range(N+1):
  g=f(i)*((-1)**i)
  ans+=g
print(ans%mod)

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

int main(){
  string s;
  cin >>s;
  int q;cin>>q;
  int t,f;
  char c;
  int tmp=0;
  for(int i=0;i<q;i++){
    cin >>t;
    if(t==1){
      tmp++;
    }
    else{
      cin >>f;
      cin >>c;
      if((f==1&&tmp%2==0)||f==2&&tmp%2==1){
        s=c+s;
      }
      else if((f==2&&tmp%2==0)||f==1&&tmp%2==1){
        s.push_back(c);
      }
    }
  }
  int size=s.size();
  if(tmp%2==0){
    for(int i=0;i<size;i++){
      cout<<s.at(i);
    }
    cout <<endl;
  }
  else{
    for(int i=size-1;i>=0;i--){
      cout <<s.at(i);
    }
    cout <<endl;
  }
}

Measured memory_bytes: 4584
/* ***********************************************
Author        :yang12138
Created Time  :2018/5/26 20:30:00
File Name     :C.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;

const int N=2005;
const int INF=1e9+10;
int a[N];
int n,k,q;

int solve(int x){
	vector<int>ans;
	for(int i=1;i<=n;i++){
		if(a[i]<x) continue;
		vector<int>tmp;
		while(i<=n && a[i]>=x) tmp.push_back(a[i]),i++;
		if((int)tmp.size()<k) continue;
		sort(tmp.begin(),tmp.end());
		for(int i=0;i<=(int)tmp.size()-k;i++) ans.push_back(tmp[i]);
	}
	if((int)ans.size()<q) return INF;
	sort(ans.begin(),ans.end());
	return ans[q-1]-x;
}

void solve(){
	scanf("%d%d%d",&n,&k,&q);

	for(int i=1;i<=n;i++) scanf("%d",a+i);

	int ans=INF;
	for(int i=1;i<=n;i++){
		ans=min(ans,solve(a[i]));
	}
	printf("%d\n",ans);
}


int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	solve();
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793


int main(){
  int N;
  cin >> N;
  int h[N];
  rep(i, N){
    cin >> h[i];
  }
  int dp[N];
  dp[0] = 0; dp[1] = abs(h[1]-h[0]);
  for(int i=2; i<N; i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[N-1] << endl;
 
}

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

#define BUFSIZE 256
#define N 10
int main(void)
{
	char buf[BUFSIZE];
	int L[N];
	int v1, v2, i;
	while (fgets(buf, BUFSIZE, stdin) != NULL) {
		char *p = strtok(buf, ",");
		double t, d;
		for (i = 0; i < N; ++i) {
			L[i] = atoi(p);
			if (i > 0) L[i] += L[i-1];
			p = strtok(NULL, ",");
		}
		v1 = atoi(p);
		v2 = atoi(strtok(NULL, ","));

		t = (double)L[N-1] / (v1 + v2);
		d = v1 * t;
		for (i = 0; i < N; ++i) {
			if (d <= L[i]) { printf("%d\n", i+1); break; }
		}
	}
	return 0;
}

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

int N,c;
int main() {
	int p;
	cin >>N;
	for (int i=1;i<=N;i++){
		cin>>p;
		c += (p!=i);
	}
	if(c<=2)cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll n,r;
	cin>>n>>r;
	int l=(10-n)*100;
	cout<<max(l,0)+r<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  a-=1;
  if(c==1||d==1){
    cout << 0 << endl;
    return 0;
  }
  long long int tmp_c=c, tmp_d=d;
  if(tmp_c<tmp_d){
    long long int tmp = tmp_c;
    tmp_c = tmp_d;
    tmp_d = tmp;
  }
  long long int r = tmp_c % tmp_d;
  while(r!=0){
    tmp_c = tmp_d;
    tmp_d = r;
    r = tmp_c % tmp_d;
  }
  long long int e = (b/c+b/d-b/((c/tmp_d)*d)) - (a/c+a/d-a/((c/tmp_d)*d));
  long long int ans = b-a-e;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
class UnionFind {
public:
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}

  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x != y) {
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
  int size(int x) {
    return -data[find(x)];
  }
};

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

  cin >> n >> m;

  UnionFind uf(n);

  int ans = 1;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a, b);

    ans = max(uf.size(a), ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3972
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  int a;
  cin >> a;
  cout << "ABC" << a << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Runtime.Remoting;


namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public ulong NextUlong()
        {
            return ulong.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    struct MyStruct
    {
        public long N;
        public int Cnt;
    }

    class Program
    {
        private int N;
        private int K;
        private int[] H;
        void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            K = sc.NextInt();
            H = sc.IntArray();
        }

        public void Solve()
        {
            Scan();
            var ans = new int[N];
            ans[0] = 0;
            for (int i = 1; i < N; i++)
            {
                int a = int.MaxValue;
                for (int j = 1; j <= K; j++)
                {
                    if (i - j >= 0)
                    {
                        a = Math.Min(a, ans[i - j] + Math.Abs(H[i] - H[i - j]));
                    }
                }

                ans[i] = a;
            }
            Console.WriteLine(ans[N - 1]);
        }



        static void Main() => new Program().Solve();
    }


}

Measured memory_bytes: 17248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll inf=1000000007;
const ll maxinput=100005;
const ll mod=998244353;
#define mp make_pair
ll n,w;
ll weightval[105][2]; //weightval[i][0] is weight of ith item,weightval[i][1] is value of ith item
ll dp[105][maxinput];
ll maxval(ll pos,ll weightremaining)
{
    if(pos==n)
        return(0);

    if(dp[pos][weightremaining]!=-1)
        return(dp[pos][weightremaining]);

    if(weightval[pos][0]<=weightremaining)
        return(dp[pos][weightremaining]=max(weightval[pos][1]+maxval(pos+1,weightremaining-weightval[pos][0]),maxval(pos+1,weightremaining)));
    else
        return(dp[pos][weightremaining]=maxval(pos+1,weightremaining));
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>w;
    for(ll i=0;i<n;i++)
        cin>>weightval[i][0]>>weightval[i][1];

    cout<<maxval(0,w);
}

Measured memory_bytes: 82432
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
using ll = long long;

int main(){
  ll n;
  cin >> n;
  ll ans = 1000-(n%1000);
  if(ans==1000) cout << 0 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
queue<int> que;
vector<int> neigh[100010];
vector<int>::iterator it;
map<pair<int,int>,int> Dis;
map<pair<int,int>,int>::iterator it2;
int n, m, i, j, k, t, l, q, x, y;
long long a, b, c, dis[100010];
int main(){
	cin>>n;
	for(i=1;i<=n-1;i++){
		cin>>a>>b>>c;
		neigh[a].push_back(b);
		neigh[b].push_back(a);
		Dis[make_pair(a,b)]=c;
		Dis[make_pair(b,a)]=c;
	}
	cin>>q>>k;
	que.push(k);
	dis[k]=0;
	for(i=1;i<=n;i++){
		t=que.front();
		que.pop();
		for(it=neigh[t].begin();it!=neigh[t].end();it++){
			if(dis[*it]==0){
			que.push(*it);
			dis[*it]=dis[t]+Dis[make_pair(t,*it)];
			}
		}
	}
	for(i=1;i<=q;i++){
		cin>>x>>y;
		cout<<dis[x]+dis[y]<<endl;
	}
	return 0;
}

Measured memory_bytes: 20856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

void solve(long long N, std::vector<std::string> S){
    map<string,ll> mp1;
    rep(i,N){
        mp1[S[i]]++;
    }

    ll ma=0;
    for(auto p:mp1){
        chmax(ma,p.second);
    }

    vector<string> ans;
    for(auto p:mp1){
        if(p.second==ma){
            ans.push_back(p.first);
        }
    }

    sort(all(ans));
    for(string s:ans){
        cout<<s<<endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
}


Measured memory_bytes: 28404
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    ll w,h,x,y;
    cin>>w>>h>>x>>y;

    int d = 0;
    if(w%2==0 && w/2==x && h%2==0 && h/2==y) d = 1;
    cout<<((double)w*h/2)<<" "<<d<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


const ll INF = 1e18;
using P = pair<int, ll>;
vector<ll> dijkstra(int n, vector<vector<P> > edge, int s) {
    vector<ll> d(n, INF);
    priority_queue<P, vector<P>, greater<P> > que;
    d[s] = 0;
    que.push(P(s, 0));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int cur = p.F;
        if (d[cur] < p.S) continue;
        rep(i, sz(edge[cur])) {
            int nxt = edge[cur][i].F;
            ll cost = edge[cur][i].S;
            if (d[nxt] > d[cur] + cost) {
                d[nxt] = d[cur] + cost;
                que.push(P(nxt, d[nxt]));
            }
        }
    }
    return d;
}
int main() {
    int n, m;
    cin >> n >> m;
    
    vector<vector<P> > v(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].eb(P(b, 1));
        v[b].eb(P(a, 1));
    }
    
    auto dijk = dijkstra(n, v, 0);
    if (dijk[n - 1] <= 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 34672
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
int  main(){
	int i,j,k,n,a;
  	long long int ans=0;
	char * s;
	scanf ("%d",&n);
	s=(char*)malloc(n*sizeof(char));
	scanf ("%s",s);
	int *red,*green,*blue,s_r=0,s_g=0,s_b=0;
	red=(int*)malloc(n*sizeof(int));
	blue=(int*)malloc(n*sizeof(int));
	green=(int*)malloc(n*sizeof(int));
	for(i=0;i<n;i++){
		if(s[i]=='R') s_r+=1;
		if(s[i]=='G') s_g+=1;
		if(s[i]=='B') s_b+=1;
		red[i]=s_r;
		blue[i]=s_b;
		green[i]=s_g;
	}
	for(i=0;i<n;i++){
		for(k=i+2;k<n;k++){
			if(s[i]!=s[k]){
				if((s[i]=='R' && s[k]=='B')|| (s[i]=='B' && s[k]=='R')){
					ans+=green[k-1]-green[i];
				}
				if((s[i]=='R' && s[k]=='G')|| (s[i]=='G' && s[k]=='R')){
					ans+=blue[k-1]-blue[i];
				}
				if((s[i]=='G' && s[k]=='B')|| (s[i]=='B' && s[k]=='G')){
					ans+=red[k-1]-red[i];
				}
				if((i+k)%2==0){
					a=(i+k)/2;
					if(s[a]!=s[i] && s[a]!=s[k]) ans-=1;
				}
			}
		}
	}
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
#define N 200005
#define ll long long 
#define int ll
using namespace std;
int n,k;
double mx,local;
int dizi[N];
int32_t main(){
    scanf("%lld %lld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&dizi[i]);
    }
    for(int i=0;i<k;i++){
        local+=(dizi[i]+1)/(double)2;
    }
    mx=local;
    for(int i=k;i<n;i++){
        local-=(dizi[i-k]+1)/(double)2;
        local+=(dizi[i]+1)/(double)2;
        mx=max(local,mx);
    }
    printf("%0.12lf\n",mx );
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int month;
  int day;
  cin>>month;
  cin>>day;

  int cnt=0;
  for(int i=1;i<=month;i++){
    for(int j=22;j<=day;j++){
      int upper=j/10;
      int lower=j%10;
      if(upper>=2&&lower>=2&&upper*lower==i){
	cnt++;
      }
    }
  }

  cout<<cnt<<endl;
  return(0);
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, K): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let a: Vec<usize> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    fn bis<P: Fn(i64) -> bool>(ok: i64, ng: i64, p: P) -> i64 {
        let mid = (ok + ng) / 2;
        if (ok - ng).abs() == 1 {
            ok
        } else if p(mid) {
            bis(mid, ng, p)
        } else {
            bis(ok, mid, p)
        }
    }

    let b = {
        let mut b = a.clone();
        b.push(0);
        b.sort();
        b
    };
    let ans = bis(0, (N + 1) as i64, |m| {
        let m = m as usize;
        let mut dp = vec![false; K];
        dp[0] = true;
        for i in 1..(N + 1) {
            if i != m {
                let x = b[i];
                for j in (x..K).rev() {
                    dp[j] |= dp[j - x];
                }
            }
        }
        let s = if K >= b[m] { K - b[m] } else { 0 };
        !dp[s..].iter().any(|&r| r)
    });

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


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

vector<int> dijkstra(const vector<vector<int>> &G, int s){
    using Pi = pair<int, int>;
    const int INF = 1e9;
    vector<int> dist(G.size(), INF); 
    priority_queue<Pi, vector<Pi>, greater<Pi>> que; 
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        int sum_dist; int node;
        tie(sum_dist, node) = que.top(); que.pop();
        if (dist[node] < sum_dist) continue;
        for (auto& next_node : G[node]) {
            if (dist[next_node] > dist[node] + 1) {
                dist[next_node] = dist[node] + 1;
                que.emplace(dist[next_node], next_node);
            }
        }
    }
    for (auto& d : dist) if (d != INF) { d /= 3; }
    return dist;
}

int main(){
    int N, M, s, t;
    cin >> N >> M;
    vector<vector<int>> G(3*N);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; a--; b--;
        G[a].emplace_back(N+b);
        G[N+a].emplace_back(N+N+b);
        G[N+N+a].emplace_back(b);
    }
    cin >> s >> t; s--; t--; 
    vector<int> dist = dijkstra(G, s);
    int ans = dist[t];
    cout << ((ans==1e9) ? -1 : ans) << endl;
    return 0;
}

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

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

int dr , dc , k;
int val[3005][3005];
ll dp[3005][3005][4];

ll solve(int sr , int sc , int curCnt){
	if(sr < 0 || sr >= dr || sc < 0 || sc >= dc)
		return -1e12;
	if(sr == (dr-1) && sc == (dc-1)){
		if(curCnt < 3)
			return val[sr][sc];
		return 0;
	}
	ll &ret = dp[sr][sc][curCnt];
	if(~ret) return ret;
	ret = 0;
	ret = max(solve(sr+1 , sc , 0) , solve(sr , sc+1 , curCnt)); // leave
	if(curCnt < 3){ // take
		ret = max(ret , solve(sr , sc+1 , curCnt + 1)+val[sr][sc]);
		ret = max(ret , solve(sr+1 , sc , 0)+val[sr][sc]);
	}
	return ret;
}

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	scanf("%d %d %d" , &dr , &dc , &k);
	for(int i = 0 ; i < k ; ++i){
		int r , c , v;
		scanf("%d %d %d", &r , &c , &v);
		--r , --c;
		val[r][c] = v;
	}
	
	memset(dp , -1 , sizeof dp);
	printf("%lld\n" , solve(0 , 0 , 0));
	
    return 0;
}




Measured memory_bytes: 321500