akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    int N;
    int M;
    ArrayList<Integer>[] g;
    boolean[] used;
    boolean[] qued;
    int[] dis;
    int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        g = new ArrayList[N];
        for (int i = 0; i < N; i++) {
            g[i] = new ArrayList<Integer>();
        }
        used = new boolean[N];
        qued = new boolean[N];
        Arrays.fill(used, false);
        Arrays.fill(qued, false);
        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            int D = sc.nextInt();
            g[L - 1].add(R - 1);
            g[L - 1].add(D);
            g[R - 1].add(L - 1);
            g[R - 1].add(D * -1);
        }
        dis = new int[N];
        for (int i = 0; i < N; i++) {
            dis[i] = INF;
        }
        boolean ans = true;
        for (int i = 0; i < N; i++) {
            if (!used[i]) {
                boolean res = dfs(i);
                if (!res) {
                    ans = false;
                }
            }
        }
        System.out.println(ans ? "Yes" : "No");
    }

    boolean dfs(int v) {
        boolean res = true;
        Deque<Integer> q = new ArrayDeque<Integer>();
        q.push(v);
        dis[v] = 0;
        while (q.size() != 0) {
            int now = q.pop();
            used[now] = true;
            for (int i = 0; i < g[now].size(); i += 2) {
                int next = g[now].get(i);
                if (!used[next]) {
                    dis[next] = dis[now] + g[now].get(i + 1);
                } else if (dis[next] != dis[now] + g[now].get(i + 1)) {
                    res = false;
                }
                if (!qued[next]) {
                    q.push(next);
                    qued[next] = true;
                }
            }
        }
        return res;
    }
}

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


int main() {

  int N;
  cin>>N;

  vector<int> t(N+1),x(N+1),y(N+1);

  t.at(0)=x.at(0)=y.at(0)=0;

for(int i=0;i<N;i++){
 
  cin>>t.at(i+1)>>x.at(i+1)>>y.at(i+1);
 
  }//時間、xy座標の初期値をともに1として、各旅行計画を入力

  bool travel = true;//旅行が可能かどうか

  
    for (int i=0;i<N;i++) {
      int dt=t.at(i+1)-t.at(i);
      int dl=abs(x.at(i+1)-x.at(i))+abs(y.at(i+1)-y.at(i));

      if(dt<dl) travel=false;//一度のフライトで必要時間より必要距離が長ければ旅行は不可能

      if(dl%2!=dt%2) travel=false;//必要時間の偶奇と、移動距離の偶奇は同じでなければならない   
       
    }

    if (travel) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll MOD = 1e9+7;
map<P,ll> mp;
ll func(ll s,ll x)
{
	if(mp.count(P(s,x))>0)
		return mp[P(s,x)];
	else{
		//cerr<<s<<" "<<x<<endl;
		mp[P(s,x)]=(func(s/2LL,x/2LL)+func((s-1LL)/2LL,(x-1LL)/2LL))%MOD;
		if(s>=2)
		{
			mp[P(s,x)]+=func((s-2LL)/2LL,x/2LL);
			mp[P(s,x)]%=MOD;
		}
		if(mp[P(s,x)]<0)
			mp[P(s,x)]+=MOD;
		return mp[P(s,x)];
	}
}
int main()
{
	ll n;
	cin>>n;
	mp[P(0,0)]=1;
	mp[P(0,1)]=1;
	mp[P(1,0)]=1;
	mp[P(1,1)]=2;
	mp[P(2,0)]=3;
	mp[P(2,1)]=3;
	mp[P(2,2)]=4;
	mp[P(0,2)]=1;
	mp[P(1,2)]=2;
	ll ans=func(n,n);
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define cross(a,b) (conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define vec(a,b) b-a
#define Reka ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int n;
int cost[999999];
int ans;
int c[999999];
int jump(int ind)
{
    if(ind == n-1)
        return c[ind] = 0 ;
    if(c[ind]!=-1)
        return c[ind];
    int r=1e9,r2=1e9;
    if(ind+1 <n ){
     r = jump(ind+1)+abs(cost[ind]-cost[ind+1]);
    }
    if(ind+2<n){
     r2 =jump(ind+2)+abs(cost[ind]-cost[ind+2]);
    }
     ans = min(r,r2);

    return c[ind] = ans;
}

int main()
{
    Reka
    memset(c,-1,sizeof(c));
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>cost[i];
   }
cout<<jump(0);
   return 0;
}


Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();

		int time = A + B;
		if(time > 23) {
			System.out.println(time - 24);
		}else {
			System.out.println(time);
		}

	}
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[1000005];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    scanf("%s", str);
    int Q;
    scanf("%d", &Q);
    vector<int> KK(Q);
    int i;
    for(i=0; i<Q; i++) {
        scanf("%d", &KK[i]);
    }
    int q;
    for(q=0; q<Q; q++) {
        int K=KK[q];

        ll cnt0=0,cnt1=0,cnt01=0;
        ll ans=0;
        int i;
        for(i=0; i<n; i++) {
            if(i-K>=0) {
                if(str[i-K]=='D') {
                    cnt01-=cnt1;
                    cnt0--;
                }
                if(str[i-K]=='M') {
                    cnt1--;
                }
            }

            if(str[i]=='C') {
                ans+=cnt01;
            }
            if(str[i]=='M') {
                cnt01+=cnt0;
                cnt1++;
            }
            if(str[i]=='D') {
                cnt0++;
            }
        }
        printf("%lld\n",ans);
    }

    return 0;
}



Measured memory_bytes: 1152
<?php

fscanf(STDIN, "%d %d", $n, $k);
$X = array_map('intval', explode(' ', trim(fgets(STDIN))));

$min = PHP_INT_MAX;

$r = 0;
for ($l = 0; $l < $n; ++$l) {
    while ($r < $n && $r - $l < $k) {
        ++$r;
    }

    if ($r - $l != $k) break;

    $min = min(
        $min, 
        abs($X[$l]) + abs($X[$l] - $X[$r - 1]),
        abs($X[$r - 1]) + abs($X[$l] - $X[$r - 1])
    );
}
echo $min;


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

int main(){
    string s;

    while(cin>>s){
        if((s[0] == s[1] && s[1] == s[2]) || (s[3] == s[1] && s[1] == s[2]))
            puts("Yes");
        else
            puts("No");
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    int n, i, j, l;
    double s[1000];
    double b, m, a;
    
    while(1){
        m=0;
        b=0;
        scanf("%d", &n);
        if(n==0){
            break ;
        }
        
        for(i=0; i<n; i++){
            scanf("%lf", &s[i]);
            m=m+s[i];
        }
        m=m/n;
        
        for(i=0; i<n; i++){
            b=b+(s[i]-m)*(s[i]-m);
        }
        b=b/n;
        printf("%.8lf\n", sqrt(b));
    }
    return 0;
}



Measured memory_bytes: 2732
// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <ctime>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
 
#define mod 1000000007
#define INF 1000000000

#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define len(x) ((int)(x).size())
#define contains(a, x) (a.find(x) != end(a))
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define F(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)
#define RF(i,a,b)for(int i = (int)(a); i >= (int)(b); --i)

typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

#define fast() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define log(x) cout << (x) << endl;


string rev (string s) {
	map<char,char> rv;
	rv['U']='D', rv['D']='U', rv['L']='R', rv['R']='L';
	string r = "";
	for (auto c: s) r+=rv[c];
	return r;
}



string route(int sx,int sy,int tx,int ty) {
	string r = "";
	int ex = tx - sx, ey = ty - sy;
	while (ex) --ex, r += 'R';
	while (ey) --ey, r += 'U';
	return r;
}


int main() {
	fast();

	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;

	string s_t = route(sx,sy,tx,ty);
	s_t += rev(s_t);

	string t_s = 'D' + route(sx-1,sy,tx,ty+1) + 'L';
	t_s += rev(t_s);

	log(s_t + t_s)

	return 0;
}




Measured memory_bytes: 256
def main():
    k, n = map(int, input().split())
    houses = list(map(int, input().split()))

    distances = []
    for i in range(n):
        if i != n-1:
            distances.append(houses[i+1] - houses[i])
        else:
            distances.append(k-houses[-1] + houses[0])

    print(sum(distances) - max(distances))


if __name__ == '__main__':
    main()


Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	if(a.length()==2)
	{
		cout<<a<<endl;
	}
	else
	{
		for(int x=a.size()-1;x>=0;x--)
		{
			cout<<a[x];
		}
		cout<<endl;
	}
}

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

using namespace std;

int main()
{
    long long h;
    cin>>h;
    long long answer;
    for(long long i = 0;i<=50;i++)
    {
        if((1ll<<i) > h)
        {
            answer = (1ll<<i) - 1;
            break;
        }
    }

    cout<<answer;

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int h = s.size() / 2;
  int ans;
  for (int i = 1; i < h; ++i) {
    bool same = true;
    rep(j, h - i) if (s[j] != s[j + h - i]) same = false;
    if (same) {
      ans = s.size() - 2 * i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};


const int H = 210;

int in[H], out[H], inc[H], outc[H];

int main(void){
  int n, h;
  cin >> n >> h;
  set<int> app;
  UnionFind uf(2 * H);
  REP(i, 0, n) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int u, v;
    if (c == 0) {
      in[a] += 1;
      app.insert(u = a);
    } else {
      inc[c] += 1;
      app.insert(u = c + H);
    }
    if (d == 0) {
      out[b] += 1;
      app.insert(v = b + H);
    } else {
      outc[d] += 1;
      app.insert(v = d);
    }
    uf.unite(u, v);
  }
  set<int> roots;
  for (set<int>::iterator it = app.begin(); it != app.end(); ++it) {
    roots.insert(uf.root(*it));
  }
  bool ok = true;
  int ncc = roots.size();
  int cnt = 0;
  REP(i, 0, h + 1) {
    if (0) {
      cerr << i << ":";
      cerr << "in=" << in[i] << ", out=" << out[i];
      cerr << "inc=" << inc[i] << ", outc=" << outc[i];
      cerr << endl;
    }
    if (in[i] != outc[i]) {
      cnt += in[i] - outc[i];
      if (in[i] < outc[i]) {
	ok = false;
      }
    }
    if (out[i] != inc[i]) {
      cnt += out[i] - inc[i];
      if (out[i] < inc[i]) {
	ok = false;
      }
    }
  }
  assert (cnt % 2 == 0);
  ok &= cnt % 2 == 0 && cnt >= 2 * ncc;
  cout << (ok ? "YES" : "NO") << endl;
}


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

#define ll long long
#define ar array

int main() {

    ios::sync_with_stdio(false);
    
   int a, b, x,y,z;
   
   cin >> a >> b;
   
   x = a+b;
   y = a-b;
   z = a*b;
   
   cout << max(max(x,y),z) << endl;
   
   
    return 0;
}

Measured memory_bytes: 256
// yo2.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m, a[1001];
	
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	for (int k = 1; k <= m; ++k) {
		for (int i = 0; i < n - 1; ++i) {
			if (a[i] % k > a[i + 1] % k) {
				swap(a[i], a[i + 1]);
			}
		}
	}

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

    return 0;
}

Measured memory_bytes: 3076
n = int(input())
red  = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]

red.sort(key=lambda x:x[1])
blue.sort()

count = 0
for xb, yb in blue:
    max_y = -1
    max_i = -1
    for i in range(n):
        xr, yr = red[i]
        if xb > xr and yb > yr and max_y < yr:
            max_y, max_i = yr, i
    if max_y >= 0:
        red[max_i] = (201, 201)
        count += 1
print(count)


    

Measured memory_bytes: 9216
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(S: String) {
    // RLのところだけ考えればよい
    // (RRR)RL(LLL)として、 Rからなら距離==Odd -> L, Even->R, Lからなら逆
    val N = S.length
    val posOfRL = mutableListOf<Int>()
    val ans = IntArray(N)
    for (i in 0 until N - 1) {
        if (S[i] == 'R' && S[i + 1] == 'L') {
            posOfRL.add(i)
        }
    }
    for (i in 0 until N) {
        val pos = posOfRL.binarySearch(i)
        val rightNeigbor: Int? = when {
            pos >= 0 -> posOfRL[pos]
            -pos - 1 >= posOfRL.size -> null
            else -> posOfRL[-pos - 1]
        }
        val leftNeigbor: Int? = when {
            pos == 0 -> null
            pos > 0 -> posOfRL[pos - 1]
            -pos - 2 < 0 -> null
            else -> posOfRL[-pos - 2]
        }
        if (S[i] == 'R') {
            if (rightNeigbor == null) { ans[N - 1]++ }
            else ans[rightNeigbor + if ((rightNeigbor - i) % 2 == 0) 0 else 1]++
        } else {
            if (leftNeigbor == null) { ans[0]++ }
            else ans[leftNeigbor + if ((i-leftNeigbor) % 2 == 0) 0 else 1]++
        }
    }
    println(ans.joinToString(separator = " "))
    return
}

fun <T : Comparable<T>> List<T?>.lowerBound(
    element: T,
    fromIndex: Int = 0,
    toIndex: Int = size
): Int {
    var low = fromIndex
    var high = toIndex
    while (low < high) {
        val mid = (low + high) / 2
        if (element <= this.get(mid)!!) {
            high = mid
        } else {
            low = mid + 1
        }
    }
    return low
}

fun <T : Comparable<T>> List<T?>.upperBound(
    element: T,
    fromIndex: Int = 0,
    toIndex: Int = size
): Int {
    var low = fromIndex
    var high = toIndex
    while (low < high) {
        val mid = (low + high) / 2
        if (element >= this.get(mid)!!) {
            low = mid + 1
        } else {
            high = mid
        }
    }
    return low
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    solve(S)
}


Measured memory_bytes: 39636
using System;

namespace ABC106_A_Garden
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] inStr = Console.ReadLine().Split(' ');
			int a = int.Parse(inStr[0]);
			int b = int.Parse(inStr[1]);
			
			Console.WriteLine(a * b - a - b + 1);

		}
	}
}

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

int main()
{
    char s, t;
    int j = 0, k = 1;
    char fnl[250];
    int n;
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> s;
        fnl[j] = s;
        j += 2;
    }

    for(int i = 0; i < n; i++)
    {
        cin >> t;
        fnl[k] = t;
        k += 2;
    }

    for(int i = 0; i < n*2; i++)
        cout << fnl[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

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

	vector<int> a(n), b(n), c(n - 1);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n-1)cin >> c[i];

	int sus = 0;
	rep(i, n) {
		sus += b[a[i]-1];
		if (i < n - 1 and a[i] + 1 == a[i + 1]) sus += c[a[i]-1];
	}

	cout << sus << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <time.h>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);		//最大公倍数
ll lcm(ll m, ll n);		//最小公倍数

int main(void) {

	int ans = 0;
	int a;
	cin >> a;
	vector<int> v;
	v.push_back(a);
	bool flg = false;
	while (!flg) {
		if (a % 2 == 0) {
			a = a / 2;
		}
		else {
			a = 3 * a + 1;
		}
		v.push_back(a);

		for (int i = 0; i < v.size() - 1; i++) {
			for (int j = i + 1; j < v.size(); j++) {
				if (v[i] == v[j]) {
					ans = j + 1;
					flg = true;
				}
			}
		}
	}
	

	cout << ans << endl;

	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  

#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll N;
    cin >> N;
    vecll p(N);
    for(auto& i : p) cin >> i;
    ll cnt = 0;
    for(ll i = 0; i < N; i++) if(i + 1 == p.at(i)) cnt++;
    cout << (cnt == N || cnt == N - 2 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;

int N, M, A[5010], B[5010][210];
long long f[5010][5010], dis[5010], ans;
		stack<pair<int, int> >s;

int main(){
//	freopen("test.in", "r", stdin);
	scanf("%d%d", &N, &M);
	for(int i=1; i<N; i++){
		scanf("%d", &A[i]);
		dis[i+1]=dis[i]+1LL*A[i];
	}
	for(int i=1; i<=N; i++)
		for(int j=1; j<=M; j++){
			scanf("%d", &B[i][j]);
		}
	for(int i=1; i<=M; i++){
		int l[5010], r[5010];
		memset(l, 0, sizeof(l));	memset(r, 0, sizeof(r));
		s.push(make_pair(B[1][i], 1));
		for(int j=2; j<=N; j++)
			if(B[j][i]<s.top().first)
				s.push(make_pair(B[j][i], j));
			else{
				while(!s.empty() && s.top().first<=B[j][i]){
					r[s.top().second]=j;
					s.pop();
				}
				s.push(make_pair(B[j][i], j));
			}
		while(!s.empty()){
			r[s.top().second]=N+1;
			s.pop();
		}
		s.push(make_pair(B[N][i], N));
		for(int j=N-1; j; j--)
			if(B[j][i]<=s.top().first)
				s.push(make_pair(B[j][i], j));
			else{
				while(!s.empty() && s.top().first<B[j][i]){
					l[s.top().second]=j;
					s.pop();
				}
				s.push(make_pair(B[j][i], j));
			}
		while(!s.empty()){
			l[s.top().second]=0;
			s.pop();
		}
		for(int j=1; j<=N; j++)
			f[l[j]+1][j]+=1LL*B[j][i], f[j+1][r[j]]+=1LL*B[j][i], 
			f[l[j]+1][r[j]]-=1LL*B[j][i], f[j+1][j]-=1LL*B[j][i];
	}
	for(int i=1; i<=N; i++)
		for(int j=1; j<=N; j++)
			f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
	for(int i=1; i<=N; i++)
		for(int j=i; j<=N; j++)
			ans=max(ans, f[i][j]-dis[j]+dis[i]);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 200576
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int matrix[105][105];
 int mul[105];
 int sum[105]={0};

 int main()
 {
   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++)
   {
     for(int j=0;j<m;j++)
     {
       cin>>matrix[i][j];        
     }        
   }
   for(int i=0;i<m;i++) cin>>mul[i];
   for(int i=0;i<n;i++) 
   {
     for(int j=0;j<m;j++)
     {
       sum[i]+=matrix[i][j]*mul[j];       
     }        
   } 
   for(int i=0;i<n;i++) cout<<sum[i]<<endl;
   //while(1);
   return 0;
 }
 

Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

int num;
long long int fac=1;

int main()
{
	cin >> num;
	
	for( int i = 1; i <= num; i++)
	{
		fac *= i;
	}
	
	cout << fac << endl;
	
	return 0;
	
}

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

int main(){

int a,b,d,r;

double x,y,f;

scanf("%d %d",&a,&b);

d=floor(a/b);

r=a-b*d;

x=a;
y=b;

f=x/y;

printf("%d %d %f",d,r,f);

return 0;

}

Measured memory_bytes: 636
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(a, b);

    cout << ( (abs(a-b) <= 1) ? "Brown" : "Alice" ) << endl;

    return 0;
}



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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

vector<vector<int>> G;

int grundy(int v, int pre)
{
    int g = 0;
    for (auto u : G[v]) {
        if (u == pre) continue;
        g ^= (grundy(u, v) + 1);
    }
    return g;
}


int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    G.resize(N);
    rep(i, N-1) {
        int X, Y;
        cin >> X >> Y;
        X--, Y--;
        G[X].push_back(Y);
        G[Y].push_back(X);
    }
    cout << (grundy(0, -1) != 0 ? "Alice" : "Bob") << endl;
}

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

using namespace std;

typedef long long ll;

int read() {
  int res = 0, w = 1; char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

const int N = 2e5 + 10;

int n, m, a[N];
ll sum[N];

bool check(int mid) {
  for (int i = 1; i <= n - mid; i++) {
    if (a[2 * mid + i] + a[2 * n - i + 1] < m) return 0;
  }
  return 1;
}

int main() {
  n = read(), m = read();
  for (int i = 1; i <= 2 * n; i++) a[i] = read();
  sort(a + 1, a + 2 * n + 1);
  int l = 0, r = n, res = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) r = mid - 1, res = mid;
    else l = mid + 1;
  }
  int ans = 0;
  for (int i = 1; i <= res; i++) {
    ans = max(ans, (a[i] + a[2 * res - i + 1]) % m);
  }
  for (int i = 1; i <= n - res; i++) {
    ans = max(ans, a[2 * res + i] + a[2 * n - i + 1] - m);
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll power(ll x,ll n)
{
	ll res =1;
	while(n>0)
	{
		if(n%2==1)
	res=res*x;
	x=x*x;
	n=n/2;
	}
	return res;
	
}
int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k,i;
    cin>>n>>k;
    int s[k],c[k];
    for(i=0;i<k;i++)
    cin>>s[i]>>c[i];
    map<int,int>m;
    int flag=0;
    for(i=0;i<k;i++)
    {
    	if(m.find(s[i])==m.end())
    	{
    		m[s[i]]=c[i];
    		
		}
		else
		{
			if(m.find(s[i])->second!=c[i])
			{
				flag=-1;
				break;
			}
			
		}
	}
	if(flag==-1)
	cout<<-1;
	else
	{
		int a[n+1]={0};
		map<int,int>::iterator it;
		if(m.begin()->first==1&&m.begin()->second==0&&n>1)
		cout<<-1;
		else
		{
			for(it=m.begin();it!=m.end();it++)
			{
				
					a[it->first]=it->second;
				
			}
			if(a[1]==0&&n>1)
			cout<<1;
			else
			cout<<a[1];
			for(i=2;i<n+1;i++)
			cout<<a[i];
			
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0)
#define ll              long long int
#define ld              long double
#define mk              make_pair
#define pb              push_back
#define f               first
#define s               second
#define fo(i,a,b)       for(i=a;i<b;i++)
#define foe(i,a,b)      for(i=a;i<=b;i++)
#define all(x)          x.begin(),x.end()
#define vi              vector<int>
#define vl              vector <long long int>
#define pii             pair <int,int>
#define pll             pair <long long int, long long int>
#define vpii            vector< pair<int,int> >
#define vpll            vector < pair <long long int,long long int> >
#define MOD             1000000007
using namespace std;
const int inf = INT_MAX;
const ll inf64 = LLONG_MAX;


int main()
{
	boost;
	ll n;
	cin >> n;
	ll arr[3];
	cin >> arr[0] >> arr[1] >> arr[2];
	string res[n];
	ll i;
	fo(i, 0, n)
	{
		cin >> res[i];
	}
	if (arr[1] == 0 and arr[0] == 0 and arr[2] == 0)
	{
		cout << "No";
		return 0;
	}
	vector <char> ans;
	bool poss = true;
	fo(i, 0, n)
	{
		string move;
		move = res[i];
		if (arr[move[0] - 'A'] == 0 and arr[move[1] - 'A'] == 0)
		{
			poss = false;
			break;
		}
		else if (arr[move[0] - 'A'] == 1 and arr[move[1] - 'A'] == 1)
		{
			if (res[i + 1] == res[i])
			{
				arr[move[0] - 'A']++;
				arr[move[1] - 'A']--;
				ans.pb(move[0]);
			}
			else
			{
				if (move[0] == res[i + 1][0] or move[0] == res[i + 1][1])
				{
					arr[move[0] - 'A']++;
					arr[move[1] - 'A']--;
					ans.pb(move[0]);

				}
				else
				{
					arr[move[1] - 'A']++;
					ans.pb(move[1]);
					arr[move[0] - 'A']--;
				}
			}
		}
		else
		{
			if (arr[move[0] - 'A'] <= arr[move[1] - 'A'])
			{
				arr[move[0] - 'A']++;
				ans.pb(move[0]);
				arr[move[1] - 'A']--;
			}
			else
			{
				arr[move[1] - 'A']++;
				ans.pb(move[1]);
				arr[move[0] - 'A']--;
			}

		}
	}
	if (poss)
	{
		cout << "Yes\n";
		for (auto x : ans)cout << x << '\n';
	}
	else cout << "No";

	return 0;
}

Measured memory_bytes: 6940
program main
  implicit none
  integer(8) :: N,K
  integer(8),allocatable :: A(:)
  integer(8),allocatable :: num(:)
  logical,allocatable :: flag(:)
  integer(8) :: loopnum
  integer(8) :: now, loop_start, now_save
  integer(8) :: step
  integer(8) :: i,j
  
  read(*,*) N,K
  allocate(A(N))
  read(*,*) A(:)
  allocate(flag(N))
  allocate(num(N))
  flag(:) = .false.
  flag(1) = .true.
  num(1) = 0
  now = 1
  now = A(now)
  do i = 1,N+1
     if ( flag(now) ) then
        exit
     else 
        flag(now) = .true.
        num(now) = i
        now = A(now)
     end if
  end do
  ! loop num
  loopnum = i - num(now)
  now_save = now
  now = 1
  do i = 1,N
     now = A(now)
     if (now == now_save ) exit
  end do
  if (  K  <= (loopnum + i) ) then
     now = 1
     do i = 1,K
        now = A(now)
     end do
     write(*,'(i0)') now
     stop
  end if
  !write(*,*) loopnum
  step = mod( K-num(now), loopnum )
  !write(*,*) now,step
  now = now_save
  do i = 1,step
     !num(int(now)) = i
     now = A(now)
  end do
  write(*,'(i0)') now
end program main


Measured memory_bytes: 6992
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int a;
int b;

void input() {
  cin >> a >> b;
}

int gcd(int a, int b) {
  while (b) {
    a %= b;

    swap(a, b);
  }

  return a;
}

void solve() {
  cout << (1ll * a * b) / gcd(a, b);
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
import scala.io.StdIn
object Main extends App {
  def digitSum(n: Int): Int = {
    def _digitSum(n: Int, sum: Int): Int = {
      if (n == 0) sum else _digitSum(n / 10, sum + (n % 10))
    }
    _digitSum(n,0)
  }
  val input = StdIn.readLine()
  val N = input.split(" ")(0).toInt
  val A = input.split(" ")(1).toInt
  val B = input.split(" ")(2).toInt
  val answer = (for {
    n <- 1 to N
    sum = digitSum(n)
    if (A <= sum && sum <= B)
  } yield n).sum
  println(answer)
}


Measured memory_bytes: 27968
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll a[300001];
	ll score=0;
	ll scoremax=-INFl;
	ll scorek[100001][2]={0};
	priority_queue<ll,vector<ll>,greater<ll> > left;
	priority_queue<ll,vector<ll>,less<ll> > right;
	scan(N);
	rep(i,3*N){
		scan(a[i]);
	}
	rep(i,N){
		left.push(a[i]);
		scorek[0][0]+=a[i];
	}
	for(int i=2*N;i<3*N;i++){
		right.push(a[i]);
		scorek[N][1]-=a[i];
	}
	for(int k=N+1;k<=2*N;k++){
		scorek[k-N][0]=scorek[k-N-1][0];
		if(a[k-1]>left.top()){
			scorek[k-N][0]-=left.top();
			scorek[k-N][0]+=a[k-1];
			left.pop();
			left.push(a[k-1]);
		}
	}
	for(int k=2*N-1;k>=N;k--){
		scorek[k-N][1]=scorek[k-N+1][1];
		if(a[k]<right.top()){
			scorek[k-N][1]+=right.top();
			scorek[k-N][1]-=a[k];
			right.pop();
			right.push(a[k]);
		}
	}
	for(int k=N;k<=2*N;k++){
		//printf("k:%d score0:%lld score1:%lld\n",k,scorek[k-N][0],scorek[k-N][1]);
		scoremax=max(scoremax,scorek[k-N][0]+scorek[k-N][1]);
	}
	prin(scoremax);
	return 0;
}


Measured memory_bytes: 6516
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] x = new long[n];
    long[] y = new long[n];
    for(int i = 0;i<n;i++){
      x[i] = sc.nextLong();
      y[i] = x[i];
    }
    Arrays.sort(x);

    if(x[n/2]==x[n/2-1]){
      for(int i = 0;i<n;i++){
        System.out.println(x[n/2]);
      }
      return;
    }

    for(long a:y){
      if(a<x[n/2]){
        System.out.println(x[n/2]);
      }else{
        System.out.println(x[n/2-1]);
      }
    }
  }
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

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

int main(){
	
	ll a,b;cin >> a >> b;
	if(a + b == 15){
		cout << '+' << endl;
	}
	else if(a * b == 15){
		cout << '*' << endl;
	}
	else{
		cout << 'x' << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   double a,b;
   cin>>a>>b;
   if(a>b) cout<<"GREATER";
   else if(a<b) cout<<"LESS";
   else cout<<"EQUAL";





return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
const int maxn=1e5+100;
const double pi=4.0*atan(1.0);
const int mod=1e9+7;
typedef pair<LL,LL> pil;
map<pil,int> mp;
int n,m,k;
int T;

int quick_pow(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1) ans=1LL*ans*a%mod;
        b>>=1;
        a=1LL*a*a%mod;
    }
    return ans;
}
int main()
{
    cin>>n;
    int S=0;
    LL x,y;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        if(x==0&&y==0)
        {
            S++;
            continue;
        }
        LL d=__gcd(x,y);
        x/=d,y/=d;
        if(x<0) x=-x,y=-y;
        mp[{x,y}]++;
    }
    LL res=1;
    int cnt=0;
    for(auto it : mp)
    {
        if(it.second==0) continue;
        x=it.first.first,y=it.first.second;
        LL r=quick_pow(2,mp[{x,y}]);
        y=-y;
        if(y<0) x=-x,y=-y;
        if(mp.count({y,x}))
        {
            r=(r+quick_pow(2,mp[{y,x}])-1)%mod;
            mp[{y,x}]=0;
        }
        res=res*r%mod;
        cnt++;
    }
    res=(res-1+S+mod)%mod;//空集
    cout<<res<<endl;
}

Measured memory_bytes: 16032
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int r[3][6] ={
	{3, 1, 0, 5, 4, 2},
	{1, 5, 2, 3, 0, 4},
	{0, 3, 1, 4, 2, 5}
};
set<vi> s;
vector<vi> ptn;
vi rot(const vi &v, int d){
	vi res;
	rep(i, 6) res.pb(v[r[d][i]]);
	return res;
}
void dfs(const vi &v){
	if(s.count(v)) return;
	s.insert(v);
	rep(i, 3) dfs(rot(v, i));
}
const int dy[] = {1, 0, 0, -1}, dx[] = {0, 1, -1, 0};
int n, bl[100][100][100], h[100][100];

int main(){
	vi v;
	rep(i, 6) v.pb(i + 1);
	dfs(v);
	
	while(cin >> n, n){
		memset(h, 0, sizeof(h));
		
		rep(it, n){
			int t, f;
			cin >> t >> f;
			int y = 50, x = 50;
			vi v(6); v[0] = t; v[1] = f;
			v = *s.lower_bound(v);
			vi nv = rot(v, 0);
			
			while(1){
				int mxd = -1;
				rep(d, 4){
					if(v[d + 1] < 4) continue;
					if(h[y + dy[d]][x + dx[d]] >= h[y][x]) continue;
					if(mxd < 0 || v[mxd + 1] < v[d + 1]) mxd = d;
				}
				if(mxd < 0){
					bl[y][x][h[y][x]++] = v[0];
					break;
				}
				if(mxd == 0) rep(i, 3) v = rot(v, 1);
				else if(mxd == 1) v = rot(v, 0);
				else if(mxd == 2) rep(i, 3) v = rot(v, 0);
				else v = rot(v, 1);
				y += dy[mxd];
				x += dx[mxd];
			}
		}
		int ans[6] = {};
		rep(i, 100) rep(j, 100) if(h[i][j]) ans[bl[i][j][h[i][j] - 1] - 1]++;
		rep(i, 6) cout << ans[i] << (i == 5 ? "\n" : " ");
	}
	return 0;
}

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


void solve(std::string S){
  long long mymax = 0;
  long long count = 0;
  for(long long i = 0; i < S.size(); i++) {
    if(S[i] == 'R') count++;
    else {
      mymax = max(mymax, count);
      count = 0;
    }
  }

  mymax = max(mymax, count);

  cout << mymax << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	static int max;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true) {
			max = sc.nextInt();
			if(max == 0) break;
			int n = sc.nextInt();
			int[] d = new int[n+2];
			for(int i = 0; i < n; i++) {
				d[i+1] = sc.nextInt();
			}
			Node[] list = new Node[n+2];
			for(int i = 0; i < n+2; i++) {
				list[i] = new Node(i);
			}
			dfs(0,list,d);
			boolean[] ok = new boolean[n+2];
			dfs(n+1,list,ok);
			boolean ans = dfs2(0,list,ok,new boolean[n+2]);
			System.out.println((ans)?"OK":"NG");
		}
		
	}
	static class Node {
		ArrayList<Node> to = new ArrayList<Node>();
		ArrayList<Node> dst = new ArrayList<Node>();
		int id;
		Node(int a) {
			id = a;
		}
	}
	static boolean dfs2(int a,Node[] b, boolean[] c, boolean[] d) {
		if(!c[a]) return false;
		if(d[a]) return true;
		d[a] = true;
		boolean ret = true;
		for(int i = 0; i < b[a].to.size(); i++) {
			ret &= dfs2(b[a].to.get(i).id,b,c,d);
		}
		return ret;	
	}
	
	
	
	static void dfs(int a, Node[] b, boolean[] c) {
		if(c[a]) return;
		c[a] = true;
		for(int i = 0; i < b[a].dst.size(); i++) {
			dfs(b[a].dst.get(i).id,b,c);
		}	
	}
	
	static void dfs(int a, Node[] b, int[] c) {
		for(int i = 1; i <= max; i++) {
			int to = a + i;
			if(to >= b.length) to = b.length-1;
			to += c[to];
			if(to >= b.length) to = b.length-1;
			if(to < 0) to = 0;
			if(b[a].to.contains(b[to])) continue;
			b[a].to.add(b[to]);
			if(b[to].dst.contains(b[a])) continue;
			b[to].dst.add(b[a]);
			
			dfs(to,b,c);
		}
	}
	
}

Measured memory_bytes: 52160
x,n=gets.split.map(&:to_i)
ary=gets.split.map(&:to_i)
# puts x; exit if n.zero? || !ary.include?(x)
if n.zero? || !ary.include?(x)
  puts x
  exit
end
(1..100).each do |i|
  if !ary.include?(x-i)
    puts x-i
    exit
  end
  if !ary.include?(x+i)
    puts x+i
    exit
  end
end

Measured memory_bytes: 14156
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

ans = []
def dfs(a,m):
    global ans
    if len(a) == m:
        s = ""
        for i in range(m):
            s += str(a[i])
        if "7" in s and "5" in s and "3" in s:
            ans.append(int(s))
        return
    for i in [3,5,7]:
        a.append(i)
        dfs(a,m)
        a.pop()
if __name__ == "__main__":
    n = int(input())
    m = len(str(n))
    a = []
    for i in range(3,m+1):
        dfs(a,i)
    ans.sort()
    cnt = 0
    for i in range(len(ans)):
        if ans[i] <= n:
            cnt+=1
    print(cnt)


Measured memory_bytes: 4584
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    if (n == 1) {
        if (a[0] == 0) {
            cout << 0 << endl;
        } else {
            cout << 1 << endl;
            cout << 1 << endl;
        }
        return 0;
    }
    
    int cnt = 0;
    vector<int> b;
    for (int i = n; i > 0; i--) {
        if (a[i - 1] == 1) {
            b.push_back(i);
            cnt++;
            
            a[0] = (a[0] + 1) % 2;
            for (int j = 2; j * j <= i; j++) {
                if (i % j == 0) {
                    a[j - 1] = (a[j - 1] + 1) % 2;
                    int k = i / j;
                    if (k != j) {
                        a[k - 1] = (a[k - 1] + 1) % 2;
                    }
                }
            }
        }
    }
    
    cout << cnt << endl;
    for (int i = 0; i < b.size(); i++) {
        cout << b.at(i) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2424
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
MAX_N=10**5
num=array(MAX_N+1,0)
A=get_i
A.each do|a|
    num[a]+=1
end
ans=0
1.upto(MAX_N-1) do|i|
  val=num[i-1]+num[i]+num[i+1]
  ans=val if ans<val 
end
puts ans

Measured memory_bytes: 9484
N, M = map(int, input().split())
mid, las = [], []
ans = 0

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        mid.append(b)
    
    elif b == N:
        las.append(a)

if len(set(mid) & set(las)) != 0:
    ans =1

print('POSSIBLE' if ans == 1 else 'IMPOSSIBLE') 

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

int main()
{
    int n,q;
    cin>>n>>q;
    list<int> a[n];
    REP(i,q)
    {
        int x,y,z;
        cin>>x>>y;
        if(x==0)
        {
            cin>>z;
            a[y].push_back(z);
        }
        if(x==1)
        {
            for(list<int>::iterator itr=a[y].begin();itr!=a[y].end();itr++)
            {
                if(itr!=a[y].begin())cout<<" ";
                cout<<*itr;
            }cout<<endl;
        }
        if(x==2)
        {
            cin>>z;
            a[z].splice(a[z].end(),a[y]);
        }
    }
}


Measured memory_bytes: 18628
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


void solve(LL N, LL C, vector<vector<LL>> D, vector<vector<LL>> c){
    VVI t(3, VI(C));
    REP(i, N) {
        REP(j, N) {
            t[(i + j + 2) % 3][c[i][j] - 1]++;
        }
    }

    LL ans = LLONG_MAX;
    REP(c0, C) {
        LL sum0 = 0;
        REP(i, C) {
            if (i == c0) continue;
            sum0 += t[0][i] * D[i][c0];
        }
        if (ans <= sum0) continue;
        REP(c1, C) {
            if (c0 == c1) continue;
            LL sum1 = 0;
            REP(i, C) {
                if (i == c1) continue;
                sum1 += t[1][i] * D[i][c1];
            }
            if (ans <= sum0 + sum1) continue;
            REP(c2, C) {
                if (c0 == c2 || c1 == c2) continue;
                LL sum2 = 0;
                REP(i, C) {
                    if (i == c2) continue;
                    sum2 += t[2][i] * D[i][c2];
                }
                LL sum = sum0 + sum1 + sum2;
                ans = min(ans, sum);
            }
        }
    }
    cout << ans << endl;
}

int main(){
    LL N;
    scanf("%lld",&N);
    LL C;
    scanf("%lld",&C);
    vector<vector<LL>> D(C, vector<LL>(C));
    for(int i = 0 ; i < C ; i++){
        for(int j = 0 ; j < C ; j++){
            scanf("%lld",&D[i][j]);
        }
    }
    vector<vector<LL>> c(N, vector<LL>(N));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < N ; j++){
            scanf("%lld",&c[i][j]);
        }
    }
    solve(N, C, move(D), move(c));
    return 0;
}


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

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;
const int N = 1e5 + 5;

ll dp[N];
bool broke[N];

main(){
    int n , m;
    scanf("%d %d" , &n , &m);
    for(int i = 1 ; i <= m ; i ++){
            int x;
            scanf("%d" , &x);
            broke[x] = true;
    }
    dp[0] = 1;
    if(!broke[1])dp[1] = 1;

    for(int i = 2 ; i <= n ; i ++){
            if(!broke[i]){
                dp[i] += ((dp[i-1]%mod) + (dp[i-2]%mod)) %mod;
                dp[i] %= mod;
            }
    }
    printf("%lld\n" , dp[n]);

    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>

int main() {
	int n, i;
	int cnt = 0;
	int a[200];
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	int check() {
		for (i = 0; i <n; i++) {
			if (a[i] % 2 == 1) return 0;
		}
		return 1;
	};
	void div() {
		for (i = 0; i < n; i++) {
			a[i] /= 2;
		}
	};
	while (check()) {
		div();
		cnt++;
	}
	printf("%d", cnt);
}

Measured memory_bytes: 128
(n,m), *ab = [list(map(int, s.split())) for s in open(0)]

from collections import defaultdict

d = defaultdict(list)

for a,b in ab:
    d[a] += [b]
    d[b] += [a]

def count_paths(passed, cur, d, n):
#     print(f'{passed=}, {cur=}')
    if len(passed) == n-1:
        return 1
    ans = 0
    for nx in d[cur]:
        if nx not in passed:
            ans += count_paths(passed+[cur], nx, d, n)
    return ans

print(count_paths([],1,d,n))

Measured memory_bytes: 74004